/* Rope Math — the page around the field. The field itself is a canvas
   (render.js); each player's card and keypad sit in a frame that lies along
   the screen's long axis and turns with it, the far player's turned round.
   Colours that change with the field are custom properties under
   [data-theme]. */

:root {
  --round: "SF Pro Rounded", ui-rounded, "Nunito", "Arial Rounded MT Bold", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.25, 0.8, 0.3, 1.15);
  --p1: #e3572b;
  --p2: #2f6fd6;
  --fx: 50%;
  --fy: 50%;
  --fw: 375px;
  --fh: 700px;
  --rot: 0deg;
  --key: 54px;
  --keyh: 50px;
  --cardh: 60px;
  --zone: 190px;
  --hud: 58px;
  --col: 300px;
  --e-near: 0px;
  --e-far: 0px;
  --e-l: 0px;
  --e-r: 0px;
}

/* ------------------------------------------------------------- themes */
/* Meadow: a bright summer field (light) */
:root,
[data-theme="meadow"] {
  color-scheme: light;
  --bg-a: #dcefc4;
  --bg-b: #a9d27c;
  --ink: #1f2a17;
  --ink-soft: #55623f;
  --paper: #fffdf6;
  --paper-2: #f2eedf;
  --glass: rgba(255, 252, 242, 0.96);
  --line: rgba(50, 60, 20, 0.15);
  --accent: #3b8a3f;
  --accent-soft: rgba(59, 138, 63, 0.22);
  --btn-bg: rgba(255, 255, 255, 0.6);
  --btn-hover: rgba(255, 255, 255, 0.92);
  --btn-line: rgba(50, 60, 20, 0.16);
  --primary-a: #f2803f;
  --primary-b: #d6512a;
  --primary-line: #b04020;
  --primary-ink: #ffffff;
  --backdrop: rgba(25, 35, 15, 0.38);
  --toast: rgba(30, 36, 22, 0.92);
  --scrim-top: rgba(236, 246, 222, 0.92);
  --scrim-bottom: rgba(190, 220, 150, 0.5);
  --card: #fffaf0;
  --card-line: rgba(90, 70, 30, 0.16);
  --card-ink: #2a2016;
  --zone-bg: rgba(250, 245, 228, 0.86);
  --wood-a: #fbebcb;
  --wood-b: #ebd09f;
  --wood-edge: #c59b5e;
  --wood-shadow: #a87c44;
  --wood-ink: #4a3218;
  --grain: rgba(150, 100, 40, 0.07);
  --right: #2e8b45;
  --wrong: #c63b33;
  --pause-bg: rgba(255, 252, 242, 0.85);
}

/* Autumn: straw-gold grass (light) */
[data-theme="autumn"] {
  color-scheme: light;
  --bg-a: #f1e3b8;
  --bg-b: #cfb871;
  --ink: #2b2212;
  --ink-soft: #6a5a38;
  --paper: #fffaf0;
  --paper-2: #f4ead3;
  --glass: rgba(255, 249, 236, 0.96);
  --line: rgba(80, 60, 20, 0.16);
  --accent: #b8642a;
  --accent-soft: rgba(184, 100, 42, 0.22);
  --btn-bg: rgba(255, 255, 255, 0.6);
  --btn-hover: rgba(255, 255, 255, 0.92);
  --btn-line: rgba(80, 60, 20, 0.17);
  --primary-a: #ef7c38;
  --primary-b: #cf4c28;
  --primary-line: #a63e1f;
  --primary-ink: #ffffff;
  --backdrop: rgba(40, 30, 10, 0.38);
  --toast: rgba(44, 34, 16, 0.92);
  --scrim-top: rgba(246, 236, 210, 0.92);
  --scrim-bottom: rgba(210, 190, 120, 0.5);
  --card: #fffaf0;
  --card-line: rgba(100, 70, 30, 0.18);
  --card-ink: #2b2012;
  --zone-bg: rgba(250, 242, 222, 0.86);
  --wood-a: #fbebcb;
  --wood-b: #e9cd99;
  --wood-edge: #bf9257;
  --wood-shadow: #a2763f;
  --wood-ink: #4a3218;
  --grain: rgba(150, 100, 40, 0.07);
  --right: #2e8b45;
  --wrong: #c63b33;
  --pause-bg: rgba(255, 249, 236, 0.85);
}

