/* ============================================================
   MindBio Evaluation — kiosk theme (plain CSS port of the
   legacy CheckIn design system: dark slate + cyan accent,
   Outfit / IBM Plex Mono).
   ============================================================ */

/* ---------- Fonts (self-hosted, latin subset) ---------- */
@font-face {
    font-family: "Outfit";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/assets/outfit-latin-400-normal.woff2") format("woff2");
}
@font-face {
    font-family: "Outfit";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("/assets/outfit-latin-500-normal.woff2") format("woff2");
}
@font-face {
    font-family: "Outfit";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("/assets/outfit-latin-600-normal.woff2") format("woff2");
}
@font-face {
    font-family: "Outfit";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("/assets/outfit-latin-700-normal.woff2") format("woff2");
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("/assets/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("/assets/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
}
/* ---------- Design tokens ---------- */
:root {
    /* Brand */
    --accent: #00aeef;          /* secondary-500 (MindBio cyan) */
    --accent-hover: #008bbf;    /* secondary-600 */
    --accent-active: #00688f;   /* secondary-700 */
    --accent-soft: rgba(0, 174, 239, 0.12);
    --accent-glow: 0 0 24px rgba(0, 174, 239, 0.35);

    /* Surfaces (slate/neutral dark) */
    --bg: #020617;              /* neutral-950 */
    --bg-elevated: #0b1222;
    --surface: #111827;         /* neutral-900 */
    --surface-2: #1f2937;       /* neutral-800 */
    --border: #1f2937;          /* neutral-800 */
    --border-strong: #374151;   /* neutral-700 */

    /* Text */
    --text: #f3f4f6;            /* neutral-100 */
    --text-muted: #9ca3af;      /* neutral-400 */
    --text-strong: #ffffff;     /* headings, phrase card, keypad keys */
    --text-on-accent: #ffffff;  /* labels over the accent fill (same in both themes) */

    /* Translucent chrome over the page background: pills, clock, inputs, hairlines */
    --glass: rgba(255, 255, 255, 0.04);
    --glass-hover: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.04);
    --line: rgba(255, 255, 255, 0.07);
    --line-strong: rgba(255, 255, 255, 0.16);
    --shadow: rgba(0, 0, 0, 0.35);

    /* Background layers: body glow, perspective grid, vignette */
    --bg-glow: rgba(0, 174, 239, 0.10);
    --grid-line: rgba(0, 174, 239, 0.05);
    --grid-line-soft: rgba(0, 174, 239, 0.038);
    --grid-glow: rgba(148, 163, 184, 0.10);
    --vignette-mid: rgba(2, 6, 23, 0.5);
    --vignette: rgba(2, 6, 23, 0.95);

    /* Feedback */
    --success: #22c55e;
    --error: #f87171;
    --warning: #eab308;

    --radius: 12px;
    --radius-sm: 8px;
    --font-sans: "Outfit", system-ui, -apple-system, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

/* Light theme: `light` on <html>, toggled per device from the welcome screen (theme controller)
   and applied before first paint by the layout's inline script. Every token mirrors one above,
   so components adapt without per-rule overrides. */
html.light {
    --accent-soft: rgba(0, 174, 239, 0.14);
    --accent-glow: 0 0 24px rgba(0, 174, 239, 0.25);

    --bg: #f8fafc;              /* neutral-50 */
    --bg-elevated: #ffffff;
    --surface: #ffffff;
    --surface-2: #f1f5f9;       /* neutral-100 */
    --border: #e2e8f0;          /* neutral-200 */
    --border-strong: #cbd5e1;   /* neutral-300 */

    --text: #0f172a;            /* neutral-900 */
    --text-muted: #64748b;      /* neutral-500 */
    --text-strong: #0f172a;

    /* Darker feedback tones for contrast on light surfaces */
    --success: #16a34a;
    --error: #dc2626;
    --warning: #ca8a04;

    --glass: rgba(15, 23, 42, 0.04);
    --glass-hover: rgba(15, 23, 42, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.6);
    --line: rgba(15, 23, 42, 0.08);
    --line-strong: rgba(15, 23, 42, 0.16);
    --shadow: rgba(15, 23, 42, 0.10);

    --bg-glow: rgba(0, 174, 239, 0.08);
    --grid-line: rgba(0, 174, 239, 0.09);
    --grid-line-soft: rgba(0, 174, 239, 0.06);
    --grid-glow: rgba(0, 174, 239, 0.08);
    --vignette-mid: rgba(226, 232, 240, 0.2);
    --vignette: rgba(248, 250, 252, 0.9);
}

* {
    box-sizing: border-box;
}

html, body {
    min-height: 100%;
    /* Kiosk tablets: no rubber-band overscroll dragging the whole screen. */
    overscroll-behavior-y: none;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 50% -10%, var(--bg-glow), transparent 60%),
        var(--bg);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Background: perspective grid + glow (legacy-inspired) ---------- */
.app-bg-grid,
.app-bg-gradient {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.app-bg-grid {
    overflow: hidden;
    /* Accentuate the grid in the center and fade it out toward all four edges. */
    -webkit-mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, #000 0%, rgba(0, 0, 0, 0.55) 30%, rgba(0, 0, 0, 0.12) 62%, transparent 84%);
            mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, #000 0%, rgba(0, 0, 0, 0.55) 30%, rgba(0, 0, 0, 0.12) 62%, transparent 84%);
    -webkit-mask-repeat: no-repeat;
            mask-repeat: no-repeat;
    -webkit-mask-size: 100% 100%;
            mask-size: 100% 100%;
}

/* Tilted plane -> horizon compression, with faint cyan grid lines. */
.app-bg-grid::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -42%;
    width: 260%;
    height: 135%;
    margin-left: -130%;
    transform-origin: 50% 0%;
    transform: perspective(560px) rotateX(76deg) translateZ(0);
    background-image:
        repeating-linear-gradient(90deg, transparent 0, transparent 84px, var(--grid-line) 84px, var(--grid-line) 86.3px),
        repeating-linear-gradient(180deg, transparent 0, transparent 40px, var(--grid-line-soft) 40px, var(--grid-line-soft) 42.3px);
    filter: blur(0.6px);
}

.app-bg-gradient {
    background-image:
        radial-gradient(ellipse 110% 85% at 50% 8%, var(--grid-glow) 0%, transparent 58%),
        radial-gradient(125% 125% at 50% 50%, transparent 42%, var(--vignette-mid) 68%, var(--vignette) 100%);
}

/* Keep all chrome and content above the background layers. */
.app-header,
.container,
.app-footer {
    position: relative;
    z-index: 1;
}

/* ---------- Header (legacy-inspired, ported to our theme) ---------- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.8rem 2.7rem;
    border-bottom: 1px solid var(--line);
}

.app-header__logo-link {
    display: inline-flex;
    border-radius: var(--radius-sm);
}

.app-header__logo-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.45);
}

/* IntoxAI app icon (square, full colour: the same in both themes). */
.app-header__logo {
    height: 50px;
    width: 50px;
    display: block;
    filter: drop-shadow(0 0 14px rgba(0, 174, 239, 0.22));
}

.app-header__clock {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--text);
    padding: 0.66rem 1.3rem;
    background: var(--glass);
    border: 2px solid var(--line-strong);
    border-radius: 999px;
    box-shadow: inset 0 1px 0 var(--glass-highlight);
}

