@font-face {
    font-family: 'RethinkSans';
    src: url('fonts/RethinkSans-ExtraBoldItalic.woff2') format('woff2');
    font-weight: 800;
    font-style: italic;
    font-display: swap;
}

button { transition: filter 0.15s ease; }
button:not(:disabled):hover { filter: brightness(1.1); }
button:not(:disabled):active { filter: brightness(0.85); }
button, textarea { -webkit-tap-highlight-color: transparent; } /* suppress mobile Safari/Chrome's tap-flash */

/* QR-03: reachable one-handed on a small phone, retention decision answerable
   without scrolling. Everything else here is a placeholder — refined later. */
:root {
    --accent: #d32f2f;      /* theme accent: matches index.php's "Sparring" wordmark red */
    --link-visited: #7b5940;
    /* bubble colors, naming mirrors arena.css's --accent-bubble-* pair —
       dojo.css needs two full pairs (visitor + sparring), arena.css only
       needed one since the projector renders the AI side differently. */
    --bubble-visitor-bg: #f8e7e7;
    --bubble-visitor-text: #8b2d26;
    --bubble-sparring-bg: #eaeaea;
    --bubble-sparring-text: #111;
}
* { box-sizing: border-box; }

/* The chat surface fills the viewport and never scrolls as a whole —
   #history is the only scroll region. Without this, a swipe anywhere
   outside #history rubber-band-scrolls the whole document on mobile:
   the composer rides up and the body background shows below it. */
html, body { overflow: hidden; }

body {
    margin: 0;
    overscroll-behavior: none;
    /* Figma specifies Helvetica Neue throughout this screen; system-ui
       resolves to San Francisco on Apple devices, a visibly different
       typeface. Helvetica Neue is a standard iOS/macOS system font, so
       this costs nothing and matches the mockups directly. */
    font-family: system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh; /* no dvh support */
    height: 100dvh; /* dvh, but no JS / no visualViewport */
    /* dojo.js keeps --vvh = window.visualViewport.height. On iOS Safari that
       is the only value that shrinks when the software keyboard opens (100dvh
       and innerHeight do not), so the flex column then lays #history and the
       composer out above the keyboard instead of behind it. */
    height: var(--vvh, 100dvh);
    touch-action: manipulation; /* suppress double-tap-to-zoom, keep pinch-zoom for accessibility */
    background:
        radial-gradient(circle, rgba(0,0,0,0.04) 2px, transparent 2px) 0 0/16px 16px,
        #fff;
}

a { color: var(--accent); }
a:visited { color: var(--link-visited); }


main {
    position: relative; /* anchors #playbook (position:absolute) to this box */
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 0.5rem;
    /* inset-aware padding needs viewport-fit=cover on dojo.php's meta to be non-zero */
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right))
             max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
}

#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    /* Lifted out of flow so #history's scroll box runs full height *behind*
       the bar — messages slide under it as you scroll up, rather than being
       clipped at a hard edge below it. Offsets match <main>'s padding so the
       bar sits exactly where it did as a flow child. */
    position: absolute;
    top: max(0.75rem, env(safe-area-inset-top));
    left: max(0.75rem, env(safe-area-inset-left));
    right: max(0.75rem, env(safe-area-inset-right));
    z-index: 2;
    background: var(--accent); /* sparring brand red — same source as the wordmark */
    /* Rounded red card inset from the edges — <main>'s padding already clears
       the notch/safe-areas, so plain padding here. */
    padding: 0.625rem 0.75rem;
    border-radius: 0.875rem; /* 14px */
    /* Feathered, mostly-downward cast — same layered stack as #composer-row,
       so the two bars that frame the history share one shadow language. */
    box-shadow: 0 27px 8px rgba(0, 0, 0, 0), 0 17px 7px rgba(0, 0, 0, 0.02),
                0 10px 6px rgba(0, 0, 0, 0.04), 0 4px 4px rgba(0, 0, 0, 0.06),
                0 1px 2px rgba(0, 0, 0, 0.08);
}

#top-bar-leading {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#session-title-group {
    flex: 1;
    min-width: 0; /* required on a flex child or the children's text-overflow:ellipsis silently fails */
}

/* Visitor alias, sitting just above the session title — smaller and dimmer
   than the title so it reads as a label, not the heading. Replaces the old
   press-the-avatar popover; always visible once consent is recorded. */
#avatar-alias {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.75rem; /* 12px */
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
}

