/* ==========================================================================
   ReflexBuddy shared game shell — Phase 4. Loaded on games with 'shell' => true.
   States on [data-game-root][data-state]: start | playing | result.
   Mobile-first; depends on tokens.css + ui.css.
   ========================================================================== */

.rb-game-page { padding-bottom: var(--rb-space-12); }

/* ---------- Title block (compact so the Start button is visible early on phones) ---------- */
.rb-game-head { max-width: 880px; padding-top: var(--rb-space-2); text-align: center; }
.rb-game-head .rb-eyebrow { justify-content: center; margin-bottom: var(--rb-space-2); }
.rb-game-head__title { margin: 0 0 var(--rb-space-2); color: var(--rb-text); font-size: clamp(1.75rem, 1.35rem + 2vw, 2.75rem); font-weight: var(--rb-fw-extrabold); letter-spacing: -.04em; line-height: 1.1; text-wrap: balance; }
.rb-game-head__intro { max-width: 60ch; margin: 0 auto var(--rb-space-3); color: var(--rb-text-muted); font-size: var(--rb-fs-base); line-height: 1.55; }
.rb-game-head__instruction {
    display: inline-flex; align-items: flex-start; gap: var(--rb-space-2);
    max-width: 62ch; margin: 0 auto var(--rb-space-4); padding: .5rem .875rem;
    border-radius: var(--rb-radius-sm); background: var(--rb-primary-soft);
    color: var(--rb-text); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-semibold); line-height: 1.45; text-align: left;
}
.rb-game-head__instruction svg { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px; color: var(--rb-primary); }

/* ---------- Game container ---------- */
.rb-game {
    --rb-stage-height: clamp(260px, 52vh, 400px);
    position: relative;
    max-width: 880px;
    padding: clamp(.75rem, .5rem + 1vw, 1.25rem);
    padding-bottom: 4.75rem;
    border: 1px solid var(--rb-border);
    border-radius: var(--rb-radius-xl);
    background: var(--rb-surface);
    box-shadow: var(--rb-shadow-card);
    scroll-margin-top: calc(var(--rb-header-height) + 8px);
}
.rb-game__sound { position: absolute; z-index: 2; bottom: 1rem; left: 1rem; display: inline-grid; width: 44px; min-width: 44px; min-height: 44px; place-items: center; padding: 0; border-radius: 50%; transition: color var(--rb-duration) ease, background-color var(--rb-duration) ease, border-color var(--rb-duration) ease, box-shadow var(--rb-duration) ease, transform var(--rb-duration) ease; }
.rb-game__sound-icon { display: grid; width: 19px; height: 19px; place-items: center; font-size: 19px; line-height: 1; }
.rb-game__sound[aria-pressed="true"] [data-game-sound-icon="on"],
.rb-game__sound[aria-pressed="false"] [data-game-sound-icon="off"] { display: block; }
.rb-game__sound[aria-pressed="true"] [data-game-sound-icon="off"],
.rb-game__sound[aria-pressed="false"] [data-game-sound-icon="on"] { display: none; }
.rb-game__sound:hover:not(:disabled) { border-color: var(--rb-primary); background: var(--rb-primary-soft); color: var(--rb-primary); box-shadow: var(--rb-shadow-sm); transform: translateY(-2px); }
.rb-game__sound:focus-visible { outline: 3px solid var(--rb-focus-ring); outline-offset: 3px; }
.rb-game__sound[aria-pressed="true"] { border-color: var(--rb-primary); color: var(--rb-primary); }
@media (prefers-reduced-motion: reduce) { .rb-game__sound { transition: none; } .rb-game__sound:hover:not(:disabled) { transform: none; } }

/* Every game uses this compact game-first identity; copy and instructions follow the playable area. */
.rb-game__identity { margin: 0 0 var(--rb-space-3); text-align: center; }
.rb-game__identity-kicker { margin: 0 0 var(--rb-space-1); color: var(--rb-text-secondary); font-size: .6875rem; font-weight: var(--rb-fw-bold); letter-spacing: .1em; line-height: 1.3; text-transform: uppercase; }
.rb-game__identity-title { margin: 0; color: var(--rb-text); font-size: clamp(1.5rem, 1.2rem + 1.15vw, 2rem); font-weight: var(--rb-fw-extrabold); letter-spacing: -.035em; line-height: 1.12; text-wrap: balance; }
.rb-game__start-actions { display: flex; align-items: center; justify-content: center; width: min(100%, 420px); }
.rb-game__start-actions .rb-game__start-button { width: min(100%, 320px); }