/* Dusk: golden evening (dark) */
[data-theme="dusk"] {
  color-scheme: dark;
  --bg-a: #2b2440;
  --bg-b: #121020;
  --ink: #f6eee4;
  --ink-soft: rgba(246, 238, 228, 0.7);
  --paper: #241f36;
  --paper-2: #322a49;
  --glass: rgba(34, 28, 52, 0.96);
  --line: rgba(255, 220, 190, 0.15);
  --accent: #ffb26b;
  --accent-soft: rgba(255, 178, 107, 0.24);
  --btn-bg: rgba(255, 255, 255, 0.07);
  --btn-hover: rgba(255, 255, 255, 0.13);
  --btn-line: rgba(255, 220, 190, 0.2);
  --primary-a: #ff9356;
  --primary-b: #e0582c;
  --primary-line: #b5431f;
  --primary-ink: #ffffff;
  --backdrop: rgba(6, 4, 14, 0.6);
  --toast: rgba(40, 32, 62, 0.95);
  --scrim-top: rgba(26, 22, 40, 0.9);
  --scrim-bottom: rgba(16, 12, 28, 0.55);
  --card: #2a2340;
  --card-line: rgba(255, 220, 190, 0.16);
  --card-ink: #fff3e6;
  --zone-bg: rgba(28, 22, 44, 0.86);
  --wood-a: #e9cc9d;
  --wood-b: #cfa676;
  --wood-edge: #8d673a;
  --wood-shadow: #5e4325;
  --wood-ink: #36220d;
  --grain: rgba(90, 50, 10, 0.09);
  --right: #6fd38a;
  --wrong: #ff7a6e;
  --pause-bg: rgba(34, 28, 52, 0.82);
}

/* before the script runs, a dark device starts on Dusk (no flash) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg-a: #2b2440;
    --bg-b: #121020;
    --ink: #f6eee4;
    --ink-soft: rgba(246, 238, 228, 0.7);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b)) fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------- stage */
.stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* the safe-area insets, read by the layout */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  transition: filter 0.4s var(--ease), opacity 0.4s var(--ease);
}
.stage.dimmed canvas { filter: saturate(0.75) brightness(0.82); }
.stage.dimmed .zone { opacity: 0.28; pointer-events: none; }

/* the layer over the field: same place, same turn */
.frame {
  position: absolute;
  left: var(--fx);
  top: var(--fy);
  width: var(--fw);
  height: var(--fh);
  transform: translate(-50%, -50%) rotate(var(--rot));
  pointer-events: none;
}

/* ------------------------------------------------------------- zones */
.zone {
  position: absolute;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  pointer-events: auto;
  touch-action: none;
  transition: opacity 0.3s var(--ease);
}
.frame.playing .zone { display: flex; }
.zone.near { --me: var(--p1); }
.zone.far { --me: var(--p2); }
.zone:not(.hud)::before {
  content: "";
  position: absolute;
  inset: -26px 0 0;
  z-index: -1;
  background: linear-gradient(to bottom, transparent, var(--zone-bg) 30px);
  pointer-events: none;
}

/* two players: a zone at each end, the far one turned to face its player */
.frame.p2 .zone {
  left: 0;
  right: 0;
  height: calc(var(--zone) + var(--edge));
  padding: 8px calc(8px + var(--e-r)) calc(8px + var(--edge)) calc(8px + var(--e-l));
}
.frame.p2 .zone.near { bottom: 0; --edge: var(--e-near); }
.frame.p2 .zone.far {
  top: 0;
  --edge: var(--e-far);
  transform: rotate(180deg);
  padding-left: calc(8px + var(--e-r));
  padding-right: calc(8px + var(--e-l));
}

/* alone, portrait: the keypad below, the bears' card or the clock on top */
.frame.solo .zone.near {
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--zone) + var(--e-near));
  padding: 8px calc(8px + var(--e-r)) calc(8px + var(--e-near)) calc(8px + var(--e-l));
}
.frame.solo .zone.far {
  left: 0;
  right: 0;
  top: 0;
  justify-content: center;
  padding: calc(8px + var(--e-far)) calc(64px + var(--e-r)) 0 calc(10px + var(--e-l));
  height: calc(var(--hud) + 8px + var(--e-far));
}
/* alone, landscape: the keypad in a column on the right */
.frame.solo.land .zone.near {
  left: auto;
  top: 0;
  width: var(--col);
  height: auto;
  justify-content: center;
  padding: calc(8px + var(--e-far)) calc(10px + var(--e-r)) calc(8px + var(--e-near)) 10px;
}
.frame.solo.land .zone.near::before { inset: 0 0 0 -26px; background: linear-gradient(to right, transparent, var(--zone-bg) 30px); }
.frame.solo.land .zone.far { right: var(--col); padding-right: 64px; }