#session-title {
    min-width: 0; /* required on a flex child or text-overflow:ellipsis silently fails */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1rem; /* 16px */
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7); /* placeholder "Untitled" shade on the brand-red bar */
    padding-bottom: 0.125rem; /* nudge the baseline down so the title lines up with the avatar/alias beside it */
}
#session-title.set { color: #fff; }

/* Shimmers only while /api/title is actually in flight (dojo.js adds/removes
   'title-pending' around that fetch) — not for the whole "Untitled" span,
   which also covers the time before any submission. Same shimmer treatment
   as the in-progress status text (#history .turn--pending, keyframes above),
   reused rather than a second effect. */
#session-title.title-pending {
    background: linear-gradient(90deg, #bbb, #666, #bbb);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: shimmer 1.6s linear infinite;
}

#top-bar-trailing {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.locale-switcher {
    display: flex;
    gap: 0.375rem;
    font-size: 0.75rem;
}
.locale-switcher a,
.locale-switcher span {
    color: #999;
    text-decoration: none;
}
.locale-switcher .locale-current {
    color: #111;
    font-weight: 700;
}

#avatar-btn {
    width: 2.5rem; /* 40px */
    height: 2.5rem;
    display: flex;
    align-items: flex-end;   /* sit the glyph low in the disc */
    justify-content: center;
    border-radius: 50%;
    border: none;
    overflow: hidden;        /* oversized emoji is clipped by the round edge */
    /* Light rosé disc so the avatar reads as a container, not a bare emoji —
       translucent pink over the brand-red bar lands as a soft lighter tint. */
    background: rgba(255, 228, 236, 0.22);
    font-size: 1.875rem;     /* 30px — overflows the 40px disc, clips top & sides */
    line-height: normal;     /* browser default line box; flex-end + overflow
                                still clip the oversized glyph top & sides */
    padding: 0;
    cursor: pointer;
}

#new-session-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem; /* 6px between icon and label */
    padding: 0.625rem 0.875rem; /* 10px/14px */
    font: inherit;
    font-size: 0.875rem; /* 14px */
    font-weight: 500;
    color: #fff;
    background: rgba(255, 255, 255, 0); /* not `transparent` — keyword hazes through black mid-fade, see #composer::before */
    border: none;
    border-radius: 0.5rem; /* 8px */
    cursor: pointer;
    transition: background-color 0.12s ease;
}
#new-session-btn:hover { background: rgba(255, 255, 255, 0.18); }
#new-session-btn:active { background: rgba(255, 255, 255, 0.28); }
/* Opt out of the global button:hover/:active brightness() filter (line ~10):
   this button has its own background-based press feedback, and the filter
   stacked on top of it made the active state read as two conflicting tints. */
#new-session-btn:hover, #new-session-btn:active { filter: none; }
/* Icon as a CSS mask so it inherits the button's color via currentColor
   (same pattern as #submit .icon further down). */
#new-session-btn .icon {
    width: 1.125rem; /* 18px */
    height: 1.125rem;
    background-color: currentColor;
    -webkit-mask: url('img/run-fast.svg') no-repeat center / contain;
    mask: url('img/run-fast.svg') no-repeat center / contain;
}

#debug-panel {
    font-size: 0.7rem;
    background: #111;
    color: #7f7;
    padding: 0.5rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    max-height: 8rem;
}

#history {
    flex: 1;
    font-size: 1.125rem; /* base for the chat bubbles; descendants with their own size still win */
    min-height: 0; /* without this, flex:1 can't shrink #history below its
                      content, so <main> overflows the keyboard-shortened
                      --vvh <body> and iOS reveal-scrolls the whole page */
    overflow-y: auto;
    overscroll-behavior-y: contain; /* reaching top/bottom doesn't bounce-scroll anything behind it */
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    /* #top-bar is position:absolute now, so #history spans from <main>'s top.
       padding-top clears the bar; the mask fades content out as it slides
       behind the bar instead of a hard slice at the bar's lower edge.
       ponytail: 4.75rem is a fixed guess at bar height (~2 text lines + its
       0.75rem padding, plus breathing room). If the alias/title ever wrap to
       more lines, have dojo.js publish --topbar-h from #top-bar.offsetHeight
       (same place it sets --vvh) and swap both values for
       calc(var(--topbar-h) + 0.75rem). */
    padding-top: 4.75rem;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 4.75rem);
            mask-image: linear-gradient(to bottom, transparent 0, #000 4.75rem);
    padding-bottom: 1rem; /* subtle space for avoiding overlap with the composer scrim */
    /* <main>'s padding-right would hold this scroll box — and so its
       scrollbar — inset from the physical edge. Cancel it with a negative
       margin, then restore the content inset with matching padding, so the
       scrollbar sits flush right while the bubbles stay where they were. */
    margin-right: calc(-1 * max(0.75rem, env(safe-area-inset-right)));
    padding-right: max(0.75rem, env(safe-area-inset-right));
}

