/*
 * Home and play: one document, two views (body[data-view="home"|"play"]).
 * Builds on base.css. The 3D board is one canvas (#stage) that the hero frames
 * on the right (below the copy on phones) and the game frames full-screen.
 */

body.app { overflow-x: hidden; }

/* ── The stage ───────────────────────────────────────────────────────── */
/* One canvas behind everything: the story scrolls over it, the coda covers
   it, the game sits on it. */
.stage-wrap {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background: var(--night-0);
}
.stage { width: 100%; height: 100%; display: block; opacity: 0; transition: opacity 1.1s var(--ease-out); }
.stage.ready { opacity: 1; }
.stage-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(120% 90% at 60% 45%, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}
.stage-fallback { position: absolute; inset: 0; }
body[data-view="play"] .stage { touch-action: none; }

/* ── The story ───────────────────────────────────────────────────────── */
/* Without JavaScript the chapters are simply stacked sections. With it
   (body.story-live) the track is tall, the chapters pin, and the scroll
   drives the camera (story.js). */
.story { position: relative; z-index: 1; }
.chapter {
    position: relative;
    max-width: 36rem;
    padding: var(--s-8) var(--gutter);
    padding-left: max(var(--gutter), calc((100vw - 84rem) / 2 + var(--gutter)));
}
body.story-live .story { height: 560vh; }
/* The chapters pad themselves clear of the site bar, so the track starts
   under it, not below it; otherwise every chapter sat a bar-height low and
   the hero's button fell below the fold on phones. */
body.story-live .story { margin-top: calc(-1 * var(--bar-h)); }
body.story-live .chapters {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100svh;
    pointer-events: none;
}
body.story-live .chapter {
    position: absolute;
    inset: 0;
    max-width: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: calc(var(--bar-h) + var(--s-6));
    padding-bottom: var(--s-8);
    opacity: 0;
    visibility: hidden;
    will-change: opacity, transform;
    /* A scrim that follows the copy, so text never sits on a busy board. */
    /* Deep enough across the headline's full width that the table's rails
       don't run through the words. */
    background: linear-gradient(90deg, rgba(5, 11, 8, 0.9) 0%, rgba(5, 11, 8, 0.8) 28%, rgba(5, 11, 8, 0.5) 44%, rgba(5, 11, 8, 0) 62%);
}
body.story-live .chapter > * { max-width: 34rem; }
body.story-live .chapter.is-live a, body.story-live .chapter.is-live button { pointer-events: auto; }
body.story-live .chapter-0 { opacity: 1; visibility: visible; }

.chapter .kicker {
    display: inline-flex;
    align-items: center;
    gap: 0.8em;
    margin-bottom: var(--s-5);
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--emph);
}
.chapter .kicker .n { color: var(--text-3); letter-spacing: 0.04em; }
.chapter .kicker .n::after { content: ''; display: inline-block; width: 1.6rem; height: 1px; margin-left: 0.8em; vertical-align: middle; background: var(--line-2); }
.chapter h1 { font-size: clamp(3.3rem, 1.8rem + 5.6vw, 6.6rem); max-width: 9.5ch; line-height: 0.96; letter-spacing: -0.02em; }
.chapter h2 { font-size: clamp(2.7rem, 1.6rem + 4vw, 5rem); max-width: 11ch; line-height: 0.98; letter-spacing: -0.015em; }
.chapter h1 em, .chapter h2 em { font-style: italic; color: var(--emph); }
.chapter h1, .chapter h2 { text-wrap: balance; }
.lead-short { display: none; }
@media (max-width: 430px) { .lead-long { display: none; } .lead-short { display: inline; } }
.chapter p:not(.kicker):not(.scroll-cue) { margin-top: var(--s-5); max-width: 30rem; font-size: var(--t-4); line-height: 1.55; color: var(--text-2); text-wrap: pretty; }
.chapter .cta { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-4) var(--s-6); margin-top: var(--s-6); }
.chapter .arrow-link { margin-top: var(--s-5); }
.chapter .cta .arrow-link { margin-top: 0; }
.scroll-cue {
    position: absolute;
    left: 50%;
    bottom: var(--s-5);
    transform: translateX(-50%);
    font-size: var(--t-1);
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.04em;
}
.scroll-cue::after { content: ''; display: block; width: 1px; height: 26px; margin: 8px auto 0; background: linear-gradient(var(--text-3), transparent); animation: cue 2.2s var(--ease-in-out) infinite; }
@keyframes cue { 0%, 100% { transform: scaleY(0.4); transform-origin: top; } 50% { transform: scaleY(1); transform-origin: top; } }
body:not(.story-live) .scroll-cue { display: none; }