@media (max-width: 480px) {
    .app-header {
        padding: 1rem 1.2rem;
    }

    .app-header__logo {
        height: 38px;
        width: 38px;
    }

    /* Mobile: drop the clock (not needed) — the language toggle takes the top-right corner. */
    .app-header__clock {
        display: none;
    }
}

/* Right side of the header: page actions (device info on the welcome screen), then the clock. */
.app-header__end {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

/* ---------- Device info (welcome screen header) ---------- */
/* Round button next to the clock, same glass pill look; opens a native popover with the kiosk's
   name/code/location (as Dashboard > Fleet shows them) and its battery. */
.device-info__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    color: var(--text-muted);
    background: var(--glass);
    border: 2px solid var(--line-strong);
    border-radius: 999px;
    box-shadow: inset 0 1px 0 var(--glass-highlight);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.device-info__button:hover,
.device-info:has(.device-info__panel:popover-open) .device-info__button {
    background: var(--glass-hover);
    color: var(--text-strong);
    border-color: var(--accent);
}

.device-info__button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.45);
}

.device-info__button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Native popover (top layer, closes on an outside tap), anchored under the header's right side.
   Never set `display` here: the UA hides a closed popover with display:none. */
.device-info__panel {
    position: fixed;
    inset: auto;
    top: 7.4rem;
    right: 2.7rem;
    margin: 0;
    width: min(23rem, calc(100vw - 2.4rem));
    padding: 1.3rem 1.4rem;
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    box-shadow: 0 18px 48px var(--shadow);
}

