/*
 * Reset, typography and the handful of controls the archive uses.
 *
 * Buttons and fields are styled by class rather than by element, so the filter
 * sheet's close cross and a group's summary row don't have to undo a chrome
 * they never wanted.
 */

*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
}

html {
    -webkit-text-size-adjust: 100%;

    /*
     * The scrollbar's space is reserved whether or not a scrollbar is there.
     * Opening the filter sheet locks the page's scrolling, which on a platform
     * with classic scrollbars would otherwise reclaim that strip and slide the
     * whole page sideways as the sheet came in. A no-op where scrollbars
     * overlay the content rather than taking room from it.
     */
    scrollbar-gutter: stable;
}

/*
 * The page behind whatever is open over it does not scroll: the filter sheet,
 * and the reading options, which as a modal dialog leaves the page inert to
 * clicks but not to a thumb.
 *
 * On the root rather than on the body. A body's overflow is handed to the
 * viewport only while the root's own is visible, and the search page clips the
 * root sideways to hide the sheet waiting off its edge - so the lock the body
 * used to carry was doing nothing on the one page that asked for it.
 *
 * And on the body as well, because on iOS neither is enough: hidden overflow
 * there is a suggestion, and the page keeps scrolling under the sheet. Out of
 * the flow it cannot. scroll-lock.js sets the top, which is where the page had
 * got to, so taking it out of the flow does not jump it back to the beginning.
 */
html.is-locked {
    overflow-y: hidden;
}

html.is-locked body {
    position: fixed;
    left: 0;
    right: 0;
}

body {
    min-height: 100dvh;

    font-family: var(--font-ui);
    font-size: 1rem;
    line-height: 1.65;

    background: var(--color-background);
    color: var(--color-foreground);
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
    height: auto;
}

input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

table {
    border-collapse: collapse;
}

[hidden] {
    display: none !important;
}

a {
    color: var(--color-link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 400;
    line-height: 1.25;
    text-wrap: pretty;
    overflow-wrap: break-word;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.375rem;
}

h3 {
    font-size: 1.125rem;
}

h4 {
    font-size: 1rem;
}

p {
    overflow-wrap: break-word;
}

:focus-visible {
    outline: 2px solid var(--color-field-focus-border);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Buttons --------------------------------------------------------------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);

    min-height: var(--control-height);
    padding: 0 var(--space-4);

    border: 1px solid var(--color-border);
    border-radius: var(--radius-small);
    background: var(--color-button-background);
    color: var(--color-button-foreground);

    text-align: center;
    text-decoration: none;
    line-height: 1.2;
}

.button:hover,
.button:focus {
    background: var(--color-button-hover-background);
    text-decoration: none;
}

.button--primary {
    border-color: transparent;
    background: var(--color-primary-background);
    color: var(--color-primary-foreground);
    font-weight: 500;
}

.button--primary:hover,
.button--primary:focus {
    background: var(--color-primary-background);
    filter: brightness(1.15);
}

.button[disabled] {
    opacity: 0.5;
    cursor: default;
}

/* A button that reads as a link: Reset, the theme switch, close crosses. */
.button--bare {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: var(--space-1) var(--space-2);
    border: 0;
    background: none;
    color: var(--color-link);

    text-decoration: none;
}

.button--bare:hover {
    text-decoration: underline;
}

/* Fields ---------------------------------------------------------------- */

.field,
.select {
    display: block;
    width: 100%;
    min-height: var(--control-height);
    padding: var(--space-2);

    /* Otherwise the body's 1.65 makes the box taller than min-height ever gets
       to decide, and a field stays 44px while the button beside it trims down. */
    line-height: 1.2;

    border: 1px solid var(--color-field-border);
    border-radius: var(--radius-small);
    background: var(--color-field-background);
}

.field:focus,
.select:focus {
    border-color: var(--color-field-focus-border);
}

/*
 * A select is the one control that will not take a height from us while it is
 * wearing the platform's own clothes: WebKit renders `menulist` at its own
 * 23px whatever min-height says, so the sort control came out half the height
 * of the button beside it and the toolbar was as tall as the taller of the two.
 * `menulist-button` makes no difference; only dropping the appearance does.
 *
 * Which means drawing the arrow ourselves. Two gradients rather than an SVG,
 * because an SVG in a data URI is its own document and cannot see currentColor
 * - it would need a copy per theme, and would then be a third place the theme
 * is written down.
 */
.select {
    appearance: none;
    -webkit-appearance: none;

    padding-right: var(--space-7);
    background-image:
        linear-gradient(-45deg, transparent 50%, currentColor 50%),
        linear-gradient(-135deg, currentColor 50%, transparent 50%);
    background-position:
        right var(--space-3) center,
        right calc(var(--space-3) + 5px) center;
    background-size: 5px 5px;
    background-repeat: no-repeat;
}

input[type='checkbox'],
input[type='radio'] {
    accent-color: var(--color-accent);
    width: 1.05em;
    height: 1.05em;
    margin: 0;
    flex: none;
    cursor: pointer;
}

.help {
    margin: var(--space-1) 0 0;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--color-muted);
}

.warning {
    color: var(--color-warning-foreground);
}

/* Utilities ------------------------------------------------------------- */

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 200;
    padding: var(--space-2) var(--space-4);

    border-radius: var(--radius-small);
    background: var(--color-section-background);
    color: var(--color-link);

    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
}

/* Trimmer where a pointer is doing the aiming. */
@media (min-width: 701px) {
    :root {
        --control-height: 2.125rem;
    }

    /* Enough padding that min-height is what decides the height. */
    .field,
    .select {
        padding-top: var(--space-1);
        padding-bottom: var(--space-1);
    }
}