#history .turn { padding: 0.5rem 0.75rem; border-radius: 0.875rem; max-width: 90%; line-height: 1.3; }
/* white-space: pre-wrap so a QR-reply's "quote"\n\n reply textContent (see
   dojo.js's withQuotePrefix) actually shows the blank line separating the
   quoted text from the visitor's own reply, instead of the default
   `normal` collapsing it to one run-on line — still plain textContent, no
   markup, purely a rendering difference. Scoped to .visitor only. */
#history .visitor { align-self: flex-end; background: var(--bubble-visitor-bg); color: var(--bubble-visitor-text); white-space: pre-wrap; }
#history .sparring { align-self: flex-start; background: var(--bubble-sparring-bg); color: var(--bubble-sparring-text); }

/* Status turns (formerly the separate #status element — QR-02's "no
   condition leaves the surface unexplained" now satisfied inline, as the
   last history item, instead of in a dedicated region). Not a speech
   bubble: no background, so it doesn't read as something either party said. */
#history .turn--status { align-self: flex-start; background: none; padding: 0.5rem 0.75rem; max-width: 100%; color: #a33; }

/* In-progress ("Conse  quently sparring…") gets the gradient-shimmer treatment;
   terminal status messages (errors/limits) stay the plain color above. */
#history .turn--pending {
    background: linear-gradient(90deg, #da9393, #d32f2f, #da9393);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: shimmer 1.6s linear infinite;
}

/* SA-01-8: inline extend-or-feedback block shown at the turn limit instead
   of the feedback dialog. Not a speech bubble (same reasoning as
   .turn--status above); full width, its own copy line plus a stacked
   button pair — feedback is the primary action, extend the quiet one. */
#history .turn--endchoice {
    align-self: stretch;
    background: none;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
#history .endchoice-copy { margin: 0; color: #a33; }
#history .endchoice-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
#history .endchoice-actions button {
    width: 100%;
    padding: 0.65rem;
    font: inherit;
    border: none;
    border-radius: 0.5rem;
}
#history .endchoice-feedback { background: var(--accent); color: #fff; }
/* transparent bg: the global brightness() hover has nothing to act on, so give
   it an explicit hover/active + fade, same as #new-session-btn. rgba(...,0), not
   the `transparent` keyword — see #composer::before on why the keyword hazes. */
#history .endchoice-extend { background: rgba(255, 255, 255, 0); color: #333; transition: background-color 0.12s ease; }
#history .endchoice-extend:not(:disabled):hover { background: #f0f0ee; }
#history .endchoice-extend:not(:disabled):active { background: #e4e4e0; }
#history .endchoice-actions button:disabled { opacity: 0.5; }

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Playbook: floating card, positioned the same way #title-card already is
   (fixed + centered via translate) rather than inventing a second overlay
   pattern. [hidden] by default; dojo.js fades it in for a new/empty session
   and fades it out again on the first sent message — same collapsed/[hidden]
   split as #title-card below, opacity instead of height since this card
   doesn't need to reflow anything as it appears/disappears. */
#playbook {
    /* absolute (not fixed) — fixed rubber-bands separately from the page
       during iOS overscroll, visibly detaching from the rest of the UI.
       Anchored to main instead of the viewport, so it scrolls with it. */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(88vw, 296px);
    opacity: 0.8;
    transition: opacity 300ms ease;
}
#playbook[hidden] { display: none; }
#playbook.fading { opacity: 0; }

#playbook-body {
    position: relative;
    background: #fff;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    border-radius: 1rem;
    border: 1px solid #eee;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.06), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
}

#playbook-heading { margin: 0; font-size: 1.125rem; font-weight: 700; color: #666; text-align: center; }

#playbook-heading::before,
#playbook-heading::after {
    content: "";
    display: block;
    width: 3rem;
    height: 1rem;
    background: #ddd;
    position: absolute;
    opacity: 0.8;
    border-radius: 1px;
}

