/* buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;

    border-style: solid;
    border-radius: 0;

    background: var(--text);
    color: var(--bg);

    font: inherit;
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
}

.btn:hover {
    background: var(--bg);
    color: var(--text);
}

.btn:focus-visible {
    outline: var(--border-width) solid var(--text);
    outline-offset: 2px;
}

/* secondary action: same shape, no fill until hovered */
.btn--secondary {
    background: transparent;
    color: inherit;
}

/* icon-only action: the mask paints in the button's label colour */
.btn .logo {
    width: 1.25em;
    height: 1.25em;

    background-color: currentColor;
}

/* fields */
.field {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;

    min-width: 0;
    max-width: 100%;

    font-size: var(--font-size-sm);
}

.field>label {
    font-weight: 600;
}

/* text inputs, selects and textareas */
.input,
.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 10px;

    border-style: solid;
    border-radius: 0;

    background: transparent;
    color: inherit;

    font: inherit;
    font-size: var(--font-size-base);
}

.input:focus-visible,
.field input:not([type="checkbox"]):not([type="radio"]):focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
    outline: var(--border-width) solid var(--text);
    outline-offset: 2px;
}

.field textarea {
    resize: vertical;
}

/* number inputs: no native spinners; duration inputs have their own units */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/*
 * iOS Safari renders date/datetime-local inputs as native controls that keep
 * their intrinsic width: width: 100% is ignored and padding is added on top
 * (WebKit bug 301648), so the control spills past its field on mobile.
 * Dropping the native appearance lets it size like a text input; tapping it
 * still opens the native picker.
 */
@supports (-webkit-touch-callout: none) {

    .field input[type="date"],
    .field input[type="datetime-local"],
    .input[type="date"],
    .input[type="datetime-local"] {
        -webkit-appearance: none;
        appearance: none;
        overflow: hidden;
    }
}

input::placeholder,
textarea::placeholder {
    color: var(--text);
    opacity: 0.7;
}

/* checkbox: a square control with the same border as everything else */
.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;

    font-size: var(--font-size-sm);
    cursor: pointer;
}

.checkbox>input {
    appearance: none;
    -webkit-appearance: none;

    flex: 0 0 auto;

    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;

    border-style: solid;
    border-radius: 0;

    background: transparent;
    cursor: pointer;
    transition: background-color 120ms ease;
}

.checkbox>input:checked {
    background: var(--primary);
}

.checkbox>input:focus-visible {
    outline: var(--border-width) solid var(--text);
    outline-offset: 2px;
}

/* segmented switcher: mutually exclusive views */
.switcher {
    display: flex;
    align-self: flex-start;
    width: fit-content;

    border-style: solid;
}

.switcher__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;

    border-style: none;
    border-radius: 0;

    background: transparent;
    color: inherit;
    font: inherit;
    font-size: var(--font-size-sm);
    text-decoration: none;
    cursor: pointer;
}

.switcher__button+.switcher__button {
    border-left-style: solid;
}

.switcher__button[aria-pressed="true"],
.switcher__button[aria-current="page"] {
    background: var(--text);
    color: var(--bg);
}

.switcher__button:not([aria-pressed="true"]):not([aria-current="page"]):hover {
    opacity: 0.6;
}

.switcher__button:focus-visible {
    outline: var(--border-width) solid var(--text);
    outline-offset: -2px;
}

@media (max-width: 600px) {
    .switcher {
        width: 100%;
    }

    .switcher__button {
        flex: 1;
        padding: 4px 6px;
    }
}

/* errors */
.errorlist {
    padding: 8px 10px;
    border-style: solid;
    border-color: var(--primary);
    background: var(--primary);
    color: var(--on-primary);
    font-size: var(--font-size-sm);
    list-style: none;
}

/* error lists are grid children inside .field; keep them full-width */
.field>.errorlist {
    justify-self: stretch;
}

/* full-page fallback for overlay-only forms (invalid POST without HTMX) */
.form-page {
    width: 100%;
    max-width: 800px;
    margin-inline: auto;
}

/* overlay panel header: back | title | actions */
.overlay-panel-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.overlay-panel-header__back {
    display: flex;
}

.overlay-panel-header__title {
    font-size: var(--font-size-lg);
    overflow-wrap: anywhere;
}