.device-info__panel:popover-open {
    animation: device-info-in 0.16s ease-out;
}

@keyframes device-info-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.device-info__title {
    margin: 0 0 1rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.device-info__list {
    display: grid;
    gap: 0.8rem;
    margin: 0;
}

.device-info__row {
    display: grid;
    grid-template-columns: 6.5rem 1fr;
    gap: 0.75rem;
    align-items: baseline;
}

.device-info__row dt {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.device-info__row dd {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-strong);
    overflow-wrap: anywhere;
}

.device-info__code {
    font-family: var(--font-mono);
    letter-spacing: 0.08em;
}

.device-info__sub {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.device-info__sub.is-charging {
    color: var(--success);
}

.device-info__sub.is-low {
    color: var(--warning);
}

/* Battery gauge: outline with a terminal nub, fill = level (green charging, amber low). */
.battery {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
}

.battery__gauge {
    position: relative;
    width: 2.3rem;
    height: 1.1rem;
    padding: 2px;
    border: 2px solid var(--text-muted);
    border-radius: 5px;
}

.battery__gauge::after {
    content: "";
    position: absolute;
    top: 50%;
    right: -6px;
    width: 3px;
    height: 7px;
    transform: translateY(-50%);
    background: var(--text-muted);
    border-radius: 0 2px 2px 0;
}

.battery__fill {
    display: block;
    width: 0;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.battery.is-charging .battery__fill {
    background: var(--success);
}

.battery.is-low .battery__fill {
    background: var(--warning);
}

.battery__level {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* Mobile: the clock is hidden and the theme pill moves to the top-right corner (see .welcome-controls),
   so the device-info button stays at the corner and the pill sits just left of it. */
@media (max-width: 480px) {
    .device-info__button {
        width: 2.5rem;
        height: 2.5rem;
    }

    .device-info__button svg {
        width: 19px;
        height: 19px;
    }

    .device-info__panel {
        top: 5.2rem;
        right: 1.2rem;
    }

    /* Centred on the button's row (the pill is shorter than the 40px button). */
    body:has(.device-info) .welcome-controls {
        top: 1.28rem;
        right: 4.2rem;
    }
}

/* ---------- Layout ---------- */
.container {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 3.2rem 1.5rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.5rem;
}

/* ---------- Footer ---------- */
.app-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 1.5rem 1.8rem;
    /* Decorative only ("Powered by MindBio") — must never swallow clicks. `.container` (z-index:1)
       traps the fixed `.welcome-controls`; this later same-z footer paints over the toggles'
       bottom-left corner, so let pointer events pass through to the toggle underneath.
       Scoped to `.app-footer` ONLY — never the grouped `.container` rule above. */
    pointer-events: none;
}

.app-footer__line {
    width: 100%;
    max-width: 616px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

.app-footer__text {
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    opacity: 0.75;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 1.5rem;
    color: var(--text-strong);
}

p {
    color: var(--text-muted);
    line-height: 1.6;
}

@media (max-width: 480px) {
    .app-footer {
        padding: 1.2rem 1rem 1.5rem;
        gap: 0.8rem;
    }

    .app-footer__text {
        font-size: 0.85rem;
    }
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1.75rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease,
                color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.45);
}

.btn:active {
    transform: translateY(1px);
}

.btn--primary {
    background: var(--accent);
    color: var(--text-on-accent);
    box-shadow: var(--accent-glow);
}

.btn--primary:hover {
    background: var(--accent-hover);
    /* Keep the dark brand text in every state so the label colour stays
       consistent (no white-on-hover that "sticks" after back-navigation). */
}

.btn--primary:active {
    background: var(--accent-active);
}

.btn--secondary {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text);
}

.btn--secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- Button identity (subtle micro-interactions) ---------- */
.btn {
    position: relative;
    overflow: hidden;
    /* Shared width so every CTA across views is the same size. */
    min-width: 230px;
    transition: background-color 0.15s ease, border-color 0.15s ease,
                color 0.15s ease, box-shadow 0.2s ease, transform 0.12s ease;
}

/* Lift on hover, settle into a real press on click. */
.btn--primary:hover,
.btn--secondary:hover {
    transform: translateY(-2px);
}

.btn--primary:hover {
    /* Stay bright (don't darken) and lift with a soft glow. */
    background: var(--accent);
    filter: brightness(1.04);
    box-shadow: 0 8px 22px rgba(0, 174, 239, 0.4), var(--accent-glow);
}

.btn--primary:active,
.btn--secondary:active {
    transform: translateY(1px);
}

.btn:disabled {
    transform: none;
}

/* Light sheen sweeping across the primary CTA on hover. */
.btn--primary::after {
    content: "";
    position: absolute;
    top: 0;
    left: -150%;
    width: 55%;
    height: 100%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: skewX(-20deg);
    transition: left 0.55s ease;
    pointer-events: none;
}

.btn--primary:hover::after {
    left: 160%;
}

@media (prefers-reduced-motion: reduce) {
    .btn--primary::after { display: none; }
}

/* ---------- Inputs ---------- */
input[type="text"],
.input {
    width: 100%;
    max-width: 420px;
    padding: 0.9rem 1.1rem;
    font-family: inherit;
    font-size: 1.125rem;
    color: var(--text);
    background: var(--glass);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]::placeholder {
    color: var(--text-muted);
}

input[type="text"]:focus,
.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.25);
}

