/* The first fight's page. The arena is a physical stage, so the page is dark in both themes.
   combat-v1/stick.css is linked read-only (it ships at /play); every fix below is scoped to body.first-loop. */
:root {
  color-scheme: dark;
  --bg: #0f1114;
  --panel: #191c21;
  --ink: #f1e9dc;
  --muted: #a99c8a;
  --line: rgba(241, 233, 220, 0.14);
  --saffron: #f28c1e;
  --hp: #f2a33a;
  --agni: #d8344a;
  --strike: #6fb2ff;
  --grab: #ff9f45;
  --launch: #ffd25a;
  --counter: #ffffff;
  --perfect: #7fe08a;
  --bad: #ff6b6b;
  --gutter: 12px;
  --stage: #0b0e11; /* stick.css paints the phone-landscape letterbox with it */
}
:root[data-theme="light"], :root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, canvas:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--saffron); outline-offset: 3px;
}
.skip { position: absolute; left: 8px; top: -80px; z-index: 60; padding: 10px 14px; background: var(--panel); color: var(--ink); }
.skip:focus { top: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* One line at every width: the brand never wraps (the audit's 390 px header wrap). */
.bar {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: nowrap;
  width: min(960px, 100% - 2 * var(--gutter)); margin: 8px auto 6px; min-width: 0;
}
.bar p { margin: 0; white-space: nowrap; }
.brand { font-weight: 800; letter-spacing: 0.14em; font-size: 14px; color: var(--saffron); flex: none; }
.where { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.play { position: relative; width: min(960px, 100% - 2 * var(--gutter)); margin: 0 auto; }
.arena {
  position: relative; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden;
  background: #0b0e11; border: 1px solid var(--line);
}
.arena canvas { display: block; width: 100%; height: 100%; touch-action: none; }
/* The canvas is the play surface: an inset ring for keyboard focus, none on touch (it read as two orange bars
   beside the letterboxed arena in phone landscape). */
.arena canvas:focus-visible { outline: 2px solid var(--line); outline-offset: -2px; }
body.stick-on .arena canvas:focus-visible { outline: none; }

/* HUD strip, inside the arena so phone-landscape fullscreen keeps it. */
.hud {
  position: absolute; left: 8px; right: 8px; top: 6px; display: grid; align-items: center; gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) 30px; pointer-events: none;
  font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.08em;
  text-shadow: 0 1px 2px #000;
}
.gauge { display: flex; align-items: center; gap: 6px; min-width: 0; }
.gauge i { flex: 1; height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.16); overflow: hidden; min-width: 30px; }
.gauge b { display: block; height: 100%; width: 100%; transform-origin: left; background: var(--hp); transition: transform 0.12s; }
.gauge.agni { flex-direction: row-reverse; }
.gauge.agni b { background: var(--agni); transform-origin: left; }
.waves { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pips { display: inline-flex; gap: 4px; }
.pips i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); opacity: 0.6; }
.pips i.done { background: var(--perfect); border-color: var(--perfect); opacity: 1; }
.pips i.now { background: var(--saffron); border-color: var(--saffron); opacity: 1; }
.up { color: var(--muted); }
.pause-btn {
  pointer-events: auto; width: 30px; height: 26px; padding: 0; border-radius: 6px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.45); color: var(--ink); font-size: 11px; letter-spacing: -1px;
}