@media (max-width: 860px) {
    body.story-live .story { height: 520vh; }
    /* Phones: the scene fills the top, the words sit in the bottom third on
       a scrim rising from the bottom edge. */
    body.story-live .chapter {
        justify-content: flex-end;
        padding: calc(var(--bar-h) + var(--s-4)) var(--gutter) max(var(--s-6), calc(env(safe-area-inset-bottom) + var(--s-3)));
        /* Rises past the headline: the track's bright tiles sit right behind it. */
        background: linear-gradient(0deg, rgba(5, 11, 8, 0.95) 0%, rgba(5, 11, 8, 0.86) 40%, rgba(5, 11, 8, 0.6) 56%, rgba(5, 11, 8, 0) 76%);
    }
    .chapter .kicker { margin-bottom: var(--s-3); }
    .chapter h1 { font-size: clamp(2.6rem, 1.5rem + 6.4vw, 3.4rem); }
    .chapter h2 { font-size: clamp(2.3rem, 1.4rem + 5.4vw, 3.1rem); }
    .chapter p:not(.kicker):not(.scroll-cue) { margin-top: var(--s-3); font-size: 1rem; }
    .chapter .cta { margin-top: var(--s-4); }
    .scroll-cue { display: none; }
}

/* ── Coda (after the story) ──────────────────────────────────────────── */
.coda {
    position: relative;
    z-index: 2;
    /* The arena's jade carries over the edge instead of stopping cold. */
    background: radial-gradient(90% 34rem at 50% 0, color-mix(in srgb, var(--night-3) 70%, var(--bg)), transparent 72%), var(--bg);
    box-shadow: 0 -40px 80px 20px var(--bg);
}

/* The last word before the footer: an invitation, not a link list. */
.finale { text-align: center; background: radial-gradient(60% 80% at 50% 100%, color-mix(in srgb, var(--jade) 26%, transparent), transparent 70%); }
.finale .wrap { display: grid; justify-items: center; gap: var(--s-4); }
.finale h2 { font-size: clamp(2.6rem, 1.6rem + 4vw, 4.5rem); line-height: 1; letter-spacing: -0.015em; }
.finale h2 em { font-style: italic; color: var(--emph); }
.finale p:not(.eyebrow) { max-width: 30rem; color: var(--text-2); font-size: var(--t-4); text-wrap: pretty; }
.finale .btn { margin-top: var(--s-3); }

/* ── Home, lower sections ───────────────────────────────────────────── */
.band { padding: var(--s-9) 0; border-top: 1px solid var(--line); }
.band:first-child { border-top: 0; }
.band h2 { max-width: 20ch; }
.two { display: grid; grid-template-columns: 1fr 1.1fr; gap: var(--s-7); align-items: start; }
.intro-text { font-size: 1.125rem; line-height: 1.7; color: var(--text-2); }
.intro-text p + p { margin-top: 1em; }
.band .eyebrow { margin-bottom: var(--s-3); }

.home-fig .fig-head { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3) var(--s-7); align-items: end; margin-bottom: var(--s-6); }
.home-fig .fig-head .eyebrow, .home-fig .fig-head h2 { grid-column: 1; }
.home-fig .fig-sub { grid-column: 2; grid-row: 1 / span 2; color: var(--text-2); }
.home-fig .fig-frame {
    padding: var(--s-5) var(--s-5) var(--s-3);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    background: var(--bg-raised);
}
.home-fig figcaption { margin-top: var(--s-3); font-size: var(--t-2); color: var(--text-2); }
.key { display: inline-block; width: 0.9em; height: 0.9em; border-radius: 3px; vertical-align: -0.1em; margin-right: 0.35em; }
.key-you { background: color-mix(in srgb, var(--you) 45%, transparent); border: 1px solid var(--you); }
.key-ai { background: color-mix(in srgb, var(--ai) 45%, transparent); border: 1px solid var(--ai); margin-left: 0.3em; }