/* Programmatic focus target for screen readers; headings are not interactive. */
[data-overlay-title]:focus,
[data-overlay-title]:focus-visible {
    outline: none;
}

.overlay-panel-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.overlay-panel-back {
    display: grid;
    place-items: center;

    width: 32px;
    height: 32px;
    padding: 0;

    background: none;
    border-style: none;
    cursor: pointer;
}

.overlay-panel-back .logo {
    width: 18px;
    height: 18px;
}

.overlay-panel-back:focus-visible {
    outline: var(--border-width) solid var(--text);
    outline-offset: 2px;
}

/* feedback panel: success / error / info */
.feedback {
    display: grid;
    gap: 6px;
    padding: 10px;

    border-style: solid;
    border-color: var(--primary);
    background: var(--primary);
    color: var(--on-primary);
}

.feedback--error {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--on-primary);
}

.feedback__title {
    font-size: var(--font-size-base);
}

.feedback__message {
    font-size: var(--font-size-sm);
}

.feedback__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* confirmation dialog: a native <dialog> in the top layer, so it covers an
   open sheet. Cancel is focused first to make the safe choice the default. */
.confirm-dialog {
    width: calc(100% - 2 * var(--base-padding));
    max-width: 420px;
    max-height: calc(100% - 2 * var(--base-padding));
    margin: auto;
    padding: 0;
    overflow: auto;

    border-style: solid;
    border-radius: 0;

    background: var(--bg);
    color: var(--text);
}

.confirm-dialog::backdrop {
    background: color-mix(in srgb, var(--text) 55%, transparent);
}

.confirm-dialog__form {
    display: grid;
    gap: 12px;
    padding: var(--base-padding);
}

.confirm-dialog__title {
    font-size: var(--font-size-lg);
}

.confirm-dialog__message {
    font-size: var(--font-size-base);
}

.confirm-dialog__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

@media (max-width: 600px) {
    .confirm-dialog__actions .btn {
        flex: 1 1 auto;
    }
}

/* static content page: title plus a bordered text block */
.page {
    display: flex;
    flex-direction: column;
    gap: 12px;

    width: 100%;
    max-width: 800px;
    height: 100%;
    min-height: 0;
    margin-inline: auto;
}

.page>h1 {
    flex: 0 0 auto;
}

.page__body {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;

    padding: 14px;
}

/* Keep the scrollport a block; the inner wrapper handles content spacing. */
.page__body-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100%;
}

.page__body h2 {
    font-size: var(--font-size-lg);
}

.page__body a {
    color: var(--primary);
}

.page__contact {
    display: flex;
    flex-direction: column;
    gap: 4px;
    list-style: none;
}

/*
 * Fox: decorative walking sprite. The modifiers place it and set the travel;
 * size it with --fox-height and point --fox-sheet at the walk sheet.
 *
 * Three transforms on three elements, so none of them overwrite each other:
 * the travel on .fox__travel, the flip on .fox__flip, the frame step on
 * .fox__sprite.
 */
.fox {
    --fox-height: 30px;
    --fox-width: calc(var(--fox-height) * 1.975);

    /* fixed at 12 fps; the ground speed is --fox-travel-duration per instance */
    --fox-frame-duration: 83.33ms;

    --fox-walk-sheet: url("../sprites/fox/walk.054a847b57d4.webp");
    --fox-turn-sheet: url("../sprites/fox/turn.c8fe1ad3863b.webp");

    position: absolute;
    height: var(--fox-height);

    pointer-events: none;
}

/* The modifier animates this across its own width, so it has to be the
   container-width box rather than the fox. */
.fox__travel {
    height: 100%;
}

.fox__flip {
    position: relative;

    width: var(--fox-width);
    height: 100%;
    overflow: hidden;
}

/* Fetches and decodes the turn sheet with the page. A background is only
   requested once an element actually uses it, and .fox__sprite switches to the
   turn sheet only when the turn starts, so without this the first turn paints
   an empty sprite until the image arrives. Parked outside the clip, so it is
   never visible. */
