/*
 * Decision game: phone-first styles and motion layer.
 *
 * Motion rules (checked by test/ui/motion.test.ts):
 *  - Only transform and opacity may appear in any transition, transition-property
 *    or keyframes body. No transition: all. No colour, shadow or filter animation.
 *  - Reduced motion removes movement; test mode (?test=1) forces zero durations.
 *  - will-change is used sparingly and only for transform/opacity.
 */

:root {
  --ink: #f3ecdf;
  --ink-soft: #bdb3a1;
  --paper: #171b26;
  --paper-2: #1f2433;
  --edge: #3a4157;
  --disabled-ink: #9b9aa0;
  --meter-track: #747b8b;
  --accent: #e0a458;
  --primary-ink: #14161f;
  --disabled-edge: #9b9aa0;
  --hit: #5fd39a;
  --miss: #ef6a5b;
  --radius: 14px;
  --gutter: 16px;
  --tap: 48px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --flip-ms: 650ms;
  --panel-ms: 480ms;
  --stagger-ms: 140ms;
  --fx-ms: 420ms;
  --kb-ms: 22000ms;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: #0d0f16;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background: radial-gradient(120% 80% at 50% 0%, #232a3e 0%, #11141d 60%, #0b0d13 100%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---------- App shell (mobile base) ---------- */

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: max(var(--gutter), var(--safe-top)) max(var(--gutter), var(--safe-right))
    max(var(--gutter), var(--safe-bottom)) max(var(--gutter), var(--safe-left));
  gap: 12px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
  font-size: 0.875rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* 3D stage: perspective lives on the parent of the flipping page. */
.stage {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  perspective: 1400px;
  perspective-origin: 50% 40%;
}

/* ---------- Page ---------- */

.page {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform-style: preserve-3d;
  transform-origin: left center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--paper-2) 0%, var(--paper) 100%);
  border: 1px solid var(--edge);
  overflow: hidden;
  transform: rotateY(0deg);
}

/* Before the flip starts the page rests edge-on and invisible. */
.page.is-entering {
  transform: rotateY(-96deg);
  opacity: 0;
}

.page.is-flipping {
  animation: page-flip-in var(--flip-ms) var(--ease-out) both;
  will-change: transform, opacity;
}

.page.is-flipping.is-flip-back {
  transform-origin: right center;
  animation-name: page-flip-back;
}

.page.is-flipped,
.page.is-ready {
  transform: rotateY(0deg);
  opacity: 1;
}

.page.is-paused,
.page.is-paused * {
  animation-play-state: paused;
}

/* Spine shading on the hinge side; static, never animated. */
.page::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 18px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0));
}

/* ---------- Placeholder art: parallax layers + Ken Burns ---------- */

.art {
  position: relative;
  flex: 0 0 auto;
  height: 36vh;
  height: 36dvh;
  min-height: 180px;
  max-height: 340px;
  overflow: hidden;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #0f121a;
}

.art__scene {
  position: absolute;
  inset: 0;
  transform: scale(1) translate3d(0, 0, 0);
  transform-origin: 50% 60%;
}

.art__scene.kb-on {
  animation: ken-burns var(--kb-ms) var(--ease-in-out) infinite alternate;
  will-change: transform;
}

.art__layer {
  position: absolute;
  inset: -8%;
  transform: translate3d(var(--px, 0px), var(--py, 0px), 0);
  transition: transform 180ms var(--ease-out);
}

.art__layer--far {
  background:
    radial-gradient(60% 50% at 70% 30%, rgba(255, 214, 150, 0.55), rgba(255, 214, 150, 0) 70%),
    linear-gradient(180deg, #2c3a63 0%, #5a4a6e 55%, #b4735f 100%);
}

.art__layer--mid {
  background:
    radial-gradient(90% 40% at 20% 100%, #20263a 0 60%, rgba(32, 38, 58, 0) 61%),
    radial-gradient(80% 36% at 85% 100%, #1a2033 0 60%, rgba(26, 32, 51, 0) 61%);
}

.art__layer--near {
  background:
    radial-gradient(70% 28% at 50% 110%, #0c0f17 0 62%, rgba(12, 15, 23, 0) 63%),
    linear-gradient(0deg, rgba(8, 10, 16, 0.75), rgba(8, 10, 16, 0) 45%);
}

.art::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: none;
}

/* ---------- Panels: staggered reveal ---------- */

.page__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 var(--gutter) var(--gutter);
}

.panel {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  opacity: 0;
  transform: translate3d(0, 28px, 0) scale(0.97);
}

.page.is-revealing .panel {
  animation: panel-rise var(--panel-ms) var(--ease-out) calc(var(--i, 0) * var(--stagger-ms)) both;
  will-change: transform, opacity;
}

.page.is-ready .panel,
.page.is-skipped .panel {
  animation: none;
  opacity: 1;
  transform: none;
  will-change: auto;
}

.panel h2,
.panel p {
  margin: 0;
}

.panel h2 {
  font-size: 1.125rem;
  line-height: 1.3;
  margin-bottom: 4px;
}

.panel p {
  color: var(--ink-soft);
}

/* ---------- Choices (touch targets >= 44px) ---------- */

.choices {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.choice,
.btn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: var(--tap);
  min-width: 44px;
  padding: 12px 16px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 160ms var(--ease-out), opacity 160ms var(--ease-out);
}

.choice:active,
.btn:active {
  transform: scale(0.98);
}

.choice:focus-visible,
.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.choice[disabled],
.choice[aria-disabled="true"],
.btn[disabled] {
  color: var(--disabled-ink);
  opacity: 1;
  cursor: not-allowed;
}
.choice[data-pending-choice="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); cursor: progress; }

/* ---------- Hit / miss feedback ---------- */

.fx-flash {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
}

.fx-hit .fx-flash {
  background: radial-gradient(90% 70% at 50% 50%, rgba(95, 211, 154, 0.55), rgba(95, 211, 154, 0) 70%);
  animation: fx-flash-hit var(--fx-ms) var(--ease-out) both;
}

.fx-miss .fx-flash {
  background: radial-gradient(90% 70% at 50% 50%, rgba(239, 106, 91, 0.6), rgba(239, 106, 91, 0) 70%);
  animation: fx-flash-miss var(--fx-ms) var(--ease-out) both;
}

.fx-hit .fx-pulse {
  animation: fx-pop var(--fx-ms) var(--ease-out) both;
}

.fx-miss .fx-shake {
  animation: fx-shake var(--fx-ms) linear both;
}

/* ---------- Keyframes: transform and opacity only ---------- */

@keyframes page-flip-in {
  0% {
    transform: rotateY(-96deg);
    opacity: 0.4;
  }
  55% {
    transform: rotateY(-22deg);
    opacity: 1;
  }
  100% {
    transform: rotateY(0deg);
    opacity: 1;
  }
}

@keyframes page-flip-back {
  0% {
    transform: rotateY(96deg);
    opacity: 0.4;
  }
  55% {
    transform: rotateY(22deg);
    opacity: 1;
  }
  100% {
    transform: rotateY(0deg);
    opacity: 1;
  }
}

@keyframes panel-rise {
  0% {
    transform: translate3d(0, 28px, 0) scale(0.97);
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
  }
}

@keyframes ken-burns {
  0% {
    transform: scale(1.04) translate3d(0, 0, 0);
  }
  100% {
    transform: scale(1.16) translate3d(-3%, -2%, 0);
  }
}

@keyframes fx-flash-hit {
  0% {
    opacity: 0;
  }
  22% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
  }
}

@keyframes fx-flash-miss {
  0% {
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes fx-pop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes fx-shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  15% {
    transform: translate3d(-9px, 0, 0);
  }
  30% {
    transform: translate3d(8px, 0, 0);
  }
  45% {
    transform: translate3d(-6px, 0, 0);
  }
  60% {
    transform: translate3d(5px, 0, 0);
  }
  80% {
    transform: translate3d(-2px, 0, 0);
  }
}

/* ---------- Larger screens (min-width, mobile base above) ---------- */

@media (min-width: 640px) {
  :root {
    --gutter: 24px;
  }

  .app {
    max-width: 720px;
    margin: 0 auto;
  }

  .art {
    height: 40dvh;
    max-height: 380px;
  }

  .choices {
    grid-template-columns: 1fr 1fr;
  }

  .panel h2 {
    font-size: 1.25rem;
  }
}

@media (min-width: 1024px) {
  .app {
    max-width: 880px;
  }

  .page__body {
    padding: 0 28px 28px;
  }
}

@media (hover: hover) {
  .choice:hover:not([disabled]),
  .btn:hover:not([disabled]) {
    transform: translate3d(0, -2px, 0);
  }
}

/*
 * ---------- UI shell: notice, HUD, reader panels, decision controls ----------
 * Added by the app-shell task. Mobile base; min-width queries only. No transitions or
 * keyframes are added here, so the transform/opacity-only rule above is untouched; meter
 * fills are scaled with transform (never width) and are not animated.
 */

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.notice {
  padding: 10px 14px;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--ink);
  background: rgba(224, 164, 88, 0.12);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

.notice[data-notice="recovery_required"],
.notice[data-notice="save_failed"] {
  border-color: var(--miss);
  background: rgba(239, 106, 91, 0.12);
}

/* HUD: labels keep their exact casing ("Intelligence Meter" / "game rating"). */
.hud {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  justify-content: stretch;
  gap: 10px 14px;
  text-transform: none;
  letter-spacing: 0.02em;
}

.hud__item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.hud__item--intelligence {
  grid-column: 1 / -1;
}

.hud__label {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.hud__sub {
  font-size: 0.75rem;
  color: var(--ink-soft);
  opacity: 1;
}

.hud__value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.hud__item--intelligence .hud__value {
  font-size: 1.5rem;
  color: var(--accent);
}

.hud__item--track[data-track="ON"] .hud__value {
  color: var(--hit);
}

.hud__item--track[data-track="OFF"] .hud__value {
  color: var(--miss);
}

.meter {
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--meter-track);
}

.meter__fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
}

.hud__item--drift .meter__fill {
  background: var(--miss);
}

.hud__item--recovery .meter__fill {
  background: var(--hit);
}

.hud__item--hint .hud__value {
  font-size: 0.875rem;
  color: var(--miss);
}

/* Stage and pages */
.stage > .page {
  min-width: 0;
}

.page > .page__body {
  padding-top: var(--gutter);
}

.page__controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 var(--gutter) var(--gutter);
}

.page--flow .page__body,
.page--review .page__body,
.page--recovery .page__body,
.page--idle .page__body {
  padding-top: var(--gutter);
}

.layout-stack-2,
.layout-stack-3,
.layout-stack-4,
.layout-grid-2x2,
.page__body[data-layout="hero+2"],
.review__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.review__body {
  gap: 12px;
}

/* Panel art: the existing .art box is sized per panel here. */
.panel-art {
  margin: -14px -16px 10px;
}

.panel-art .art {
  height: auto;
  min-height: 0;
  max-height: none;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius) var(--radius) 0 0;
}

.panel-art .art--medium {
  aspect-ratio: 4 / 3;
}

.panel-art .art--close,
.panel-art .art--detail {
  aspect-ratio: 1 / 1;
  max-height: 60vh;
  max-height: 60dvh;
}

svg.art__layer {
  display: block;
  width: 116%;
  height: 116%;
  inset: -8% auto auto -8%;
}