/* Start area and status bar share one slot of fixed height, so switching never moves the stage. */
.rb-game__bar { display: grid; min-height: 92px; margin-bottom: clamp(.625rem, .4rem + 1vw, 1rem); }
.rb-game__start, .rb-game__status { grid-area: 1 / 1; min-height: 92px; }
.rb-game__start { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--rb-space-2); }
.rb-game__start-button { width: min(100%, 320px); min-height: 60px; font-size: 1.125rem; }
.rb-game__start-button svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.rb-game__start-best { margin: 0; color: var(--rb-text-muted); font-size: var(--rb-fs-sm); }
.rb-game__start-best strong { color: var(--rb-text); font-variant-numeric: tabular-nums; }

.rb-game__status {
    display: flex; align-items: center; justify-content: space-between; gap: var(--rb-space-3);
    padding: var(--rb-space-2) var(--rb-space-2) var(--rb-space-2) var(--rb-space-4);
    border-radius: var(--rb-radius-md); background: var(--rb-surface-soft);
}
.rb-game__stats { display: flex; flex: 1 1 auto; gap: clamp(.75rem, .4rem + 2vw, 2rem); min-width: 0; margin: 0; }
.rb-game__stat { min-width: 0; }
.rb-game__stat dt { color: var(--rb-text-secondary); font-size: .6875rem; font-weight: var(--rb-fw-bold); letter-spacing: .08em; line-height: 1.3; text-transform: uppercase; }
.rb-game__stat dd { margin: 0; color: var(--rb-text); font-size: clamp(1rem, .9rem + .5vw, 1.25rem); font-weight: var(--rb-fw-extrabold); letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rb-game__restart { flex: 0 0 auto; }
.rb-game__restart svg { width: 16px; height: 16px; }

/* Stage: the game's playfield. Fixed height so nothing below it jumps while playing. */
.rb-game__stage { position: relative; overscroll-behavior: contain; }

/* State switching (display:none also removes hidden controls from the tab order). */
.rb-game:not([data-state="start"]) .rb-game__start { display: none; }
.rb-game:not([data-state="playing"]) .rb-game__status { display: none; }
.rb-game[data-state="result"] .rb-game__bar,
.rb-game[data-state="result"] .rb-game__stage { display: none; }
.rb-game:not([data-state="result"]) .rb-game-result { display: none; }
.rb-game[data-state="start"] .rb-game__stage { opacity: .92; }

/* ---------- Result screen (inside the same container) ---------- */
.rb-game-result { display: flex; flex-direction: column; gap: var(--rb-space-5); min-height: calc(var(--rb-stage-height) + 92px); padding: clamp(.5rem, .3rem + 1vw, 1rem); }
.rb-game-result__summary { display: flex; flex-direction: column; align-items: center; text-align: center; }
.rb-game-result__summary > * { margin: 0; }
.rb-game-result__summary .rb-eyebrow { margin-bottom: var(--rb-space-1); }
.rb-game-result__title { color: var(--rb-text); font-size: var(--rb-fs-lg); font-weight: var(--rb-fw-bold); letter-spacing: -.02em; outline: none; }
.rb-game-result__title:focus { outline: none; } /* programmatic focus target only (tabindex=-1), not interactive */
.rb-game-result__label { margin-top: var(--rb-space-4) !important; color: var(--rb-text-secondary); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-bold); letter-spacing: .08em; text-transform: uppercase; }
.rb-game-result__score { color: var(--rb-text); font-size: clamp(3rem, 2.2rem + 4vw, 4.5rem); font-weight: var(--rb-fw-extrabold); letter-spacing: -.05em; line-height: 1; font-variant-numeric: tabular-nums; }
.rb-game-result__unit { color: var(--rb-text-muted); font-size: .4em; font-weight: var(--rb-fw-bold); letter-spacing: 0; }
.rb-game-result__badge-row { min-height: 0; margin-top: var(--rb-space-3) !important; }
.rb-game-result__badge-row:has([hidden]) { display: none; }
.rb-game-result__badge { font-size: var(--rb-fs-sm); padding: .3rem .8rem; }
.rb-game-result__best { margin-top: var(--rb-space-3) !important; color: var(--rb-text-muted); font-size: var(--rb-fs-sm); }
.rb-game-result__best strong { color: var(--rb-text); font-variant-numeric: tabular-nums; }
.rb-game-result__note { color: var(--rb-text-muted); font-size: var(--rb-fs-xs); }
.rb-game-result__actions { display: flex; flex-direction: column; gap: var(--rb-space-3); }
.rb-game-result__actions .rb-btn svg { width: 18px; height: 18px; }
.rb-game-result__stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: var(--rb-space-2); margin: 0; }
.rb-game-result__stat { padding: var(--rb-space-3); border-radius: var(--rb-radius-sm); background: var(--rb-surface-soft); text-align: center; }
.rb-game-result__stat dt { color: var(--rb-text-secondary); font-size: var(--rb-fs-xs); font-weight: var(--rb-fw-bold); }
.rb-game-result__stat dd { margin: 0; color: var(--rb-text); font-size: var(--rb-fs-md); font-weight: var(--rb-fw-extrabold); font-variant-numeric: tabular-nums; }
.rb-game-result__stat dd span { color: var(--rb-text-secondary); font-size: .75em; font-weight: var(--rb-fw-bold); }
.rb-game-result__block { padding-top: var(--rb-space-4); border-top: 1px solid var(--rb-border); }
.rb-game-result__subtitle { margin: 0 0 var(--rb-space-3); color: var(--rb-text); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-bold); }
.rb-game-result__subtitle span { color: var(--rb-text-muted); font-weight: var(--rb-fw-regular); }
.rb-game-result__detail { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: var(--rb-space-2); margin: 0; }
.rb-game-result__detail .rb-game-result__stat { background: transparent; border: 1px solid var(--rb-border); }
.rb-game-result__recent { display: grid; gap: var(--rb-space-1); margin: 0; padding: 0; list-style: none; }
.rb-game-result__recent li { display: flex; justify-content: space-between; gap: var(--rb-space-3); padding: .5rem .75rem; border-radius: var(--rb-radius-xs); color: var(--rb-text-muted); font-size: var(--rb-fs-sm); }
.rb-game-result__recent li:nth-child(odd) { background: var(--rb-surface-soft); }
.rb-game-result__recent li strong { color: var(--rb-text); font-variant-numeric: tabular-nums; }
.rb-game-result__recent li.is-current { color: var(--rb-primary); font-weight: var(--rb-fw-bold); }
.rb-game-result__share { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--rb-space-2); }
.rb-game-result__share svg { width: 16px; height: 16px; }
.rb-game-result__share-status { margin: 0; color: var(--rb-text-muted); font-size: var(--rb-fs-xs); }