#playbook-heading::before {
    left: 1.5rem;
    top: -0.5rem;
    transform: rotate(-2deg);
}

#playbook-heading::after {
    right: 1.5rem;
    top: -0.5rem;
    transform: rotate(-1deg);
}

#playbook-rules {
    margin: 0;
    padding: 0;
    list-style: none;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#playbook-rules li { display: flex; align-items: center; gap: 1rem; }
#playbook-rules p { margin: 0; font-size: 0.875rem; line-height: 1.4; color: #666; }

/* Base circle is a plain flat-color disc — a solid-color SVG circle and a
   border-radius:50% div render identically, so no fidelity is lost keeping
   this one as CSS. Numerals were exported vector digits (illustrated, not a
   typeface) — now that RethinkSans is self-hosted anyway (title card), the
   digit glyphs render as real text in that font instead of per-digit SVGs. */
.playbook-bullet {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: right;
    width: 32px;
    height: 32px;
    padding-top: 0.5rem; /* nudges the digit down to center it in the circle */
    border-radius: 50%;
    background: #aaa; /* was red (var(--accent)), then #666 — mockup lightened the bullet fill again */
    font-family: 'RethinkSans', system-ui, sans-serif;
    font-weight: 800;
    font-style: italic;
    font-size: 36px;
    line-height: 1;
    color: #fefefe;
}

/* Shared by every dark "gate" card that interrupts the surface — consent,
   the end-of-session evaluation, and the custom confirm dialog: absolute,
   centered over main (position:relative), same top/left/transform recipe
   as #playbook. Deliberately inverted against the page's light theme so
   these pop — not a prefers-color-scheme response, always dark. Each ID
   still sets its own z-index (stacking order between them) and
   border-radius (varies slightly by card). */
.gate-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 360px);
    max-height: 70dvh; /* escape hatch if content ever runs long, on a small phone */
    overflow-y: auto;
    background: #1a1a1a;
    border: 1px solid #333;
    color: #f2f2f2;
    color-scheme: dark; /* native checkbox rendering matches the dark card */
    padding: 0.75rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); /* lifts the card off the page it's floating over */
    border-radius: 1.25rem;
    opacity: 1;
    transition: opacity 300ms ease; /* same recipe as #playbook's fade */
}
.gate-card[hidden] { display: none; } /* same explicit belt-and-suspenders as #playbook/#reply-quote/#title-card */
.gate-card.fading { opacity: 0; }
/* Global `a`/`a:visited` (line 58) are tuned for the light page background and
   fail contrast against this card's #1a1a1a — lighten both for the ToS/Privacy
   links in #retention's consent copy. */
.gate-card a { color: #ff6b6b; }
.gate-card a:visited { color: #c99a75; }

#retention {
    /* z-index above #playbook (stacks above it wherever the two overlap —
       ToS is the one that must win), below #eval-dialog's 12 and
       #confirm-dialog's 13 (never shown together in practice, but if they
       ever were, the more time-sensitive prompt should win). */
    z-index: 11;
}

#consent-heading {
    margin: 0.25rem 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: #fefefe;
}

#consent-optional-heading {
    margin: 0.75rem 0 0.25rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #aaa;
    text-transform: uppercase;
}

.consent-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0.6rem 0;
    line-height: 1.35;
}

.consent-row input { margin-top: 0.2rem; width: 1.2rem; height: 1.2rem; flex-shrink: 0; }

#consent-confirm {
    width: 100%;
    padding: 0.65rem;
    font: inherit;
    margin-top: 0.25rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 0.5rem;
}
#consent-confirm:disabled { opacity: 0.5; }

/* End-of-session feedback dialog — see .gate-card above for the shared
   overlay treatment. z-index above #retention's 11, below
   #confirm-dialog's 13: the two never show together in practice, but if
   they ever did, the dialog reporting on a session that's already ending
   should win. */
#eval-dialog {
    z-index: 12;
}

/* Custom confirm dialog, replacing window.confirm() for "End this
   session?" — see .gate-card above for the shared overlay treatment.
   Highest of the three gate cards: the most time-sensitive prompt, and
   the one whose own action can open #eval-dialog next. */
#confirm-dialog {
    z-index: 13;
}

