/* =====================================================================
   Marble Run — spectator UI
   The race fills the screen; everything else is a small, solid panel
   floating over it. One radius, one button height, one type scale.
   ===================================================================== */
:root {
  /* The marbles' 2D artwork has a margin around the sphere; round avatars
     zoom it by this factor so the sphere's edge meets the circle's edge
     (same value in gallery.html and champions.html). */
  --skin-zoom: 1.34;
  --bg: #0a0d14;
  --panel: #141a26;          /* solid surfaces — text always reads */
  --panel-2: #1c2333;        /* rows, inputs, secondary buttons */
  --panel-3: #262f43;        /* hover */
  --line: #2a3448;
  --text: #eef2f8;
  --muted: #a3afc4;          /* 4.9:1 on --panel */
  --gold: #ffcf5c;           /* primary actions, selection, winners */
  --gold-ink: #1a1204;
  --live: #35d07f;
  --out: #ff8a7a;
  --info: #7cc4ff;
  --radius: 12px;
  --radius-s: 8px;
  --btn-h: 40px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --top-h: 56px;
  --bottom-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
/* rem stays the browser's 16px (or the user's preference); body text is 14px. */
html { font-size: 100%; margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 400 0.875rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* Pin the document so iOS never scrolls the page itself; panels scroll inside. */
body { position: fixed; inset: 0; width: 100%; height: 100%; overscroll-behavior: none; }
a { color: var(--gold); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- shared controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--btn-h); padding: 0 16px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-weight: 700; font-size: 0.8125rem; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--panel-3); border-color: #3a4763; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn.primary:hover { background: #ffd978; border-color: #ffd978; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn.quiet:hover { background: var(--panel-2); color: var(--text); }
.btn.big { min-height: 46px; padding: 0 22px; font-size: 0.9375rem; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 0.75rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.modal-close {
  width: 36px; height: 36px; flex: none; border-radius: var(--radius-s); cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-size: 0.875rem; line-height: 1;
}
.modal-close:hover { color: var(--text); background: var(--panel-3); }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 2px;
}
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); border-top-color: var(--gold); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { display: inline-block; height: 0.8em; min-width: 5em; border-radius: 4px; background: var(--panel-3); animation: shimmer 1.4s ease-in-out infinite; vertical-align: middle; }
@keyframes shimmer { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* Round marble avatar: lane colour underneath, artwork circle-cropped on top. */
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex: none; position: relative; overflow: hidden; background: var(--gold); border: 1px solid rgba(255, 255, 255, 0.28); }
.sw img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; transform: scale(var(--skin-zoom, 1)); }
.sw.lg { width: 40px; height: 40px; }
.sw.xl { width: 64px; height: 64px; }

/* Status text: colour plus words, never colour alone. */
.tag { display: inline-block; font-size: 0.6875rem; font-weight: 800; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--panel-2); white-space: nowrap; }
.tag.live { color: var(--live); border-color: rgba(53, 208, 127, 0.45); }
.tag.out { color: var(--out); border-color: rgba(255, 138, 122, 0.4); }
.tag.gold { color: var(--gold); border-color: rgba(255, 207, 92, 0.5); }
.tag.info { color: var(--info); border-color: rgba(124, 196, 255, 0.4); }

/* ---------- the stage ---------- */
.stage { position: fixed; inset: 0; z-index: 0; background: #05070c; }
.stage iframe { width: 100%; height: 100%; border: 0; display: block; }
.stage-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; font-weight: 900; letter-spacing: 0.04em; color: #fff;
  text-shadow: 0 4px 30px #000; opacity: 0; transition: opacity 0.3s;
}
/* Renderer states live inside the stage, under the top bar and above the
   bottom bar, so they never cover the intro or the controls. */
.stage-state { position: absolute; inset: 0; z-index: 4; pointer-events: none; display: none; overflow-y: auto; padding: calc(var(--top-h) + 20px) 16px calc(var(--bottom-h) + 20px + var(--safe-b)); }
.stage[data-renderer='failed'] .stage-state { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; }
body.hero-open .stage-state { padding-top: 300px; }
/* The one loading screen: covers the stage from the first paint (no blank
   stage, nothing of the game's own loader shows through), then fades out
   once the game reports its first usable frame. */