/* ---------- Sections below the game ---------- */
.rb-game-section { max-width: 880px; margin-top: clamp(2rem, 1.5rem + 2vw, 3rem); }
.rb-game-section__head { margin-bottom: var(--rb-space-5); }
.rb-game-section__head > * { margin: 0; }
.rb-game-section__head .rb-eyebrow { margin-bottom: var(--rb-space-2); }
.rb-game-how__card { padding: clamp(1.25rem, 1rem + 1.5vw, 2rem); border: 1px solid var(--rb-border); border-radius: var(--rb-radius-lg); background: var(--rb-surface); }
.rb-game-how__card .rb-h2 { margin-bottom: var(--rb-space-4); }
.rb-game-how__intro { display: grid; gap: var(--rb-space-3); margin: 0 0 var(--rb-space-4); }
.rb-game-how__description { max-width: 68ch; margin: 0; color: var(--rb-text-muted); font-size: var(--rb-fs-md, 1.0625rem); line-height: 1.6; }
.rb-game-how__intro .rb-game-head__instruction { margin: 0; }
.rb-game-how__steps { display: grid; gap: var(--rb-space-3); margin: 0; padding: 0; list-style: none; counter-reset: how; }
.rb-game-how__steps li { position: relative; padding-left: 2.75rem; color: var(--rb-text-muted); line-height: 1.6; counter-increment: how; }
.rb-game-how__steps li::before { position: absolute; top: -.1rem; left: 0; display: grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--rb-primary-soft); color: var(--rb-primary); font-size: var(--rb-fs-sm); font-weight: var(--rb-fw-extrabold); content: counter(how); }
.rb-game-how__steps strong { color: var(--rb-text); }
.rb-game-how__steps kbd { padding: .1em .45em; border: 1px solid var(--rb-border-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--rb-surface-soft); color: var(--rb-text); font-family: var(--rb-font-mono); font-size: .85em; }
.rb-game-how__managed { margin: var(--rb-space-4) 0 0; color: var(--rb-text-muted); }
.rb-game-how__note { margin: var(--rb-space-4) 0 0; }
.rb-game-ad { max-width: 880px; margin-top: var(--rb-space-8); }
.rb-game-ad .ad-placement { min-height: 100px; }