/* --------------------------------------------------------------- card */
.card {
  position: relative;
  width: 100%;
  max-width: 500px;
  height: var(--cardh);
  flex: 0 0 auto;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 5px 12px 4px 14px;
  background: var(--card);
  color: var(--card-ink);
  border: 1px solid var(--card-line);
  border-radius: 16px;
  box-shadow: 0 6px 18px -10px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  overflow: hidden;
  transition: box-shadow 0.3s var(--ease), transform 0.2s var(--ease);
}
.card::before {
  /* the team's stripe */
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--me);
}
.who {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
  line-height: 18px;
  color: var(--ink-soft);
  white-space: nowrap;
}
.who .name { font-weight: 650; color: var(--card-ink); overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 11px;
  font-weight: 600;
  line-height: 17px;
  flex: 0 0 auto;
}
.chip.lvl { color: var(--me); background: color-mix(in oklab, var(--me) 14%, transparent); }
.chip.clock { margin-left: auto; font: 700 13px/17px var(--round); font-variant-numeric: tabular-nums; color: var(--card-ink); }
.chip.clock.low { color: var(--wrong); animation: blink 1s steps(2) infinite; }
.chip.streak { color: #e8590c; background: rgba(255, 140, 40, 0.16); }
.chip.streak svg { width: 13px; height: 13px; color: #ff6b1a; }
.chip.notice { color: #fff; background: var(--me); }
@keyframes blink { 50% { opacity: 0.45; } }

.crest { display: inline-grid; place-items: center; width: 20px; height: 20px; flex: 0 0 auto; color: var(--p1); }
.crest.far, .zone.far .crest { color: var(--p2); }
.crest svg { width: 100%; height: 100%; }
.crest.big { width: 46px; height: 46px; position: relative; margin: 0 auto 2px; filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.25)); }

.sum {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.28em;
  min-width: 0;
  font: 800 clamp(20px, calc(var(--cardh) * 0.46), 34px) / 1 var(--round);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.sum .q { display: inline-flex; align-items: baseline; gap: 0.22em; }
.sum .op, .sum .eq { color: var(--me); font-weight: 700; }
.sum .par { color: var(--ink-soft); font-weight: 600; }
.sum sup { font-size: 0.55em; margin-left: 0.04em; }
.sum .root .rad { color: var(--me); margin-right: 0.04em; }
.sum .root .under { border-top: 0.07em solid currentColor; padding-top: 0.04em; }
.sum .pct { font-size: 0.86em; }
.sum .ans {
  min-width: 1.9em;
  height: 1.25em;
  padding: 0 0.22em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.18em;
  border-radius: 0.24em;
  background: color-mix(in oklab, var(--me) 10%, var(--paper-2));
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--me) 45%, transparent);
  color: var(--me);
}
.sum .ans s { color: var(--wrong); font-size: 0.7em; text-decoration-thickness: 0.09em; opacity: 0.85; }
.sum .ans b.right { color: var(--right); }
.sum .ans.nudge { animation: nudge 0.32s var(--ease); }
@keyframes nudge { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
.caret { display: block; width: 0.09em; height: 0.85em; background: currentColor; border-radius: 1px; animation: blink 1s steps(2) infinite; }
.think { display: block; width: 1em; height: 0.25em; background: radial-gradient(circle, currentColor 45%, transparent 50%) 0 50% / 0.33em 0.25em repeat-x; animation: think 1s steps(3) infinite; opacity: 0.7; }
@keyframes think { from { clip-path: inset(0 66% 0 0); } to { clip-path: inset(0 0 0 0); } }
.card.fresh .q { animation: deal 0.32s var(--spring); }
@keyframes deal { from { opacity: 0; transform: translateY(0.4em) scale(0.92); } }
.card.lock { animation: shake 0.4s var(--ease); }
.card.lock .bar { transform: scaleX(0); transition: transform 1.6s linear; }
.card .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--wrong); transform-origin: left; transform: scaleX(1); opacity: 0; }
.card.lock .bar { opacity: 1; }
@keyframes shake { 15%, 55% { transform: translateX(-5px) rotate(-0.6deg); } 35%, 75% { transform: translateX(5px) rotate(0.6deg); } }
.card.hot { box-shadow: 0 0 0 2px rgba(255, 120, 30, 0.75), 0 0 22px -2px rgba(255, 110, 20, 0.6), 0 6px 18px -10px rgba(0, 0, 0, 0.5); animation: hot 1.4s ease-in-out infinite alternate; }
@keyframes hot { to { box-shadow: 0 0 0 2px rgba(255, 170, 40, 0.9), 0 0 30px 2px rgba(255, 130, 20, 0.55), 0 6px 18px -10px rgba(0, 0, 0, 0.5); } }
.msg {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--card);
  color: var(--me);
  font: 900 clamp(24px, calc(var(--cardh) * 0.58), 44px) / 1 var(--round);
  letter-spacing: 0.02em;
}
.card.cd .msg { display: grid; }
.msg.beat { animation: beat 0.5s var(--spring); }
@keyframes beat { from { transform: scale(1.6); opacity: 0; } }
.pop {
  position: absolute;
  right: 10px;
  top: 22px;
  padding: 2px 10px;
  border-radius: 999px;
  font: 800 13px/1.5 var(--round);
  color: #fff;
  background: var(--me);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.pop.lightning { background: linear-gradient(90deg, #ffb703, #fb5607); }
.pop.oops { background: var(--wrong); }
.pop.show { animation: pop 1.1s var(--ease) forwards; }
@keyframes pop { 0% { opacity: 0; transform: translateY(8px) scale(0.8); } 15% { opacity: 1; transform: none; } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }

/* the computer's card and the sprint clock: one compact strip */
.zone.hud .card { height: var(--hud); max-width: 460px; }
.zone.hud .sum { font-size: 22px; }
.sprint-hud {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--hud);
  max-width: 460px;
  width: 100%;
  padding: 0 16px;
  background: var(--card);
  color: var(--card-ink);
  border: 1px solid var(--card-line);
  border-radius: 16px;
  box-shadow: 0 6px 18px -10px rgba(0, 0, 0, 0.5);
}
.sprint-hud .clock { font: 800 28px/1 var(--round); font-variant-numeric: tabular-nums; min-width: 2.6em; }
.sprint-hud .clock.low { color: var(--wrong); }
.sprint-hud .count { font-size: 13px; color: var(--ink-soft); }
.sprint-hud .count b { font: 800 24px var(--round); color: var(--p1); font-variant-numeric: tabular-nums; }
.sprint-hud .best { margin-left: auto; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--paper-2); white-space: nowrap; }
.sprint-hud .best.rec { color: #fff; background: linear-gradient(90deg, #ffb703, #fb5607); animation: beat 0.5s var(--spring); }

/* --------------------------------------------------------------- keys */
.keys {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 500px;
  flex: 0 0 auto;
}
.keys.wide { grid-template-columns: repeat(6, 1fr); grid-auto-rows: var(--keyh); }
.keys.tall { grid-template-columns: repeat(3, 1fr); grid-auto-rows: var(--keyh); max-width: 320px; }
.key {
  appearance: none;
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--wood-edge);
  border-radius: 13px;
  color: var(--wood-ink);
  font: 800 clamp(20px, calc(var(--keyh) * 0.5), 32px) / 1 var(--round);
  background:
    repeating-linear-gradient(97deg, transparent 0 7px, var(--grain) 7px 9px, transparent 9px 15px),
    linear-gradient(180deg, var(--wood-a), var(--wood-b));
  box-shadow: 0 3px 0 var(--wood-shadow), 0 5px 10px -4px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.65);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.25s, filter 0.25s;
}
.key svg { width: 46%; height: 46%; max-width: 26px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.key.del { color: color-mix(in oklab, var(--wood-ink) 75%, var(--wrong)); }
.key.ok {
  color: #fff;
  border-color: color-mix(in oklab, var(--me) 70%, #000);
  background: linear-gradient(180deg, color-mix(in oklab, var(--me) 82%, #fff), var(--me));
  box-shadow: 0 3px 0 color-mix(in oklab, var(--me) 60%, #000), 0 5px 10px -4px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.key.ok svg { stroke-width: 3; }
.key:active, .key.hit { transform: translateY(3px); box-shadow: 0 0 0 var(--wood-shadow), 0 2px 4px -2px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.5); }
.key.hit { animation: hit 0.16s var(--ease); }
@keyframes hit { from { transform: translateY(3px); filter: brightness(0.94); } }
.zone.locked .key, .zone.waiting .key { opacity: 0.5; filter: saturate(0.4); }

/* --------------------------------------------------------------- pause */
.pause-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--btn-line);
  background: var(--pause-bg);
  color: var(--ink);
  display: grid;
  place-items: center;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 4px 14px -6px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s, opacity 0.2s;
}
.pause-btn:active { transform: scale(0.92); }
.pause-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.frame.p2 .pause-btn { left: calc(10px + var(--e-l)); top: calc(var(--e-far) + var(--zone) + (var(--fh) - 2 * var(--zone) - var(--e-far) - var(--e-near)) / 2 - 22px); }
.frame.solo .pause-btn { right: calc(10px + var(--e-r)); top: calc(15px + var(--e-far)); }
.frame.solo.land .pause-btn { right: calc(var(--col) + 8px); }
.frame:not(.playing) .pause-btn { display: none; }

/* ------------------------------------------------------------- panels */
.half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px calc(10px + var(--e-r)) calc(10px + var(--e-near)) calc(10px + var(--e-l));
  pointer-events: none;
}
.half.near { bottom: 0; }
.half.far { top: 0; transform: rotate(180deg); padding: 10px calc(10px + var(--e-l)) calc(10px + var(--e-far)) calc(10px + var(--e-r)); }
.upright {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.panel {
  position: relative;
  pointer-events: auto;
  width: min(100%, 360px);
  max-height: 100%;
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  background: var(--glass);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px 16px 14px;
  text-align: center;
  box-shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.6);
  animation: rise-in 0.36s var(--spring);
  touch-action: pan-y;
}
.upright .panel { width: min(100%, 400px); padding: 20px 20px 18px; }
@keyframes rise-in { from { opacity: 0; transform: translateY(16px) scale(0.95); } }
.panel[data-side="0"] { --me: var(--p1); }
.panel[data-side="1"] { --me: var(--p2); }
.panel .glow {
  position: absolute;
  inset: -50% -20% auto;
  height: 80%;
  background: radial-gradient(ellipse at 50% 45%, color-mix(in oklab, var(--me) 34%, transparent), transparent 68%);
  pointer-events: none;
}
.panel h2 { position: relative; margin: 0; font: 800 23px/1.15 var(--round); letter-spacing: 0.01em; }
.panel.won h2 { color: var(--me); }
.panel p { position: relative; margin: 4px 0 10px; font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.panel p.standing { color: var(--ink); font-weight: 600; margin-top: 8px; }
.panel .score { position: relative; margin: 4px 0 0; font: 900 52px/1 var(--round); font-variant-numeric: tabular-nums; color: var(--me); }
.panel .chips { position: relative; display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.panel .chips span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.panel .chips b { font: 700 14px var(--round); letter-spacing: 0; text-transform: none; color: var(--ink); }
.panel .row { position: relative; display: flex; gap: 8px; }
.panel .row + .row { margin-top: 8px; }
.panel .row .btn { min-width: 0; }
.panel .tools { position: relative; display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.panel .tools .icon-btn { width: 44px; height: 44px; border: 1px solid var(--btn-line); background: var(--btn-bg); }
.panel .friends-board { position: relative; text-align: left; margin: 0 0 12px; }
@media (max-height: 700px) and (orientation: portrait), (max-width: 700px) and (orientation: landscape) {
  .half .panel { padding: 12px 12px 10px; border-radius: 18px; }
  .half .panel h2 { font-size: 20px; }
  .half .panel p { margin: 2px 0 6px; font-size: 13px; }
  .half .panel .chips { margin: 4px 0 8px; }
  .half .panel .crest.big { width: 34px; height: 34px; }
  .half .panel .btn { min-height: 44px; padding: 8px 10px; }
}

/* --------------------------------------------------------------- menu */
.menu {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: linear-gradient(180deg, var(--scrim-top) 0, transparent 20%, transparent 42%, var(--scrim-bottom) 100%);
  animation: fade 0.35s var(--ease);
  pointer-events: none;
}
.menu > * { pointer-events: auto; }
@keyframes fade { from { opacity: 0; } }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 10px 4px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font: 800 22px var(--round); letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-size: 11px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.account-chip { display: flex; align-items: center; margin-left: 4px; }
.account-chip:empty { display: none; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.icon-btn:hover { background: var(--btn-bg); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

#menu-card {
  width: min(100% - 20px, 560px);
  margin: auto auto 12px;
  padding: 16px 16px 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.5);
}
#menu-card .label, .opt-row h3 {
  margin: 0 0 8px 2px;
  font: 700 11px var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode {
  appearance: none;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  text-align: left;
  padding: 9px 10px;
  min-height: 60px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
}
.mode svg { grid-row: 1 / 3; width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; color: var(--accent); }
.mode b { font: 700 15px var(--round); }
.mode small { font-size: 11.5px; color: var(--ink-soft); line-height: 1.2; }
.mode:active { transform: scale(0.98); }
.mode[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }

.opts-grid { display: grid; gap: 10px; margin: 12px 0 14px; }
.opt-row { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; }
.opt-row h3 { margin: 0; display: flex; align-items: center; gap: 6px; }
.opt-row h3 .crest { width: 18px; height: 18px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 600 14px var(--sans);
  padding: 7px 14px;
  min-height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
.opt.small { min-width: 38px; padding: 6px 0; flex: 1 1 0; font: 700 15px var(--round); }
.stepper {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 16px;
  background: var(--paper-2);
  border: 1.5px solid var(--line);
}
.step {
  appearance: none;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  border: 0;
  background: var(--paper);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  transition: transform 0.15s, opacity 0.2s;
}
.step svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.step:active { transform: scale(0.92); }
.step:disabled { opacity: 0.35; cursor: default; }
.lv { display: flex; flex-direction: column; align-items: center; min-width: 0; text-align: center; line-height: 1.2; }
.lv b, .lv small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv b { font: 700 14px/1.15 var(--round); white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lv small { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.hint { margin: 10px 4px 2px; font-size: 12.5px; line-height: 1.4; color: var(--ink-soft); text-align: center; }

.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--ink);
  font: 600 15px var(--sans);
  padding: 10px 14px;
  min-height: 46px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s, filter 0.2s;
}
.btn svg { width: 19px; height: 19px; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn.wide { width: 100%; }
.btn.primary {
  background: linear-gradient(180deg, var(--primary-a), var(--primary-b));
  color: var(--primary-ink);
  border-color: var(--primary-line);
  box-shadow: 0 6px 16px -6px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.play { width: 100%; min-height: 54px; font: 800 18px var(--round); border-radius: 16px; }
.btn.play svg { width: 20px; height: 20px; }

/* short landscape: the card goes wide, two columns */
@media (orientation: landscape) and (max-height: 560px) {
  .top { padding-top: 4px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 19px; }
  #menu-card {
    width: min(100% - 24px, 780px);
    margin-bottom: 8px;
    display: grid;
    grid-template-columns: 0.9fr 1.3fr;
    grid-template-areas: "label label" "modes opts" "play play" "hint hint";
    column-gap: 16px;
    padding: 12px 14px 8px;
  }
  #menu-card .label { grid-area: label; }
  .modes { grid-area: modes; grid-template-columns: 1fr; align-content: start; gap: 6px; }
  .mode { min-height: 48px; padding: 6px 10px; }
  .mode small { display: none; }
  .opts-grid { grid-area: opts; margin: 0; gap: 6px; align-content: start; }
  .opt-row { grid-template-columns: 86px 1fr; }
  .opt { min-height: 40px; padding: 5px 12px; }
  .btn.play { grid-area: play; margin-top: 10px; min-height: 46px; }
  .hint { grid-area: hint; margin-top: 6px; }
}
@media (orientation: landscape) and (max-height: 420px) {
  .hint { display: none; }
  .brand small { display: none; }
}
@media (max-width: 440px) and (orientation: portrait) {
  .opt-row { grid-template-columns: 1fr; gap: 5px; }
  .opts .opt { flex: 1 1 0; padding-left: 8px; padding-right: 8px; }
  .modes { gap: 6px; }
  .mode { grid-template-columns: 1fr; grid-template-rows: auto auto auto; justify-items: center; text-align: center; row-gap: 2px; padding: 8px 6px; }
  .mode svg { grid-row: auto; width: 28px; height: 28px; }
  .mode small { font-size: 11px; }
}
@media (max-width: 420px) {
  .brand b { white-space: normal; font-size: 18px; line-height: 1.02; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .brand b:not(:only-child) { max-width: 11em; }
}
@media (max-width: 400px) {
  .brand small { letter-spacing: 0.03em; font-size: 10.5px; }
  .top { padding-left: 10px; padding-right: 4px; }
  .brand { gap: 7px; }
  .brand img { width: 32px; height: 32px; }
  .brand b { font-size: 18px; letter-spacing: 0; }
  .nav { gap: 0; }
}
@media (max-width: 360px) {
  .mode small { display: none; }
}

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
  animation: fade 0.25s;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 580px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; flex: 0 0 auto; }
.sheet h2 { font: 800 23px var(--round); margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
  -webkit-user-select: text;
  user-select: text;
  touch-action: pan-y;
}
.sheet-body h3 { font: 700 16px var(--round); margin: 20px 0 8px; color: var(--ink); }
.sheet-body h3:first-child { margin-top: 6px; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.prose li b { font-weight: 650; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 12px; text-align: center; }
.about b { display: block; font-weight: 650; color: var(--ink); }
@media (min-width: 700px) and (min-height: 560px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 24px; max-height: 84dvh; animation: popm 0.28s var(--ease); }
}
@media (orientation: landscape) and (max-height: 560px) {
  .sheet { max-height: 94dvh; }
}
@keyframes popm { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

/* ------------------------------------------------------------- results */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin: 4px 0 6px; }
.tile { background: var(--paper-2); border-radius: 16px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.tile small { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.tile b { font: 800 22px var(--round); font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; vertical-align: bottom; font-weight: 600; color: var(--ink-soft); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.num, td.num { text-align: right; }
td.name { font-weight: 600; max-width: 12em; overflow: hidden; text-overflow: ellipsis; }
td.name .crest { width: 18px; height: 18px; margin-right: 6px; vertical-align: -4px; }
td.who { max-width: 12em; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
td.res { font-weight: 650; }
.note { font-size: 12.5px; color: var(--ink-soft); margin: 10px 0 0; }
.friends { margin-top: 10px; }
.levels-pick { flex-wrap: nowrap; margin-bottom: 8px; }
@media (max-width: 420px) {
  table.recent { font-size: 12.5px; }
  table.recent td, table.recent th { padding-left: 2px; padding-right: 2px; }
  .opt.small { min-width: 0; font-size: 14px; }
}

/* ------------------------------------------------------------- settings */
.swatch {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex: 0 0 auto;
  position: relative;
  background: linear-gradient(90deg, transparent 47%, #e8c78f 47% 53%, transparent 53%), radial-gradient(ellipse 60% 26% at 50% 50%, var(--s1) 96%, transparent 100%), var(--s0);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
.swatch::before, .swatch::after { content: ""; position: absolute; left: 50%; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; }
.swatch::before { top: 2px; background: var(--s3); }
.swatch::after { bottom: 2px; background: var(--s2); }
.swatch.auto { background: linear-gradient(135deg, #8dc65f 50%, #2b2440 50%); }
.swatch.auto::before, .swatch.auto::after { display: none; }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 16px; cursor: pointer; font-size: 15px; line-height: 1.35; min-height: 32px; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.25s; box-shadow: inset 0 0 0 1px var(--line); }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: grid; gap: 4px; margin-top: 10px; }
.field span { font-size: 12.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.field .crest { width: 18px; height: 18px; }
.field input {
  appearance: none;
  font: 500 16px var(--sans);
  color: var(--ink);
  background: var(--paper-2);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 44px;
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) translateY(6px);
  z-index: 15;
  background: var(--toast);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  width: max-content;
  max-width: min(88vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

@media (prefers-reduced-motion: reduce) {
  .panel, .sheet, .backdrop, .menu, .card.fresh .q, .card.lock, .card.hot, .msg.beat, .sum .ans.nudge, .key.hit, .sprint-hud .best.rec { animation: none; }
  .pop.show { animation: fade-out 1.2s linear forwards; }
  .stage canvas { transition: none; }
}
@keyframes fade-out { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