/* The tell: the incoming attack and the one answer. Colour carries the kind; the word carries it too. */
.tell {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); display: grid; justify-items: center;
  gap: 2px; padding: 6px 14px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.55); pointer-events: none;
  border: 2px solid var(--cue, var(--ink)); text-align: center; white-space: nowrap;
}
.tell b { font: 900 clamp(18px, 4.2vw, 34px)/1 system-ui, sans-serif; letter-spacing: 0.08em; color: var(--cue); }
.tell span { font: 800 clamp(12px, 2.4vw, 18px)/1.1 system-ui, sans-serif; letter-spacing: 0.1em; color: var(--ink); }
.tell[hidden], .flash[hidden], .coach[hidden] { display: none; }
.tell[data-kind="strike"] { --cue: var(--strike); }
.tell[data-kind="grab"] { --cue: var(--grab); }
.tell[data-kind="launch"] { --cue: var(--launch); }
.flash {
  position: absolute; left: 50%; top: 52%; transform: translateX(-50%); pointer-events: none; white-space: nowrap;
  font: 900 clamp(13px, 2.8vw, 22px)/1 system-ui, sans-serif; letter-spacing: 0.1em; color: var(--cue, var(--ink));
  text-shadow: 0 2px 6px #000, 0 0 2px #000;
}
.flash small { display: block; text-align: center; font-size: 0.6em; color: var(--ink); margin-top: 3px; }
.flash[data-kind="counter"] { --cue: var(--counter); }
.flash[data-kind="perfect"] { --cue: var(--perfect); }
.flash[data-kind="break"] { --cue: var(--bad); }
.flash[data-kind="ender"], .flash[data-kind="ko"] { --cue: var(--launch); }
.flash[data-kind="wave"], .flash[data-kind="clear"] { --cue: var(--saffron); }
.coach {
  position: absolute; left: 8px; bottom: 6px; max-width: calc(100% - 16px); margin: 0; padding: 4px 8px;
  border-radius: 6px; background: rgba(0, 0, 0, 0.55); font-size: 12px; pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.coach b { color: var(--launch); }

/* Keyboard legend for fine pointers; the fight stick replaces it on touch. */
.keys { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.9; }
.keys kbd {
  font: 600 11px/1 ui-monospace, Menlo, Consolas, monospace; padding: 2px 5px; border-radius: 4px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
body.stick-on .keys { display: none; }

/* The fight stick, re-laid for this page: the plate's PAUSE/RESET row gets its own strip above the buttons, so the
   pills never sit on LIGHT/HEAVY (the audit's 390 px overlap). Portrait and desktop only; phone landscape keeps
   stick.css's floating layout, where the pills sit bottom-centre between the lever and the buttons. */
body.first-loop .deck { margin: 8px 0 0; }
@media not all and (orientation: landscape) and (max-height: 520px) {
  body.first-loop .deck { height: 200px; }
  body.first-loop .deck .plate { display: none; }
  body.first-loop .deck .sys { top: 8px; }
  body.first-loop #stick { top: 62px; }
  body.first-loop .deck .buttons { top: 46px; }
}
@media (max-width: 430px) { /* never a landscape phone: those are wider than 430 px */
  body.first-loop #stick { top: 66px; }
}
.deck .buttons button.suggest {
  outline: 3px solid var(--cue, var(--ink)); outline-offset: 5px; animation: suggest 0.42s ease-in-out infinite alternate;
}
.deck .buttons button.suggest[data-action="guard_down"] { --cue: var(--strike); }
.deck .buttons button.suggest[data-action="dodge"] { --cue: var(--grab); }
.deck .buttons button.suggest[data-action="jump"] { --cue: var(--launch); }
@keyframes suggest { to { outline-offset: 1px; } }

/* Title, pause and result cards: over the arena and the stick, never a page of notes. No backdrop blur: over a
   live WebGL canvas it held software-rendered frames at 130-250 ms (proof README, "Frame pacing"). */
.card {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 10px;
  background: rgba(8, 9, 11, 0.78); border-radius: 8px; overflow: auto;
}
.card[hidden] { display: none; }
.card-body {
  width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px 16px; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}
.card h1 { margin: 0 0 8px; font-size: 20px; line-height: 1.15; }
.card p { margin: 0 0 8px; color: var(--muted); font-size: 13.5px; }
.card .loading { color: var(--muted); }
.stages { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.stages li { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; font-size: 13.5px; }
.stages .n {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 12px;
  border: 1.5px solid var(--line); color: var(--muted);
}
.stages li.live .n { background: var(--saffron); border-color: var(--saffron); color: #160c02; }
.stages .t b { display: block; }
.stages .t span { color: var(--muted); font-size: 12px; }
.chip {
  font: 700 10px/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.06em; padding: 4px 6px;
  border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.stages li.live .chip { color: #160c02; background: var(--perfect); border-color: var(--perfect); }
.howto { margin: 0 0 12px; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 13px; }
.howto b.s { color: var(--strike); } .howto b.g { color: var(--grab); } .howto b.l { color: var(--launch); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 10px; }
.stats div { background: rgba(255, 255, 255, 0.05); border-radius: 6px; padding: 6px 8px; }
.stats dt { font: 700 10px/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.06em; color: var(--muted); }
.stats dd { margin: 3px 0 0; font-size: 18px; font-weight: 800; }
.next { font-size: 13px; color: var(--muted); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card-actions button {
  min-height: 44px; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--ink); font-weight: 700;
}
.card-actions button.primary { background: var(--saffron); border-color: var(--saffron); color: #160c02; flex: 1 1 160px; }

.error { width: min(960px, 100% - 2 * var(--gutter)); margin: 8px auto; padding: 10px 12px; border-radius: 8px; background: #3a1414; color: #ffd6d6; }

.debug { width: min(960px, 100% - 2 * var(--gutter)); margin: 12px auto 0; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.debug summary { padding: 10px 12px; cursor: pointer; color: var(--muted); font-size: 13px; }
.debug-grid { display: grid; gap: 8px; padding: 0 12px 12px; }
.debug .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.debug .lab { width: 3.2rem; color: var(--muted); font: 700 11px/1 ui-monospace, Menlo, Consolas, monospace; }
.debug button { min-height: 36px; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); background: transparent; color: var(--ink); }
.debug button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.readout { margin: 0; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; color: var(--muted); overflow-wrap: anywhere; }
.foot { width: min(960px, 100% - 2 * var(--gutter)); margin: 12px auto 24px; color: var(--muted); font-size: 12px; }
.foot code { font-size: 11px; }
.foot a { color: var(--ink); }
.brand a { color: inherit; text-decoration: none; }

/* Narrow portrait: the card takes the whole screen (the arena and stick are only ~410 px tall), and the tell sits
   just under the HUD so it never covers the fighters. */
@media (max-width: 600px) {
  .card { position: fixed; inset: 0; z-index: 40; border-radius: 0; }
  .tell { top: 30px; padding: 3px 12px 5px; }
  .tell b { font-size: 20px; }
  .tell span { font-size: 13px; }
  .flash { top: 60%; }
}
/* Phone held sideways: stick.css makes the arena and the stick fullscreen; the cards and the coach follow. */
@media (orientation: landscape) and (max-height: 520px) {
  body.stick-on .card { position: fixed; z-index: 40; border-radius: 0; }
  body.stick-on .coach { bottom: auto; top: 38px; }
  body.stick-on .tell { top: 18%; }
}
@media (prefers-reduced-motion: reduce) {
  .deck .buttons button.suggest { animation: none; }
  .gauge b { transition: none; }
}