.winchart { width: 100%; height: auto; font-family: var(--mono); }
.winchart.wcm { display: none; }
@media (max-width: 600px) { .winchart.wc { display: none; } .winchart.wcm { display: block; } }
.winchart .raw { fill: none; stroke: var(--text-3); stroke-width: 1; opacity: 0.35; }
.winchart .end { fill: var(--text); }
.winchart text { fill: var(--text-3); }
/* A halo in the frame's colour, so labels read over the line and grid. */
.winchart .note, .winchart .scrub text { paint-order: stroke; stroke: var(--bg-raised); stroke-width: 5px; stroke-linejoin: round; }
.winchart .note { fill: var(--text-2); }
.winchart .note.you { fill: var(--you-text); }
.winchart .note.ai { fill: var(--ai-text); }
.winchart .scrub line { stroke: var(--text-2); stroke-width: 1; }
.winchart .scrub text { fill: var(--text); }
.winchart .scrub circle { fill: var(--text); }
.winchart .grid { stroke: var(--line); stroke-width: 1; }
.winchart .mid { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 3 4; }
.winchart .line { fill: none; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; }
.winchart .area-you { fill: color-mix(in srgb, var(--you) 26%, transparent); }
.winchart .area-ai { fill: color-mix(in srgb, var(--ai) 30%, transparent); }
.winchart .cap { stroke: var(--bg-raised); stroke-width: 2; }
.winchart .cap-you { fill: var(--you); }
.winchart .cap-ai { fill: var(--ai-deep); }

.numbers-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--line);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
.numbers-grid li { background: var(--bg); padding: var(--s-6) var(--s-5) var(--s-6) 0; display: grid; gap: var(--s-2); align-content: start; color: var(--text-2); font-size: var(--t-2); }
.numbers-grid li + li { padding-left: var(--s-5); }
.numbers-grid .big { font-family: var(--serif); font-size: clamp(2.6rem, 1.8rem + 2.4vw, 3.8rem); font-weight: 400; letter-spacing: -0.02em; color: var(--text); line-height: 1; }
.band.numbers { padding: var(--s-7) 0; }

.teaser-head { display: grid; grid-template-columns: 1fr auto; gap: var(--s-3) var(--s-6); align-items: end; margin-bottom: var(--s-6); }
.teaser-head .eyebrow, .teaser-head h2 { grid-column: 1; }
.teaser-head .arrow-link { grid-column: 2; grid-row: 2; white-space: nowrap; }
.teaser-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4); }
.teaser-cards a {
    display: grid;
    gap: var(--s-3);
    height: 100%;
    padding: var(--s-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    background: var(--bg-raised);
    text-decoration: none;
    transition: border-color 0.2s, transform 0.25s var(--ease-out), box-shadow 0.25s;
}
.teaser-cards a:hover { border-color: var(--line-2); transform: translateY(-3px); box-shadow: var(--shadow); }
.teaser-cards .k { font-family: var(--mono); font-size: 0.75rem; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--emph); }
.teaser-cards .t { font-family: var(--serif); font-size: 1.6rem; line-height: 1.15; color: var(--text); }
/* Version names in the sans: in Instrument Serif "V16" reads as "Vl6". */
.teaser-cards .ver { font-family: var(--sans); font-size: 0.8em; font-weight: 600; letter-spacing: -0.01em; }

.band.closing { text-align: center; padding: var(--s-9) 0; border-top: 0; background: radial-gradient(50rem 20rem at 50% 0%, rgba(143, 217, 182, 0.07), transparent 70%), var(--bg); }
.closing-inner { display: grid; justify-items: center; gap: var(--s-4); }
.closing h2 { max-width: none; font-size: var(--t-7); }
.closing h2 em { font-style: italic; color: var(--emph); }
.closing p { color: var(--text-2); max-width: 32rem; }
.closing .btn { margin-top: var(--s-3); }


@media (max-width: 860px) {
    .band { padding: var(--s-8) 0; }
    .two, .home-fig .fig-head, .teaser-head { grid-template-columns: 1fr; gap: var(--s-4); }
    .home-fig .fig-sub { grid-column: 1; grid-row: auto; }
    .teaser-head .arrow-link { grid-column: 1; grid-row: auto; }
    .numbers-grid { grid-template-columns: 1fr 1fr; }
    .numbers-grid li, .numbers-grid li + li { padding: var(--s-5) var(--s-4) var(--s-5) 0; }
    .numbers-grid li:nth-child(even) { padding-left: var(--s-4); }
    .teaser-cards { grid-template-columns: 1fr; }
    .home-fig .fig-frame { padding: var(--s-3) var(--s-2) var(--s-2); }
}

/* ── Views ───────────────────────────────────────────────────────────── */
body[data-view="play"] #main,
body[data-view="play"] .hero-scroll { display: none; }
body[data-view="play"] .play { display: block; }
body[data-view="home"] .play { display: none; }
.play[hidden] { display: none !important; }
body[data-view="play"] .play[hidden] { display: block !important; }
body[data-view="play"] { overflow: hidden; height: 100dvh; }
body[data-view="play"] .sitebar { position: fixed; left: 0; right: 0; background: color-mix(in srgb, var(--night-0) 72%, transparent); }