/* ---------- Identify screen ---------- */
.identify-icon {
    width: 84px;
    height: 84px;
    margin: 0 auto 1.5rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent-soft);
    border: 1px solid rgba(0, 174, 239, 0.3);
    box-shadow: 0 0 28px rgba(0, 174, 239, 0.22), inset 0 0 18px rgba(0, 174, 239, 0.08);
}

.identify-icon svg {
    width: 40px;
    height: 40px;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.identify-screen form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.75rem;
    width: 100%;
    /* Wide enough to give the on-screen keypad touch-friendly keys. */
    max-width: 820px;
    margin: 0 auto;
}

/* Prominent, code-style ID field (no card) so the background stays visible.
   Capped narrower than the keypad below so the empty field doesn't look stretched. */
.identify-screen input[type="text"] {
    margin-bottom: 0;
    width: 100%;
    max-width: 460px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 1.3rem;
    letter-spacing: 0.12em;
    padding: 1.1rem 1.3rem;
    background: var(--glass);
    box-shadow: inset 0 1px 0 var(--glass-highlight);
}

.identify-screen input[type="text"]::placeholder {
    font-family: var(--font-sans);
    letter-spacing: normal;
    color: var(--text-muted);
}

.identify-screen input[type="text"]:focus {
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.25), 0 0 28px rgba(0, 174, 239, 0.18);
}

/* ---------- On-screen keypad (tablet/desktop; phones use the native OS keyboard) ----------
   Numbers on top, letters below (single stacked block). */
.identify-keypad {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    width: 100%;
    user-select: none;
}

/* Small touch screens (phones): hide the on-screen keyboard from the first paint via CSS (so it
   never flashes on load) — same breakpoint as the identity controller's matchMedia, which makes
   the field editable so the device's native keyboard is used instead. */
@media (pointer: coarse) and (max-width: 767px) {
    .identify-keypad {
        display: none;
    }
}

.keypad-row {
    display: flex;
    justify-content: center;
    gap: 0.7rem;
}

.key {
    flex: 1 1 0;
    min-width: 0;
    max-width: 6rem;
    height: 2.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-strong);
    background: var(--glass-hover);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.12s ease, border-color 0.12s ease,
                color 0.12s ease, transform 0.06s ease, box-shadow 0.12s ease;
}