.fox__flip::after {
    content: "";

    position: absolute;
    inset: 0 auto 0 calc(-1 * var(--fox-width) * 20);

    width: calc(var(--fox-width) * 20);

    background-image: var(--fox-turn-sheet);
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.fox__sprite {
    width: calc(var(--fox-width) * 10);
    height: 100%;

    background-image: var(--fox-walk-sheet);
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

/* Only the frame step is animated here; the modifiers animate the travel. Both
   are gated on no-preference so reduced motion gets frame 0, standing still. */
@media (prefers-reduced-motion: no-preference) {
    .fox__sprite {
        animation: fox-walk calc(var(--fox-frame-duration) * 10) steps(10) infinite;
    }

    /* The look-to-camera sheet: 20 frames, two walk cycles, played once by
       fox.js and then swapped back to the walk. */
    .fox__sprite--turn {
        width: calc(var(--fox-width) * 20);

        background-image: var(--fox-turn-sheet);

        animation: fox-turn calc(var(--fox-frame-duration) * 20) steps(20) 1 both;
    }
}

@keyframes fox-walk {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(calc(var(--fox-width) * -10));
    }
}

@keyframes fox-turn {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(calc(var(--fox-width) * -20));
    }
}

/*
 * Title card (splash). Shown on the first page load of a tab, whatever page
 * that is: an opaque layer with a full-width band across the middle, held by a
 * dark bar above and below. The fox walks on top of the upper bar.
 *
 * --splash-duration scales the whole sequence: the timings below are fractions
 * of it, so tuning the length never desynchronises the steps.
 */
.splash {
    --splash-duration: 3s;

    position: fixed;
    inset: 0;
    z-index: 1200;

    display: flex;
    flex-direction: column;
    justify-content: center;

    /* the shell pads body for the notch; a fixed layer has to do that itself */
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--base-padding));
    padding-right: calc(env(safe-area-inset-right, 0px) + var(--base-padding));
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--base-padding));
    padding-left: calc(env(safe-area-inset-left, 0px) + var(--base-padding));

    background: var(--bg);

    animation: splash-out calc(var(--splash-duration) * 0.2) calc(var(--splash-duration) * 0.8) ease-in forwards;
}

.splash__card {
    flex: 0 0 auto;

    /* bounds the bar, which keeps the fox's travel (and so its speed) close to
       the same on every screen */
    width: 100%;
    max-width: 360px;
    margin-inline: auto;

    display: flex;
    flex-direction: column;
}

.splash__bar {
    position: relative;

    flex: 0 0 auto;
    height: 24px;

    background: var(--text);
}

.splash__title {
    flex: 0 0 auto;
    padding: 48px var(--base-padding);

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5ch;
}

.splash__hi {
    font-size: calc(var(--font-size-xl) * 2.5);
    font-weight: 600;
    line-height: 1;

    animation: splash-hi-in calc(var(--splash-duration) * 0.18) ease-out both;
}

/* Starts collapsed, so "Hi" is centred until this opens and shifts it left. */
.splash__aside {
    font-size: var(--font-size-lg);
    line-height: 1;

    max-width: 0;
    overflow: hidden;
    white-space: nowrap;

    animation: splash-aside-in calc(var(--splash-duration) * 0.3) calc(var(--splash-duration) * 0.25) ease-out both;
}

@keyframes splash-hi-in {
    from {
        opacity: 0;
        transform: translateY(0.2em) scale(0.94);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes splash-aside-in {
    from {
        max-width: 0;
        opacity: 0;
    }

    to {
        max-width: 20ch;
        opacity: 1;
    }
}

/* Ends hidden and without pointer events, so the page behind stays usable even
   if nothing removes the element. */
@keyframes splash-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* Set before first paint when the card has already been shown in this tab. */
html.splash-seen .splash {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    .splash {
        display: none;
    }
}

/*
 * The title fox walks along the top bar, feet on it. The card and the splash
 * above it must not clip it, so neither gets `overflow`.
 */
.fox--title {
    --fox-height: 52px;
    --fox-travel-duration: 3.2s;

    /* full bar width, bottom edge on the top edge of the bar */
    inset: auto 0 100% 0;
}

/* Gated like the frame step, so reduced motion leaves the fox standing at the
   start of the bar. */
@media (prefers-reduced-motion: no-preference) {
    .fox--title .fox__travel {
        animation: fox-title-travel var(--fox-travel-duration) linear forwards;
    }
}

@keyframes fox-title-travel {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(calc(100% - var(--fox-width)));
    }
}
