:root {
  --bg: #0b1016;
  --panel: rgba(10, 16, 24, 0.82);
  --panel-solid: #101820;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f3f5f7;
  --muted: #b6c0ca;
  --accent: #ffc23d;
  --accent-ink: #1a1200;
  --teal: #37d0c0;
  --danger: #ff5c5c;
  --focus: #7cc8ff;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
/* Machine-draft translation note (Volume XIV GL-006/GL-007). */
.draft-note { margin: -6px 0 12px; font-size: 0.78rem; color: #ffe2a0; background: rgba(60, 40, 0, 0.55); border: 1px solid #8a6a20; border-radius: 8px; padding: 4px 8px; }
/* Names and codes keep their own direction inside RTL text (Volume XIV §31). */
bdi, .board .st { unicode-bidi: isolate; }
[dir="rtl"] .board .st, [dir="rtl"] .stat .val, [dir="rtl"] .clock { direction: ltr; }

#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }

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

button {
  font: inherit; font-weight: 600; color: var(--text); background: #1d2a36; border: 1px solid var(--line);
  border-radius: 10px; padding: 0.7em 1.1em; cursor: pointer; min-height: 44px;
}
button:hover { background: #26384a; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.primary:hover { background: #ffd36e; }

.screen { position: fixed; inset: 0; display: grid; place-items: safe center; padding: 16px; overflow: auto;
  background: linear-gradient(180deg, rgba(5, 10, 16, 0.25), rgba(5, 10, 16, 0.7)); }
.menu-card { width: min(1040px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px 28px; backdrop-filter: blur(6px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45); }
.menu-card.narrow { width: min(520px, 100%); }
.brand h1 { margin: 0 0 4px; font-size: clamp(1.7rem, 4vw, 2.6rem); letter-spacing: -0.02em; line-height: 1.05; }
.brand h1 span { color: var(--accent); }
.eyebrow { margin: 0 0 6px; color: var(--teal); text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.75rem; font-weight: 700; }
.menu-grid { display: grid; grid-template-columns: 1.05fr 1.2fr 0.9fr; gap: 22px; margin-top: 18px; }
.menu-section h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 0 0 10px; }
.field { display: grid; gap: 4px; margin: 0 0 12px; border: 0; padding: 0; }
.field > span, legend { font-size: 0.85rem; color: var(--muted); padding: 0; }
input[type="text"], select { font: inherit; color: var(--text); background: #0d151d; border: 1px solid #3a4a5a; border-radius: 8px; padding: 0.55em 0.7em; min-height: 42px; }
/* Menu pickers (DEC-185..189, DEC-195): fill the column but never widen it (long event names on a 390 px phone). */
.menu-section select { width: 100%; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.how { margin: 0; padding-inline-start: 1.1em; color: var(--text); line-height: 1.5; font-size: 0.95rem; }
.how li { margin-bottom: 6px; }
kbd { font-family: var(--mono); font-size: 0.85em; background: #24313d; border: 1px solid #44566a; border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0; }
.seg label { display: inline-flex; align-items: center; gap: 6px; background: #16212b; border: 1px solid var(--line); padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--accent); background: #2a2410; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
small { color: var(--muted); }
/* Spoken voice settings (DEC-100..DEC-104): master switch, options folded away, status line */
.voice-set { display: grid; gap: 2px; margin-top: 2px; }
.voice-more summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; padding-inline-start: 26px; }
.voice-opts { display: grid; gap: 4px; font-size: 0.88rem; padding-inline-start: 26px; margin: 6px 0; }
.voice-opts .range { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.voice-opts input[type="range"] { inline-size: 8em; accent-color: var(--accent); }
.voice-opts button { justify-self: start; padding: 0.3em 0.8em; font-size: 0.85rem; }
.voice-set:has(#in-voice:not(:checked)) .voice-opts { opacity: 0.5; }
.audio-set:has(#in-audio:not(:checked)) .voice-opts { opacity: 0.5; }
/* Sound captions (DEC-241): a small label above the HUD, never covering the start call. */
.sound-caption { position: fixed; inset-inline-start: 50%; transform: translateX(-50%); bottom: 22vh; z-index: 30; padding: 4px 12px; border-radius: 6px; background: rgba(0, 0, 0, 0.72); color: #fff; font-size: 1rem; pointer-events: none; }
.sound-caption[hidden] { display: none; }
[dir="rtl"] .sound-caption { transform: translateX(50%); }
#voice-status { padding-inline-start: 26px; }
#voice-status:empty { display: none; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
.status { color: var(--muted); }
.fineprint { color: var(--muted); font-size: 0.8rem; margin-top: 16px; }
.ai-tag { display: inline-block; font-size: 0.7em; font-weight: 800; letter-spacing: 0.05em; color: #001a17; background: var(--teal); border-radius: 4px; padding: 0 4px; vertical-align: 0.1em; }
.you-tag { display: inline-block; font-size: 0.7em; font-weight: 800; color: var(--accent-ink); background: var(--accent); border-radius: 4px; padding: 0 4px; vertical-align: 0.1em; }

.dev-notice { position: fixed; left: 50%; top: 4px; transform: translateX(-50%); z-index: 50; font-size: 0.75rem;
  background: rgba(60, 40, 0, 0.88); color: #ffe2a0; border: 1px solid #8a6a20; border-radius: 999px; padding: 3px 12px; pointer-events: none; max-width: calc(100% - 16px); text-align: center; }

.status.small { font-size: 0.82rem; margin-top: 4px; }
/* Online championship: announces each race (lane or spectating). */
.round-banner { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%); z-index: 30; pointer-events: none;
  background: var(--panel-solid); border: 1px solid var(--accent); color: var(--text); border-radius: 12px; padding: 8px 16px;
  font-weight: 700; font-size: 1rem; max-width: calc(100% - 24px); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
@media (max-width: 760px) { .round-banner { bottom: 170px; font-size: 0.86rem; } }

.lobby-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.lobby-list li { display: flex; justify-content: space-between; gap: 8px; background: #121c25; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; padding: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.hud-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
/* A tappable way out of every race on every device (Esc does the same; the Esc hint is hidden on touch). */
.clock-box { position: relative; padding-inline-end: 84px; }
.hud-menu-btn { position: absolute; top: 8px; inset-inline-end: 8px; pointer-events: auto; min-height: 36px; min-width: 64px; padding: 4px 12px; font-size: 0.85rem; font-weight: 700; }
/* While the results are up they have their own Menu: keep focus inside the results (a11y audit), hide the race one. */
body:has(#results-inner:not([hidden])) #btn-hud-menu, body:has(#proto-results-inner:not([hidden])) #btn-proto-hud-menu { display: none; }
.hud-top { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; }
.label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.clock { unicode-bidi: isolate; font-family: var(--mono); font-size: 2.3rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.sub { color: var(--muted); font-size: 0.85rem; margin: 2px 0 0; }
.call { justify-self: center; align-self: start; margin-top: 18px; font-size: clamp(1.6rem, 5vw, 3.4rem); font-weight: 900; letter-spacing: 0.02em;
  text-transform: uppercase; color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55), 0 0 24px rgba(0, 0, 0, 0.6); text-align: center; }
.call.go { color: var(--accent); }
.call.fs { color: #fff; background: var(--danger); padding: 0.1em 0.5em; border-radius: 10px; text-shadow: none; }
.call.pop { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(1.35); opacity: 0.2; } to { transform: scale(1); opacity: 1; } }
.reduced .call.pop { animation: none; }
.board { list-style: none; margin: 0; min-width: 230px; font-size: 0.86rem; display: grid; gap: 2px; }
.board li { display: grid; grid-template-columns: 1.4em 1.1em 1fr auto; gap: 6px; align-items: center; white-space: nowrap; }
.board .pos { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.board .sw { width: 0.9em; height: 0.9em; border-radius: 3px; }
.board .nm { overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.board .st { font-family: var(--mono); color: var(--muted); font-size: 0.8rem; }
.has-results .board { display: none; }
.board li.me .nm { color: var(--accent); font-weight: 700; }
.hud-bottom { position: absolute; inset-inline: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.stats { display: flex; gap: 22px; }
.stat { display: grid; grid-template-columns: auto auto; column-gap: 4px; align-items: baseline; }
.stat .label { grid-column: 1 / -1; }
.stat .val { unicode-bidi: isolate; font-family: var(--mono); font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .unit { color: var(--muted); font-size: 0.8rem; }
.meters { display: grid; gap: 6px; min-width: 260px; }
.meter-row { display: grid; grid-template-columns: 4.6em 1fr 3.4em; align-items: center; gap: 8px; }
.bar { position: relative; height: 10px; border-radius: 6px; background: #22303c; overflow: hidden; }
.bar i { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0%; background: linear-gradient(90deg, var(--teal), #7df0a8); border-radius: 6px; }
#effort-fill { background: linear-gradient(90deg, #ff9f43, var(--accent)); }
.bar.rhythm { overflow: visible; direction: ltr; }
.bar.rhythm .zone { position: absolute; top: 0; bottom: 0; left: 52.5%; width: 12%; background: rgba(125, 240, 168, 0.55); border-radius: 3px; }
.bar.rhythm i { width: 4px; left: 0; background: #fff; border-radius: 2px; top: -3px; bottom: -3px; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.mini { unicode-bidi: isolate; font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.esc-hint { position: absolute; inset-inline-end: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 0.8rem; background: var(--panel); padding: 4px 10px; border-radius: 8px; }
.reject { position: absolute; left: 50%; top: 120px; transform: translateX(-50%); font-size: 0.8rem; color: #ffd0d0; opacity: 0; transition: opacity 0.2s; }
.reject.show { opacity: 0.9; }
.conn-pill { position: absolute; left: 50%; top: 34px; transform: translateX(-50%); background: rgba(80, 20, 20, 0.9); color: #ffd6d6; border-radius: 999px; padding: 4px 12px; font-size: 0.8rem; }

.touch { display: none; position: absolute; inset-inline: 0; direction: ltr; bottom: calc(150px + env(safe-area-inset-bottom)); justify-content: space-between; padding: 0 14px; pointer-events: none; }
.touch-btn { pointer-events: auto; width: 32vw; max-width: 150px; aspect-ratio: 1; border-radius: 50%; font-size: 2.2rem; font-weight: 900;
  background: rgba(20, 30, 40, 0.72); border: 2px solid rgba(255, 255, 255, 0.45); touch-action: none; user-select: none; -webkit-user-select: none; }
.touch-btn.pressed { background: var(--accent); color: var(--accent-ink); }
@media (pointer: coarse), (max-width: 760px) { .touch { display: flex; } .esc-hint { display: none; } }
/* The 100 m touch buttons sit in the band between the top boxes and the bottom boxes (DEC-537): clear of the stats and
   meters on portrait phones, and smaller and lower on phones held sideways, where 150 px buttons covered the clock and
   the lane board. */
@media (max-width: 760px) and (orientation: portrait) { #touch { bottom: calc(168px + env(safe-area-inset-bottom)); } }
@media (orientation: landscape) and (max-height: 480px) {
  #touch { bottom: calc(100px + env(safe-area-inset-bottom)); }
  #touch .touch-btn { width: min(130px, 32vw, calc(100vh - 250px)); font-size: 1.8rem; }
}

#tags { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.tag { position: absolute; transform: translate(-50%, -100%); font-size: 0.72rem; font-weight: 700; white-space: nowrap; background: rgba(8, 12, 18, 0.72);
  border-radius: 6px; padding: 1px 6px; color: #fff; border-inline-start: 3px solid var(--c, #fff); unicode-bidi: isolate; }
.tag.me { background: rgba(60, 44, 0, 0.85); }
/* Equipped test-store nameplates on the player's own tag (DEC-632): original frames; display only. */
.tag.me.plate-steel { box-shadow: inset 0 0 0 1.5px #b9bec4; background: linear-gradient(180deg, rgba(70, 74, 80, 0.9), rgba(36, 38, 42, 0.9)); }
.tag.me.plate-neon { box-shadow: 0 0 0 1.5px #3dffa8, 0 0 8px rgba(61, 255, 168, 0.75); }
.tag.me.plate-woven { box-shadow: inset 0 0 0 1.5px #e0b44c; background: repeating-linear-gradient(45deg, rgba(90, 52, 20, 0.92) 0 4px, rgba(60, 34, 12, 0.92) 4px 8px); }
@media (prefers-reduced-motion: reduce) { .tag.me.plate-neon { box-shadow: 0 0 0 1.5px #3dffa8; } }

/* Results */
.results { position: fixed; inset-inline-start: 14px; top: 112px; z-index: 20; max-width: calc(100% - 28px); }
.has-results .hud-bottom { display: none; }
#results-inner, #proto-results-inner { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; width: min(560px, calc(100vw - 28px)); max-height: calc(100vh - 140px); overflow: auto; box-shadow: 0 18px 48px rgba(0,0,0,.5); }
#results-inner h2, #proto-results-inner h2 { margin: 0; font-size: 1.25rem; }
#results-inner h3 { font-size: 0.95rem; margin: 14px 0 6px; color: var(--muted); }
.results-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 8px; }
.results-table th { text-align: start; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); border-bottom: 1px solid var(--line); padding: 4px 6px; }
.results-table td { padding: 5px 6px; border-bottom: 1px solid rgba(255,255,255,.06); font-variant-numeric: tabular-nums; }
.results-table td.t { font-family: var(--mono); font-weight: 700; unicode-bidi: isolate; }
.results-table tr.me td { background: rgba(255, 194, 61, 0.12); }
.dq { color: var(--danger); font-weight: 700; }

@media (max-width: 900px) {
  .menu-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #hud { padding: 8px; }
  .hud-top { grid-template-columns: auto 1fr; }
  .board { display: none; }
  .clock { font-size: 1.7rem; }
  .call { margin-top: 64px; grid-column: 1 / -1; grid-row: 2; }
  .hud-bottom { inset-inline: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); gap: 8px; }
  .stats { gap: 14px; width: 100%; justify-content: space-between; }
  .stat .val { font-size: 1.3rem; }
  .meters { min-width: 0; width: 100%; }
  .results { top: 70px; inset-inline: 8px; }
  .has-results .touch { display: none; }
  .dev-notice { top: 0; left: 0; right: 0; transform: none; border-radius: 0; max-width: none; font-size: 0.68rem; }
  body.online-mode #hud { padding-top: 26px; }
  body.online-mode .screen { padding-top: 30px; }
  #results-inner, #proto-results-inner { width: 100%; padding: 12px; }
  .results-table { font-size: 0.8rem; }
  .tag { font-size: 0.6rem; padding: 0 4px; }
}

/* Offline championship round results */
#champ-inner { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; width: min(600px, calc(100vw - 28px)); max-height: calc(100vh - 140px); overflow: auto; box-shadow: 0 18px 48px rgba(0,0,0,.5); }
#champ-inner h2 { margin: 0; font-size: 1.25rem; }
#champ-inner h3 { font-size: 0.95rem; margin: 14px 0 2px; color: var(--muted); }
#champ-inner td.mark { font-weight: 700; color: #ffc23d; }
.medal { display: inline-block; font-size: 0.68rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; color: #111; }
.medal.gold { background: #e8c547; }
.medal.silver { background: #c9ced6; }
.medal.bronze { background: #c98a55; }
@media (max-width: 759px) {
  #champ-inner { width: 100%; padding: 12px; }
}

/* Other sports (prototype), DEC-022 */
.proto-menu { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.proto-menu .actions { margin-top: 4px; }
.proto-note { color: var(--muted); font-size: 0.85rem; margin: 0 0 6px; }
#proto-hud { position: fixed; inset: 0; pointer-events: none; padding: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.proto-hint { position: absolute; left: 50%; top: 128px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px 12px; font-size: 0.9rem; font-weight: 600; color: var(--accent); max-width: calc(100% - 28px); text-align: center; }
.proto-hint:empty { display: none; }
.sight { position: absolute; inset-inline-end: 16px; bottom: 140px; width: 240px; height: 240px; border-radius: 12px; border: 1px solid var(--line); background: rgba(10, 16, 24, 0.6); }
.proto-help { max-width: min(560px, 60vw); text-align: start; }
/* The how-to line is the last item of the bottom row (DEC-537): it can no longer sit on top of the stats and meters
   boxes at any width (it wraps to its own row when there is no room, at 1280×720 it overlapped the meters). Phones and
   short screens still leave it out: the companion shows the event's controls and the start overlay the how-to (O2). */
#proto-hud .hud-bottom .proto-help { position: static; margin-inline-start: auto; align-self: flex-end; }
@media (max-width: 760px), (max-height: 520px) { .proto-help { display: none; } }
.proto-touch { flex-wrap: wrap; gap: 8px; justify-content: center; }
.proto-touch .touch-btn { width: 17vw; max-width: 92px; font-size: 1.05rem; }
#proto-results-inner td.detail { color: var(--muted); font-size: 0.82rem; }
.has-results .proto-hint, .has-results .sight { display: none; }
/* A replay is watched, not played (DEC-576): no controls, meters, hints or coach over the replay bar. */
.proto-replaying .hud-bottom, .proto-replaying .proto-hint, .proto-replaying .sight, .proto-replaying .touch,
.proto-replaying .proto-help, .proto-replaying #companion { display: none !important; }
@media (max-width: 760px) {
  #proto-hud { padding: 8px; }
  .proto-hint { top: 96px; font-size: 0.8rem; }
  .sight { width: 150px; height: 150px; bottom: auto; top: 96px; inset-inline-end: 8px; }
  .proto-help { display: none; }
}
#proto-call { text-transform: none; }
/* The event line under the race clock stays one line (online trials add "Unranked trial" and calibration, DEC-443):
   the full text is in its title and in the results; it never runs under the stats on short or narrow screens. */
#proto-mode { max-width: min(46ch, 52vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px), (max-height: 480px) { #proto-mode { max-width: 44vw; } }
/* Phones held sideways (short screens): the bottom stats and meters must stay below the clock box, so the prototype HUD
   is compacted; the board keeps only its leading rows. */
@media (orientation: landscape) and (max-height: 480px) {
  #proto-hud { padding: 6px 10px; }
  #proto-hud .hud-box { padding: 6px 10px; }
  #proto-hud .clock { font-size: 1.5rem; }
  #proto-hud .label { font-size: 0.62rem; }
  #proto-hud .sub { font-size: 0.72rem; }
  #proto-hud .board { font-size: 0.74rem; min-width: 190px; }
  #proto-hud .board li:nth-child(n + 5):not(.me) { display: none; }
  /* Four rows at most (the companion dock sits in the band below): when the player is not among the first four,
     the fourth leader makes room for the player's own row (O2, fields of eight). */
  #proto-hud .board:has(li:nth-child(n + 5).me) li:nth-child(4) { display: none; }
  #proto-hud .hud-bottom { bottom: calc(6px + env(safe-area-inset-bottom)); gap: 6px; inset-inline: 10px; }
  #proto-hud .stats { gap: 12px; }
  #proto-hud .stat .val { font-size: 1.1rem; }
  #proto-hud .stat .unit { font-size: 0.68rem; }
  #proto-hud .meters { min-width: 200px; gap: 3px; }
  #proto-hud .meter-row { font-size: 0.7rem; }
}
/* Judges' marks for the judged acrobatic sports (DEC-152): every mark, dropped marks struck through. */
.proto-panel { position: absolute; inset-inline-end: 16px; bottom: 150px; max-width: min(380px, calc(100vw - 32px)); padding: 8px 10px; font-size: 0.78rem; pointer-events: none; }
.proto-panel h3 { margin: 0 0 4px; font-size: 0.85rem; }
.proto-panel table { border-collapse: collapse; }
.proto-panel th { text-align: start; font-weight: 600; padding-inline-end: 8px; color: var(--muted); white-space: nowrap; }
.proto-panel td { padding: 1px 4px; font-variant-numeric: tabular-nums; text-align: end; }
.proto-panel td.dropped { opacity: 0.5; }
.proto-panel p { margin: 4px 0 0; }
@media (max-width: 640px) { .proto-panel { bottom: auto; top: 150px; inset-inline-end: 8px; font-size: 0.68rem; max-width: calc(100vw - 16px); } }

/* ===== Ceremonies, Athletes' Village, AI coach and commentary (DEC-050..DEC-054) ===== */
/* Coach panel: right side on wide screens, bottom sheet on narrow ones. */
.coach { position: fixed; inset-inline-end: 14px; top: 112px; z-index: 21; width: min(400px, calc(100vw - 28px)); max-height: calc(100vh - 140px); overflow: auto;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; box-shadow: 0 18px 48px rgba(0,0,0,.5); }
.coach summary { cursor: pointer; font-weight: 800; font-size: 1.05rem; }
.coach-tips { margin: 8px 0 0; padding-inline-start: 1.2em; display: grid; gap: 10px; }
.coach-tips .tip-text { margin: 0; line-height: 1.4; }
.coach-tips .tip-session { margin: 4px 0 0; color: var(--teal); font-size: 0.88rem; }
.coach-tips .tip-meta { margin: 4px 0 0; color: var(--muted); font-size: 0.78rem; }
.coach-tips .tip-evidence { margin: 4px 0 0; padding-inline-start: 1em; color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.coach .fineprint { margin-top: 8px; }
@media (max-width: 1100px) { .coach { top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); max-height: 46vh; } }
/* DEC-751: on the results screen the coach tips sit between the lesson card and the companion dock (measured by
   src/ui/resultsStack.ts) and scroll inside that space. */
.has-results .coach { top: var(--stack-top, 112px); max-height: calc(100vh - var(--stack-top, 112px) - var(--stack-bottom, 14px)); }
@media (max-width: 1100px) { .has-results .coach { top: auto; bottom: var(--stack-bottom, 14px); max-height: min(46vh, calc(100vh - var(--stack-top, 112px) - var(--stack-bottom, 14px))); } }

.captions { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 15; pointer-events: none; max-width: min(680px, calc(100% - 24px));
  background: rgba(6, 10, 16, 0.86); border-radius: 10px; padding: 6px 12px; text-align: center; }
.captions .cap-label { margin: 0; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--teal); }
.captions ul { list-style: none; margin: 2px 0 0; padding: 0; font-size: 0.95rem; font-weight: 600; }
.has-results .captions { display: none; }
@media (max-width: 760px) { .captions { bottom: 200px; font-size: 0.85rem; } }

.ceremony { position: fixed; inset: 0; pointer-events: none; padding: 14px; z-index: 18; }
.ceremony .hud-box, .ceremony button, .ceremony details { pointer-events: auto; }
.cer-top { display: inline-block; max-width: min(640px, 100%); }
.cer-top h2 { margin: 0; font-size: 1.15rem; }
.cer-caption { position: absolute; left: 50%; top: 96px; transform: translateX(-50%); margin: 0; width: max-content; max-width: min(720px, calc(100% - 28px)); text-align: center;
  font-size: clamp(1.05rem, 2.6vw, 1.6rem); font-weight: 800; text-shadow: 0 2px 0 rgba(0,0,0,.6), 0 0 20px rgba(0,0,0,.6); }
.cer-caption:empty { display: none; }
.cer-card { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); display: grid; gap: 4px; width: max-content; max-width: min(460px, calc(100% - 28px));
  background: rgba(238, 241, 244, 0.95); color: #10161d; border: 2px dashed #6f7b87; border-radius: 12px; padding: 12px 16px; text-align: center; }
.cer-card strong { font-size: 1.05rem; }
.cer-card span { font-size: 0.85rem; }
.cer-bottom { position: absolute; inset-inline: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); display: grid; gap: 4px; max-width: 760px; }
.cer-bottom .fineprint { margin: 0; }
.cer-bottom .actions { margin-top: 2px; }
.cer-order summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.cer-order ol { margin: 6px 0; padding-inline-start: 1.4em; max-height: 26vh; overflow: auto; font-size: 0.82rem; columns: 2; }
.cer-order li.cer-del { color: var(--teal); }
.tag.cer-tag { font-size: 0.78rem; border-inline-start-color: var(--accent); }
.tag.cer-tag.m-gold { border-inline-start-color: #e8c547; }
.tag.cer-tag.m-silver { border-inline-start-color: #c9ced6; }
.tag.cer-tag.m-bronze { border-inline-start-color: #c98a55; }
.tag.flag-tag { font-family: var(--mono); background: rgba(240,242,245,.9); color: #111; }
.tag.del-tag { font-size: 0.8rem; border-inline-start-color: var(--teal); }
@media (max-width: 760px) {
  .ceremony { padding: 8px; }
  .cer-caption { top: 84px; }
  .cer-order ol { columns: 1; }
  .cer-bottom { inset-inline: 8px; }
}

#village { position: fixed; inset: 0; pointer-events: none; padding: 14px; z-index: 12; }
#village .hud-box, #village button, #village select, #village canvas, #village .joy { pointer-events: auto; }
.vil-top { display: inline-block; max-width: min(520px, calc(100% - 250px)); }
.vil-top h2 { margin: 0; font-size: 1.05rem; }
.vil-top-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.vil-top-actions button { min-height: 36px; padding: 0.3em 0.9em; }
.vil-turn { display: inline-flex; gap: 6px; }
.vil-turn button { font-size: 1.2rem; min-width: 44px; }
.vil-map { position: absolute; inset-inline-end: 14px; top: 14px; width: 220px; height: 220px; border-radius: 12px; border: 1px solid var(--line); }
.vil-prompt { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); max-width: calc(100% - 28px); border-color: var(--accent); background: rgba(20, 16, 0, 0.88); color: var(--accent); }
.vil-prompt:disabled { color: var(--muted); border-color: var(--line); cursor: default; }
.vil-panels { position: absolute; inset-inline-start: 14px; top: 142px; display: grid; gap: 8px; width: min(340px, calc(100% - 28px)); }
.vil-panel summary { cursor: pointer; font-weight: 700; }
.vil-panel p { margin: 6px 0 0; font-size: 0.86rem; color: var(--muted); }
.vil-steps { margin: 6px 0 0; padding-inline-start: 1.3em; font-size: 0.86rem; display: grid; gap: 3px; }
.vil-dialog { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100% - 28px)); max-height: calc(100% - 40px); overflow: auto; background: var(--panel-solid); }
.vil-dialog h3 { margin: 0 0 8px; }
.vil-notsaved { margin: 0 0 10px; padding: 6px 10px; border-radius: 8px; background: rgba(60, 40, 0, 0.7); border: 1px solid #8a6a20; color: #ffe2a0; font-weight: 700; font-size: 0.88rem; }
.vil-result { min-height: 1.2em; font-weight: 600; color: var(--teal); }
.vil-help { pointer-events: none; }
/* Online Village (DEC-245..DEC-249) */
.vil-conn { margin: 4px 0 0; color: var(--teal); }
.vil-conn[data-state="reconnecting"], .vil-conn[data-state="offline"] { color: #ffd28a; }
.vil-conn[data-state="refused"] { color: #ff9b9b; }
#village .vil-panels { top: 154px; max-height: calc(100% - 168px); overflow-y: auto; }
.vil-online { display: grid; gap: 10px; margin-top: 6px; }
.vil-sec h3 { margin: 4px 0; font-size: 0.92rem; }
.vil-chat-log { list-style: none; margin: 0; padding: 6px 8px; max-height: 150px; min-height: 2.4em; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: rgba(0, 0, 0, 0.35); display: grid; gap: 2px; font-size: 0.86rem; }
.vil-chat-log li { overflow-wrap: anywhere; }
.vil-chat-log li.self { color: var(--teal); }
.vil-chat-log li.emote { font-style: italic; color: var(--muted); }
.vil-chat-log li .masked { color: var(--muted); font-size: 0.8em; margin-inline-start: 4px; }
.vil-note { min-height: 1.1em; margin-bottom: 6px !important; color: #ffd28a !important; }
.vil-row { display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; }
.vil-grow { flex: 1 1 140px; min-width: 0; }
.vil-row input, .vil-row select { width: 100%; }
.vil-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.86rem; }
.vil-list li { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.vil-list li .who { flex: 1 1 100%; font-weight: 600; }
.vil-list li button { min-height: 32px; padding: 0.2em 0.7em; font-size: 0.82rem; }
.vil-list li .badge { font-size: 0.72rem; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.vil-report { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; }
.tag.peer-tag { border-inline-start-color: #6fc3ff; }
.tag.peer-tag.npc { border-inline-start-style: dashed; }
.tag.zone-tag { font-size: 0.82rem; padding: 2px 8px; border-inline-start-color: var(--c, #fff); }
.tag.zone-tag.stadium-tag { font-size: 0.95rem; border-inline-start-color: var(--accent); }
.joy { display: none; position: absolute; inset-inline-start: 24px; bottom: calc(40px + env(safe-area-inset-bottom)); width: 132px; height: 132px; border-radius: 50%;
  background: rgba(20, 30, 40, 0.6); border: 2px solid rgba(255,255,255,.4); touch-action: none; direction: ltr; }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255,255,255,.55); }
@media (pointer: coarse), (max-width: 760px) { .joy { display: block; } .vil-help { display: none; } }
@media (max-width: 760px) {
  #village { padding: 8px; }
  .vil-top { max-width: calc(100% - 136px); }
  .vil-top h2 { font-size: 0.9rem; }
  .vil-map { width: 120px; height: 120px; inset-inline-end: 8px; top: 8px; }
  .vil-panels { top: auto; bottom: calc(184px + env(safe-area-inset-bottom)); inset-inline-start: 8px; width: calc(100% - 16px); }
  .vil-prompt { bottom: calc(184px + env(safe-area-inset-bottom)); }
  .vil-prompt:not([hidden]) + .vil-panels { display: none; }
  /* Online Village: keep the panel between the top box and the joystick. */
  #village .vil-panels { top: auto; max-height: calc(100% - 184px - 150px - env(safe-area-inset-bottom)); background: var(--panel-solid); }
  /* The full-width development notice sits at the very top on phones: start the Village below it. */
  body:has(#dev-auth-notice:not([hidden])) #village { top: 36px; }
}

/* Review screenshots only (?qaHideUi=1, DEC-072): show the 3D scene without overlays. */
.qa-hide-ui #hud,
.qa-hide-ui #tags,
.qa-hide-ui #results,
.qa-hide-ui .touch,
.qa-hide-ui #coach {
  visibility: hidden;
}

/* About ads (DEC-194) */
.ads-about { margin: 6px 0 2px; font-size: 0.85rem; }
.ads-about summary { cursor: pointer; font-weight: 700; }
.ads-about p { margin: 6px 0; color: var(--muted); line-height: 1.4; }
/* ---------- Onboarding guide (DEC-170..DEC-174) ---------- */
.brand { position: relative; }
.guide-open-btn { position: absolute; inset-inline-end: 0; top: 0; padding: 0.45em 1em; border-color: var(--teal); color: #c9fff8; background: rgba(55, 208, 192, 0.12); }
.guide-open-btn:hover { background: rgba(55, 208, 192, 0.24); }
@media (max-width: 760px) { .brand { padding-inline-end: 96px; } }
.guide-offer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px; margin: 14px 0 0;
  padding: 12px 16px; border: 1px solid rgba(55, 208, 192, 0.55); border-radius: 12px; background: linear-gradient(90deg, rgba(55, 208, 192, 0.14), rgba(55, 208, 192, 0.04)); }
.guide-offer h2 { margin: 0 0 4px; font-size: 1.05rem; color: #c9fff8; }
.guide-offer p { margin: 0 0 4px; }
.guide-offer-text { flex: 1 1 13em; min-width: 0; }
.guide-offer .actions { margin: 0; }
.guide-settings-btn { margin-top: 10px; padding: 0.4em 0.9em; font-size: 0.88rem; }

/* Spotlight: a ring around the element being explained; the rest of the page is dimmed (never the guide panel). */
.guide-spot { position: fixed; z-index: 60; pointer-events: none; border: 3px solid var(--accent); border-radius: 12px;
  box-shadow: 0 0 0 4px rgba(255, 194, 61, 0.28), 0 0 0 200vmax rgba(2, 6, 10, 0.42); transition: left 0.25s, top 0.25s, width 0.25s, height 0.25s; }
.reduced .guide-spot { transition: none; }
body.guide-open .screen { padding-bottom: calc(var(--guide-h, 40vh) + 48px); }
.guide-target { scroll-margin-top: 24px; scroll-margin-bottom: calc(var(--guide-h, 40vh) + 44px); }

.guide { position: fixed; z-index: 70; inset-inline-end: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: min(700px, calc(100vw - 32px));
  display: grid; grid-template-columns: 200px 1fr; gap: 0; background: rgba(9, 15, 22, 0.94); border: 1px solid rgba(55, 208, 192, 0.45);
  border-radius: 18px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6); overflow: hidden; backdrop-filter: blur(8px); }
.guide-stage { position: relative; min-height: 250px; background: radial-gradient(120% 90% at 50% 30%, #2b4a55 0%, #142730 45%, #0a141a 100%); }
.guide-stage .guide-canvas, .guide-stage .guide-portrait { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.guide-ai { position: absolute; inset-inline: 8px; bottom: 8px; margin: 0; font-size: 0.72rem; color: #d8f6f2; background: rgba(4, 12, 16, 0.72);
  border-radius: 8px; padding: 3px 7px; text-align: center; }
.guide-body { display: grid; gap: 8px; padding: 14px 16px 12px; min-width: 0; }
.guide-head { display: grid; gap: 4px; }
.guide-progress { margin: 0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--teal); font-weight: 700; }
.guide-head h2 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.guide-head h2:focus { outline: none; }
.guide-bar { position: relative; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.guide-bar i { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0%; background: linear-gradient(90deg, var(--teal), var(--accent)); }
.guide-caption-box { max-height: 9.5em; overflow: auto; touch-action: pan-y; }
.guide-caption { margin: 0; font-size: 1.06rem; line-height: 1.55; }
.guide-caption .gw { border-radius: 4px; }
.guide-caption .gw.now { background: rgba(255, 194, 61, 0.3); box-shadow: 0 0 0 1px rgba(255, 194, 61, 0.45); }
.guide-status { margin: 0; min-height: 1em; font-size: 0.76rem; color: var(--muted); }
.guide-status:empty { display: none; }
.guide-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.guide-actions button { flex: 1 1 auto; }
.guide-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.guide-foot button { padding: 0.35em 0.8em; min-height: 36px; font-size: 0.82rem; font-weight: 500; }
#btn-guide-voice[aria-pressed="false"] { text-decoration: line-through; color: var(--muted); }
#btn-guide-voice[aria-pressed="true"] { border-color: var(--teal); }
.guide-chapters { flex: 1 1 100%; order: 2; }
.guide-chapters summary { cursor: pointer; color: var(--muted); font-size: 0.82rem; min-height: 28px; }
.guide-chapters ol { margin: 6px 0 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px; max-height: 30vh; overflow: auto; }
.guide-chapters li button { width: 100%; text-align: start; padding: 0.3em 0.6em; min-height: 32px; font-size: 0.8rem; font-weight: 500; }
.guide-chapters li button[aria-current] { border-color: var(--accent); color: var(--accent); }
.guide-keys { font-size: 0.72rem; }
#guide .guide-target { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 12px; }
.guide-return { position: fixed; z-index: 40; inset-inline-end: 16px; bottom: calc(52px + env(safe-area-inset-bottom)); padding: 0.4em 1em; min-height: 38px;
  background: rgba(10, 30, 36, 0.92); border-color: var(--teal); }
@media (pointer: coarse), (max-width: 760px) { .guide-return { inset-inline-end: auto; left: 50%; transform: translateX(-50%); bottom: calc(160px + min(32vw, 150px) + env(safe-area-inset-bottom)); } }
@media (max-width: 760px) {
  .guide { inset-inline: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto; grid-template-columns: 104px 1fr; max-height: 62vh; overflow: auto; }
  .guide-stage { min-height: 150px; }
  .guide-ai { font-size: 0.6rem; inset-inline: 4px; bottom: 4px; padding: 2px 4px; }
  .guide-body { padding: 10px 10px 8px; gap: 6px; }
  .guide-head h2 { font-size: 1rem; }
  .guide-caption { font-size: 0.95rem; }
  .guide-caption-box { max-height: 8em; }
  .guide-keys { display: none; }
  .guide-actions button { padding: 0.5em 0.7em; }
}
@media (pointer: coarse) { .guide-keys { display: none; } }

/* Lessons (DEC-578): the checklist sits under the standings board; in the results (board hidden) it moves up. */
#lesson { position: fixed; inset-inline-end: 14px; top: 196px; z-index: 21; width: min(300px, calc(100vw - 28px)); padding: 10px 14px; font-size: 0.82rem; }
#lesson h2 { margin: 0 0 6px; font-size: 0.78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#lesson ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lesson-item { display: flex; gap: 6px; align-items: baseline; color: var(--muted); }
.lesson-item.now { color: var(--ink, #fff); font-weight: 600; }
.lesson-item.done { color: #7ee2b8; }
.lesson-item.skipped { opacity: .55; }
.lesson-mark { flex: 0 0 1.1em; text-align: center; }
.lesson-count { font-variant-numeric: tabular-nums; }
#lesson-result { margin: 8px 0 0; font-weight: 600; }
.lesson-stars { color: #ffd35a; font-size: 1.15rem; letter-spacing: .1em; }
.lesson-best { font-weight: 400; color: var(--muted); }
.has-results #lesson { top: 14px; }
.proto-replaying #lesson { display: none; }
/* Practice drills (DEC-663). */
#drill { position: fixed; inset-inline-end: 14px; top: 196px; z-index: 21; width: min(300px, calc(100vw - 28px)); padding: 10px 14px; font-size: 0.82rem; }
#drill h2 { margin: 0 0 6px; font-size: 0.78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#drill p { margin: 0 0 6px; }
.drill-hint { color: var(--muted); font-style: italic; }
.drill-live { font-variant-numeric: tabular-nums; font-weight: 600; }
#drill-result { font-weight: 600; }
.drill-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.drill-pick { border: 1px solid var(--line, rgba(255,255,255,.18)); border-radius: 10px; padding: 8px 12px; margin: 0 0 10px; }
.drill-pick-goal { margin: 4px 0 8px; color: var(--muted); }
.tag-style { font-size: .85em; opacity: .85; }
@media (max-width: 760px) {
  #lesson { top: auto; bottom: calc(150px + env(safe-area-inset-bottom)); width: auto; inset-inline-start: 14px; }
  body:not(.has-results) .lesson-item:not(.now) { display: none; }
  .has-results #lesson { bottom: auto; top: 14px; }
}

/* Achievements (DEC-597): the unlock toast and the screen's list. */
.ach-toast { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 60; padding: 0.6rem 1.1rem; border-radius: 999px; background: rgba(20, 24, 32, 0.92); color: #ffe08a; font-weight: 700; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35); pointer-events: none; }
.ach-toast[hidden] { display: none; }
.sc-ach-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.sc-ach { display: grid; gap: 0.25rem; padding: 0.7rem 0.8rem; border-radius: 0.7rem; background: rgba(255, 255, 255, 0.06); opacity: 0.8; }
.sc-ach-done { opacity: 1; outline: 2px solid rgba(255, 210, 90, 0.7); }
.sc-ach-desc, .sc-ach-status { font-size: 0.85em; }
.sc-ach-bar { width: 100%; height: 0.5rem; }
.sc-protest-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
.sc-protest-form input { flex: 1 1 12rem; }
/* Leaderboard views and pages (DEC-650). */
.sc-ladder-scopes, .sc-ladder-pager { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
.sc-ladder-scopes button[aria-pressed="true"] { outline: 2px solid currentColor; outline-offset: 1px; font-weight: 600; }
.sc-protests { margin: 0.4rem 0 0; padding-inline-start: 1.1rem; }

/* DEC-714: the online 100 m on the flagship screen: the 100 m HUD (#hud) and the proto controller's touch buttons
   (its input path); the prototype HUD's own readouts and the 100 m's v1 touch buttons are not shown. */
body.flagship100 #proto-hud > :not(#proto-touch):not(.assist-badge) { display: none !important; }
body.flagship100 #hud #touch { display: none !important; }
/* DEC-716: the 100 m's instant replay over the online results covers them, like the v1 results. */
body.results-covered #proto-results, body.replaying #proto-touch { display: none !important; }

/* In-frame confirmation of sensitive actions (clickjacking guard, DEC-784): drawn by WorldSport above everything. */
.frame-guard-backdrop { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.6); }
.frame-guard { width: min(440px, calc(100% - 28px)); max-height: calc(100% - 40px); overflow: auto; background: var(--panel-solid); }
.frame-guard h3 { margin: 0 0 8px; }
.frame-guard .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.frame-guard a.button { display: inline-block; padding: 8px 14px; border-radius: 8px; text-decoration: none; }