/* Only on real hover-capable (mouse) devices — otherwise the hover colour "sticks" to the
   last-tapped key on touch screens (tablet/kiosk) until another key is pressed. */
@media (hover: hover) {
    .key:hover {
        border-color: var(--accent);
        color: var(--accent);
    }
}

/* Clear press feedback for the kiosk: the key sinks and lights up in the accent colour
   (the transition eases it back on release). */
.key:active {
    transform: scale(0.93);
    color: var(--text-on-accent);
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(0, 174, 239, 0.5);
}

.key:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 174, 239, 0.4);
}

.key--control {
    color: var(--text-muted);
    font-size: 1.45rem;
}

/* Lowercase mode: letter labels follow the appended case (digits/symbols unaffected). */
.identify-keypad.is-lower .key {
    text-transform: lowercase;
}

/* Active Shift/Caps toggle. */
.key[aria-pressed="true"] {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* On narrow screens that still show the keypad the 10-key rows get cramped, so make the keys
   chunkier: taller and with tighter horizontal gaps (more width per key). */
@media (max-width: 600px) {
    .keypad-row {
        gap: 0.4rem;
    }

    .key {
        height: 3.6rem;
    }
}

/* ---------- Brand / logo ---------- */
/* Kiosk wordmark — "IntoxAI" + tagline in the centre of the welcome screen (the app icon is in the
   header; the company MindBio in the footer). Designer's SVG; scales with the viewport so it fits
   small kiosks and phones. */
.brand-logo {
    display: block;
    width: min(440px, 80vw);
    height: auto;
}

/* Light theme: the designer's light version (dark lettering). Swapped in CSS (content: url) so each
   theme downloads only its own file. */
html.light .brand-logo {
    content: url("/assets/intoxai-wordmark-claro.svg");
}

/* ---------- Screens ---------- */
.welcome-screen,
.identify-screen,
.capture-screen,
.thank-you-screen,
.error-screen,
.expired-screen {
    width: 100%;
    text-align: center;
    /* `backwards` (not `both`): the fade-in still plays, but no `transform` lingers
       after it. A lingering transform would make the descendant `.session-overlay`
       anchor to this box instead of `.container` (clipping it to a card). */
    animation: fade-in-up 0.45s ease-out backwards;
}

/* Welcome screen: even vertical rhythm between the logo, heading and button. A single flex
   gap governs the spacing so no child margin (e.g. the logo's) makes one gap bigger. */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.welcome-screen > * {
    margin: 0;
}

/* ---------- Welcome controls: theme toggle ---------- */
/* Ambient pill pinned bottom-left of the welcome screen; flips <html> between dark and light
   for the device. (The kiosk language is set from the Dashboard, not on the device.) */
.welcome-controls {
    position: fixed;
    bottom: 2.2rem;
    left: 2.7rem;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: 999px;
    background: var(--glass);
    border: 1px solid var(--line);
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.theme-toggle:hover {
    background: var(--glass-hover);
    color: var(--text-strong);
    border-color: var(--line-strong);
}

.theme-toggle__icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* Sun/moon swap is pure CSS, driven by the html.light class. */
.theme-toggle__icon--moon,
html.light .theme-toggle__icon--sun {
    display: none;
}

html.light .theme-toggle__icon--moon {
    display: block;
}

/* Mobile: the clock is hidden (see the header rule), so the pill takes the top-right corner. */
@media (max-width: 480px) {
    .welcome-controls {
        top: 1.1rem;
        right: 1.2rem;
        bottom: auto;
        left: auto;
        gap: 0.5rem;
    }

    .theme-toggle {
        min-width: 2.6rem;
        padding: 0.35rem 0.7rem;
        font-size: 0.8rem;
    }
}

/* ---------- Capture / phrase card ---------- */
/* Subtle "this is you" chip, pinned top-left (under the header) as an ambient
   session indicator so it doesn't crowd the centered task column. */
.capture-identity {
    position: fixed;
    top: 10.5rem;
    left: 2.7rem;
    z-index: 2;
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.95rem;
    border-radius: 999px;
    background: var(--glass);
    border: 1px solid var(--line);
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1;
    /* Fixed + opacity-hidden from first paint so it never renders in the
       centered flow (no flash); the script fades it in once the name is set. */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.capture-identity.is-shown {
    opacity: 1;
    visibility: visible;
}

.capture-identity__icon {
    width: 15px;
    height: 15px;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: 0 0 auto;
}

.phrase {
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-strong);
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px var(--shadow);
    margin: 0 auto 1.25rem;
    max-width: 540px;
}

@media (max-width: 480px) {
    .capture-identity {
        top: 6.8rem;
        left: 1.2rem;
        font-size: 0.75rem;
        padding: 0.3rem 0.7rem;
    }

    h1 {
        font-size: 1.4rem;
        margin-bottom: 1rem;
    }

    .phrase {
        font-size: 1.15rem;
        padding: 1.3rem;
        margin-bottom: 1.3rem;
    }
}

.recording-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin: 1.25rem 0 0;
    /* Keep a button's height even while both are hidden (the countdown between readings), so the
       screen never jumps when Stop appears. */
    min-height: 3.1rem;
}

.capture-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    /* Reserve the error pill's height (1.6 line + 2 x 0.5rem padding + 2px border = 43.6px) so
       switching plain status <-> error pill never shifts the waveform below it. */
    min-height: 2.75rem;
    margin: 1rem 0;
    color: var(--text-muted);
    font-size: 1rem;
}