/* Match status in the bar */
.match-status {
    display: none;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    margin-right: auto;
    padding: 0.3rem 0.8rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    font-size: var(--t-2);
    font-weight: 600;
}
body[data-view="play"] .match-status:not([hidden]) { display: inline-flex; }
body[data-view="play"] .brand { margin-right: var(--s-3); }
body[data-view="play"] .nav-play { display: none; }
.ms-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.match-status[data-turn="you"] .ms-dot { background: var(--you); box-shadow: 0 0 0 3px color-mix(in srgb, var(--you) 30%, transparent); }
.match-status[data-turn="ai"] .ms-dot { background: var(--ai); animation: think 1.1s ease-in-out infinite; }
@keyframes think { 50% { opacity: 0.35; } }
.ms-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Play ────────────────────────────────────────────────────────────── */
.play {
    position: fixed;
    inset: var(--bar-h) 0 0 0;
    z-index: 5;
    pointer-events: none;
    --panel-w: 22.5rem;
}
.play > * { pointer-events: auto; }

.dock {
    position: absolute;
    left: 0;
    right: calc(var(--panel-w) + 2rem);
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-3);
    pointer-events: none;
}
.dock > * { pointer-events: auto; }
.dock-pill {
    display: flex;
    align-items: center;
    gap: var(--s-4);
    /* A fixed width: the pill doesn't jump as its message changes. */
    width: min(28rem, calc(100vw - 2rem));
    padding: 0.5rem 0.5rem 0.5rem 1.4rem;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    background: color-mix(in srgb, var(--night-1) 86%, transparent);
    box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.8);
}
.dock-status { flex: 1; min-width: 0; }
.turn-line { font-weight: 650; font-size: var(--t-3); line-height: 1.3; }
.turn-sub { font-size: var(--t-1); color: var(--text-2); min-height: 1.3em; }
.turn-line, .turn-sub { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
@media (max-width: 400px) { .turn-line { font-size: var(--t-2); } }
/* AlphaLudo's aside: a few words in the serif, in its colour. */
.turn-sub .voice { margin-left: 0.4em; font-family: var(--serif); font-style: italic; font-size: 1.15em; color: var(--ai-text); }

.roll-btn {
    position: relative;
    flex: none;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 3px;
    width: 4.5rem;
    height: 4.5rem;
    border: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fffaf0, var(--ivory) 55%, #c9bc98);
    color: var(--accent-ink);
    font-weight: 700;
    box-shadow: 0 8px 24px -8px rgba(239, 228, 200, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.16);
    transition: transform 0.2s var(--ease-out), background 0.3s, box-shadow 0.3s;
    -webkit-tap-highlight-color: transparent;
}
.roll-btn:hover:not([aria-disabled="true"]) { transform: translateY(-2px) scale(1.04); }
.roll-btn:active:not([aria-disabled="true"]) { transform: scale(0.95); }
.roll-btn:disabled, .roll-btn[aria-disabled="true"] {
    cursor: default;
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line-2);
}
.roll-btn[data-state="ready"] { animation: ready 1.8s ease-in-out 4; }
.roll-btn[data-who="ai"] { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ai) 75%, transparent); }
@keyframes ready { 50% { box-shadow: 0 8px 34px -2px rgba(143, 217, 182, 0.7), inset 0 -3px 0 rgba(0, 0, 0, 0.16); } }
.roll-face {
    width: 1.75rem; height: 1.75rem;
    border-radius: 6px;
    background: #fbf5e8;
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.25);
    display: grid;
    grid-template: repeat(3, 1fr) / repeat(3, 1fr);
    padding: 3px;
    transition: transform 0.3s var(--ease-out);
}
.roll-btn[data-state="rolling"] .roll-face { animation: tumble 0.5s linear infinite; }
@keyframes tumble { to { transform: rotate(360deg); } }
.roll-face i { width: 5px; height: 5px; border-radius: 50%; background: #1c140e; place-self: center; }
/* Before a roll the face is an icon, not a result: faint pips. */
.roll-btn.idle-face .roll-face i { opacity: 0.28; }
.roll-label { font-size: var(--t-1); letter-spacing: 0.02em; line-height: 1; }
.roll-label:empty { display: none; }
.roll-btn[aria-disabled="true"] .roll-label { color: var(--text-2); }

/* 1–4 over the pieces you can move, matching the choices in the dock. */
.play > .piece-badges { position: fixed; inset: 0; pointer-events: none; z-index: 1; }
.piece-badge {
    position: absolute;
    left: 0; top: 0;
    min-width: 1.35rem; height: 1.35rem;
    padding: 0 0.3rem;
    display: grid; place-items: center;
    border-radius: 999px;
    background: var(--ivory);
    color: var(--accent-ink);
    font: 600 0.75rem/1 var(--mono);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 2px color-mix(in srgb, var(--you) 70%, transparent);
    animation: badge-in 0.25s var(--ease-out);
}
@keyframes badge-in { from { opacity: 0; } }
.play.reviewing .piece-badges { display: none; }

.token-keys { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s-2); }
.token-keys:empty { display: none; }
.token-keys button {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 44px;
    padding: 0 0.9rem 0 0.45rem;
    border: 1px solid color-mix(in srgb, var(--you) 55%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--night-1) 90%, transparent);
    color: var(--text);
    font-size: var(--t-2);
    font-weight: 600;
}
.token-keys button:hover, .token-keys button:focus-visible { background: color-mix(in srgb, var(--you) 24%, var(--night-1)); }
.token-keys .chip-detail { font-family: var(--mono); font-size: 0.75rem; font-weight: 500; color: var(--text-3); }
.token-keys kbd { min-width: 1.6rem; text-align: center; border-radius: 999px; background: color-mix(in srgb, var(--you) 30%, transparent); border: 0; }
.token-keys .coach { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Panel */
.panel {
    position: absolute;
    top: var(--s-4);
    right: var(--s-4);
    bottom: var(--s-4);
    width: var(--panel-w);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    background: color-mix(in srgb, var(--night-1) 90%, transparent);
    box-shadow: var(--shadow);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}
.panel > section, .panel > header, .panel > footer { padding: var(--s-4) var(--s-5); }
/* The panel scrolls; its sections never shrink into each other. */
.panel > * { flex-shrink: 0; }
.panel-foot { position: sticky; bottom: 0; background: color-mix(in srgb, var(--night-1) 96%, transparent); }
.panel > section + section { border-top: 1px solid var(--line); }
.panel h2 { font-family: var(--sans); font-size: var(--t-1); font-weight: 650; color: var(--text-3); letter-spacing: 0.02em; }
.sheet-bar, .sheet-scrim { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); border-bottom: 1px solid var(--line); }
.side-caption { font-family: var(--mono); font-size: 0.6875rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3); }
.side { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 650; }
.side-home { color: var(--text-2); font-size: var(--t-2); font-weight: 500; }
.odds-top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s-3); }
.odds-read { font-size: var(--t-1); color: var(--text-2); }
.odds-read b { color: var(--text); font-weight: 500; }
.odds-wrap { position: relative; margin-top: var(--s-3); }
.odds-chart { display: block; width: 100%; height: 110px; overflow: visible; }
.odds-chart.big { height: 150px; margin-top: var(--s-2); }
.odds-chart .mid { stroke: var(--line-2); stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.odds-chart .line-you { fill: none; stroke: var(--you-text); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.odds-chart .line-ai { fill: none; stroke: var(--ai-text); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.odds-chart .you { fill: color-mix(in srgb, var(--you) 22%, transparent); }
.odds-chart .ai { fill: color-mix(in srgb, var(--ai) 22%, transparent); }
.odds-chart .end { fill: var(--text); }
.odds-lbl { position: absolute; left: 0; font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.04em; color: var(--text-3); pointer-events: none; }
.odds-lbl.top { top: 0; }
.odds-lbl.bot { bottom: 0; }
.odds-note { margin-top: var(--s-2); font-size: var(--t-1); color: var(--text-3); }

.insight { min-height: 8.5rem; }
.insight h2 { margin-bottom: var(--s-3); }
.insight .muted, .muted { color: var(--text-3); font-size: var(--t-2); }
.decision { font-size: var(--t-2); }
.decision-line { color: var(--text); }
.decision-line b { font-weight: 650; }
.bars { list-style: none; padding: 0; margin: var(--s-3) 0 0; display: grid; gap: 6px; }
.bars li { display: grid; grid-template-columns: 6.8rem 1fr 3rem; align-items: center; gap: var(--s-2); font-size: var(--t-1); color: var(--text-2); }
.bars .bar { height: 8px; border-radius: 4px; background: var(--bg-sunk); overflow: hidden; }
.bars .bar i { display: block; height: 100%; background: var(--ai); border-radius: 4px; transition: width 0.5s var(--ease-out); }
.bars li.chosen { color: var(--text); font-weight: 600; }
.bars .pct { text-align: right; font-family: var(--mono); }
.decision-note { margin-top: var(--s-3); font-size: var(--t-1); color: var(--text-3); }

.moves { flex: 1 1 12rem; min-height: 12rem; display: flex; flex-direction: column; }
.move-list { flex: 1; min-height: 0; overflow-y: auto; margin: var(--s-2) 0 0; padding: 0; list-style: none; font-size: var(--t-1); scrollbar-width: thin; }
.move-list li { display: grid; grid-template-columns: 1.6rem 1fr auto; gap: var(--s-2); align-items: center; padding: 0.35rem 0; border-bottom: 1px solid var(--line); color: var(--text-2); }
.move-list li .who { width: 0.55rem; height: 0.55rem; border-radius: 50%; justify-self: center; }
.move-list li.you .who { background: var(--you); }
.move-list li.quiet { opacity: 0.6; }
.move-list li.ai .who { background: var(--ai); border-radius: 1px; transform: rotate(45deg) scale(0.9); }
.move-list li .d { font-family: var(--mono); color: var(--text-3); }
.move-list li.cap { color: var(--text); }
.move-list li.cap .what::after { content: ' · capture'; color: var(--alarm); font-weight: 600; }

.panel-foot {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: var(--s-2) var(--s-3) !important;
    border-top: 1px solid var(--line);
}
.pf {
    display: grid;
    justify-items: center;
    gap: 3px;
    min-height: 52px;
    padding: 6px 2px;
    border: 0;
    border-radius: var(--radius);
    background: none;
    color: var(--text-2);
    font-size: 0.75rem;
    font-weight: 550;
    transition: background 0.15s, color 0.15s;
}
.pf svg { width: 20px; height: 20px; }
.pf:hover, .pf[aria-expanded="true"] { background: var(--surface); color: var(--text); }
.pf.quiet { color: var(--text-3); }
.pf.quiet:hover { color: #ff8f7a; }
.options {
    display: grid;
    gap: var(--s-3);
    padding: var(--s-4) var(--s-5) !important;
    border-top: 1px solid var(--line);
    background: var(--bg-raised);
}
.options .sound { justify-self: start; min-height: 44px; padding: 0 0.8rem; }
.switch { display: flex; align-items: center; min-height: 44px; gap: var(--s-3); font-size: var(--t-2); color: var(--text-2); cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; border-radius: 999px; background: var(--surface-2); position: relative; margin: 0; flex: none; cursor: pointer; transition: background 0.2s; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-2); transition: transform 0.2s var(--ease-out), background 0.2s; }
.switch input:checked { background: color-mix(in srgb, var(--mint) 70%, transparent); }
.switch input:checked::after { transform: translateX(16px); background: var(--accent-ink); }

.strip { display: none; }

/* News from the table ("A six. Roll again.") appears where you're looking:
   just above the dock and its choices, not at the top of the screen. */
.toast {
    position: absolute;
    left: 50%;
    bottom: calc(100% + var(--s-3));
    translate: -50% 0;
    width: max-content;
    max-width: 90%;
    padding: 0.55rem 1rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--night-2) 92%, transparent);
    border: 1px solid var(--line-2);
    font-weight: 600;
    font-size: var(--t-2);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.25s, transform 0.3s var(--ease-out);
    pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
/* Captures are events: yours in mint, AlphaLudo's in amber. */
.toast[data-kind="you"] { color: var(--mint); border-color: color-mix(in srgb, var(--mint) 55%, transparent); }
.toast[data-kind="ai"] { color: var(--ai-text); border-color: color-mix(in srgb, var(--ai) 55%, transparent); }

@media (max-width: 1023px) {
    .play { --panel-w: 0rem; }
    .dock { left: 0; right: 0; bottom: 0; padding: 0 max(var(--s-3), env(safe-area-inset-right)) max(var(--s-3), env(safe-area-inset-bottom)) max(var(--s-3), env(safe-area-inset-left)); }
    .dock-pill { width: 100%; min-width: 0; padding-left: 1.1rem; }
    .roll-btn { width: 4.25rem; height: 4.25rem; }
    /* Clear the odds strip, unless it's hidden while you choose. */
    .toast { bottom: calc(100% + 5.5rem); }
    .play.choosing .toast { bottom: calc(100% + var(--s-3)); }
    .panel {
        top: auto; left: 0; right: 0; bottom: 0;
        width: auto;
        max-height: 78dvh;
        border-radius: var(--radius-l) var(--radius-l) 0 0;
        border-bottom: 0;
        transform: translateY(100%);
        transition: transform 0.35s var(--ease-out);
        z-index: 3;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .panel.open { transform: none; }
    /* On a phone the sheet is solid, and closes by the ✕, a tap outside it,
       a swipe down, or Esc. */
    .panel { background: var(--night-1); z-index: 4; }
    .panel-foot { background: var(--night-1); }
    .sheet-bar { display: block; position: sticky; top: 0; z-index: 1; height: 2.75rem; background: var(--night-1); touch-action: none; }
    .panel-grip { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); margin: var(--s-2) auto 0; }
    .sheet-close { position: absolute; top: 0; right: 0.25rem; width: 44px; min-height: 44px; color: var(--text-2); }
    .panel > .panel-head { padding-top: var(--s-2); }
    .insight { min-height: 0; }
    .sheet-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 3;
        background: rgba(3, 8, 6, 0.55);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s var(--ease-out);
    }
    body.sheet-open .sheet-scrim { opacity: 1; pointer-events: auto; }
    .strip {
        position: absolute;
        left: max(var(--s-3), env(safe-area-inset-left));
        right: max(var(--s-3), env(safe-area-inset-right));
        bottom: calc(max(var(--s-3), env(safe-area-inset-bottom)) + 5.75rem);
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 4px var(--s-3);
        align-items: center;
        padding: 0.6rem 0.9rem;
        border: 1px solid var(--line);
        border-radius: var(--radius-l);
        background: color-mix(in srgb, var(--night-1) 82%, transparent);
        text-align: left;
        z-index: 2;
    }
    .strip-odds { display: flex; align-items: center; gap: 0.45rem; font-size: var(--t-1); }
    .strip-odds b { font-weight: 500; color: var(--text); }
    .strip-bar { flex: 1; height: 5px; border-radius: 3px; background: var(--ai); overflow: hidden; }
    .strip-bar i { display: block; height: 100%; width: 50%; background: var(--you); transition: width 0.6s var(--ease-out); }
    .strip-last { grid-column: 1; font-size: var(--t-1); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .strip-more { grid-column: 2; grid-row: 1 / span 2; font-size: var(--t-1); font-weight: 650; color: var(--accent); }
    .strip-more::after { content: ' ↑'; }
    .odds-mini { display: block; }
}
@media (max-width: 640px) {
    .match-status { font-size: var(--t-1); padding: 0.25rem 0.65rem; }
    body[data-view="play"] .brand span { display: none; }
}

/* ── Result dialog ───────────────────────────────────────────────────── */
.result {
    width: min(34rem, calc(100vw - 2rem));
    padding: 0;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-l);
    background: var(--night-1);
    color: var(--text);
    box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.8);
}
.result::backdrop { background: rgba(8, 6, 4, 0.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.result[open] { animation: rise 0.45s var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(0.98); } }
.result-inner { padding: var(--s-6); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-4); }
.result .odds-chart { width: 100%; }
.result h2 { font-size: var(--t-6); }
.result h2 em { font-style: italic; color: var(--emph); }
/* The winner's colour: mint when you win, amber when AlphaLudo does. */
.result[data-winner="ai"] h2 em { color: var(--ai-text); }
.result .odds-chart.big { height: 120px; }
.result-sub { color: var(--text-2); }
.result-fig figcaption { margin-top: var(--s-2); font-size: var(--t-1); color: var(--text-3); }
.result-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-3); margin: 0; }
.result-stats div { padding: var(--s-3); border-radius: var(--radius); background: var(--surface); }
.result-stats dt { font-size: var(--t-1); color: var(--text-3); }
.result-stats dd { margin: 0; font-family: var(--serif); font-size: 2rem; line-height: 1.1; }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3) var(--s-4); margin-top: var(--s-2); }
.result { max-height: calc(100dvh - 2rem); overflow-y: auto; overscroll-behavior: contain; }
.result-stats dd { white-space: nowrap; }
/* Small phones: the whole result on one screen, actions full width. */
@media (max-width: 480px), (max-height: 700px) {
    .result-inner { padding: var(--s-5) var(--s-4) var(--s-4); gap: var(--s-3); }
    .result h2 { font-size: var(--t-5); }
    .result .odds-chart.big { height: 96px; }
    .result-stats { gap: var(--s-2); }
    .result-stats div { padding: var(--s-2) var(--s-3); }
    .result-stats dd { font-size: 1.5rem; }
    .result-sub { font-size: var(--t-2); }
    .result-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
    .result-actions #rematchBtn { grid-column: 1 / -1; }
    .result-actions .btn { width: 100%; justify-content: center; padding-inline: var(--s-3); }
    .result-actions .wide-only { display: none; }
}