.rb-game-related__list { display: grid; gap: var(--rb-space-3); margin: 0; padding: 0; list-style: none; }
.rb-game-related__item {
    display: flex; align-items: center; gap: var(--rb-space-3);
    min-height: 72px; padding: var(--rb-space-3) var(--rb-space-4);
    border: 1px solid var(--rb-border); border-radius: var(--rb-radius-md);
    background: var(--rb-surface); color: var(--rb-text);
    transition: border-color var(--rb-duration) ease, transform var(--rb-duration) var(--rb-ease), box-shadow var(--rb-duration) ease;
}
.rb-game-related__item:hover { border-color: var(--rb-border-strong); box-shadow: var(--rb-shadow-sm); transform: translateY(-2px); color: var(--rb-text); }
.rb-game-related__item > svg { flex: 0 0 auto; width: 18px; height: 18px; color: var(--rb-primary); }
.rb-game-related__icon { --tone: #3730a3; display: grid; place-items: center; flex: 0 0 auto; width: 44px; height: 44px; border-radius: 14px; background: color-mix(in srgb, var(--tone) 12%, var(--rb-surface)); color: var(--tone); }
[data-tone="violet"] .rb-game-related__icon { --tone: #7c3aed; }
[data-tone="sky"] .rb-game-related__icon { --tone: #0e7490; }
[data-tone="amber"] .rb-game-related__icon { --tone: #b45309; }
[data-tone="mint"] .rb-game-related__icon { --tone: #047857; }
[data-tone="rose"] .rb-game-related__icon { --tone: #be123c; }
:root[data-theme="dark"] .rb-game-related__icon { --tone: #a5b4fc; }
:root[data-theme="dark"] [data-tone="violet"] .rb-game-related__icon { --tone: #c4b5fd; }
:root[data-theme="dark"] [data-tone="sky"] .rb-game-related__icon { --tone: #67e8f9; }
:root[data-theme="dark"] [data-tone="amber"] .rb-game-related__icon { --tone: #fcd34d; }
:root[data-theme="dark"] [data-tone="mint"] .rb-game-related__icon { --tone: #6ee7b7; }
:root[data-theme="dark"] [data-tone="rose"] .rb-game-related__icon { --tone: #fda4af; }
.rb-game-related__icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.rb-game-related__text { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; }
.rb-game-related__text strong { font-weight: var(--rb-fw-bold); line-height: 1.3; }
.rb-game-related__text small { color: var(--rb-text-muted); font-size: var(--rb-fs-sm); line-height: 1.4; }

@media (min-width: 576px) {
    .rb-game-result__actions { flex-direction: row; justify-content: center; }
    .rb-game-result__actions .rb-btn { min-width: 200px; }
}
@media (min-width: 768px) {
    .rb-game-related__list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* Phones: tighter status bar; Restart shows its icon only (accessible name stays "Restart"). */
@media (max-width: 429.98px) {
    .rb-game__status { padding-left: var(--rb-space-3); }
    .rb-game__stats { gap: .75rem; }
    .rb-game__stat dd { font-size: 1rem; }
    .rb-game__restart { padding-inline: .625rem; font-size: 0; gap: 0; }
    .rb-game__restart svg { width: 20px; height: 20px; }
}

/* ---------- Phase 12: "About this test" (intro, what it measures, scoring, tips) ---------- */
.rb-game-about__intro { max-width: 68ch; margin: 0 0 var(--rb-space-5); color: var(--rb-text); font-size: var(--rb-fs-md, 1.0625rem); line-height: 1.65; }
.rb-game-about__grid { display: grid; gap: var(--rb-space-4); }
.rb-game-about__card { padding: clamp(1.1rem, .9rem + 1vw, 1.5rem); border: 1px solid var(--rb-border); border-radius: var(--rb-radius-lg); background: var(--rb-surface); }
.rb-game-about__title { margin: 0 0 var(--rb-space-3); color: var(--rb-text); font-size: 1.0625rem; font-weight: var(--rb-fw-bold); letter-spacing: -.01em; }
.rb-game-about__card p { margin: 0; color: var(--rb-text-muted); line-height: 1.65; }
.rb-game-about__list { display: grid; gap: var(--rb-space-2); margin: 0; padding: 0 0 0 1.15rem; color: var(--rb-text-muted); line-height: 1.6; }
.rb-game-about__list li::marker { color: var(--rb-primary); }
@media (min-width: 768px) {
    .rb-game-about__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .rb-game-about__card:first-child { grid-column: 1 / -1; }
}