/* Errors (too short, mic unavailable, submission failed, retest) render in the same
   status line as a red pill — matching the Identify "user not found" alert — so every
   message is homogeneous and the layout stays put. */
.capture-status__text.is-error {
    padding: 0.5rem 1rem;
    color: var(--error);
    background: rgba(248, 113, 113, 0.10);
    border: 1px solid rgba(248, 113, 113, 0.35);
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.recording-dot {
    display: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--error);
}

.is-recording .recording-dot {
    display: inline-block;
    animation: pulse-dot 1.1s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.35; transform: scale(0.75); }
}

.waveform {
    width: 100%;
    max-width: 560px;
    /* Tall enough that the 3-2-1 between readings (which takes this zone's place) fits with room for
       its ripple. Matches the canvas height attribute so the bars are not stretched. */
    height: 96px;
    margin: 0 auto 1.5rem;
    /* No box: the bars float over the page background to keep the recording
       state light and uncluttered. */
}

.timer {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 1.05rem;
    color: var(--accent);
}

/* ---------- Messages ---------- */

/* Reusable alert container matching the Dashboard's styled alerts, adapted to the
   dark kiosk aesthetic: a translucent tinted background, a colored border and
   colored text. Lives inside centered flex columns, so it stays fluid. */
.alert {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.15rem;
    border-radius: var(--radius-sm);
    border: 1px solid;
    font-weight: 500;
    line-height: 1.4;
    text-align: left;
}

.alert--error {
    color: var(--error);
    background: rgba(248, 113, 113, 0.10);
    border-color: rgba(248, 113, 113, 0.35);
}

.alert--success {
    color: var(--success);
    background: rgba(34, 197, 94, 0.10);
    border-color: rgba(34, 197, 94, 0.35);
}

/* The identity/capture error renders as a compact red alert pill: centered and
   sized to its content, with its vertical space RESERVED when hidden so showing
   or clearing the error never shifts the surrounding content up — it just
   appears below (kept in flow via .error-message.hidden below). */
.error-message {
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    max-width: 100%;
    /* Reserve one line's height even while empty/hidden (an empty flex box has no line
       box), so the box never grows when the text is set — the layout stays put. */
    min-height: 2.6rem;
    margin: 1rem auto 0;
    padding: 0.5rem 1rem;
    color: var(--error);
    background: rgba(248, 113, 113, 0.10);
    border: 1px solid rgba(248, 113, 113, 0.35);
    border-radius: var(--radius-sm);
    font-weight: 500;
    line-height: 1.4;
}

.error-message.hidden {
    /* Reserve the space (more specific than the global .hidden's display:none). */
    display: flex !important;
    visibility: hidden;
}

.welcome-message {
    margin-top: 1rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--accent);
}

.error-code {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 1.5rem;
}