#confirm-heading {
    margin: 0.25rem 0 0.5rem;
    font-size: 1.125rem;
    font-weight: 700;
    color: #fefefe;
}

#confirm-description {
    margin: 0;
    color: #ccc;
    line-height: 1.35;
}

#eval-heading {
    margin: 0.25rem 0 0.5rem;
    font-size: 1.125rem;
    font-weight: 700;
    color: #fefefe;
}

.eval-question { border: none; margin: 0 0 1rem; padding: 0; }
.eval-question legend { padding: 0 0 0.4rem; font-weight: 600; }

/* Reserves one line above the gloves for the selected option's label, so
   picking a value doesn't shift anything else in the dialog. */
.eval-scale-label {
    min-height: 1.2em;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
    color: #ccc;
    text-align: center;
}

.eval-glove-rating {
    display: flex;
    flex-direction: row-reverse; /* DOM is high-to-low; this displays it low-to-high — see dojo.php's note */
    justify-content: center;
    gap: 0.4rem;
}

/* Visually hidden, not display:none — stays in the tab/focus order (native
   radio semantics, same as any other input here) even though the icon
   label is what's actually seen. */
.eval-glove-rating input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.eval-glove-rating label {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    background-color: #444; /* unfilled */
    -webkit-mask-image: url('img/glove.svg');
    mask-image: url('img/glove.svg');
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
    cursor: pointer;
}

.eval-glove-rating input:checked ~ label { background-color: var(--accent); }

#eval-feedback-label { display: block; margin: 0.5rem 0 0.4rem; font-weight: 600; }

#eval-feedback {
    width: 100%;
    min-height: 4rem;
    padding: 0.5rem;
    font: inherit;
    color: inherit;
    background: #262626;
    border: 1px solid #333;
    border-radius: 0.5rem;
    resize: vertical;
}

#eval-actions, #confirm-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

#eval-skip, #eval-submit, #eval-start-new, #eval-go-to-start, #confirm-cancel, #confirm-ok {
    flex: 1;
    width: 100%;
    padding: 0.65rem;
    font: inherit;
    border: none;
    border-radius: 0.5rem;
}
#eval-skip, #eval-go-to-start, #confirm-cancel { background: #333; color: #f2f2f2; }
#eval-submit, #eval-start-new, #confirm-ok { background: var(--accent); color: #fff; }
#eval-go-to-start { margin-top: 0.5rem; }

#eval-success-message { margin: 0 0 0.75rem; color: #ccc; line-height: 1.35; } /* same text style as #confirm-description */

/* QR-reply flow: non-editable quote of the AI response being replied to,
   shown above #composer-row. Never inserted into the textarea (never counted
   against CONTRIBUTION_MAX_CHARS) — see dojo.js's showReplyQuote/hideReplyQuote. */
#reply-quote {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    margin-bottom: 0.5rem;
    padding: 0.6rem 2rem 0.6rem 0.85rem; /* right padding clears the cancel button */
    background: var(--bubble-sparring-bg);
    border-radius: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.35;
}

/* #reply-quote's own `display: flex` above outranks the UA stylesheet's
   [hidden] { display: none } (author rule beats UA default regardless of
   attribute state) — without this, toggling the `hidden` attribute in JS
   (showReplyQuote/hideReplyQuote) has no visible effect at all. Same fix
   already applied to #title-card below. */
#reply-quote[hidden] { display: none; }

#reply-quote-label {
    margin: 0;
    font-weight: 600;
    font-size: 0.75rem;
    color: #666;
}

#reply-quote-text {
    margin: 0;
    /* long AI responses are still fully sent to the LLM as context — this
       clamp is cosmetic only, it never truncates what's actually stored/sent. */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

#reply-quote-cancel {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    width: 1.5rem;
    height: 1.5rem;
    line-height: 1;
    font-size: 1.1rem;
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
}

#composer {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Scrim: fades history content out before it reaches the composer, matching
   the Prompt Area's floating-over-content look in the mockups. rgba(...,0),
   not the `transparent` keyword, for the transparent stop — some engines
   interpolate `transparent` through transparent-black and produce a visible
   gray haze instead of a clean fade. */
#composer::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    height: 1.5rem;
    background: linear-gradient(rgba(255, 255, 255, 0), #fff);
    pointer-events: none;
}