.ss-loading { position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: calc(var(--top-h) + 20px) 24px calc(var(--bottom-h) + 20px + var(--safe-b)); background: radial-gradient(120% 80% at 50% 30%, #182033 0%, var(--bg) 70%); color: var(--muted); font-weight: 700; transition: opacity 0.45s ease; }
.ss-loading.done { opacity: 0; pointer-events: none; }
.ss-loading[hidden] { display: none; }
.ss-logo { width: min(260px, 70vw); height: auto; filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.5)); }
.ss-status { font-size: 0.875rem; letter-spacing: 0.02em; color: var(--text); }
.ss-bar { position: relative; width: min(280px, 70vw); height: 6px; border-radius: 999px; background: var(--panel-3); overflow: hidden; }
.ss-fill { position: absolute; left: 0; top: 0; bottom: 0; width: var(--p, 0%); border-radius: 999px; background: var(--gold); transition: width 0.35s ease; }
.ss-bar.indeterminate .ss-fill { width: 40%; animation: ssSlide 1.4s ease-in-out infinite; }
@keyframes ssSlide { 0% { left: -40%; } 100% { left: 100%; } }
.stage[data-renderer='failed'] iframe { opacity: 0.15; pointer-events: none; }
.stage[data-renderer='failed'] .stage-overlay { display: none; }
.ss-failed { pointer-events: auto; width: min(520px, 100%); max-height: 100%; display: flex; flex-direction: column; padding: 18px 18px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.ss-failed h2 { margin: 0 0 6px; font-size: 1.125rem; }
.ss-failed p { margin: 0 0 12px; color: var(--muted); }
.ss-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ss-fallback { margin-top: 14px; min-height: 0; overflow-y: auto; }
.ss-fallback:empty { display: none; }
/* While the Tournament drawer shows "This race", the standings live there:
   the stage keeps only the explanation and the retry. */
.ss-failed.compact { width: min(380px, 100%); }
.ss-failed.compact .ss-fallback { display: none; }
.ss-failed.compact .ss-fallback.replaying { display: block; } /* a replay's recorded result stays visible with the drawer open */
/* While a recorded replay is on the panel, the panel is the replay: the
   generic failure text and its retry step aside (the replay has its own). */
.ss-failed.replaying .ss-msg, .ss-failed.replaying .ss-actions { display: none; }
.ss-failed.replaying { padding-top: 44px; }
.ss-replay-acts { margin-top: 10px; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30; height: var(--top-h);
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 0 max(14px, var(--safe-r)) 0 max(14px, var(--safe-l));
  background: rgba(10, 13, 20, 0.92); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; font-weight: 900; flex: none; min-height: 40px; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-name:not([hidden]) { display: inline; color: var(--gold); }
.race-console { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rc-info { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.race-title { font-weight: 800; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.race-title.final { color: var(--gold); }
.rc-meta { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; }
.rc-count { font-variant-numeric: tabular-nums; }
.rc-note:empty { display: none; }
.rc-note { color: var(--gold); }
.cd { position: relative; width: 40px; height: 40px; flex: none; }
.cd-ring { width: 40px; height: 40px; transform: rotate(-90deg); display: block; }
.cd-bg { fill: none; stroke: var(--line); stroke-width: 5; }
.cd-fg { fill: none; stroke: var(--gold); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 175.93; stroke-dashoffset: 175.93; transition: stroke-dashoffset 0.25s linear, stroke 0.3s; }
.cd-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.6875rem; font-variant-numeric: tabular-nums; color: var(--gold); }
.cd.live .cd-fg { stroke: var(--live); }
.cd.live .cd-num { color: var(--live); }
.topbar-right { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar-btn {
  display: inline-flex; align-items: center; gap: 7px; min-height: var(--btn-h); padding: 0 12px;
  border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel-2); cursor: pointer;
  font-weight: 700; font-size: 0.8125rem; white-space: nowrap;
}
.bar-btn:hover { background: var(--panel-3); }
.bar-btn[aria-expanded='true'] { border-color: var(--gold); color: var(--gold); }
.conn, .watching { font-size: 0.75rem; color: var(--muted); padding: 0 10px; min-height: 32px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; background: var(--panel-2); }
.conn[data-state='live'], .conn[data-state='connecting'] { display: none; }
.conn[data-state='local'] { color: var(--gold); }
.conn[data-state='reconnecting'], .conn[data-state='delayed'] { color: #ffb36b; }
.conn[data-state='offline'] { color: var(--out); }
.watching { color: var(--live); font-weight: 800; }
.watching .w-count { color: var(--muted); font-weight: 600; }
.watching #watchingN { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }
.li-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); box-shadow: 0 0 8px var(--live); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ---------- menu popover ---------- */
.menu-pop, .cam-pop {
  position: fixed; z-index: 45; width: min(320px, calc(100vw - 20px)); max-height: calc(100vh - var(--top-h) - 20px); overflow-y: auto;
  padding: 8px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.menu-pop { top: calc(var(--top-h) + 6px); right: max(10px, var(--safe-r)); }
.mp-group { font-size: 0.6875rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }
.mp-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; text-decoration: none; cursor: pointer;
  color: var(--text); font-weight: 600; font-size: 0.875rem; padding: 0 12px; min-height: 42px; border-radius: var(--radius-s); border: 0; background: none;
}
.mp-item:hover { background: var(--panel-2); }
.mp-toggle .mp-state { margin-left: auto; font-size: 0.75rem; color: var(--muted); padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); }
.mp-toggle.on .mp-state { color: var(--live); border-color: rgba(53, 208, 127, 0.45); }
.mp-details summary { cursor: pointer; padding: 10px 12px; min-height: 42px; display: flex; align-items: center; font-weight: 600; color: var(--muted); border-radius: var(--radius-s); }
.mp-details summary:hover { background: var(--panel-2); color: var(--text); }
.mp-tech { padding: 4px 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.seedline { color: var(--muted); font-size: 0.6875rem; font-family: ui-monospace, Menlo, Consolas, monospace; line-height: 1.5; word-break: break-word; }

/* ---------- camera popover ---------- */
.cam-pop { bottom: calc(var(--bottom-h) + 4px + var(--safe-b)); right: max(10px, var(--safe-r)); max-height: calc(100vh - var(--bottom-h) - var(--top-h) - 20px); }
.cp-title { font-size: 0.6875rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 6px 10px 6px; }
.cp-list { display: flex; flex-direction: column; gap: 4px; }
.cp-mode {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'b k' 's k'; align-items: center; column-gap: 8px; width: 100%; text-align: left;
  cursor: pointer; padding: 9px 12px; min-height: 48px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel-2);
}
.cp-mode b { grid-area: b; font-size: 0.875rem; font-weight: 800; }
.cp-mode small { grid-area: s; font-size: 0.75rem; color: var(--muted); line-height: 1.35; }
.cp-mode kbd { grid-area: k; font: 800 0.6875rem/1 ui-monospace, Menlo, Consolas, monospace; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 3px 5px; }
.cp-mode:hover { background: var(--panel-3); }
.cp-mode[aria-pressed='true'] { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.cp-mode[aria-pressed='true'] b { color: var(--gold); }
.cp-mode[aria-pressed='true'] b::after { content: ' · on'; font-weight: 700; font-size: 0.75rem; }
.cp-mode[disabled] { opacity: 0.55; cursor: not-allowed; }
.cp-mode.small { min-height: 42px; padding: 7px 12px; }
.cp-more, .cp-kbd { margin-top: 4px; }
.cp-more summary, .cp-kbd summary { cursor: pointer; font-size: 0.8125rem; font-weight: 700; color: var(--muted); padding: 9px 10px; min-height: 38px; display: flex; align-items: center; border-radius: var(--radius-s); }
.cp-more summary:hover, .cp-kbd summary:hover { color: var(--text); background: var(--panel-2); }
.cp-more[open] > summary, .cp-kbd[open] > summary { color: var(--text); }
.cp-more .cp-list { padding: 4px 0 2px; }
.cp-keys { margin: 4px 0 0; padding: 0 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.cp-keys div { display: flex; align-items: center; gap: 8px; }
.cp-keys dt { flex: none; min-width: 22px; text-align: center; font: 800 0.75rem/1 ui-monospace, Menlo, Consolas, monospace; color: var(--gold); background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 4px 5px; }
.cp-keys dd { margin: 0; font-size: 0.75rem; color: var(--muted); }
.cp-kbd-note { margin: 8px 6px 4px; font-size: 0.75rem; color: var(--muted); }
.cp-now { font-size: 0.75rem; color: var(--muted); padding: 8px 10px 4px; }
.cp-now:empty { display: none; }

/* ---------- onboarding ---------- */
.hero { position: fixed; top: calc(var(--top-h) + 10px); left: 0; right: 0; z-index: 19; display: flex; justify-content: center; padding: 0 14px; pointer-events: none; animation: rise 0.35s ease both; }
.hero-card {
  pointer-events: auto; text-align: center; width: min(520px, 100%); padding: 18px 20px 16px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.hero-title { margin: 0; font-size: clamp(1.25rem, 3.4vw, 1.625rem); font-weight: 900; line-height: 1.15; }
.hero-tag { margin: 0; font-size: 0.875rem; color: var(--muted); max-width: 46ch; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
body.hero-open .prerace { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- modals (how it works, picker) ---------- */
.modal-veil { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(5, 7, 12, 0.7); }
.modal { position: relative; width: min(560px, 100%); max-height: min(720px, 92vh); overflow-y: auto; padding: 22px 22px 18px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.modal h2 { margin: 0 32px 8px 0; font-size: 1.25rem; }
.modal p { margin: 0 0 12px; color: var(--muted); }
.modal .modal-close { position: absolute; top: 14px; right: 14px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.how-stages { margin: 0 0 12px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.how-stages li { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 10px 12px; border-radius: var(--radius-s); background: var(--panel-2); }
.how-stages li i { font-style: normal; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; min-width: 1.2em; }
.how-stages li b { display: block; font-size: 0.875rem; }
.how-stages li span { display: block; font-size: 0.8125rem; color: var(--muted); }
.how-stages li.now { box-shadow: inset 0 0 0 1px var(--gold); }
.how-stages li.now b::after { content: ' · now'; color: var(--gold); font-size: 0.75rem; }
.how-note { font-size: 0.8125rem; }

/* picker */
.picker { display: flex; flex-direction: column; width: min(640px, 100%); max-height: min(760px, 92vh); padding: 16px 16px 12px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.picker-head, .picker-tools, .picker-note, .picker-foot, .picker-empty { flex: none; }
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.picker-head h2 { margin: 0; font-size: 1.125rem; }
.picker-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.picker-tools input { flex: 1 1 160px; min-width: 120px; min-height: var(--btn-h); padding: 0 12px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg-btn { min-height: calc(var(--btn-h) - 2px); padding: 0 12px; border: 0; background: var(--panel-2); color: var(--muted); font-weight: 700; font-size: 0.8125rem; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn[aria-pressed='true'] { background: var(--gold); color: var(--gold-ink); }
.picker-note { margin: 10px 2px 8px; font-size: 0.8125rem; color: var(--muted); min-height: 1.2em; }
.picker-note:empty { display: none; }
.picker-grid { flex: 1; min-height: 160px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; padding: 2px; }
.picker-empty { padding: 30px 10px; text-align: center; color: var(--muted); }
/* A <button> won't size itself from flex children in Chromium, so the flex
   column lives on an inner span and the button is a plain block. */
.pk {
  cursor: pointer; text-align: center; padding: 10px 6px 8px; border-radius: var(--radius-s); display: block; width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.pk-in { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.pk:hover { background: var(--panel-3); }
.pk-in > * { flex: none; }
.pk .sw { width: 56px; height: 56px; }
.pk-num { font-size: 0.6875rem; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 700; }
.pk-name { font-size: 0.8125rem; font-weight: 800; line-height: 1.2; min-height: 1.2em; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-status { font-size: 0.6875rem; color: var(--muted); }
.pk.out .sw { filter: grayscale(0.7) brightness(0.75); }
.pk.out .pk-status { color: var(--out); }
.pk.champ .pk-status { color: var(--gold); }
.pk.followed { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.pk.followed .pk-name { color: var(--gold); }
.picker-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; font-size: 0.75rem; color: var(--muted); }

/* ---------- in-race standings board (top-left) ---------- */
.race-board { position: fixed; left: max(12px, var(--safe-l)); top: calc(var(--top-h) + 8px); z-index: 22; width: 230px; padding: 8px 8px 6px; border-radius: var(--radius); background: rgba(20, 26, 38, 0.83); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
/* Folded: a one-line strip of lane dots and numbers in running order. */
.race-board.collapsed { width: auto; padding: 4px 5px; cursor: pointer; }
.race-board.collapsed .rb-head, .race-board.collapsed .rb-pos, .race-board.collapsed .rb-name, .race-board.collapsed .rb-fin { display: none; }
.race-board.collapsed .rb-rows { flex-direction: row; gap: 2px; }
.race-board.collapsed .rb-row { width: auto; height: 20px; padding: 0 3px; gap: 3px; pointer-events: none; }
.race-board.collapsed .rb-row .sw { width: 9px; height: 9px; }
.race-board.collapsed .rb-num { width: auto; font-size: 0.6875rem; }
.race-board.collapsed .rb-row.mine { box-shadow: inset 0 0 0 1px rgba(255, 207, 92, 0.6); }
.rb-head { display: flex; flex-direction: column; gap: 1px; padding: 0 4px 6px; font-size: 0.6875rem; font-weight: 800; color: var(--gold); }
.rb-rule { color: var(--muted); font-weight: 600; }
.rb-rule:empty { display: none; }
.rb-rows { display: flex; flex-direction: column; gap: 2px; }
.rb-row { display: flex; align-items: center; gap: 7px; height: 24px; width: 100%; padding: 0 4px; border: 0; border-radius: 6px; background: none; color: inherit; font: inherit; font-size: 0.8125rem; text-align: left; cursor: pointer; }
.rb-row:hover { background: rgba(255, 255, 255, 0.07); }
.rb-row:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.rb-row.lead .rb-pos { color: var(--gold); }
.rb-row.mine { background: rgba(255, 207, 92, 0.14); box-shadow: inset 0 0 0 1px rgba(255, 207, 92, 0.45); }
.rb-row.done { color: var(--muted); }
.rb-pos { width: 12px; text-align: right; font-weight: 900; color: var(--muted); font-size: 0.75rem; }
.rb-num { font-weight: 700; color: var(--muted); font-size: 0.75rem; width: 20px; }
.rb-row.mine .rb-num, .rb-row.mine .rb-name { color: var(--gold); }
.rb-name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-fin { color: var(--live); font-size: 0.75rem; font-weight: 800; }
.rb-fin:empty { display: none; }

/* ---------- between races ---------- */
.prerace { position: fixed; inset: 0; z-index: 18; display: flex; align-items: flex-start; justify-content: center; padding: calc(var(--top-h) + 10px) 14px calc(var(--bottom-h) + 20px); pointer-events: none; }
.pr-card { pointer-events: auto; text-align: center; position: relative; width: min(380px, 100%); padding: 14px 16px 14px; border-radius: var(--radius); background: rgba(20, 26, 38, 0.94); border: 1px solid var(--line); box-shadow: var(--shadow); animation: rise 0.3s ease both; }
.pr-close { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: var(--radius-s); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; background: transparent; color: var(--muted); border: 1px solid transparent; font-size: 0.8125rem; line-height: 1; }
.pr-close:hover, .pr-close:focus-visible { color: var(--text); border-color: var(--line); }
.pr-mini { pointer-events: auto; display: inline-flex; align-items: center; gap: 8px; max-width: min(380px, 100%); min-height: var(--btn-h); padding: 0 12px 0 14px; border-radius: 999px; cursor: pointer; background: rgba(20, 26, 38, 0.94); border: 1px solid var(--line); box-shadow: var(--shadow); color: var(--text); font-weight: 800; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.pr-mini:hover { background: var(--panel-3); }
.pr-mini-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-mini-caret { color: var(--muted); flex: none; }
.pr-context { font-size: 0.75rem; color: var(--muted); font-weight: 700; margin: 0 32px; }
.pr-flavor:not(:empty)::before { content: ' · '; }
.pr-title { font-size: clamp(1.125rem, 3.6vw, 1.375rem); font-weight: 900; margin-top: 2px; font-variant-numeric: tabular-nums; }
.pr-remaining { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.pr-remaining:empty { display: none; }
.pr-guess { font-size: 0.75rem; font-weight: 700; color: var(--muted); margin-top: 12px; }
.pr-starters { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.pr-starters:empty { display: none; }
.pr-starters .um { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 0 11px; min-height: 38px; font-weight: 700; font-size: 0.8125rem; color: var(--text); }
.pr-starters .um:hover { background: var(--panel-3); }
.pr-starters .um[aria-pressed='true'] { border-color: var(--gold); color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.pr-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.pr-actions:empty, .pr-actions:not(:has(:not([hidden]))) { display: none; }

/* Stage strip: the fixed format, current stage highlighted. */
.stages { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 10px; flex-wrap: nowrap; }
.stg { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); font-size: 0.6875rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.stg.active { color: var(--gold); border-color: var(--gold); }
.stg.done { color: var(--live); }
.stg.done::before { content: '✓'; font-weight: 900; }
.stg.todo { opacity: 0.6; }
.stg-arrow { color: var(--line); font-size: 0.75rem; }

/* ---------- toast / replay chip / tv static ---------- */
.race-toast { position: fixed; left: 50%; bottom: calc(var(--bottom-h) + 14px + var(--safe-b)); transform: translateX(-50%) translateY(6px); z-index: 26; display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; white-space: nowrap; max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis; background: var(--panel); border: 1px solid var(--line); color: var(--text); font-size: 0.8125rem; font-weight: 700; box-shadow: var(--shadow); opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; }
.race-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.replay-chip { position: fixed; top: calc(var(--top-h) + 10px); left: 50%; transform: translateX(-50%); z-index: 26; display: flex; align-items: center; gap: 10px; padding: 0 6px 0 14px; min-height: 38px; border-radius: 999px; background: var(--panel); border: 1px solid rgba(53, 208, 127, 0.5); color: var(--live); font-size: 0.75rem; font-weight: 800; max-width: calc(100vw - 24px); }
.replay-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.replay-chip button { cursor: pointer; width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(53, 208, 127, 0.5); background: transparent; color: var(--live); font-size: 0.6875rem; line-height: 1; flex: none; }
.tv-static { position: fixed; inset: 0; z-index: 45; background: #000; }
.tv-static canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; opacity: 0.85; }
.ts-label { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center; font-size: clamp(1.375rem, 5vw, 2.5rem); font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; color: #fff; text-align: center; text-shadow: 0 0 18px rgba(0, 0, 0, 0.9), 0 2px 6px #000; padding: 0 20px; }
.ts-label .ts-live { color: #ff5c5c; }
.ts-label .ts-sub { font-size: 0.52em; letter-spacing: 0.06em; color: #e8edf5; }

/* ---------- moments ---------- */
.moment { position: fixed; inset: 0; z-index: 58; display: flex; align-items: center; justify-content: center; padding: calc(var(--top-h) + 14px) 18px calc(var(--bottom-h) + 20px + var(--safe-b)); background: rgba(5, 7, 12, 0.72); opacity: 0; transition: opacity 0.3s; }
.moment.show { opacity: 1; }
.mo-inner { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 720px; width: 100%; }
.mo-kicker { font-size: 0.8125rem; font-weight: 800; color: var(--muted); }
.mo-title { font-size: clamp(1.75rem, 7vw, 3.75rem); font-weight: 900; line-height: 1.05; color: #fff; text-shadow: 0 6px 34px rgba(0, 0, 0, 0.9); }
.moment.good .mo-title { color: var(--live); }
.moment.bad .mo-title { color: var(--out); }
.moment.wait .mo-title { color: var(--gold); }
.mo-sub { font-size: clamp(0.875rem, 2.2vw, 1.0625rem); font-weight: 700; color: var(--text); line-height: 1.5; }
.mo-sub .mo-count { display: block; margin-top: 6px; font-size: 0.85em; color: var(--muted); font-weight: 600; }
.mo-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

/* ---------- tournament drawer ---------- */
.drawer { position: fixed; top: var(--top-h); right: 0; bottom: 0; z-index: 40; width: min(420px, 100vw); display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow); animation: slideIn 0.25s ease both; }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.dr-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 8px; }
.dr-head h2 { margin: 0; font-size: 1.0625rem; }
.dr-sub { color: var(--muted); font-size: 0.75rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dr-tabs { display: flex; gap: 4px; padding: 0 12px 8px; border-bottom: 1px solid var(--line); }
.dr-tab { flex: 1; min-height: var(--btn-h); border-radius: var(--radius-s); border: 1px solid transparent; background: none; color: var(--muted); font-weight: 700; font-size: 0.8125rem; cursor: pointer; }
.dr-tab:hover { background: var(--panel-2); color: var(--text); }
.dr-tab[aria-selected='true'] { background: var(--panel-2); color: var(--gold); border-color: var(--line); }
.dr-body { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px calc(16px + var(--safe-b)); }
.dr-body::-webkit-scrollbar { width: 8px; }
.dr-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.dr-sec { margin-bottom: 18px; }
.dr-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 0 8px; font-size: 0.75rem; font-weight: 800; color: var(--muted); }
.dr-h b { color: var(--text); font-size: 0.875rem; }
.dr-h small { font-weight: 600; }
.dr-empty { color: var(--muted); font-size: 0.8125rem; padding: 8px 2px; }
.dr-empty.err { color: var(--out); }
.dr-inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-list { display: flex; flex-direction: column; gap: 4px; }
.mrow { display: grid; grid-template-columns: 30px auto minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 44px; padding: 4px 8px; border-radius: var(--radius-s); background: var(--panel-2); border: 1px solid transparent; }
.mrow.mine { border-color: rgba(255, 207, 92, 0.6); }
.mrow.win .mrow-name { color: var(--gold); }
.mrow.tbd { opacity: 0.6; }
.mrow-pos { font-weight: 900; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; font-size: 0.8125rem; }
.mrow.win .mrow-pos, .mrow.lead .mrow-pos { color: var(--gold); }
.mrow-name { font-weight: 700; font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow-name small { color: var(--muted); font-weight: 700; margin-right: 5px; font-variant-numeric: tabular-nums; }
.mrow-name .you { color: var(--gold); font-size: 0.6875rem; margin-left: 4px; }
.mrow-status { font-size: 0.6875rem; color: var(--muted); white-space: nowrap; text-align: right; }
.mrow-status.live { color: var(--live); }
.mrow-status.out { color: var(--out); }
.mrow .btn.sm { grid-column: 4; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px 3px 4px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 0.6875rem; font-weight: 700; color: var(--text); }
.chip.mine { border-color: var(--gold); color: var(--gold); }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 5px; }
.fg { display: flex; align-items: center; gap: 5px; padding: 4px 6px; border-radius: 6px; background: var(--panel-2); font-size: 0.6875rem; font-weight: 700; min-width: 0; }
.fg span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fg.eliminated { color: var(--muted); }
.fg.eliminated span { text-decoration: line-through; }
.fg.champion { color: var(--gold); }
.fg.mine { box-shadow: inset 0 0 0 1px var(--gold); }
.round-sel { display: flex; gap: 4px; margin-bottom: 10px; }
.round-sel button { flex: 1; min-height: 36px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-weight: 700; font-size: 0.75rem; cursor: pointer; }
.round-sel button[aria-pressed='true'] { color: var(--gold); border-color: var(--gold); }
.round-sel button i { font-style: normal; font-size: 0.625rem; font-weight: 800; color: var(--live); margin-left: 5px; vertical-align: 1px; }
.round-sel button i::before { content: '●'; margin-right: 3px; }
.round-sel button:hover { background: var(--panel-3); }
.dr-details summary { cursor: pointer; font-size: 0.8125rem; font-weight: 700; color: var(--muted); padding: 10px 4px; min-height: 40px; display: flex; align-items: center; }
.dr-details summary:hover { color: var(--text); }
.dr-details[open] summary { color: var(--text); }
.race-rows { display: flex; flex-direction: column; gap: 4px; }
.rr { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 40px; padding: 4px 8px; border-radius: var(--radius-s); background: var(--panel-2); border: 1px solid transparent; font-size: 0.8125rem; }
.rr.current { border-color: rgba(53, 208, 127, 0.5); }
.rr.mine { border-color: rgba(255, 207, 92, 0.5); }
.rr.tbd { opacity: 0.6; }
.rr.champ { border-color: var(--gold); }
/* Upcoming races expand to their five competitors. */
.rr-x { border-radius: var(--radius-s); background: var(--panel-2); border: 1px solid transparent; }
.rr-x.current { border-color: rgba(53, 208, 127, 0.5); }
.rr-x.mine { border-color: rgba(255, 207, 92, 0.5); }
.rr-x > summary.rr { cursor: pointer; list-style: none; border: 0; background: none; }
.rr-x > summary.rr::-webkit-details-marker { display: none; }
.rr-x > summary.rr .rr-l::before { content: '▸'; color: var(--muted); margin-right: 6px; display: inline-block; transition: transform 0.15s; }
.rr-x[open] > summary.rr .rr-l::before { transform: rotate(90deg); }
.rr-x > summary.rr:hover { background: var(--panel-3); border-radius: var(--radius-s); }
.rr-body { display: flex; flex-wrap: wrap; gap: 5px; padding: 2px 8px 10px; }
/* A finished race opens to its finishing order (the favourite marked in it). */
.rr-x.done > summary.rr .rr-w { color: var(--text); }
.rr-body.list { display: block; padding: 0 6px 8px; }
.rr-body.list .row-list { gap: 3px; }
.mrow.compact { min-height: 40px; grid-template-columns: 0 auto minmax(0, 1fr) auto; gap: 0 8px; }
.mrow.out .mrow-name { color: var(--muted); }
.mrow-status.gold { color: var(--gold); }
.dr-details.field > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dr-details.field > summary b { color: var(--text); }
.dr-details.field .dr-link { color: var(--gold); font-weight: 700; font-size: 0.75rem; }
.dr-details.field[open] .dr-link { display: none; }
.dr-details.field .seg { margin: 4px 0 10px; }
.rr-l { font-size: 0.6875rem; font-weight: 800; color: var(--muted); }
.rr-w { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 700; }
.rr-w span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rr-w.muted { color: var(--muted); font-weight: 600; }
.rr.current .rr-w.muted { color: var(--live); }
.rr-w small { color: var(--muted); font-weight: 600; }

/* The wide two-sided bracket tree (desktop, inside "Full bracket"). */
.bd-scroll { overflow: auto; padding: 4px 0 8px; }
.bd-main { display: flex; align-items: center; gap: 12px; width: max-content; padding: 2px; }
.bd-heatcol { flex: none; width: 150px; display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.bd-core { flex: none; display: grid; grid-template-columns: 182px 20px 186px 20px 182px; align-items: stretch; gap: 6px; }
.bd-wing { display: flex; flex-direction: column; justify-content: center; gap: 10px; min-width: 0; }
.bd-center { display: flex; flex-direction: column; align-items: stretch; justify-content: center; gap: 6px; min-width: 0; }
.bd-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 4px 8px 5px; min-width: 0; }
.bd-box.current { border-color: var(--live); }
.bd-box.tbd { opacity: 0.6; }
.bd-final { border-color: var(--gold); }
.bd-box-h { font-size: 0.6875rem; font-weight: 800; color: var(--muted); margin-bottom: 2px; }
.bd-final .bd-box-h { color: var(--gold); }
.bd-tbd { font-size: 0.6875rem; color: var(--muted); padding: 6px 0; text-align: center; }
.bd-slot { display: flex; align-items: center; gap: 6px; font-size: 0.6875rem; line-height: 1.3; }
.bd-slot .pos { width: 10px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.bd-slot .sw { width: 9px; height: 9px; }
.bd-slot .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-slot .t { margin-left: auto; color: var(--muted); font-size: 0.625rem; }
.bd-slot.win { color: var(--gold); font-weight: 800; }
.bd-join { position: relative; align-self: stretch; }
.bd-join::before { content: ''; position: absolute; top: 28%; bottom: 28%; border-left: 2px solid var(--line); }
.bd-join::after { content: ''; position: absolute; top: 50%; height: 0; border-top: 2px solid var(--line); }
.bd-join.left::before { left: 0; } .bd-join.left::after { left: 0; right: -3px; }
.bd-join.right::before { right: 0; } .bd-join.right::after { right: 0; left: -3px; }
.bd-champ { display: flex; align-items: center; justify-content: center; gap: 9px; padding: 6px 10px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel-2); text-align: center; font-weight: 900; font-size: 0.8125rem; }
.bd-champ.has { border-color: var(--gold); color: var(--gold); }
.bd-champ:not(.has) { color: var(--muted); }

/* No 3D: the stage's fallback list is the standings view — the board stays off. */
body.no3d .race-board { display: none !important; }

/* ---------- bottom bar: your marble + view controls ---------- */
.bottom-bar { position: fixed; left: max(12px, var(--safe-l)); right: max(12px, var(--safe-r)); bottom: calc(12px + var(--safe-b)); z-index: 41; display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; pointer-events: none; }
.bottom-bar > * { pointer-events: auto; }
/* The card takes whatever width the view controls leave (a definite width,
   so its text knows where to wrap), capped on wide screens. */
.my-marble { min-width: 0; flex: 1 1 auto; }
.mm { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: 'ball info change' 'ball cam change'; align-items: center; column-gap: 10px; row-gap: 6px; width: 100%; max-width: 440px; min-height: 60px; padding: 8px 10px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.mm.cta { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'info act'; }
.mm-ballbtn { grid-area: ball; }
.mm-info { grid-area: info; }
.mm-change { grid-area: change; }
/* The camera toggle and the compact "Change" action: on desktop each takes
   its own grid area; on phones the wrapper becomes one row under the info. */
.mm-acts { display: contents; }
.mm-cam { grid-area: cam; justify-self: start; max-width: 100%; }
.mm-cam .sm-only { display: none; }
.mm.cta .mm-actions { grid-area: act; }
.mm-k .tag { text-transform: none; letter-spacing: 0; }
.mm-ball { width: 44px; height: 44px; }
.mm-ballbtn { padding: 0; border: 0; background: none; border-radius: 50%; cursor: pointer; display: block; line-height: 0; }
a.mrow { text-decoration: none; color: inherit; }
a.mrow:hover { background: var(--panel-3); }
.mrow-status .tag { margin-left: 4px; }
.mm-info { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
/* "YOUR MARBLE" + status tag stay on one line at any width: the words never
   wrap, and a long tag shortens with an ellipsis rather than pushing down. */
.mm-k { font-size: 0.6875rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; min-width: 0; }
.mm-kt { flex: none; }
.mm-k .tag { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.mm-name { font-size: 0.9375rem; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mm-name small { color: var(--muted); font-weight: 700; margin-right: 4px; }
/* The status line wraps in full ("4th in Qualifier 3 · back next tournament")
   rather than truncating the useful half. */
.mm-line { font-size: 0.75rem; color: var(--text); line-height: 1.3; white-space: normal; overflow-wrap: anywhere; }
.mm-line.muted { color: var(--muted); }
.mm-cam { display: inline-flex; min-width: 0; overflow: hidden; text-overflow: ellipsis; align-items: center; gap: 6px; min-height: 32px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-size: 0.6875rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.mm-cam[aria-pressed='true'] { color: var(--gold); border-color: var(--gold); }
.mm-cam[disabled] { opacity: 0.5; cursor: not-allowed; }
.mm-cam .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.mm-cam[aria-pressed='true'] .dot { background: var(--gold); }
.mm.out .mm-ball { filter: grayscale(0.6) brightness(0.8); }
.viewbar { display: flex; gap: 6px; flex: none; }
.vb-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; min-width: 44px; padding: 0 12px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--panel); color: var(--text); font-weight: 700; font-size: 0.8125rem; cursor: pointer; box-shadow: var(--shadow); }
.vb-btn:hover { background: var(--panel-3); }
.vb-btn.icon { padding: 0; justify-content: center; font-size: 1rem; }
.vb-btn[aria-expanded='true'], .vb-btn[aria-pressed='true'] { border-color: var(--gold); color: var(--gold); }
.stage[data-renderer='failed'] ~ .bottom-bar .viewbar { display: none; }
/* With the drawer open, the view controls step out from under it. */
body.drawer-open .bottom-bar { right: calc(min(420px, 100vw) + 12px); }

/* ---------- champion moment ---------- */
.champ-overlay { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; background: rgba(5, 7, 12, 0.9); opacity: 0; transition: opacity 0.5s ease; pointer-events: none; }
.champ-overlay.show { opacity: 1; pointer-events: auto; }
.champ-overlay canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.co-inner { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 64px 20px 30px; margin: auto; }
.co-kicker { font-size: 0.875rem; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.co-ball {
  --c1: #ffcf5c; --c2: #8a6a1c;
  width: clamp(150px, 32vh, 280px); height: clamp(150px, 32vh, 280px); border-radius: 50%; position: relative;
  background-size: calc(100% * var(--skin-zoom, 1)); background-position: center;
  background-image: radial-gradient(circle at 33% 27%, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.4) 12%, rgba(255,255,255,0) 32%), radial-gradient(circle at 50% 42%, var(--c1) 0%, var(--c2) 100%);
  box-shadow: inset -14px -22px 44px rgba(0, 0, 0, 0.4), 0 0 60px rgba(255, 207, 92, 0.25), 0 30px 70px rgba(0, 0, 0, 0.6);
  animation: coPop 0.9s cubic-bezier(0.22, 1.5, 0.36, 1) 0.15s both;
}
.co-ball .co-shine { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 33% 27%, rgba(255,255,255,0.85) 0%, rgba(255,255,255,0.3) 12%, rgba(255,255,255,0) 34%), radial-gradient(circle at 50% 115%, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0) 45%); pointer-events: none; }
.co-num { font-size: clamp(1.5rem, 5vw, 3rem); font-weight: 900; color: var(--gold); line-height: 1; font-variant-numeric: tabular-nums; }
.co-name { font-size: clamp(1.75rem, 6vw, 3.5rem); font-weight: 900; color: #fff; line-height: 1.05; }
.champ-overlay.mine .co-kicker { color: var(--live); }
.co-path { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.co-step { display: flex; flex-direction: column; align-items: center; min-width: 74px; padding: 7px 10px; border-radius: var(--radius-s); background: var(--panel-2); border: 1px solid var(--line); }
.co-step i { font-style: normal; font-size: 0.6875rem; color: var(--muted); font-weight: 800; }
.co-step b { font-size: 1rem; font-weight: 900; color: var(--gold); line-height: 1.2; }
.co-step small { font-size: 0.6875rem; color: var(--muted); }
.co-step small:empty { display: none; }
.co-arrow { color: var(--line); font-size: 1.125rem; font-weight: 900; }
.co-meta { font-size: 0.8125rem; color: var(--muted); font-weight: 600; }
.co-you { font-size: 0.8125rem; color: var(--text); font-weight: 700; padding: 8px 14px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.co-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.co-close { position: absolute; top: 16px; right: 16px; }
@keyframes coPop { 0% { transform: scale(0.1); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* ---------- no-JS ---------- */
.noscript-note { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 100; width: min(640px, 92vw); padding: 14px 18px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.noscript-note ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  :root { --bottom-h: 68px; }
  .topbar { gap: 8px; }
  .bb-word { display: none; }
  .bar-btn { padding: 0; min-width: 44px; justify-content: center; }
  .rc-meta { font-size: 0.6875rem; }
  .watching .w-count { display: none; }
  .menu-pop { left: 10px; right: 10px; width: auto; }
  .cam-pop { left: 10px; right: 10px; width: auto; }
  /* Drawer becomes a full-height sheet. */
  .drawer { left: 0; width: auto; animation: sheetIn 0.25s ease both; }
  @keyframes sheetIn { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
  /* Picker + modals as bottom sheets. */
  .modal-veil { align-items: flex-end; padding: 0; }
  .modal, .picker { width: 100%; max-height: 90vh; border-radius: var(--radius) var(--radius) 0 0; padding-bottom: calc(12px + var(--safe-b)); }
  .picker-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
  .pk .sw { width: 48px; height: 48px; }
  /* Bottom bar: the card takes the width it needs, controls collapse to icons;
     the drawer is a full sheet, so the bar steps aside entirely. */
  /* The bottom bar is taller on phones (two-row card), so everything that
     keeps clear of it — the stage's panels, the race card, toasts — moves up. */
  :root { --bottom-h: 116px; }
  .mm { max-width: none; min-height: 56px; padding: 6px 8px; column-gap: 8px; row-gap: 4px; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: 'ball info' 'acts acts'; }
  .mm-ball { width: 38px; height: 38px; }
  .mm-acts { display: flex; grid-area: acts; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
  .mm-cam { flex: 0 1 auto; }
  .mm-change { flex: none; }
  .mm-cam .lg-only { display: none; }
  .mm-cam .sm-only { display: inline; }
  body.drawer-open .bottom-bar { display: none; }
  .rb-rule { display: none; }
  .vb-btn .vb-word { display: none; }
  .vb-btn { padding: 0; width: 44px; justify-content: center; }
  .race-board { width: 190px; padding: 6px; }
  .rb-row { height: 22px; font-size: 0.75rem; }
  .pr-card { width: 100%; }
  .stages { flex-wrap: wrap; }
}
@media (max-width: 480px) {
  /* Narrow phones: the view controls stack in the corner so the card keeps
     enough width for its label, tag and status copy. */
  .viewbar { flex-direction: column; }
  :root { --bottom-h: 160px; }
}
@media (max-width: 360px) {
  /* The race title is the header's job on the narrowest phones; the brand
     is on the loading screen and the pages linked from the menu. */
  .brand { display: none; }
}
@media (max-width: 420px) {
  .brand-logo { height: 24px; }
  .race-title { font-size: 0.8125rem; }
  .rc-note { display: none; }
  .mm-line { font-size: 0.6875rem; }
  .race-board { width: 150px; }
  .rb-name { display: none; }
}
@media (max-height: 520px) {
  .hero-tag { display: none; }
  .race-board { display: none; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .li-dot, .spinner, .skeleton, .hero, .pr-card, .drawer, .co-ball, .ss-bar.indeterminate .ss-fill { animation: none !important; }
  .ss-loading { transition: none; }
  .cd-fg, .race-toast, .moment, .champ-overlay { transition: none; }
}

/* ---------- touch targets ---------- */
@media (pointer: coarse) {
  .pr-close, .modal-close { width: 40px; height: 40px; }
  .pr-context { margin: 0 36px; }
  .mm-cam { min-height: 36px; }
  .seg-btn { min-height: 42px; }
}