.permission-denied {
    background: rgba(248, 113, 113, 0.12);
    color: var(--error);
    border: 1px solid rgba(248, 113, 113, 0.4);
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    text-align: center;
    margin: 0;
}

/* ---------- Session overlay ---------- */
/* Confined to the band between header and footer: `.container` (the <main> between them) is
   the positioned ancestor, so the spinner centers in that band without hard-coded chrome heights. */
.session-overlay {
    position: absolute;
    inset: 0;
    /* Transparent: keep the custom grid background visible behind the spinner.
       The rest of the screen is hidden via the :has() rule below, so only the
       spinner content shows (no opaque flash that hides the background). */
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

/* While an overlay is shown, hide every other element of the screen so only the
   spinner/content is visible and the background stays in place. Driven purely by
   the overlay's `hidden` class (toggled by the controllers) — no JS changes. */
.identify-screen:has(.session-overlay:not(.hidden)) > :not(.session-overlay),
.capture-screen:has(.session-overlay:not(.hidden)) > :not(.session-overlay) {
    display: none;
}

.session-overlay__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    color: var(--text);
    font-size: 1.25rem;
    font-weight: 500;
}

/* Dual-ring spinner: two concentric arcs counter-rotating, with an accent glow. */
.spinner {
    position: relative;
    width: 54px;
    height: 54px;
    flex: 0 0 auto;
    filter: drop-shadow(0 0 10px rgba(0, 174, 239, 0.5));
}

.spinner::before,
.spinner::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    border: 3px solid transparent;
}

/* Outer ring: clockwise. */
.spinner::before {
    inset: 0;
    border-top-color: var(--accent);
    border-right-color: var(--accent);
    animation: spin 1.5s linear infinite;
}

/* Inner ring: counter-clockwise, faster, dimmer. */
.spinner::after {
    inset: 9px;
    border-bottom-color: rgba(0, 174, 239, 0.65);
    border-left-color: rgba(0, 174, 239, 0.65);
    animation: spin 1.1s linear infinite reverse;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Welcome variant (Identify): greeting title on top, spinner moved below. */
.session-overlay__content--welcome {
    gap: 1rem;
}

/* In the welcome variant the spinner element sits after the text, so it renders below. */
.session-overlay__content--welcome .spinner {
    margin-top: 0.5rem;
}

.session-overlay__title {
    margin: 0;
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--text-strong);
}

.session-overlay__subtitle {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
}

/* ---------- Result check (success screen) ---------- */
.result-check {
    width: 104px;
    height: 104px;
    margin: 0 auto 1.75rem;
}

.result-check__svg {
    width: 100%;
    height: 100%;
}

.result-check--success {
    filter: drop-shadow(0 0 18px rgba(34, 197, 94, 0.4));
}

.result-check__circle {
    stroke: var(--success);
    stroke-width: 2;
    stroke-dasharray: 151;
    stroke-dashoffset: 151;
    animation: check-circle 0.6s ease-out forwards;
}

.result-check__mark {
    stroke: var(--success);
    stroke-width: 3.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: check-mark 0.35s 0.55s ease-out forwards;
}

@keyframes check-circle { to { stroke-dashoffset: 0; } }
@keyframes check-mark { to { stroke-dashoffset: 0; } }

/* Final (Thank You) screen: larger body copy. */
.thank-you-screen p:not(.result-standby) {
    font-size: 1.25rem;
}

.result-standby {
    margin-top: 1.75rem;
    font-size: 1.05rem;
    color: var(--text-muted);
}

/* ---------- Utilities ---------- */
.hidden {
    /* Utility class: must override base rules (e.g. .session-overlay { display: flex })
       regardless of source order, so toggling `hidden` from JS actually hides the element. */
    display: none !important;
}

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; }

    /* Essential feedback must survive reduced motion (iOS turns it on in Low Power Mode).
       The loading spinner still needs to convey progress, and the success check is drawn
       BY its animation — disabling it outright leaves it stuck in its hidden initial state
       (stroke-dashoffset), so it never appears. Keep the spinner turning and snap the check
       to its final drawn state. */
    .spinner::before { animation: spin 1.5s linear infinite !important; }
    .spinner::after  { animation: spin 1.1s linear infinite reverse !important; }

    /* Keep the check's draw: it is small, functional feedback (not vestibular motion),
       and the animation is what reveals it — snapping to the final state loses the effect
       the desktop shows. Re-enable it so it draws progressively everywhere. */
    .result-check__circle { animation: check-circle 0.6s ease-out forwards !important; }
    .result-check__mark   { animation: check-mark 0.35s 0.55s ease-out forwards !important; }
}