/* This box IS Figma's "Textarea + Button" component (node 42:543) — the
   rounded/bordered/shadowed card, not the bare <textarea>. Its three
   defined states (Normal/Focused/Disabled) all restyle the whole box, not
   just an inner focus ring — border color and shadow depth both change, so
   focus is handled here via :focus-within, and the field's own native
   focus outline is suppressed below (the box IS the focus indicator). */
#composer-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem; /* 8px */
    min-height: 4.5rem; /* 72px */
    padding: 0.875rem; /* 14px */
    background: #fff;
    border: 1px solid #999; /* Normal */
    border-radius: 1.25rem; /* 20px */
    box-shadow: 0 27px 8px rgba(0, 0, 0, 0), 0 17px 7px rgba(0, 0, 0, 0.01),
                0 10px 6px rgba(0, 0, 0, 0.02), 0 4px 4px rgba(0, 0, 0, 0.03),
                0 1px 2px rgba(0, 0, 0, 0.04); /* Normal */
    transition: border-color 150ms ease, box-shadow 150ms ease;
}
#composer-row:focus-within {
    border-color: #777; /* Focused */
    box-shadow: 0 35px 10px rgba(0, 0, 0, 0), 0 22px 9px rgba(0, 0, 0, 0.01),
                0 13px 8px rgba(0, 0, 0, 0.03), 0 6px 6px rgba(0, 0, 0, 0.05),
                0 1px 3px rgba(0, 0, 0, 0.06); /* Focused */
}
#composer-row:has(#contribution:disabled) {
    background: #fafafa; /* Disabled — border/shadow same as Normal per spec */
}

#contribution {
    flex: 1;
    resize: none;
    border: none;
    padding: 0;
    background: transparent;
    font: inherit;
    font-size: 1rem; /* 16px */
    line-height: 1.25rem;
    /* 5 lines cap; JS grows height to fit content up to this, then scrolls. */
    max-height: 6.25rem;
    overflow-y: auto;
    color: #333;
}
#contribution:focus { outline: none; } /* the box's own border/shadow above is the focus indicator */
#contribution:disabled { color: #999; }
#contribution::placeholder { color: #999; }

#composer-footer { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.875rem; color: #666; }
#composer-disclaimer { margin: 0; }
/* Segmented char-progress bar (replaces the old remaining-char number).
   ~80x15px, 10 segments built by dojo.js. Segments fill red (matching the
   particle burst palette in particles.js); the lit segments pulse once
   >=80% of the limit is used — the "running out of room" warning. */
#char-progress {
    flex-shrink: 0;
    align-self: center;
    display: flex;
    gap: 2px;
    width: 80px;
    height: 15px;
    transform: skewX(-15deg);          /* slight forward slant */
}
#char-progress span {
    flex: 1 1 0;
    background: #d9d9d9;               /* light gray — empty */
    border-radius: 1px;
    transition: background-color 120ms ease;
}
#char-progress span.filled { background: #d32f2f; }       /* red */

@keyframes char-progress-bump {
    0%, 100% { transform: skewX(-15deg) translateX(0) translateY(0) scale(1); }
    20%  { transform: skewX(-15deg) translateX(-5px) translateY(2px) scale(1.15); }
    40%  { transform: skewX(-15deg) translateX(5px) translateY(-2px) scale(1.1); }
    60%  { transform: skewX(-15deg) translateX(-3px) translateY(2px) scale(1.05); }
    80%  { transform: skewX(-15deg) translateX(2px) translateY(-1px) scale(1.02); }
}
#char-progress.bumping { animation: char-progress-bump 280ms ease; }

/* >=80% used: lit segments pulse (.pulsing added by dojo.js). On the
   segments, not #char-progress, so it never collides with the container's
   one-shot .bumping shake. dojo.js re-adds the class to every lit segment
   on each change so they share one animation phase. */
@keyframes char-progress-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}
#char-progress span.pulsing { animation: char-progress-pulse 900ms ease-in-out infinite; }

#submit {
    flex-shrink: 0;
    width: 2.75rem; /* 44px */
    height: 2.75rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--accent);
}
#submit:disabled { opacity: 0.5; }

/* Icon as a CSS mask (not inline SVG) so it's colored via currentColor and
   swapping icons is a one-word class change, not an HTML/asset edit. Both
   variants stay defined here even though only one is active. */
#submit .icon {
    width: 40px; /* matches Figma's 40px icon inside the 44px send button */
    height: 40px;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}