.noscript { position: fixed; bottom: 0; left: 0; right: 0; z-index: 99; padding: var(--s-4); background: var(--night-2); text-align: center; }

/* ── Settings, rules card, result extras ─────────────────────────────── */
.settings { display: grid; gap: var(--s-2); }
.seg { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: 999px; background: var(--bg-sunk); border: 1px solid var(--line); }
.seg-label { font-size: var(--t-1); color: var(--text-3); padding: 0 0.6rem 0 0.7rem; min-width: 5.2rem; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 999px; background: none; color: var(--text-2); font-size: var(--t-1); font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.panel-actions { flex-wrap: wrap; }
.panel-actions .btn { min-height: 38px; padding: 0 0.8rem; }

.rules-card {
    position: absolute;
    left: var(--s-5);
    top: var(--s-5);
    max-height: calc(100% - 9rem);
    overflow-y: auto;
    width: min(26rem, calc(100vw - 2rem));
    padding: var(--s-5);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-l);
    background: color-mix(in srgb, var(--night-1) 94%, transparent);
    box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.8);
    z-index: 4;
    animation: rise 0.4s var(--ease-out);
}
.rules-card h2 { font-size: var(--t-4); margin-bottom: var(--s-3); }
.rules-card ul { list-style: none; padding: 0; display: grid; gap: var(--s-2); font-size: var(--t-2); color: var(--text-2); }
.rules-card li { padding-left: 1.1rem; position: relative; }
.rules-card li::before { content: ''; position: absolute; left: 0; top: 0.6em; width: 5px; height: 5px; border-radius: 50%; background: var(--text-3); }
.rules-card li:first-child::before { display: none; }
.rules-card li:first-child { padding-left: 0; }
.rules-card li .dot { margin-right: 0.35rem; }
.rules-card b { color: var(--text); font-weight: 650; }
.rules-card .btn { margin-top: var(--s-4); }
/* Focus lands on the card so a screen reader reads it; it needs no ring. */
.rules-card:focus { outline: none; }
@media (max-width: 1023px) {
    /* At the top, over AlphaLudo's side: your corner, the die and Roll stay
       in view while you read. Compact, so the board still shows. */
    .rules-card { left: var(--s-3); right: var(--s-3); top: calc(var(--bar-h) + var(--s-2)); width: auto; bottom: auto; max-height: calc(100% - var(--bar-h) - 12rem); padding: var(--s-4) var(--s-4) var(--s-3); }
    .rules-card h2 { font-size: var(--t-3); margin-bottom: var(--s-2); }
    .rules-card ul { font-size: var(--t-1); gap: var(--s-1); line-height: 1.45; }
    .rules-card .btn { margin-top: var(--s-3); min-height: 40px; }
}