.art__details {
  margin: 0;
  padding: 8px 16px 0;
  list-style: none;
  font-size: 0.8125rem;
  font-style: italic;
  color: var(--ink-soft);
}

.panel__text {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.caption {
  padding: 6px 10px;
  color: var(--ink);
  background: rgba(224, 164, 88, 0.14);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

.bubble {
  align-self: flex-start;
  max-width: 92%;
  padding: 8px 12px;
  color: #14161f;
  background: var(--ink);
  border-radius: 16px 16px 16px 4px;
}

.bubble__speaker {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sfx {
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.panel p.bubble,
.panel p.sfx,
.panel p.caption {
  margin: 0;
}

.panel p.bubble {
  color: #14161f;
}

/* Question and decision controls */
.question {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.question__prompt {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.35;
}

.choice {
  gap: 12px;
  align-items: center;
}

.choice__id {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--paper);
  background: var(--accent);
  border-radius: 50%;
}

.choice__text {
  min-width: 0;
  overflow-wrap: anywhere;
}

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

.btn {
  justify-content: center;
  text-align: center;
}

.consequence {
  --consequence-tone: var(--ink-soft);
  margin: 0 var(--gutter);
  padding: 10px 14px;
  background: color-mix(in srgb, var(--consequence-tone) 10%, transparent);
  border-left: 3px solid var(--consequence-tone);
  border-radius: 4px;
}
.consequence[data-tone="hit"] { --consequence-tone: var(--hit); }
.consequence[data-tone="miss"] { --consequence-tone: var(--miss); }
.panel--outcome { border-inline-start: 3px solid var(--outcome-accent, var(--accent)); }
.strategy-guide dl > div { scroll-margin-block: 2rem; }

.consequence p {
  margin: 0;
}

.inline-error,
.retry__text {
  margin: 0;
  color: var(--miss);
}

.retry {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flow {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.review__title {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.raw-record {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  color: var(--ink);
  font: inherit;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--edge);
  border-radius: 8px;
}

.recovery__code {
  color: var(--ink-soft);
  font-size: 0.8125rem;
}

@media (min-width: 640px) {
  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hud__item--intelligence {
    grid-column: auto;
  }

  .page__body[data-layout="grid-2x2"] {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .page__body[data-layout="hero+2"] {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .page__body[data-layout="hero+2"] > .panel:first-child {
    grid-column: 1 / -1;
  }

  .flow {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

@media (min-width: 1024px) {
  .hud {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* ---------- Reduced motion: no movement, content simply present ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .page,
  .page.is-entering {
    transform: none;
    opacity: 1;
  }

  .panel {
    opacity: 1;
    transform: none;
  }

  .art__layer {
    transform: none;
  }

  .art__scene {
    transform: none;
  }

  /* Feedback in reduced motion is a brief static tint, no movement. */
  .fx-hit .fx-flash,
  .fx-miss .fx-flash {
    opacity: 0.35;
  }
}

html[data-reduce-motion="true"] *, html[data-reduce-motion="true"] *::before, html[data-reduce-motion="true"] *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
html[data-reduce-motion="true"] .page, html[data-reduce-motion="true"] .page.is-entering, html[data-reduce-motion="true"] .panel, html[data-reduce-motion="true"] .art__layer, html[data-reduce-motion="true"] .art__scene { transform: none; opacity: 1; }

/* ---------- Test mode (?test=1): zero-duration, zero-delay ---------- */

html[data-test="1"] *,
html[data-test="1"] *::before,
html[data-test="1"] *::after,
[data-test="1"] *,
[data-test="1"] *::before,
[data-test="1"] *::after,
.test-mode *,
.test-mode *::before,
.test-mode *::after {
  animation-duration: 0s !important;
  animation-delay: 0s !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0s !important;
  transition-delay: 0s !important;
}

/* Form-factor contract: one document scroller; CSS resize never recreates a page. */
:root { --bubble-paper: #f3ecdf; --canvas: #0d0f16; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ink: #171b26; --ink-soft: #50505b; --paper: #f3ecdf; --paper-2: #fffaf0;
    --edge: #77717a; --disabled-ink: #59545c; --meter-track: #77717a;
    --accent: #805015; --primary-ink: #ffffff; --disabled-edge: #59545c; --hit: #216640; --miss: #a62d24;
    --canvas: #e5dfd3; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --ink: #171b26; --ink-soft: #50505b; --paper: #f3ecdf; --paper-2: #fffaf0;
  --edge: #77717a; --disabled-ink: #59545c; --meter-track: #77717a;
  --accent: #805015; --primary-ink: #ffffff; --disabled-edge: #59545c; --hit: #216640; --miss: #a62d24;
  --canvas: #e5dfd3; color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="high-contrast"] {
  --ink: #fff; --ink-soft: #fff; --paper: #000; --paper-2: #05070b;
  --edge: #ffd600; --disabled-ink: #fff; --meter-track: #fff;
  --accent: #ffd600; --primary-ink: #14161f; --disabled-edge: #ffd600; --hit: #fff; --miss: #ffd600;
  --bubble-paper: #05070b; --canvas: #000; color-scheme: dark;
}
:root[data-theme="high-contrast"] body,
:root[data-theme="high-contrast"] .page { background: #000; color: #fff; }
:root[data-theme="high-contrast"] .bubble,
:root[data-theme="high-contrast"] .panel p.bubble,
:root[data-theme="high-contrast"] .caption,
:root[data-theme="high-contrast"] .choice,
:root[data-theme="high-contrast"] .btn { background: #05070b; color: #fff; border-color: #ffd600; }
:root[data-theme="high-contrast"] :focus-visible { outline: 3px solid #ffd600; }
:root[data-font-scale="1"] { font-size: 100%; }
:root[data-font-scale="1.25"] { font-size: 125%; }
:root[data-font-scale="1.5"] { font-size: 150%; }
@media (min-width: 768px) {
  :root[data-font-scale="1"] { font-size: 112.5%; }
  :root[data-font-scale="1.25"] { font-size: 140.625%; }
  :root[data-font-scale="1.5"] { font-size: 168.75%; }
}
:root[data-font="readable"] .bubble,
:root[data-font="readable"] .caption,
:root[data-font="readable"] .caption-overlay-box,
:root[data-font="readable"] .hud,
:root[data-font="readable"] .choice,
:root[data-font="readable"] .btn,
:root[data-font="readable"] .question__prompt {
  font-family: "Trebuchet MS", Verdana, "Segoe UI", system-ui, sans-serif;
  letter-spacing: .02em; line-height: 1.55; word-spacing: .08em;
}
:root[data-font="readable"] body {
  font-family: "Trebuchet MS", Verdana, "Segoe UI", system-ui, sans-serif;
  letter-spacing: .02em;
  line-height: 1.55;
  word-spacing: .08em;
}
html { background: var(--canvas); scroll-padding-block: max(1rem, var(--safe-top)); }
body { background: radial-gradient(120% 80% at 50% 0%, var(--paper-2) 0%, var(--canvas) 60%, var(--canvas) 100%); }
html:has([data-region="settings"]:not([hidden])) { overflow: hidden; }
.app { width: 100%; max-width: 75rem; margin-inline: auto; }
.stage, .page, .panel, .page__body, .page__controls, .question, .flow,
.settings__dialog, .hud > * { min-width: 0; }
.stage:has([data-offline-preview]) { flex-direction: column; gap: 1rem; }
.offline-preview { min-width: 0; }
.offline-held-run { padding: 1rem; border: 1px solid var(--edge); border-left: .4rem solid var(--accent); border-radius: var(--radius); background: var(--paper-2); }
.offline-held-run h2 { margin-top: 0; }
.page { overflow: clip; }
.page__controls {
  margin-top: auto;
  padding: 0 max(var(--gutter), var(--safe-right)) max(var(--gutter), var(--safe-bottom)) max(var(--gutter), var(--safe-left));
}
.page--flow > .page__body { flex: 1; }
.page--flow .flow { margin-top: auto; }
.panel p, .consequence p, .question__prompt { max-width: 70ch; }
.bubble { background: var(--bubble-paper); }
.choice, .btn, button, input, select, textarea { touch-action: manipulation; }
button, input:not([type="hidden"]), select, textarea {
  min-width: 44px; min-height: 44px; max-width: 100%; font: inherit;
}
button, .btn { white-space: normal; overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.skip-link {
  position: fixed; z-index: 100; top: max(.5rem, var(--safe-top));
  left: max(.5rem, var(--safe-left)); transform: translateY(-200%);
  background: var(--paper); color: var(--ink);
}
.skip-link:focus { transform: none; }
.reader-heading { margin: var(--gutter) var(--gutter) 0; font-size: 1.25rem; }
.reader-jump { align-self: flex-end; margin-inline: var(--gutter); }
[data-production-legal] { max-width: 75rem; margin-inline: auto; padding: 1rem max(1rem, var(--safe-right)) max(1rem, var(--safe-bottom)) max(1rem, var(--safe-left)); }
[data-production-legal] nav { display: flex; flex-wrap: wrap; gap: .5rem; }
.page__body[data-layout], .review__body { display: flex; flex-direction: column; }
.choices, .flow { grid-template-columns: minmax(0, 1fr); }
.panel { padding-inline: 0; }
.panel.summary, .panel--outcome { padding-inline: 16px; }
.decision-mode { white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.panel-art { margin-inline: 0; }
.panel__text { padding-inline: .75rem; }
.page__controls, .panel__text, .select-card__logline { font-size: 1rem; }
.app .settings__note, .art__details, .app .retry__note, .app .flow__note, .app .select__note { font-size: 1rem; }
@media (min-width: 48rem) and (min-height: 32rem), (min-width: 60rem) {
  .page__body[data-layout="grid-2x2"], .page__body[data-layout="hero+2"] {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .page__body[data-layout="hero+2"] > .panel:first-child { grid-column: 1 / -1; }
  .panel { padding-inline: 16px; }
  .panel-art { margin-inline: -16px; }
  .panel__text { padding-inline: 0; }
  .flow { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12.5rem), 1fr)); }
  .panel-art .art__overlays { display: block; }
  .panel-art .art__legend-item:not(.art__legend-item--long) { display: none; }
  .panel-art .art__legend:not(:has(.art__legend-item--long)) { display: none; }
}
@media (hover: hover) {
  .btn:hover, .choice:hover { border-color: var(--accent); }
}
/* Title, tutorial and credits retain the ink and panel language of the reader. */
.title-screen {
  position: relative;
  isolation: isolate;
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: #171b26;
  color: #fff;
  overflow: hidden;
}
.title-screen--art { background-image: linear-gradient(90deg, rgba(8, 10, 17, .92), rgba(8, 10, 17, .84)), var(--title-cover); background-position: center; background-size: cover; }
.title-screen__content { position: relative; max-width: 70rem; margin: auto; padding: clamp(1rem, 5vw, 4rem); }
.title-screen__eyebrow { color: #f1bb77; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.title-screen h1 { font-size: clamp(3.5rem, 13vw, 8rem); line-height: 1; margin: .2em 0; text-transform: uppercase; text-shadow: 3px 4px #691c22; animation: title-arrive 650ms ease-out both; }
@media (max-width: 420px) { .title-screen h1 { margin-bottom: 0; } .title-screen h1 + p { margin-top: .35rem; } }
.title-screen nav[data-role="start-menu"] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: .6rem; max-width: 45rem; margin-block: 2rem; }
.title-screen .btn, .tutorial .btn, .credits .btn { min-height: 48px; min-width: 44px; }
/* The title stays dark over cover art in light mode; its controls need the same high-contrast ink and a solid backing. */
:root[data-theme="light"] .title-screen .btn { color: #fff; background: #263041; border-color: #aeb6c6; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .title-screen .btn { color: #fff; background: #263041; border-color: #aeb6c6; }
}
.title-screen__continue, .title-screen__legal, .title-screen__confirm { max-width: 45rem; margin: 1rem 0; padding: 1rem; border: 1px solid #aeb6c6; background: rgba(8, 10, 17, .9); }
.title-screen__continue { display: flex; flex-direction: column; gap: .35rem; width: 100%; min-height: 64px; color: #fff; font: inherit; text-align: left; cursor: pointer; border: 2px solid #ffd18e; }
.title-screen__continue-title { font-size: 1.25rem; font-weight: 800; }
.title-screen__continue:hover { background: #1f2b3d; }
.app[data-screen="title"] .bar, .app[data-screen="tutorial"] .bar { display: none; }
.title-screen__legal { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.title-screen__legal p { flex-basis: 100%; margin: 0; }
.title-screen__legal a { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; padding: .5rem .75rem; border: 1px solid #ffd18e; border-radius: .4rem; }
.title-screen__history { max-width: 45rem; padding-left: 1.4rem; }
.title-screen__history li { margin-bottom: .6rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
@media (max-width: 400px) { .title-screen__history li > span { min-width: 0; } .title-screen__history [data-action="history-delete"] { flex: 0 0 auto; white-space: nowrap; } }
.title-screen footer { margin-top: 2rem; color: #ddd7cb; font-size: .875rem; }
.title-screen a { color: #ffd18e; }
.title-screen__confirm { display: flex; flex-wrap: wrap; gap: 16px; }
.history-confirm-layer { align-items: center; justify-content: center; padding: max(12px, var(--safe-top)) max(12px, var(--safe-right)) max(12px, var(--safe-bottom)) max(12px, var(--safe-left)); }
.history-confirm-layer .title-screen__confirm { width: min(100%, 32rem); max-height: calc(100dvh - 24px); overflow: auto; margin: 0; border: 3px solid var(--accent); background: var(--paper); color: var(--ink); box-shadow: 0 1rem 3rem rgb(0 0 0 / .55); }
.title-screen__warning { max-width: 45rem; padding: .75rem 1rem; border-inline-start: 4px solid var(--miss); background: var(--paper); color: var(--ink); font-weight: 700; }
.title-screen__confirm h2, .title-screen__confirm p { flex-basis: 100%; margin: 0; }
.tutorial, .credits { padding: clamp(1rem, 4vw, 3rem); }
.tutorial__cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 1rem; }
.tutorial article { padding: 1.25rem; border: 1px solid var(--edge); border-left: .4rem solid var(--accent); border-radius: var(--radius); background: var(--paper-2); }
.tutorial article h2 { margin-top: 0; }
.credits nav, .settings__dialog nav[aria-label] { display: flex; flex-wrap: wrap; gap: .5rem; margin-block: 1rem; }
.credits nav a, .settings__dialog nav[aria-label] a { display: inline-flex; align-items: center; min-height: 44px; padding: .5rem .75rem; color: var(--ink); border: 1px solid var(--edge); border-radius: .4rem; }
.title-screen :focus-visible, .tutorial :focus-visible, .credits :focus-visible, .settings__dialog nav[aria-label] :focus-visible { outline: 3px solid #ffd18e; outline-offset: 3px; }
@keyframes title-arrive { from { opacity: 0; transform: translateY(.4em); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .title-screen h1 { animation: none; } }

/* ---- styles/art.css ---- */
/*
 * Real panel art (src/ui/art.ts): the picture fills the slot the shot gets in styles.css (cover), and the
 * panel's visual details sit on top as overlay labels the game draws (the picture itself never carries lettering). Phone-first: min-width queries only. No transitions and no keyframes here, so the
 * transform/opacity-only motion rule in styles.css is untouched; label positions are static.
 */

.panel-art--image .art {
  background: #0f121a;
}

/* Real art carries its own lighting: no placeholder vignette over it or over the labels. */
.panel-art--image .art::after {
  content: none;
}

/* The five ratios of the image tool. The shot classes of styles.css already give 16/9, 4/3 and 1/1. */
.panel-art--image .art--r-16x9 {
  aspect-ratio: 16 / 9;
}

.panel-art--image .art--r-4x3 {
  aspect-ratio: 4 / 3;
}

.panel-art--image .art--r-1x1 {
  aspect-ratio: 1 / 1;
}

.panel-art--image .art--r-3x4 {
  aspect-ratio: 3 / 4;
}

.panel-art--image .art--r-9x16 {
  aspect-ratio: 9 / 16;
}

/*
 * The picture is this box's background (a <style> rule beside the figure sets background-image from the build's
 * art index), so no image bytes sit in an element attribute. Cover: the image fills the slot, cropped never stretched.
 */
.art__img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background-color: #0f121a;
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: cover;
}
.art__img[aria-busy="true"]::before {
  content: attr(data-loading-label);
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 1rem; color: #fff; font: 700 1rem/1.5 var(--font-ui, system-ui, sans-serif);
  text-align: center; background-color: #101723;
  background-image: radial-gradient(circle, rgb(255 255 255 / .15) 1.5px, transparent 1.5px);
  background-size: 12px 12px;
}

/* Short labels use two rows along the picture edge; authored anchors remain in the markup for art metadata. */
.panel-art--image { container-type: inline-size; }
.art__overlays {
  position: absolute;
  inset: auto 0 0;
  z-index: 2;
  margin: 0;
  padding: 8px;
  list-style: none;
  pointer-events: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.art__label {
  box-sizing: border-box;
  width: max-content;
  max-width: 100%;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  background: rgba(8, 12, 22, 0.8);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  overflow-wrap: anywhere;
}

/*
 * Clips (src/ui/art-video.ts). The still stays the picture box's background; the <video> lies on it, transparent
 * until it plays (the clip layer sets data-clip-state on the .art box: idle, playing, ended or failed), cover-fitted
 * like the still so the slot keeps its ratio. A button over the whole box plays the clip again; its badge sits in the
 * top right corner, away from the labels along the bottom edge, and shows only while the clip is not playing. The
 * labels remain at the lower edge. No transition and no keyframe: the state switch is instant.
 */
/* The corner control and labels stack inside the picture box and never reach out over the page. */
.panel-art--clip .art {
  isolation: isolate;
}

/*
 * The clip is scaled up by 1.2 percent (the box clips it): the first and last rows of a generated clip are often a black
 * hairline (the real Veo pilot clip has two or three), and they fall outside the box. A still has none, and the picture
 * is not changed in any way a player could see.
 */
.art__clip {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transform: scale(1.012);
  transform-origin: 50% 50%;
}

/* Fill close frames; authored focal points remain centred in the visible crop. */
.art--close .art__clip, .art--detail .art__clip {
  object-fit: cover;
  object-position: 50% 50%;
}

.art[data-clip-state="playing"] .art__clip,
.art[data-clip-state="ended"] .art__clip {
  opacity: 1;
}

.art__clip-btn,
.select-card__cover-btn {
  appearance: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  color: #ffffff;
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.art__clip-btn::before,
.select-card__cover-btn::before {
  content: "";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  background: rgba(8, 12, 22, 0.72);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
}

.art__clip-btn::after,
.select-card__cover-btn::after {
  content: "";
  position: absolute;
  top: 20px;
  right: 21px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 9px 0 9px 14px;
  border-color: transparent transparent transparent #ffffff;
}

.art[data-clip-state="playing"] .art__clip-btn::before,
.art[data-clip-state="playing"] .art__clip-btn::after,
.select-card__cover[data-clip-state="playing"] .select-card__cover-btn::before,
.select-card__cover[data-clip-state="playing"] .select-card__cover-btn::after {
  display: none;
}

.art[data-clip-state="failed"] .art__clip-btn,
.select-card__cover[data-clip-state="failed"] .select-card__cover-btn {
  display: none;
}

.art__clip-btn:focus-visible,
.select-card__cover-btn:focus-visible {
  outline: 3px solid var(--accent, #e0a458);
  outline-offset: -3px;
}
.art__clip-btn {
  inset: 8px 8px auto auto; z-index: 4; width: 44px; height: 44px; min-width: 44px; min-height: 44px;
  padding: 0; background: #0a0e16; border: 2px solid #fff; border-radius: 50%; font-size: 0;
}
.art__clip-btn::before { display: none; }
.art__clip-btn::after { display: block; top: 11px; right: 11px; border-width: 9px 0 9px 14px; }
.art[data-clip-state="playing"] .art__clip-btn::after { display: block; top: 11px; right: 12px; width: 14px; height: 18px; border: 0; background: linear-gradient(90deg, #fff 0 4px, transparent 4px 10px, #fff 10px 14px); }
.art[data-clip-state="ended"] .art__clip-btn { opacity: .45; }
.art__clip-btn:is(:focus-visible, :hover) { opacity: 1; }
@media (min-width: 48rem) and (min-height: 32rem), (min-width: 60rem) {
  .art__clip-btn { inset: 10px 10px auto auto; width: auto; height: auto; min-width: 96px; min-height: 44px; padding: .35rem .6rem; border-radius: 4px; font: 700 .875rem/1.3 var(--font-ui, system-ui, sans-serif); opacity: 1; }
  .art__clip-btn::after, .art[data-clip-state="playing"] .art__clip-btn::after { display: none; }
}

/*
 * The cover of a scenario card (src/ui/select.ts): the image is a background set by a <style> rule beside it (like
 * a panel's), the optional clip lies on it the same way.
 */
.select-card__cover {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background-color: #0f121a;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  background-size: cover;
  border-radius: 10px;
}

.select-card__cover-clip {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transform: scale(1.012);
  transform-origin: 50% 50%;
}

.select-card__cover[data-clip-state="playing"] .select-card__cover-clip,
.select-card__cover[data-clip-state="ended"] .select-card__cover-clip {
  opacity: 1;
}

@media (min-width: 640px) {
  .art__label {
    font-size: 0.8125rem;
    padding: 4px 10px;
  }
}

/* On phones all clues sit below the picture. Long clues always flow as text, never clip inside an art box. */
.panel-art.panel-art--image .art__overlays { display: none; }
.art__legend { padding: .5rem .75rem 0; color: var(--ink-soft); font-size: 1rem; }
.art__legend ul { margin: 0; padding-inline-start: 1.25rem; }
.art__legend-item { overflow-wrap: anywhere; }
.art__legend-item--long { display: list-item; }
.art__legend-hint { margin: .35rem 0 0; color: var(--ink-soft); font-size: .8125rem; }
/* Keep the hint in normal reading order, including when the wide layout hides short clues. */
.panel-art.panel-art--image .art__legend:has(.art__legend-hint) { display: block; }
figure.panel-art.panel-art--image .art__legend { display: block; }
.panel-art.panel-art--image .art__legend-item:not(.art__legend-item--long) { display: list-item; }
.art__label[data-long="true"] { display: none; }

@media (min-width: 48rem) and (min-height: 32rem), (min-width: 60rem) {
  @container (min-width: 32rem) {
    .panel-art.panel-art--image .art__overlays { display: flex; }
  /* The overlay supplies these short notes visually; retain their list semantics for assistive technology. */
  .panel-art.panel-art--image .art__legend-item--overlay {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  }
}

/* Trailer is a 44px sibling overlay, not a button stretched over another action. */
.select-card__cover-btn { inset: 8px 8px auto auto; width: 44px; height: 44px; }
.select-card__cover-btn::before { top: 3px; right: 3px; }
.select-card__cover-btn::after { top: 13px; right: 14px; }

.scenario-intro { max-width: 60rem; margin-inline: auto; padding: 1rem; }
.scenario-intro__title { font-size: 1.5em; margin-block: .83em; }
.scenario-intro__media { display: block; width: min(100%, 106.67vh); max-height: 60vh; aspect-ratio: 16 / 9; object-fit: contain; object-position: center; margin-inline: auto; background: #101b2a; }
.scenario-intro__video-controls { position: relative; z-index: 2; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin: .5rem .75rem 1rem; }
.scenario-intro__video-controls:not(:has(button:not([hidden]))) { display: none; }
.scenario-intro__video-controls .btn { width: fit-content; background: #0a0e16; color: #fff; border: 2px solid #fff; }
.scenario-intro__transcript { margin-block: .5rem; padding: .5rem .75rem; border: 1px solid var(--edge); }
.scenario-intro__transcript summary { min-height: 44px; cursor: pointer; }
.scenario-intro__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-block: .75rem; }
.scenario-intro__actions > p { flex-basis: 100%; margin: 0; }
.scenario-intro .btn { min-height: 44px; }
.scenario-intro video::cue { color: #fff; background: #101b2a; }
@media (max-width: 420px) { .scenario-intro video::cue { font-size: max(14px, 4vw); line-height: 1.35; } }
.video-transcript { margin: .5rem 0; padding: .4rem .6rem; border: 1px solid currentColor; }
.video-transcript > summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; }
.panel-art__media { position: relative; }

/* ---- styles/game.css ---- */
/*
 * Game shell: top bar, settings panel, HUD pips, end screens and the chapter review.
 * Phone-first (min-width queries only); every control is at least 44 x 44 CSS px.
 * No transitions and no keyframes here, so the transform/opacity-only motion rule in styles.css holds.
 * Labels keep their exact casing ("Intelligence Meter" / "game rating"): no text-transform on them.
 */

/* ---------- Screens ---------- */

.boot-intro { width: 100%; max-width: 42rem; align-self: center; margin-inline: auto; padding: var(--gutter); border: 2px solid var(--edge); background: var(--paper); color: var(--ink); }
.boot-intro h1 { font-size: 2rem; }
.offline-preview { max-width: 68ch; margin-inline: auto; padding: var(--gutter); border: 2px solid var(--edge); background: var(--paper); }
.offline-preview__brand { padding-block: .25rem; border-bottom: 2px solid var(--accent); font-size: 1.25rem; font-weight: 800; letter-spacing: .06em; }
.offline-preview .btn { min-height: 44px; }
.boot-intro .btn { min-width: 8rem; }
.boot-intro:not(.boot-intro--art) .btn[disabled] { color: var(--ink-soft); }
.boot-intro--art { background-image: linear-gradient(rgba(8, 12, 22, .84), rgba(8, 12, 22, .84)), var(--intro-cover); background-size: cover; background-position: center; color: #fff; border-radius: var(--radius); }
.boot-intro--art .btn { color: #fff; border-color: #fff; background: rgba(8, 12, 22, .8); }
html:has([data-modal-open]) { overflow: hidden; }

.app[data-screen="select"] .hud,
.app[data-screen="intro"] .hud {
  display: none;
}
.app[data-screen="premise"] .hud { display: none; }
.premise-card { max-width: 45rem; margin-inline: auto; padding: var(--gutter); }
.premise-card__logline, .premise-card__hook { font-size: 1.2rem; font-weight: 700; }
.premise-card__actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.premise-card__actions { margin-block: .75rem 1.25rem; }
@media (max-width: 639px) {
  .app[data-screen="premise"] .bar__title, .app[data-screen="premise"] .bar__help { display: none; }
  .app[data-screen="premise"] .bar { gap: 0; }
  .app[data-screen="premise"] .bar__scroll { width: 100%; }
  .premise-card__actions .btn { flex: 1 1 9rem; }
}

/* ---------- Top bar ---------- */

.bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.bar__title:empty { display: none; }
.bar__help { align-self: flex-start; min-height: 44px; flex: 0 1 auto; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
.bar__scroll { position: relative; min-width: 0; width: 100%; }
/* Keep every phone action in view, including after keyboard focus or closing a sheet. */
.bar__actions { display: flex; flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: 8px; padding: 3px; }
.bar__actions > .btn { flex-shrink: 1; white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
@media (max-width: 639px) {
  .bar__actions { flex-wrap: wrap; overflow-x: visible; }
  .bar__scroll { overflow: visible; }
}
.bar__actions > .bar__secondary { display: none; }
@media (max-width: 420px) {
  .bar__help, .bar__actions > [data-action="scenarios"] { display: none; }
  .bar__actions { flex-wrap: nowrap; }
}
.bar__menu { position: absolute; top: calc(100% + 8px); inset-inline-start: 0; z-index: 20; box-sizing: border-box; width: min(100%, 18rem); display: grid; gap: 8px; padding: 8px; overflow-y: auto; border: 1px solid var(--edge); border-radius: var(--radius); background: var(--paper); }
.bar__menu[hidden] { display: none; }
.bar__menu > .btn { min-width: 44px; min-height: 44px; text-align: start; }
.bar__scroll::before, .bar__scroll::after { content: ""; position: absolute; top: 0; bottom: 0; width: 24px; z-index: 1; pointer-events: none; opacity: 0; }
.bar__scroll::before { left: 0; background: linear-gradient(90deg, var(--paper), transparent); }
.bar__scroll::after { right: 0; background: linear-gradient(270deg, var(--paper), transparent); }
.bar__scroll[data-overflow-start="true"]::before, .bar__scroll[data-overflow-end="true"]::after { opacity: 1; }

.app[data-screen="profile"] .hud,
.app[data-screen="results"] .hud,
.app[data-screen="leaderboard"] .hud,
.app[data-screen="retired"] .hud { display: none; }
.app:not([data-screen="play"]) .hud { display: none; }
.app[data-screen="play"][data-phase="flow"] .hud { display: none; }
.app[data-screen="play"]:is([data-phase="recovery"], [data-phase="error"], [data-phase="idle"]) .hud { display: none; }

.settings__dialog input { min-height: 44px; width: 100%; box-sizing: border-box; font: inherit; }
.settings__dialog table { width: 100%; text-align: left; }
.settings__dialog th, .settings__dialog td { padding: 8px; }

.bar__title {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  color: var(--ink-soft);
}

.btn--bar {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  font-size: 0.9375rem;
}

.btn--bar[hidden] {
  display: none;
}

/* ---------- Settings panel ---------- */

.settings {
  position: fixed;
  right: max(12px, var(--safe-right));
  bottom: max(12px, var(--safe-bottom));
  left: max(12px, var(--safe-left));
  z-index: 30;
  max-height: calc(100dvh - max(12px, var(--safe-top)) - max(12px, var(--safe-bottom)));
  overflow-y: auto;
  padding: 16px;
  color: var(--ink);
  background: linear-gradient(160deg, var(--paper-2) 0%, var(--paper) 100%);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

.settings[hidden] { display: none; }
.settings[data-region="settings"] {
  inset: 0;
  width: 100%; height: 100dvh; max-height: 100dvh;
  padding: max(16px, var(--safe-top)) max(16px, var(--safe-right)) max(16px, var(--safe-bottom)) max(16px, var(--safe-left));
  border-radius: 0;
  background: var(--paper);
  scroll-padding-top: calc(var(--safe-top) + 72px);
}
.settings[data-region="settings"] :is(button, input, select, textarea) { scroll-margin-top: calc(var(--safe-top) + 72px); }
.settings[data-region="settings"]:has(.settings__confirm-dialog) { inset: 0; width: 100%; height: 100dvh; max-height: 100dvh; display: grid; place-items: center; border-radius: 0; background: rgb(0 0 0 / .8); }
.settings__confirm-dialog { box-sizing: border-box; width: min(100%, 34rem); max-height: calc(100dvh - max(16px, var(--safe-top)) - max(16px, var(--safe-bottom))); overflow-y: auto; padding: 1.25rem; border: 2px solid var(--accent); background: var(--paper); box-shadow: 0 1rem 3rem #000; }
.settings__themes { scroll-margin-block-start: calc(var(--safe-top) + 88px); }
.settings__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--paper); padding-block: 8px; }
.settings__hint { display: block; font-size: 1rem; font-weight: 400; color: var(--ink-soft); }

.settings__dialog {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings__title {
  margin: 0;
  font-size: 1.125rem;
}

.settings__note {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.settings__list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.settings__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label switch"
    "volume level";
  align-items: center;
  column-gap: 12px;
  row-gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.settings__label {
  grid-area: label;
  font-weight: 600;
}

.settings__switch {
  grid-area: switch;
  min-width: 72px;
  min-height: 44px;
  padding: 8px 12px;
}

.settings__switch[aria-checked="true"] {
  color: #14161f;
  background: var(--hit);
  border-color: var(--hit);
}

.settings__volume {
  grid-area: volume;
  display: block;
  min-width: 0;
}

.settings__volume input[type="range"] {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
}

.settings__level {
  grid-area: level;
  min-width: 3.5em;
  font-size: 0.875rem;
  text-align: right;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.settings__done {
  align-self: stretch;
}

.settings__themes { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 8px; min-width: 0; border: 1px solid var(--edge); }
@media (max-width: 420px) {
  .settings__themes--appearance { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings__themes--appearance .btn { min-width: 0; min-height: 44px; white-space: normal; }
}
.settings__themes [aria-pressed="true"] { border-color: var(--accent); font-weight: 700; }
.settings__dialog table { table-layout: fixed; overflow-wrap: anywhere; }
.settings__switch[aria-checked="true"] { color: var(--paper); }
.install-hint { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: .75rem; border: 1px solid var(--edge); border-radius: var(--radius); }
.install-hint p { flex: 1 1 15rem; margin: 0; }
.update-notice:not([hidden]) { display: flex; flex-direction: column; gap: 8px; }

/* ---------- HUD pips ---------- */

.app .hud { display: block; }
.hud__summary { width: 100%; min-height: 44px; padding: 8px; font-size: .8125rem; letter-spacing: 0; }
.hud__details { display: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; margin-top: 8px; }
.hud__details[data-expanded="true"] { display: grid; }

.hud__value .pips {
  display: inline-flex;
  gap: 4px;
  margin-right: 8px;
  vertical-align: middle;
}

.pip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1px solid var(--ink-soft);
  border-radius: 50%;
}

.pips--drift .pip.is-on {
  background: var(--miss);
  border-color: var(--miss);
}

.pips--recovery .pip.is-on {
  background: var(--hit);
  border-color: var(--hit);
}

.hud__count {
  vertical-align: middle;
  white-space: nowrap;
}

/* ---------- End screens ---------- */

.summary h2 {
  margin: 0 0 6px;
}

.page--flow .consequence {
  margin: 8px 0 0;
}

.terminal__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.terminal__body .page__body {
  padding: 0;
}

.retry__note,
.flow__note {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.btn--unavailable {
  border-style: dashed;
}

.btn--menu {
  background: rgba(224, 164, 88, 0.12);
  border-color: var(--accent);
}

.page--chapter_end .summary {
  border-color: var(--hit);
}

.page--terminal[data-kind="TRAPPED"] .summary,
.page--terminal[data-kind="FAILED_AT_END"] .summary {
  border-color: var(--miss);
}

/* ---------- Chapter review ---------- */

.review__choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.review__choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
}

.review__choice.is-submitted {
  border-color: var(--accent);
}

.review__tag {
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--accent);
}

.review__tag--correct {
  color: var(--hit);
}

.review__tag--incorrect {
  color: var(--miss);
}

/* ---------- Larger screens ---------- */

/* Let the HUD leave the viewport with the page. Its expanded legend is taller than
   focused art controls and used to cover both those controls and the reader jump. */

.strategy-guide, .game-help { margin-block: 1rem; }
.strategy-guide summary, .game-help summary { min-height: 44px; padding: 12px 0; cursor: pointer; }
.decision-breakdown__terms summary { display: list-item; min-height: 44px; padding-block: 10px; cursor: pointer; }
.strategy-guide dt, .game-help dt { font-weight: 700; }
.strategy-guide dd, .game-help dd { margin: 0 0 1rem; }
.strategy-chip .btn { text-transform: none; }

@media (min-width: 768px) and (min-height: 512px), (min-width: 960px) {
  .bar { flex-direction: row; align-items: center; }
  .bar__title { flex: 1 1 0; width: auto; }
  .bar__scroll { width: auto; max-width: 100%; flex: 0 1 auto; margin-inline-start: auto; }
  .bar__actions { flex-wrap: nowrap; overflow-x: auto; touch-action: pan-x; scrollbar-width: thin; }
  .bar__actions > .btn { flex-shrink: 0; white-space: nowrap; max-width: none; }
  .bar__actions > .bar__secondary { display: none; }
  .bar__actions > .bar__more { display: inline-flex; }
  .bar__menu { display: grid; }
  .hud__summary { display: none; }
  .hud__details { display: grid; margin-top: 0; }
  .settings, .settings[data-region="settings"] {
    right: max(24px, var(--safe-right));
    bottom: auto;
    top: max(24px, var(--safe-top));
    left: auto;
    width: min(26.25rem, calc(100% - 48px));
    max-height: calc(100dvh - max(24px, var(--safe-top)) - max(24px, var(--safe-bottom)));
    height: auto;
    border-radius: var(--radius);
  }

  .settings__done {
    align-self: flex-end;
    min-width: 160px;
  }
}

@media (min-width: 640px) {
  .hud__details { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .hud__details { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
/* Learning feedback stays in document flow; long text wraps on narrow phones. */
.strategy-note { font-size: 1rem; color: var(--ink-soft); margin: .75rem 0; overflow-wrap: anywhere; }
.decision-breakdown { margin-block: 1rem; }
.strategy-concepts { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0; list-style: none; }
.decision-modes { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0; list-style: none; }
.strategy-chip { border: 1px solid currentColor; border-radius: 1rem; padding: .25rem .75rem; overflow-wrap: anywhere; max-width: 100%; }

/* Phase 2 public context: fixed columns wrap even on narrow phones. */
.strategy-panel { margin-block: .75rem; overflow-wrap: anywhere; }
.strategy-panel p { margin-block: .35rem; }
.strategy-payoff { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: .875rem; }
.strategy-payoff th, .strategy-payoff td { padding: .35rem; text-align: left; vertical-align: top; border-bottom: 1px solid currentColor; overflow-wrap: anywhere; }
.strategy-payoff th:first-child { width: 20%; }
.telemetry-consequence-bar {
  min-width: 0;
  overflow-wrap: anywhere;
  border: 2px solid #f6d77d;
  background: #101b28;
  color: #fff9e9;
  padding: .75rem 1rem;
  margin: .75rem 0;
  animation: telemetry-enter .18s cubic-bezier(.22, 1, .36, 1) both;
}
.page[data-screen="page"] > .strategy-note { box-sizing: border-box; margin: .75rem var(--gutter); padding: .75rem 1rem; border: 2px solid #f6d77d; background: #101b28; color: #fff9e9; }
.page[data-screen="page"] > .telemetry-consequence-bar:has(+ .strategy-note) { margin-bottom: .75rem; }
@keyframes telemetry-enter { from { opacity: 0; transform: translateY(-.4rem); } to { opacity: 1; transform: translateY(0); } }
.telemetry__deltas { display: flex; flex-wrap: wrap; gap: .5rem; margin: .4rem 0; }
.telemetry__delta { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid currentColor; padding: .2rem .4rem; }
.hud__item--drift .meter__fill { background-image: radial-gradient(circle, #101b28 1px, transparent 1.5px); background-size: 6px 6px; }
.hud__item--recovery .meter__fill { background-image: conic-gradient(#101b28 25%, transparent 0 50%, #101b28 0 75%, transparent 0); background-size: 8px 8px; }
.caption-overlay-box { border: 2px solid #f6d77d; background: rgba(10,14,22,.92); color: #fff; font-size: max(1.125rem, 18px); line-height: 1.5; padding: .6rem .85rem; margin: .5rem 0; }
.caption-overlay-box p { margin: .2rem 0; }
.recap-layer { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 1rem; background: rgba(0, 0, 0, .8); overflow: auto; }
.recap { width: min(100%, 42rem); max-height: calc(100dvh - 2rem); overflow: auto; padding: 1.25rem; border: 2px solid #f6d77d; background: #101b28; color: #fff9e9; box-shadow: 0 1rem 3rem #000; }
.recap h2 { font-size: clamp(1.1rem, 3vw, 1.5rem); }
.recap [data-action="recap-resume"] { min-height: 48px; color: #101b28; background: #f6d77d; border-color: #f6d77d; }
.app[data-screen="results"] nav[aria-label] { display: flex; flex-wrap: wrap; gap: 8px; }
.app:is([data-screen="profile"], [data-screen="results"], [data-screen="leaderboard"]) .page--idle { box-sizing: border-box; padding: clamp(1rem, 3vw, 2rem); align-self: stretch; }
.app[data-screen="leaderboard"] .page--idle { flex: 0 1 auto; min-height: 0; }
.app:is([data-screen="profile"], [data-screen="results"], [data-screen="leaderboard"]) .page--idle > .settings__dialog { padding: .75rem; }
.leaderboard-empty { display: grid; justify-items: start; gap: .5rem; padding: 1rem; border: 2px solid var(--accent); background: var(--paper); color: var(--ink); }
.leaderboard-empty p { margin: 0; }
.consequence--compact, .course-correction-detail { min-width: 0; height: auto; overflow-wrap: anywhere; }
@media (max-width: 767px) { .caption-overlay-box { font-size: max(1rem, 16px); } }
@media (prefers-reduced-motion: reduce) { .telemetry-consequence-bar, .caption-overlay-box { animation: none !important; transition: none !important; } }
.ending-stamp { display: inline-flex; align-items: center; gap: .5rem; width: fit-content; max-width: 100%; padding: .5rem .75rem; border: 3px double currentColor; font-weight: 800; letter-spacing: .08em; background: var(--paper); }
.ending-stamp--pass { color: var(--hit); }
.ending-stamp--trapped { color: var(--accent); background-image: repeating-linear-gradient(135deg, transparent 0 10px, rgb(255 214 0 / .12) 10px 14px); }
.ending-stamp--failed { color: var(--miss); background-image: repeating-linear-gradient(90deg, transparent 0 11px, rgb(239 106 91 / .12) 11px 14px); }
.ending-banner { margin: .5rem 0; font-weight: 800; letter-spacing: .04em; }
.ending-stamp { animation: ending-slam 260ms cubic-bezier(.16, 1, .3, 1) both; }
@keyframes ending-slam { from { transform: scale(1.35) rotate(-2deg); opacity: .5; } to { transform: scale(1) rotate(-2deg); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ending-stamp { animation: ending-fade 150ms ease-out both; } @keyframes ending-fade { from { opacity: 0; } to { opacity: 1; } } }
.reader-utilities { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0 var(--gutter); }
.reader-utilities .btn { min-height: 44px; }
.reader-topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.last-call-cost { margin-inline-end: var(--gutter); padding: 2px 6px; border: 1px solid var(--edge); border-radius: 4px; color: var(--ink); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.last-call-cost[data-tone="positive"] { border-color: var(--hit); color: var(--hit); }
.last-call-cost[data-tone="negative"] { border-color: var(--miss); color: var(--miss); }
.reader-rules, .offline-results { padding-inline: var(--gutter); overflow-wrap: anywhere; }
.page[data-screen="page"] > .page__body { margin-top: 8px; }
.page[data-screen="page"] { padding-top: 16px; }
.course-correction-detail { margin: .75rem var(--gutter); padding: .75rem; border: 2px solid var(--miss); background: var(--paper-2); }
.course-correction-detail p { max-width: 70ch; }
.reader-recovery-warning { margin: .75rem var(--gutter); padding: .75rem; border-left: 4px solid var(--miss); background: var(--paper-2); font-weight: 700; }
.reader-recovery-warning p { margin: 0; }
.reader-lost-banner { margin: .75rem var(--gutter); padding: .75rem; border: 3px double var(--miss); background: var(--paper-2); }
.reader-play-on-status { margin: .5rem var(--gutter); padding: .45rem .75rem; border-inline-start: 4px solid var(--miss); background: var(--paper-2); font-weight: 700; }
.reader-lost-banner h2 { margin: 0 0 .25rem; }
.reader-lost-banner p { margin: .25rem 0; }
.reader-lost-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: .75rem; }
.reader-lost-actions .btn { flex: 1 1 10rem; }
.reader-shuffle-notice { margin: .5rem var(--gutter); font-size: .875rem; }
.reader-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 var(--gutter); }
.reader-actions .reader-jump { flex: 0 0 auto; margin: 0; }
.reader-jump--after-panels { width: fit-content; min-height: 44px; margin: .5rem var(--gutter); }
.reader-skip-status { margin: .25rem var(--gutter); }
.reader-skip-status:empty { display: none; }
.reader-actions .reader-utilities { flex: 1 1 auto; padding: 0; }
@media (min-width: 768px) {
  .reader-actions, .reader-actions .reader-utilities { flex-wrap: nowrap; }
  .reader-actions .btn { white-space: nowrap; }
}
@media (min-width: 768px) and (max-width: 1179px) {
  .app[data-screen="play"] .reader-tool-full { display: none; }
  .app[data-screen="play"] .reader-tool-compact { display: inline; }
  .app[data-screen="play"] .reader-actions { gap: 8px; }
  .app[data-screen="play"] .reader-actions .reader-utilities { gap: 8px; }
}
.reader-tool-compact { display: none; }
.studio-drawer-layer { position: fixed; inset: 0; z-index: 1001; display: flex; justify-content: flex-end; background: rgb(0 0 0 / .8); }
.studio-drawer-layer.history-confirm-layer { justify-content: center; }
.history-confirm-layer .title-screen__confirm { display: flex; flex-direction: column; width: min(100%, 32rem); max-height: calc(100dvh - max(12px, var(--safe-top)) - max(12px, var(--safe-bottom))); gap: 8px; padding: .75rem; }
.history-confirm__body { min-height: 0; overflow-y: auto; }
.history-confirm__body h2, .history-confirm__body p { margin: 0 0 .5rem; }
.history-confirm__actions { display: flex; flex-wrap: wrap; gap: 8px; flex: 0 0 auto; }
@media (max-width: 400px) { .history-confirm__actions { flex-direction: column; } .history-confirm__actions .btn { width: 100%; } }
.studio-drawer { width: min(100%, 38rem); max-height: 100dvh; overflow: auto; padding: 1.25rem; border-left: 3px solid var(--accent); background: var(--paper); color: var(--ink); }
.studio-drawer h2 { margin-top: 0; }
.branch-map { width: min(100%, 62rem); }
.branch-map__nodes { display: grid; grid-auto-flow: row; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: .75rem; padding: 0; list-style: none; }
.branch-map__node { position: relative; min-width: 0; min-height: 4rem; padding: .75rem; border: 2px solid var(--edge); background: var(--paper-2); overflow-wrap: anywhere; }
.branch-map__node--active { border: 3px solid var(--accent); }
.branch-map__node--active:has(+ .branch-map__node--active)::after { content: ''; position: absolute; left: calc(50% - 1.5px); bottom: -.8rem; width: 3px; height: .8rem; background: var(--accent); transform-origin: top; animation: board-string 350ms ease-out both; }
.branch-map__node--earlier { border-style: dashed; }
.branch-map__node--classified { border-style: dotted; }
.branch-map__node summary { cursor: pointer; min-height: 44px; font-weight: 700; }
.branch-map__node summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.branch-map__node img { object-fit: cover; max-width: 100%; }
.branch-map__text { border-top: 2px solid var(--edge); padding-top: .75rem; }
@keyframes board-string { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@media (min-width: 700px) { .branch-map__nodes { grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); } }
.update-notice { position: static; align-self: stretch; width: min(100%, 36rem); padding: 1rem; border: 3px solid var(--accent); background: var(--paper); color: var(--ink); box-shadow: 0 .5rem 1.5rem rgb(0 0 0 / .45); }
.update-notice[hidden], .install-card[hidden] { display: none; }
.update-notice button, .install-card button { min-height: 44px; margin-right: .5rem; }
.install-card { margin: 1rem 0; padding: 1rem; border: 2px solid var(--accent); background: var(--paper); color: var(--ink); }
.install-card__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.mission-log__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.credits__help { display: inline-flex; align-items: center; min-width: 44px; min-height: 44px; }
@media (prefers-reduced-motion: reduce) { .branch-map *, .update-notice *, .install-card * { animation: none !important; transition: none !important; } }

.passport { width: min(100%, 64rem); }
.passport__group { margin-block: 1.25rem; }
.passport__group h3 { margin-block: 0 .75rem; }
.passport__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; padding: 0; list-style: none; }
@media (min-width: 700px) { .passport__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.passport-stamp { display: flex; flex-direction: column; gap: .3rem; min-width: 0; padding: .75rem; background: var(--paper-2); overflow-wrap: anywhere; }
.passport-stamp--locked { border: 4px double var(--edge); color: var(--ink-soft); background-image: radial-gradient(circle, rgb(127 127 127 / .06) 1px, transparent 1.5px); background-size: 5px 5px; }
.passport-stamp--earned { border: 5px double var(--accent); color: var(--accent); background-image: radial-gradient(circle, rgb(255 255 255 / .11) 1px, transparent 1.5px); background-size: 5px 5px; transform: rotate(-2deg); }
.passport-stamp__silhouette { display: block; width: 2.25rem; height: 2.25rem; border: 3px solid currentColor; border-radius: 50%; opacity: .7; }
.passport-stamp--locked .passport-stamp__silhouette { opacity: .3; box-shadow: inset 0 0 0 3px var(--paper-2), 0 0 0 2px var(--edge); transform: rotate(-2deg); }
.preparing-visual { width: min(100%, 42rem); aspect-ratio: 16 / 9; overflow: hidden; border: 2px solid var(--edge); background: linear-gradient(135deg, var(--paper-2), var(--paper)); }
.preparing-visual img { display: block; width: 100%; height: 100%; object-fit: cover; }
.passport-stamp--earned .passport-stamp__silhouette { opacity: 1; box-shadow: inset 0 0 0 3px var(--paper-2); }
.passport-stamp__badge { font-weight: 800; letter-spacing: .08em; }
.passport-stamp--new { animation: passport-ink 250ms ease-out both; }
@keyframes passport-ink { from { transform: scale(1.12); } to { transform: scale(1); } }
.share-dossier { width: min(100%, 52rem); }
.share-dossier pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 1rem; border: 2px solid var(--edge); background: var(--paper-2); color: var(--ink); user-select: text; }
.share-dossier__actions { display: flex; flex-wrap: wrap; gap: .5rem; }
@media (prefers-reduced-motion: reduce) { .passport-stamp--new { animation: none; } }
.dossier-card, .mission-log__entry { margin: .75rem 0; padding: .75rem; border: 1px solid var(--edge); background: var(--paper-2); }
.dossier-card--locked { color: var(--ink-soft); }
.mission-log ol { padding-left: 1.5rem; }
.tactical-assist { margin: .75rem 0; padding: .75rem; border: 1px solid var(--accent); }
.tactical-assist summary { min-height: 44px; cursor: pointer; }
.hud__legend { grid-column: 1 / -1; display: grid; gap: .2rem; padding: .5rem; border-top: 1px solid var(--edge); color: var(--ink); font-size: .875rem; text-transform: none; letter-spacing: 0; }
.hud__legend p { margin: .15rem 0; }
.panel-art__media { position: relative; }
.panel__art-copy { position: static; display: grid; gap: .35rem; width: 100%; max-width: 100%; padding: .5rem .75rem; background: var(--paper-2); pointer-events: auto; }
.panel__art-copy .caption, .panel__art-copy .sfx { width: fit-content; max-width: 100%; padding: .35rem .55rem; background: rgb(10 14 22 / .96); color: #fff; border: 2px solid #f6d77d; border-radius: .25rem; text-shadow: none; }
.panel__art-copy .sfx { color: #ffd600; }
.panel-art--clip .panel__art-copy { max-width: 100%; }
@media (max-width: 639px) {
  /* Caption text follows the image on phones so it cannot cover the comic panel. */
  .panel__art-copy, .panel-art--clip .panel__art-copy {
    position: static;
    max-width: 100%;
    padding: 8px;
    pointer-events: auto;
  }
}
.art__legend { padding: .4rem .75rem; }
.art__legend summary { min-height: 44px; cursor: pointer; font-weight: 700; color: var(--ink); }
.page[data-screen="page"] .panel-art .art__legend { display: block; }
.art__legend[open] .art__legend-item { display: list-item !important; position: static !important; width: auto !important; height: auto !important; margin: 0 !important; clip: auto !important; white-space: normal !important; }
.reader-jump { position: static; align-self: flex-end; width: fit-content; margin-right: var(--gutter); background: var(--paper); border: 2px solid var(--accent); }
#reader-choices { scroll-margin-block-start: 6rem; }
.share-dossier pre { line-height: 1.8; font-family: ui-monospace, monospace; }
.hud__legend { display: block; }
.hud__legend summary { cursor: pointer; width: 44px; min-height: 44px; display: grid; place-items: center; border: 1px solid var(--edge); border-radius: 50%; list-style: none; }
.hud__legend summary::-webkit-details-marker { display: none; }
.hud__legend { position: relative; z-index: 5; }
.hud__legend .plain-rules {
  position: absolute; inset-block-start: calc(100% + 4px); inset-inline-end: 0;
  width: min(25rem, 90vw); min-width: min(18rem, 90vw); max-height: min(70dvh, 30rem);
  overflow: auto; padding: .75rem; border: 2px solid var(--edge);
  background: var(--paper-2); box-shadow: 0 8px 24px rgb(0 0 0 / .35);
}
.plain-rules p { margin: .5rem 0; line-height: 1.5; }
.hud__warning { grid-column: 1 / -1; margin: 0; padding: .5rem; border: 2px solid var(--miss); color: var(--miss); font-weight: 700; }
.hud__summary-warning { display: block; color: var(--miss); font-weight: 700; }
.hud__summary-chips { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 6px; }
.hud__summary-chip { display: inline-flex; gap: 2px; align-items: baseline; white-space: normal; line-height: 1.15; }
.hud__summary-label { font-weight: 800; }
@media (max-width: 639px) {
  .app[data-screen="play"] .page[data-screen="page"] { gap: 0; }
  .app[data-screen="play"] .reader-topline .reader-heading { margin: 0 var(--gutter); }
  .app[data-screen="play"] .reader-heading__context { display: none; }
  .app[data-screen="play"] .reader-heading { white-space: nowrap; }
  .app[data-screen="play"] .reader-actions { position: relative; z-index: 1; gap: 8px; overflow-x: visible; }
  .app[data-screen="play"] .reader-actions .reader-jump { margin: 0; }
  .app[data-screen="play"] .reader-actions .reader-utilities { flex-wrap: nowrap; gap: 8px; }
  .app[data-screen="play"] .reader-actions .btn { flex: 0 0 auto; padding-inline: 5px; font-size: .75rem; }
  .app[data-screen="play"] .reader-actions .btn:focus-visible { outline-offset: 0; }
  .app[data-screen="play"] .reader-tool-full { display: none; }
  .app[data-screen="play"] .reader-tool-compact { display: inline; }
  .app[data-screen="play"] { gap: 8px; }
  .app[data-screen="play"] .bar { gap: 8px; }
  .app[data-screen="play"] .bar__title { font-size: .8125rem; line-height: 1.1; }
  .app[data-screen="play"] .bar__help { display: none; }
  .app[data-screen="play"] .bar__actions { gap: 8px; padding: 0; flex-wrap: wrap; overflow-x: visible; }
  .app[data-screen="play"] .btn--bar { padding-inline: 6px; font-size: .8125rem; }
  .app[data-screen="play"] .hud__summary { min-height: 44px; }
  .app[data-screen="play"] .reader-heading { font-size: 1rem; line-height: 1.1; }
  .app[data-screen="play"] .page[data-screen="page"] > .page__body { padding-top: 0; }
  .app[data-screen="play"] .hud__details[data-expanded="true"] { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 8px; }
  .app[data-screen="play"] .hud__item { flex-direction: row; align-items: center; justify-content: space-between; }
  .app[data-screen="play"] .hud__item--intelligence { grid-column: 1 / -1; }
  .app[data-screen="play"] .hud__item--intelligence .hud__value { font-size: 1rem; }
  .app[data-screen="play"] .hud__item .meter, .app[data-screen="play"] .hud__item .pips { display: none; }
}
@media (max-width: 420px) {
  /* Keep the first comic panel in view without reducing the reader's 8px art clearance. */
  .app[data-screen="play"] { gap: 3px; }
  .app[data-screen="play"] .bar { gap: 4px; }
  .app[data-screen="play"] .last-call-cost { padding-block: 0; }
}
@media (max-width: 480px) {
  /* The bar buttons and HUD toggle are separate targets: 3px shell gap + 7px = 10px. */
  .app[data-screen="play"] .hud { margin-block-start: 7px; }
}
@media (min-width: 360px) and (max-width: 420px) {
  /* The scenario title shares the action row; the post-choice cost chip no longer pushes art below the fold. */
  .app[data-screen="play"] .bar { flex-direction: row; align-items: center; gap: 8px; }
  .app[data-screen="play"] .bar__title { flex: 1 1 0; width: auto; }
  .app[data-screen="play"] .bar__scroll { flex: 0 1 auto; width: auto; }
}
.page[data-screen="page"] :is(button, a[href], input, select, textarea) { scroll-margin-block-start: 6rem; }
@media (min-width: 1024px) {
  /* One desktop chrome row leaves the first comic panel in view at 1280x800. */
  .app[data-screen="play"] .bar { flex-direction: row; align-items: center; gap: 8px; }
  .app[data-screen="play"] .bar__title { flex: 0 1 14rem; width: auto; }
  .app[data-screen="play"] .bar__scroll { flex: 1 1 auto; width: auto; }
  .app[data-screen="play"] .bar__help { align-self: center; }
  .app[data-screen="play"] .hud { min-height: 44px; }
  .app[data-screen="play"] .hud__details {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
    min-height: 44px; overflow-x: visible; margin: 0;
  }
  .app[data-screen="play"] .hud__item {
    flex: 0 0 auto; flex-direction: row; align-items: center; gap: 4px;
    white-space: nowrap; font-size: .8125rem;
  }
  .app[data-screen="play"] .hud__item--intelligence { grid-column: auto; }
  .app[data-screen="play"] .hud__item--intelligence .hud__value { font-size: 1rem; }
  .app[data-screen="play"] .hud__label, .app[data-screen="play"] .hud__sub { font-size: .6875rem; letter-spacing: 0; }
  .app[data-screen="play"] .hud__item .meter, .app[data-screen="play"] .hud__item .pips { display: none; }
  .app[data-screen="play"] .hud__legend { flex: 0 0 44px; margin: 0; padding: 0; border: 0; }
  .app[data-screen="play"] .page[data-screen="page"] {
    display: grid; grid-template-columns: auto minmax(0, 1fr); align-content: start; gap: 0;
  }
  .app[data-screen="play"] .page[data-screen="page"] > :not(.reader-topline):not(.reader-actions) { grid-column: 1 / -1; }
  .app[data-screen="play"] .reader-topline { grid-column: 1; grid-row: 1; min-height: 44px; padding-inline-start: var(--gutter); }
  .app[data-screen="play"] .reader-heading { margin: 0; font-size: 1rem; }
  .app[data-screen="play"] .reader-actions { grid-column: 2; grid-row: 1; min-height: 44px; }
  .page[data-screen="page"] .page__body[data-layout] { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .page[data-screen="page"] .page__body > .panel { min-width: 0; }
  .page[data-screen="page"] .panel-art .art { max-height: none; }
  /* Reserve room for the header and caption so square art fits one viewport. */
  .page[data-screen="page"] .panel-art .art--close,
  .page[data-screen="page"] .panel-art .art--detail,
  .page--review .panel-art .art--close,
  .page--review .panel-art .art--detail { width: 100%; max-width: 100%; max-height: none; margin-inline: auto; }
  .page[data-screen="page"] .page__body[data-layout="stack-3"] > .panel:last-child { grid-column: 1 / -1; width: min(100%, 42rem); margin-inline: auto; }
  /* Reserve the reader chrome and the clue/transcript area below square art. */
  .page[data-screen="page"] .page__body[data-layout] > .panel:has(.art--close, .art--detail) { width: min(100%, max(280px, calc(100dvh - 580px))); margin-inline: auto; }
  .page--review .review__body > .panel:has(.art--close, .art--detail) { width: min(100%, 60dvh); margin-inline: auto; }
}
@media (min-width: 1440px) {
  .page[data-screen="page"] .page__body[data-layout="stack-3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .page[data-screen="page"] .page__body[data-layout="stack-3"] > .panel:last-child { grid-column: auto; }
}
@media (min-width: 1440px) and (max-height: 900px) {
  /* A closed Clues control fits beside square art; opened clue text uses the full width below it. */
  .page[data-screen="page"] .panel:has(.art--close, .art--detail) .panel-art:has(> .art__legend) { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 8px; }
  /* Long captions stay full width and scroll by keyboard; the side slot made them hundreds of pixels tall. */
  .page[data-screen="page"] .panel:has(.panel__art-copy--long) .panel-art:has(> .art__legend) { display: block; }
  .page[data-screen="page"] .panel__art-copy--long { max-height: 8rem; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
  .page[data-screen="page"] .panel:has(.art--close, .art--detail) .panel-art > .art__legend { padding: 0; margin: 0; }
  .page[data-screen="page"] .panel:has(.art--close, .art--detail) .panel-art > .art__legend[open] { grid-column: 1 / -1; }
}
@media (min-width: 1180px) {
  /* A long last-call label must not steal the toolbar's row from the first panel. */
  .app[data-screen="play"] .page[data-screen="page"] { grid-template-columns: 28rem minmax(0, 1fr); }
  .app[data-screen="play"] .reader-topline { min-width: 0; }
  .app[data-screen="play"] .reader-topline .reader-heading { min-width: 0; white-space: normal; }
}
.ending-stamp { transform: rotate(-2deg); background-image: radial-gradient(circle, rgb(255 255 255 / .11) 1px, transparent 1.5px); background-size: 5px 5px; }
.results-hero { display: grid; gap: 12px; margin-block: 16px 24px; padding: 16px; border: 2px solid var(--edge); background: var(--paper-2); }
.results-hero > * { margin: 0; max-width: 68ch; }
.results-hero__meter { display: grid; gap: 2px; }
.results-hero__meter strong { font-size: clamp(2.25rem, 8vw, 4rem); line-height: 1; font-variant-numeric: tabular-nums; }
.results-scoring { max-width: 68ch; margin-block: 16px; }
.results-scoring summary { min-height: 44px; cursor: pointer; }
.app[data-screen="results"] .page--idle :is(p, li) { max-width: 68ch; }
.btn--primary, .title-screen__continue.btn--primary { border-color: var(--accent); background: var(--accent); color: var(--primary-ink); font-weight: 800; }
.title-screen:has(.title-screen__continue) [data-action="title-start"].btn--primary { border-color: var(--edge); background: var(--paper); color: var(--ink); }
.reader-heading:focus-visible, .review__title:focus-visible { outline-offset: -3px; padding-inline: 8px; }
.reader-heading:focus:not(:focus-visible), .review__title:focus:not(:focus-visible) { outline: none; }
.app[data-input-modality="pointer"] :is(.reader-heading, .review__title):focus { outline: none; padding-inline: 0; }
.app[data-input-modality="keyboard"] :is(.reader-heading, .review__title):focus { outline: 3px solid var(--accent); outline-offset: -3px; padding-inline: 8px; }
.page--scenario-complete .terminal__body { order: -1; }
@media (prefers-reduced-motion: reduce) { .ending-stamp { transform: none; animation: none; } }
/* The in-app setting has the same reach as the operating-system motion preference. */
html[data-reduce-motion="true"] *, html[data-reduce-motion="true"] *::before, html[data-reduce-motion="true"] *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
html[data-reduce-motion="true"] .ending-stamp { transform: none; animation: ending-fade 150ms ease-out both !important; }

/* M36 A1 item 3: phone HUD text has a 13-14px floor; a chip ("Misses 0 of 3") wraps as one unit, never inside. */
@media (max-width: 430px) {
  .hud__summary, .app[data-screen="play"] .hud__summary { font-size: .875rem; }
  .hud__label, .hud__sub, .app[data-screen="play"] .hud__label, .app[data-screen="play"] .hud__sub { font-size: .8125rem; letter-spacing: .01em; }
  .hud__legend { font-size: .875rem; }
  .last-call-cost, .app[data-screen="play"] .last-call-cost { font-size: .8125rem; }
  html:not([lang="qps-ploc"]) .hud__summary-chip, .hud__count { white-space: nowrap; }
  .hud__summary-chips { max-width: 100%; min-width: 0; }
}

/* M36 A1 item 6: low-risk CSS fixes from docs/M35_A4_VISUAL_AUDIT.md. */
/* V-14 orphans: balanced headings and legends, no one-word last lines in prose. */
:is(h1, h2, h3, legend, .reader-heading, .review__title) { text-wrap: balance; }
p, li, figcaption { text-wrap: pretty; }
/* V-19 toggle visuals: every role=switch shows the audio switch's on-state fill and width. */
.btn[role="switch"] { min-width: 72px; justify-content: center; }
.btn[role="switch"][aria-checked="true"] { background: var(--hit); border-color: var(--hit); color: var(--paper); }
/* V-20 nested frames: a concept pill is one frame (the button), not a bordered chip around a bordered button. */
.strategy-chip { border: 0; padding: 0; border-radius: 0; }
.strategy-chip .btn { border-radius: 1rem; }
/* V-24 disabled controls: aria-disabled controls look like disabled ones everywhere. */
.btn[aria-disabled="true"] { color: var(--disabled-ink); border-color: var(--disabled-edge); cursor: not-allowed; }
/* M36 A6 item 9: a choice gated during the reveal still queues a tap, so it is muted by data-gate, not aria-disabled. */
.btn[data-gate="closed"] { color: var(--disabled-ink); border-color: var(--disabled-edge); cursor: not-allowed; }
/* V-35 recent runs (style half): Delete reads as a destructive action, not a normal button. */
.title-screen__history [data-action="history-delete"] { border-color: var(--miss); color: var(--miss); background: transparent; }
/* M36 A6 item 12: the light theme keeps the title buttons dark (#263041); Delete uses a light red there (about 6.5:1). */
:root[data-theme="light"] .title-screen__history .btn[data-action="history-delete"] { color: #ff9b8f; border-color: #ff9b8f; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .title-screen__history .btn[data-action="history-delete"] { color: #ff9b8f; border-color: #ff9b8f; }
}
/* V-37 focus vs selected: selected is a fill, focus is the outline ring; they no longer share one treatment. */
.settings__themes [aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--accent); background: rgba(224, 164, 88, 0.16); }
.settings__themes [aria-pressed="true"]:focus-visible { outline-offset: 4px; }
.settings__volume input[type="range"]:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }

/* M36-A2: remaining visual-audit findings (docs/M35_A4_VISUAL_AUDIT.md). */
/* V-13 typefaces: one UI font token; the readable-font preference swaps only the token. */
:root { --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; }
:root[data-font="readable"] { --font-ui: "Trebuchet MS", Verdana, "Segoe UI", system-ui, sans-serif; }
body, :root[data-font="readable"] body, :root[data-font="readable"] :is(.bubble, .caption, .caption-overlay-box, .hud, .choice, .btn, .question__prompt) { font-family: var(--font-ui); }
/* V-12 locked dossier: one hint, then a compact grid of redacted bars of varied length with a lock glyph. */
.dossier-locked-hint { margin: .75rem 0 .5rem; color: var(--ink-soft); }
.dossier-locked-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.dossier-locked-grid .dossier-card--locked { display: flex; align-items: center; gap: .5rem; margin: 0; padding: .5rem .75rem; }
.dossier-locked-grid .dossier-card--locked::before { content: ""; flex: 0 0 auto; inline-size: .7em; block-size: .6em; margin-block-start: .3em; border: 2px solid currentColor; border-radius: 2px; box-shadow: 0 -.42em 0 -.1em transparent, inset 0 0 0 1px currentColor; }
.dossier-redacted { flex: 1 1 auto; block-size: .85em; max-inline-size: 85%; background: currentColor; border-radius: 2px; }
.dossier-locked-grid li:nth-child(3n + 2) .dossier-redacted { max-inline-size: 60%; }
.dossier-locked-grid li:nth-child(3n) .dossier-redacted { max-inline-size: 72%; }
/* V-17 name field: a visible hint and an invalid state the description explains. */
.field-hint { margin: .25rem 0; color: var(--ink-soft); font-size: .875rem; }
input[aria-invalid="true"] { border-color: var(--miss); box-shadow: inset 0 0 0 1px var(--miss); }
/* V-22 vertical rhythm: one small scale on the cited gaps. */
.update-notice h2 { margin: 0 0 .5rem; }
.app[data-screen="results"] .page--idle p { margin-block: .5rem; }
.branch-map__node details > p { margin: .25rem 0 0; }
.scenario-intro__transcript:not([open]) { padding-block: 0; }
.page--flow .consequence { margin-block: 16px; }
/* V-27 desktop overlays: open Settings dims the page; drawers fit their content instead of a fixed tall sheet. */
@media (min-width: 768px) {
  .settings[data-region="settings"]:not([hidden]) { box-shadow: 0 0 0 100vmax rgb(0 0 0 / .6), 0 18px 48px rgba(0, 0, 0, 0.55); }
  .studio-drawer-layer:not(.history-confirm-layer) { align-items: flex-start; }
  .studio-drawer-layer:not(.history-confirm-layer) > .studio-drawer { height: auto; max-height: 100dvh; }
}
/* V-28 board: two stat chips. */
.branch-map__stats { display: flex; flex-wrap: wrap; gap: 8px; margin: .5rem 0; }
.branch-map__stat { padding: .25rem .75rem; border: 1px solid var(--accent); border-radius: 1rem; font-weight: 700; }
.branch-map__unexplored { color: var(--ink-soft); }
/* V-35 run in progress is labelled in Recent runs. */
/* M36-A5: inherit the row's text colour; --accent in light theme was 2.52:1 on the title backdrop. Bold marks it. */
.title-screen__in-progress { color: inherit; font-weight: 800; }
/* V-36 comic lettering: SFX in a display face with skew and stroke; captions tilt slightly on a dotted paper texture.
   The readable-font preference and reduced motion keep them upright and in the UI face. */
.panel p.sfx, .panel__art-copy .sfx { font-family: Impact, "Arial Black", var(--font-ui); font-weight: 900; font-style: italic; letter-spacing: .04em; color: #ffe066; background: rgb(10 14 22 / .96); width: fit-content; max-width: 100%; padding: .2rem .5rem; -webkit-text-stroke: 1px #000; paint-order: stroke fill; transform: skew(-6deg) rotate(-2deg); }
/* M36-A3: #ffe066 always sits on its own #0a0e16 backing (14.8:1), never on light paper (1.2:1). */
.panel p.caption, .panel__art-copy .caption { transform: rotate(-.6deg); background-image: radial-gradient(circle, rgb(255 255 255 / .08) 1px, transparent 1.5px); background-size: 5px 5px; }
:root[data-font="readable"] :is(.panel p.sfx, .panel__art-copy .sfx) { font-family: var(--font-ui); font-style: normal; -webkit-text-stroke: 0; }
/* M36 A6 D10: readable font also keeps SFX and captions upright, as the comment above promises. */
:root[data-font="readable"] :is(.panel p.sfx, .panel__art-copy .sfx, .panel p.caption, .panel__art-copy .caption) { transform: none; }
html[data-reduce-motion="true"] :is(.panel p.sfx, .panel__art-copy .sfx, .panel p.caption, .panel__art-copy .caption) { transform: none; }
@media (prefers-reduced-motion: reduce) { :is(.panel p.sfx, .panel__art-copy .sfx, .panel p.caption, .panel__art-copy .caption) { transform: none; } }

/* qps-ploc expands chrome by 35%; controls grow vertically and labels wrap. */
html[lang="qps-ploc"] .bar__title { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
html[lang="qps-ploc"] .bar__actions { flex-wrap: wrap; overflow-x: visible; }
html[lang="qps-ploc"] .bar__actions > .btn { flex: 1 1 7rem; min-height: 44px; height: auto; white-space: normal; overflow-wrap: anywhere; }
html[lang="qps-ploc"] .settings__header { flex-wrap: wrap; min-height: 44px; }
html[lang="qps-ploc"] .settings__row { grid-template-columns: minmax(0, 1fr) auto; min-height: 44px; overflow-wrap: anywhere; }
html[lang="qps-ploc"] .choice, html[lang="qps-ploc"] .page .btn { flex-wrap: wrap; height: auto; min-height: 44px; overflow-wrap: anywhere; white-space: normal; }
html[lang="qps-ploc"] .hud__item, html[lang="qps-ploc"] .hud__summary, html[lang="qps-ploc"] .review__tag,
html[lang="qps-ploc"] .passport-stamp, html[lang="qps-ploc"] .reader-utilities .btn { min-width: 0; height: auto; min-height: 44px; overflow-wrap: anywhere; white-space: normal; }
html[lang="qps-ploc"] .hud__details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
html[lang="qps-ploc"] .title-screen h1 { font-size: clamp(2rem, 10vw, 4rem); line-height: 1.1; overflow-wrap: anywhere; }
html[lang="qps-ploc"] .title-screen__eyebrow { overflow-wrap: anywhere; }

/* ---- styles/select.css ---- */
/*
 * Scenario select screen (src/ui/select.ts). Phone-first: one column, 48px tap targets, min-width queries only.
 * No transitions and no keyframes, so the transform/opacity-only motion rule in styles.css is untouched.
 * Colours come from the custom properties in styles.css; each has a fallback so this file also works alone.
 * Every class is select-prefixed, so none of the page, panel or choice rules (reveal, flip) apply here.
 * Labels keep their exact casing ("Intelligence Meter" / "game rating"): no text-transform anywhere.
 */

.select {
  --select-ink: var(--ink, #f3ecdf);
  --select-soft: var(--ink-soft, #bdb3a1);
  --select-edge: var(--edge, #3a4157);
  --select-accent: var(--accent, #e0a458);
  --select-primary-ink: var(--primary-ink, #14161f);
  --select-hit: var(--hit, #5fd39a);
  --select-miss: var(--miss, #ef6a5b);
  --select-radius: var(--radius, 14px);
  --select-tap: var(--tap, 48px);
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  color: var(--select-ink);
}

.select__header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.select__title {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.select__note,
.select__empty {
  margin: 0;
  padding: 10px 14px;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--select-ink);
  border-radius: var(--select-radius);
}

.select__note {
  background: rgba(224, 164, 88, 0.12);
  border: 1px solid var(--select-accent);
}

.select__empty {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--select-edge);
}

/* Overall game rating */

.select-rating {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label value"
    "sub value"
    "detail detail";
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--select-edge);
  border-radius: var(--select-radius);
  background: rgba(255, 255, 255, 0.04);
}

.select-rating__label {
  grid-area: label;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--select-soft);
}

.select-rating__sub {
  grid-area: sub;
  font-size: 0.75rem;
  color: var(--select-soft);
}

.select-rating__value {
  grid-area: value;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  color: var(--select-accent);
  font-variant-numeric: tabular-nums;
}

.select-rating__detail {
  grid-area: detail;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--select-soft);
}

/* Scenario cards */

.select__list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  justify-items: center;
}

.select-card {
  width: 100%;
  max-width: 560px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.select-card__body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--select-edge);
  border-radius: var(--select-radius);
  background: linear-gradient(160deg, var(--paper-2, #1f2433) 0%, var(--paper, #171b26) 100%);
}

.select-card[data-in-progress="true"] .select-card__body {
  border-color: var(--select-accent);
}

.select-card__title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.select-card__status {
  margin: 0;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  color: var(--select-soft);
}

.select-card[data-status="completed"] .select-card__status,
.select-card[data-status="extended"] .select-card__status {
  color: var(--select-hit);
}

.select-card__logline {
  margin: 0;
  color: var(--select-soft);
  overflow-wrap: anywhere;
  white-space: normal;
}

.select-card .select-card__cover--placeholder { display: flex; align-items: center; justify-content: center; aspect-ratio: 16 / 9; background: var(--paper-2); color: var(--select-soft); font-size: 3rem; font-weight: 700; }

/* The title action and trailer are separate controls, in DOM reading order. */
.select-card__body > .select-card__action { width: 100%; min-width: 44px; align-items: flex-start; text-align: left; }
.select-card__action-label { font-size: 1rem; font-weight: 400; }
.select-card .select-chapter { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "num state" "title title" "len len" "note note"; }
@media (min-width: 768px) {
  .select__list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1440px) {
  .select__list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.select-card__summary {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--select-soft);
}

.select-card__best {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Chapter rows: locked, unlocked and passed are told apart by text and by colour, never by colour alone */

.select-chapters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.select-chapter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "num state"
    "title title"
    "len len"
    "note note";
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--select-edge);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.select-chapter__num {
  grid-area: num;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--select-soft);
}

.select-chapter__title {
  grid-area: title;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.select-chapter__len {
  grid-area: len;
  font-size: 0.8125rem;
  color: var(--select-soft);
}

.select-chapter__state {
  grid-area: state;
  justify-self: end;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid currentColor;
  border-radius: 999px;
}

.select-chapter__note {
  grid-area: note;
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--select-soft);
}

.select-chapter[data-state="passed"] .select-chapter__state {
  color: var(--select-hit);
}

.select-chapter[data-state="unlocked"] .select-chapter__state {
  color: var(--select-accent);
}

.select-chapter[data-state="locked"] .select-chapter__title {
  font-weight: 500;
  color: var(--select-soft);
}

.select-chapter[data-state="locked"] .select-chapter__state {
  color: var(--select-soft);
  border-style: dashed;
}

.select-chapter[data-retry="true"] .select-chapter__note {
  color: var(--select-miss);
}

/* Start and continue */

.select-card__action {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--select-tap);
  min-width: 44px;
  padding: 12px 16px;
  color: var(--select-ink);
  font: inherit;
  font-weight: 700;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--select-edge);
  border-radius: var(--select-radius);
  cursor: pointer;
}

.select-card[data-in-progress="true"] .select-card__action {
  color: var(--select-primary-ink);
  background: var(--select-accent);
  border-color: var(--select-accent);
}

.select-card__action:focus-visible {
  outline: 3px solid var(--select-accent);
  outline-offset: 2px;
}

.select-card__action[disabled] {
  color: var(--disabled-ink);
  background: var(--paper-2);
  border-color: var(--disabled-edge);
  opacity: 1;
  cursor: not-allowed;
}

/* Larger screens (min-width only; the phone layout above is the base) */

@media (min-width: 640px) {
  .select__title {
    font-size: 1.75rem;
  }

  .select-card__body {
    padding: 20px;
  }

  .select-chapter {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "num title len state"
      "note note note note";
  }

  .select-card__action {
    width: auto;
    align-self: flex-start;
    min-width: 200px;
  }
}