#submit .icon--arrow {
    -webkit-mask-image: url('img/arrow.svg');
    mask-image: url('img/arrow.svg');
}
#submit .icon--glove {
    -webkit-mask-image: url('img/glove.svg');
    mask-image: url('img/glove.svg');
}

/*
|--------------------------------------------------------------------------
| Juiciness (TODO.md JUICYNESS)
|--------------------------------------------------------------------------
*/

.particle-burst {
    position: fixed;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 2001; /* above #title-card (2000) so the SPAR! burst isn't hidden behind it */
}

@keyframes punch {
    0% { transform: scale(1); }
    30% { transform: scale(0.85); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

#submit.punching { animation: punch 220ms ease; }

@keyframes wiggle {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

#composer.wiggling { animation: wiggle 350ms ease; }

/*
|--------------------------------------------------------------------------
| Title Card (QR-02)
|--------------------------------------------------------------------------
|
| RethinkSans is a custom font, not a system font — the mockups use it for
| the title card's "SPAR!" wordmark. It's a open-source font, so it's not
| bundled with the OS; we self-host it here.
|
*/

/* Floating box, not full-screen — width fixed so translateX(-100%/100%)
   below lands exactly at the box's own edges, and overflow:hidden clips
   both the sliding lines and the box's own grow/shrink. Height is a fixed
   value (not auto) so it has a real number to transition from/to 0 — and
   because of the project-wide box-sizing:border-box rule, height:0 also
   collapses the padding, so the box truly disappears, not just its content. */
#title-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(80vw, 20rem);
    height: 8rem;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #000;
    color: #fff;
    border-radius: 1.25rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    font-size: 3.5rem;
    font-weight: 800;
    font-style: italic;
    font-family: 'RethinkSans', system-ui, sans-serif;
    letter-spacing: 0.05em;
    z-index: 2000;
    pointer-events: none;
    opacity: 1;
    transition: height 250ms ease, opacity 200ms ease;
}
#title-card[hidden] { display: none; }
#title-card.collapsed { height: 0; opacity: 0; }

/* All three words sit in the same spot — each line covers the full box
   (position:absolute + inset:0) and centers itself, so they stack in place
   instead of one under another. translateX(-100%)/(100%) then means "just
   off the box", not "off-screen", since each line is still full-width. */
.title-card__line {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.title-card__line--slide {
    transform: translateX(100%); /* pre-animation state, matches keyframe's 0% (right-to-left entry) */
    opacity: 0;
    animation: title-card-slide 1000ms ease-in-out forwards;
}
.title-card__line--slide:nth-child(2) {
    animation-delay: 1050ms; /* starts once line 1's slide-through (1000ms) has finished */
}
/* SPAR! is the payoff line: fades in/out and grows from center instead of
   sliding — accent-colored to land as the punchline. */
.title-card__line--grow {
    color: var(--accent);
    opacity: 0;
    transform: scale(0.4);
    animation: title-card-grow 1000ms ease-in-out forwards;
    animation-delay: 2100ms; /* starts once line 2's slide-through (1050ms delay + 1000ms) has finished */
}

@keyframes title-card-slide {
    0% { transform: translateX(100%); opacity: 0; }
    15% { transform: translateX(0); opacity: 1; }
    70% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(-100%); opacity: 0; }
}

@keyframes title-card-grow {
    0% { transform: scale(0.4); opacity: 0; }
    30% { transform: scale(1.15); opacity: 1; }
    45% { transform: scale(1); opacity: 1; }
    70% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.3); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    #submit.punching,
    #composer.wiggling,
    #char-progress.bumping,
    #char-progress span.pulsing {
        animation: none;
    }
    #char-progress span {
        transition: none; /* color still changes, just not eased */
    }
    #composer-row {
        transition: none;
    }
    #playbook {
        transition: none;
    }
    #history .turn--pending {
        animation: none;
        background-position: 0 0; /* freeze on a static mid-gradient frame, still legible */
    }
    #session-title.title-pending {
        animation: none;
        background-position: 0 0; /* freeze on a static mid-gradient frame, still legible */
    }
    .title-card__line {
        position: static; /* motion off: back to normal flow so all 3 stack, don't overlap */
        animation: none;
        opacity: 1; /* base state is opacity:0 pre-animation — pin it visible with motion off */
        transform: none;
    }
    #title-card {
        height: auto;
        flex-direction: column;
        padding: 1rem 1.5rem;
        transition: none;
    }
    .particle-burst { display: none; }
}