.result { position: relative; }
.result-close { position: absolute; top: var(--s-2); right: var(--s-2); }
.result-close .btn { width: 44px; min-height: 44px; color: var(--text-2); }
.agree { color: var(--you-text); }
.differ { color: var(--text-3); }
.move-list .note { grid-column: 2 / -1; font-size: 0.75rem; margin-top: -2px; }

/* ── Review ───────────────────────────────────────────────────────────── */
.play.reviewing .dock-pill, .play.reviewing .token-keys, .play.reviewing .strip { display: none; }
@media (max-width: 1023px) { .play.choosing .strip { visibility: hidden; } }
/* A phone on its side: the odds and the dock stand in a column on the
   right, and the board has the rest of the screen (app.js frameBoard). */
@media (max-width: 1023px) and (max-height: 500px) and (orientation: landscape) {
    .play { --side: min(20rem, 42vw); }
    .dock {
        left: auto;
        right: max(var(--s-3), env(safe-area-inset-right));
        width: var(--side);
        padding: 0 0 max(var(--s-2), env(safe-area-inset-bottom));
    }
    .dock-pill { padding-left: 0.9rem; gap: var(--s-3); }
    .roll-btn { width: 3.75rem; height: 3.75rem; }
    .strip { left: auto; right: max(var(--s-3), env(safe-area-inset-right)); width: var(--side); top: calc(var(--bar-h) + var(--s-2)); bottom: auto; }
    .play.choosing .strip { visibility: visible; }
    .toast, .play.choosing .toast { bottom: calc(100% + var(--s-3)); }
    .rules-card { left: max(var(--s-3), env(safe-area-inset-left)); right: calc(var(--side) + 2rem); top: calc(var(--bar-h) + var(--s-2)); bottom: var(--s-3); max-height: none; }
}
.review {
    width: min(34rem, calc(100vw - 1.5rem));
    padding: var(--s-3) var(--s-4);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-l);
    background: color-mix(in srgb, var(--night-1) 90%, transparent);
    display: grid;
    gap: var(--s-2);
}
.review-top { display: flex; align-items: center; gap: var(--s-3); }
.review-text { flex: 1; min-width: 0; font-size: var(--t-2); line-height: 1.4; }
.review-text b { font-weight: 650; }
.review-text .agree { font-weight: 600; }
.review-controls { display: flex; align-items: center; gap: var(--s-2); }
.review-controls input[type="range"] { flex: 1; accent-color: var(--accent); }
.review-controls .btn { width: 40px; min-height: 40px; font-size: 1.1rem; }
.odds-chart .cursor { stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