/* ---------- Capture session: the phrase is read several times in a row ---------- */
.capture-hint {
    margin: -0.5rem auto 1rem;
    max-width: 540px;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.5;
}

/* Step dots above the phrase: done readings filled, the current one ringed. */
.take-progress {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin: 0 0 1.25rem;
    padding: 0;
    list-style: none;
}

.take-progress__step {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    font-weight: 600;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.take-progress__step.is-current {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 14px rgba(0, 174, 239, 0.35);
}

.take-progress__step.is-done {
    border-color: var(--success);
    background: var(--success);
    color: var(--text-on-accent);
}

/* ---------- Countdown between readings (pulsing 3-2-1) ---------- */
/* Status line + waveform + controls. Between readings the countdown takes their place: they only turn
   invisible (keeping their space), so the phrase and everything else stay exactly where they are. */
.capture-stage {
    position: relative;
}

.capture-stage.is-counting > :not(.take-countdown) {
    visibility: hidden;
}

.take-countdown {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Clears the ring's ripple (it grows to 1.35x, ~17px past the ring) so the beat never touches
       the text above and below. */
    gap: 2rem;
    text-align: center;
}

/* The phrase stays put but fades while the countdown runs ("not yet"); it flashes back when the
   reading starts (.is-go). */
.phrase {
    transition: opacity 0.3s ease;
}

.capture-screen.is-counting .phrase {
    opacity: 0.35;
}

.take-countdown__label {
    margin: 0;
    font-size: clamp(1.05rem, 3vw, 1.25rem);
    font-weight: 700;
    color: var(--text-strong);
}

.take-countdown__ring {
    position: relative;
    display: grid;
    place-items: center;
    width: clamp(84px, 22vw, 100px);
    aspect-ratio: 1;
    border-radius: 50%;
    border: 3px solid var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 28px rgba(0, 174, 239, 0.35), inset 0 0 20px rgba(0, 174, 239, 0.15);
}

.take-countdown__ring::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    opacity: 0;
    animation: take-countdown-ripple 1s ease-out infinite;
}

.take-countdown__number {
    font-family: var(--font-mono);
    font-size: clamp(2.8rem, 9vw, 3.4rem);
    font-weight: 700;
    line-height: 1;
    color: var(--accent);
    text-shadow: 0 0 18px rgba(0, 174, 239, 0.55);
}

.take-countdown__number.is-beat {
    animation: take-countdown-beat 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.take-countdown__hint {
    margin: 0;
    font-size: clamp(1rem, 2.8vw, 1.15rem);
    font-weight: 600;
    color: var(--warning);
}

.take-countdown__note {
    margin: 0;
    padding: 0.35rem 0.9rem;
    color: var(--error);
    background: rgba(248, 113, 113, 0.10);
    border: 1px solid rgba(248, 113, 113, 0.35);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
}

@keyframes take-countdown-beat {
    0%   { transform: scale(1.45); opacity: 0.2; }
    45%  { transform: scale(0.95); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes take-countdown-ripple {
    0%   { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.35); opacity: 0; }
}

/* The moment a reading starts: the phrase card flashes once ("read now"). */
.phrase.is-go {
    animation: phrase-go 1.2s ease-out;
}

@keyframes phrase-go {
    0%   { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 174, 239, 0.55), 0 0 48px rgba(0, 174, 239, 0.5); }
    100% { border-color: var(--border); box-shadow: 0 12px 32px var(--shadow); }
}

@media (prefers-reduced-motion: reduce) {
    .phrase {
        transition: none;
    }

    .take-countdown__ring::after,
    .take-countdown__number.is-beat,
    .phrase.is-go {
        animation: none;
    }
}
