/* Layout: a full-bleed isometric diorama; the interface floats over it as chunky ink-outlined stickers —
   crew roster on the left, the track bar bottom-right, the driver's dash and hand along the bottom in a race.
   One deliberate daylight look (sunny toy table), so no dark variant. */
:root {
  --sky-1: #8fd0ff;        /* sky top */
  --sky-2: #e4f5ff;        /* sky horizon */
  --paper: #ffffff;        /* stickers */
  --paper-2: #eef2f7;      /* wells, rows */
  --ink: #181b23;          /* outlines, text */
  --ink-2: #5b6374;        /* secondary text */
  --signal: #ff5b1f;       /* rally orange — the accent */
  --police: #2f5cff;       /* reactions, info */
  --star: #ffb72b;         /* wanted stars */
  --grass: #8dcc5f;
  --danger: #e8344a;
  --ok: #24a148;

  --f-display: "Dela Gothic One", "Arial Black", "Segoe UI", system-ui, sans-serif;
  --f-ui: "Onest", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 8px;
  --bw: 2.5px;
  --shadow: 5px 5px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, var(--sky-1) 0%, var(--sky-2) 62%, #f4fbff 100%) fixed;
  color: var(--ink);
  font: 500 15px/1.45 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--police); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hint { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.mono { font-family: var(--f-mono); font-size: 12px; }
kbd { font: 700 10px/1 var(--f-mono); padding: 3px 5px; border-radius: 5px; border: 1.5px solid currentColor; opacity: .6; margin-left: 8px; }

/* ---------- stickers & buttons ---------- */
.sticker { background: var(--paper); border: var(--bw) solid var(--ink); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 7px 15px; border-radius: var(--r-md); cursor: pointer;
  border: 2px solid var(--ink); background: var(--paper); color: var(--ink); box-shadow: var(--shadow-sm);
  font-weight: 700; transition: transform .08s, box-shadow .08s, background .12s;
}
.btn:hover:not(:disabled) { background: #fff6ef; }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { box-shadow: none; background: transparent; }
.btn.ghost:active:not(:disabled) { transform: translate(1px, 1px); }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 13.5px; border-radius: 10px; }
.btn.primary { background: var(--signal); }
.btn.primary:hover:not(:disabled) { background: #ff7a45; }
.btn.big { min-height: 58px; font: 400 19px/1 var(--f-display); letter-spacing: .02em; text-transform: uppercase; width: 100%; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 2px solid var(--ink); border-radius: 10px; background: var(--paper); box-shadow: var(--shadow-sm); cursor: pointer; }
.icon-btn:active { transform: translate(3px, 3px); box-shadow: none; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--paper-2); border: 2px solid var(--ink); gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 13px; border-radius: 9px; cursor: pointer; font-weight: 700; font-size: 13.5px; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: var(--paper); }
.seg.mini { padding: 2px; border-radius: 10px; }
.seg.mini button { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.seg button:disabled, .slot-racer:disabled { opacity: .55; cursor: not-allowed; }
.lang-seg { background: var(--paper); box-shadow: var(--shadow-sm); }
.lang-seg button { letter-spacing: .06em; }
.view-seg { background: var(--paper); box-shadow: var(--shadow-sm); }
.view-seg button { font-family: var(--f-mono); font-weight: 800; letter-spacing: .04em; }
.count-pill { font: 700 12px/1 var(--f-mono); padding: 5px 9px; border-radius: 999px; background: var(--ink); color: var(--paper); }

/* ---------- wordmark ---------- */
.wordmark { margin: 0; font: 400 clamp(40px, 6.2vw, 78px)/.92 var(--f-display); letter-spacing: -.01em; text-transform: uppercase; color: var(--paper); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 5px 5px 0 var(--ink); }
.wordmark span:last-child { color: var(--signal); }
.wordmark.small { font-size: 18px; -webkit-text-stroke: 1.5px var(--ink); text-shadow: 2px 2px 0 var(--ink); white-space: nowrap; }

/* ---------- scenes ---------- */
.scene { position: fixed; inset: 0; z-index: 0; }
.board-scroll, .board { width: 100%; height: 100%; }
.board-scroll { position: absolute; inset: 0; overflow: hidden; }
.board-canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }

/* ================= MENU ================= */
.menu-ui {
  position: relative; z-index: 1; min-height: 100vh; padding: 22px 24px 24px;
  display: grid; grid-template-columns: minmax(0, 540px) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: 18px 28px;
  pointer-events: none;
}
.menu-ui > * { pointer-events: auto; }
.menu-brand { grid-column: 1; grid-row: 1; }
.brand-kicker { margin: 0 0 8px; font: 700 12px/1.2 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink); }
.brand-sub { margin: 14px 0 0; max-width: 46ch; font-size: 16px; font-weight: 600; }
.head-actions { grid-column: 2; grid-row: 1; justify-self: end; align-self: start; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.menu-col { grid-column: 1; grid-row: 2 / 4; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.trackbar { grid-column: 2; grid-row: 3; justify-self: end; align-self: end; width: min(560px, 100%); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; position: sticky; bottom: 24px; }
.trackbar-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.trackbar h2, .crew h2 { margin: 0; font: 400 20px/1.1 var(--f-display); text-transform: uppercase; }
.trackbar #track-stats { margin: 0; }
.seed { font: 800 13px/1 var(--f-mono); color: var(--signal); }
.crew, .setup { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.label { margin: 4px 0 0; font: 800 12px/1.2 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.label .hint { text-transform: none; letter-spacing: 0; font-family: var(--f-ui); }
.foot { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink); background: rgba(255, 255, 255, .75); border-radius: var(--r-md); padding: 8px 12px; max-width: 60ch; }

/* player slots */
.slots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.slot {
  display: grid; grid-template-columns: 148px minmax(0, 1fr) auto auto; gap: 8px; align-items: center;
  padding: 7px; border-radius: var(--r-md); background: var(--paper-2); border: 2px solid transparent; border-left: 7px solid var(--pc);
}
.slot.active { border-color: var(--ink); border-left-color: var(--pc); background: #fff; box-shadow: var(--shadow-sm); }
.slot-racer { display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px; border-radius: 999px; border: 2px solid var(--ink); background: var(--paper); cursor: pointer; min-width: 0; }
.slot-racer img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 2px solid var(--pc); }
.slot-racer span { font-weight: 800; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-name { width: 100%; min-width: 0; height: 38px; padding: 0 11px; border-radius: var(--r-sm); border: 2px solid var(--ink); background: var(--paper); font-weight: 600; }
.slot-name:disabled { background: var(--paper-2); }
.slot-del { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); cursor: pointer; font-size: 17px; line-height: 1; font-weight: 800; }
.slot-del:disabled { opacity: .3; cursor: not-allowed; }
.tag-remote { font-size: 12px; font-weight: 800; padding: 6px 10px; border-radius: 999px; background: var(--police); color: #fff; }

/* racer stickers */
.racer-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 10px; }
.rcard {
  position: relative; display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 10px; text-align: left;
  padding: 8px; border-radius: 14px; background: var(--paper); border: 2px solid var(--ink); color: var(--ink);
  cursor: pointer; transition: transform .12s, box-shadow .12s;
}
.rcard:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-sm); }
.rcard.static { cursor: default; }
.rcard.static:hover { transform: none; box-shadow: none; }
.rcard-art { aspect-ratio: 1; border-radius: 10px; border: 2px solid var(--ink); background: var(--rbg); overflow: hidden; align-self: start; }
.rcard-art img { width: 100%; height: 100%; object-fit: cover; }
.rcard-side { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rcard-name { font: 400 15px/1.15 var(--f-display); text-transform: uppercase; }
.rcard-ability { font-size: 12px; line-height: 1.3; color: var(--ink-2); font-weight: 600; flex: 1; }
.rcard-hp { display: flex; align-items: center; gap: 5px; }
.rcard-hp .ico-gear { width: 20px; height: 20px; }
.rcard-hp b { font: 800 14px/1 var(--f-mono); }
.rcard.taken { opacity: .5; }
.rcard.mine { box-shadow: 0 0 0 3px var(--signal), var(--shadow-sm); }
.rcard-badge { position: absolute; top: -10px; right: 10px; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--pc); color: var(--ink); font: 800 11px/1 var(--f-ui); padding: 4px 8px; border-radius: 999px; border: 2px solid var(--ink); }

/* settings & online */
.settings { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 800; }
.field select { height: 36px; border-radius: var(--r-sm); border: 2px solid var(--ink); background: var(--paper); padding: 0 10px; font-weight: 700; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--signal); }
.check.muted { opacity: .5; }
.check small.hint { display: block; margin-top: 2px; font-size: 12.5px; line-height: 1.35; }
.client-wait { margin: 0; padding: 12px; border-radius: var(--r-md); background: var(--paper-2); border: 2px dashed var(--ink); text-align: center; font-weight: 800; }
.online { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 2px dashed var(--ink); }
.online .label, .online > .hint { margin: 0; }
.net-idle { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.net-join { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1 1 260px; }
.net-input { height: 34px; min-width: 0; flex: 1 1 110px; padding: 0 10px; border-radius: var(--r-sm); border: 2px solid var(--ink); background: var(--paper); font-weight: 600; }
.net-input.code { flex: 0 1 92px; text-transform: uppercase; letter-spacing: .14em; font: 800 14px var(--f-mono); }
.net-status { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: var(--r-md); background: var(--paper-2); }
.net-status .hint { margin: 0; }
.net-line { margin: 0; font-weight: 700; }
.net-code { font: 800 22px/1 var(--f-mono); letter-spacing: .12em; color: var(--signal); user-select: all; }
.net-err { color: var(--danger); }
.net-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ================= GAME HUD ================= */
.game { position: fixed; inset: 0; }
.hud-top { position: absolute; z-index: 4; top: 12px; left: 14px; right: 14px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.turn-info { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px; background: var(--paper); border: 2px solid var(--ink); box-shadow: var(--shadow-sm); font-size: 13.5px; font-weight: 600; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.hud-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.cam-tools { display: inline-flex; gap: 6px; align-items: center; }
.log-wrap { position: absolute; z-index: 3; top: 64px; left: 14px; width: min(340px, calc(100% - 28px)); padding: 0; }
.log-wrap summary { list-style: none; cursor: pointer; display: flex; gap: 10px; align-items: center; padding: 9px 12px; font: 800 12px/1.2 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; }
.log-wrap summary::-webkit-details-marker { display: none; }
.log-wrap summary::before { content: "▸"; font-size: 12px; }
.log-wrap[open] summary::before { content: "▾"; }
.log-last { font: 600 12.5px/1.3 var(--f-ui); letter-spacing: 0; text-transform: none; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.log-wrap[open] .log-last { display: none; }
.log { list-style: none; margin: 0; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 6px; max-height: min(46vh, 380px); overflow-y: auto; font-size: 13px; color: var(--ink-2); }
.log li { display: flex; gap: 8px; align-items: flex-start; }
.log li:first-child { color: var(--ink); font-weight: 600; }
.who { color: var(--ink); font-weight: 800; background: linear-gradient(transparent 58%, color-mix(in srgb, var(--pc) 55%, transparent) 0); }
.ev { color: var(--signal); font-weight: 800; }

.hud-right { position: absolute; z-index: 3; top: 64px; right: 14px; width: 300px; max-height: calc(100% - 340px); overflow-y: auto; padding: 12px; }
.side-title { margin: 0 0 8px; font: 800 12px/1.2 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.side-title .hint { letter-spacing: 0; text-transform: none; font-family: var(--f-ui); font-size: 12px; }
.standings { display: flex; flex-direction: column; gap: 6px; }
.srow { display: grid; grid-template-columns: 14px auto minmax(0, 1fr) auto; gap: 9px; align-items: center; padding: 6px 8px; border-radius: var(--r-md); background: var(--paper-2); border: 2px solid transparent; }
.srow.cur { border-color: var(--ink); background: color-mix(in srgb, var(--pc) 22%, #fff); }
.srank { font: 800 12px/1 var(--f-mono); color: var(--ink-2); text-align: center; }
.sinfo { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.sname { font-weight: 800; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sracer { font-weight: 600; color: var(--ink-2); font-size: 12px; }
.sbar { height: 5px; border-radius: 3px; background: #d9dee6; overflow: hidden; }
.sbar span { display: block; height: 100%; background: var(--pc); transition: width .4s; }
.sstats { display: flex; align-items: center; gap: 7px; }
.sstats .hp, .sstats .stars { display: inline-flex; gap: 1px; }
.ccount { display: inline-flex; align-items: center; gap: 3px; font: 800 11.5px/1 var(--f-mono); color: var(--ink-2); margin-left: auto; }
.ccount i { width: 9px; height: 12px; border-radius: 2px; border: 1.5px solid currentColor; }
.schips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 999px; background: var(--paper); border: 1.5px solid var(--ink); }
.chip.pit { background: var(--grass); }
.spos { font: 800 17px/1 var(--f-mono); min-width: 2ch; text-align: right; }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; display: inline-block; border: 2px solid var(--ink); box-shadow: 0 0 0 2px var(--pc, var(--paper-2)); overflow: hidden; background: #fff; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.xs { width: 20px; height: 20px; border-width: 1.5px; box-shadow: 0 0 0 1.5px var(--pc, var(--paper-2)); vertical-align: middle; }
.avatar.sm { width: 28px; height: 28px; }
.avatar.xl { width: 104px; height: 104px; border-width: 3px; box-shadow: 0 0 0 5px var(--pc); }
.avatar.blank { background: var(--paper-2); box-shadow: none; }
.pip { display: inline-block; width: 13px; height: 13px; }
.pip svg { width: 100%; height: 100%; display: block; }
.pip.off { opacity: .2; filter: grayscale(1); }
.ico-star, .ico-gear { display: block; }

.hud-bottom { position: absolute; z-index: 3; left: 14px; right: 14px; bottom: 14px; display: flex; align-items: flex-end; gap: 18px; pointer-events: none; }
.hud-bottom > * { pointer-events: auto; }
.dash { width: 400px; flex: none; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.dash-card { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 10px; align-items: center; }
.dash-art { aspect-ratio: 1; border-radius: 12px; border: 2px solid var(--ink); background: var(--rbg); overflow: hidden; box-shadow: 0 0 0 3px var(--pc); }
.dash-art img { width: 100%; height: 100%; object-fit: cover; }
.dash-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dash-who { font-size: 12.5px; color: var(--ink-2); }
.dash-who b { color: var(--ink); }
.dash-racer { font: 400 18px/1.1 var(--f-display); text-transform: uppercase; }
.dash-ability { font-size: 12px; line-height: 1.3; color: var(--ink-2); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 120px; }
.act-title { margin: 0; font: 800 11.5px/1.2 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); }
.act-hint { margin: 0; font-size: 12px; }
.bot-note { margin: 0; display: flex; align-items: center; gap: 10px; font-weight: 700; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--signal); animation: blink 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 50% { opacity: .2; } }
.mini-dice { display: inline-flex; gap: 3px; margin-right: 4px; }
.mini-dice .die { width: 19px; height: 19px; padding: 2.5px; border-radius: 5px; border-width: 1.5px; box-shadow: none; }
.mini-dice .die i { width: 3.6px; height: 3.6px; }

/* the hand: a fan of cards along the bottom */
.hand { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.hand .side-title { background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 5px 12px; box-shadow: var(--shadow-sm); margin-bottom: 4px; }
.hand > .hint { background: var(--paper); border: 2px solid var(--ink); border-radius: var(--r-md); padding: 8px 12px; margin: 0; }
.hand-cards { display: flex; justify-content: center; align-items: flex-end; padding: 18px 10px 0; max-width: 100%; }
.hand-cards .card { width: 108px; flex: none; margin-left: -24px; transform: rotate(calc((var(--i, 0) - var(--mid, 0)) * 3deg)) translateY(calc(var(--d, 0) * 4px)); transform-origin: 50% 120%; transition: transform .15s, box-shadow .15s; }
.hand-cards .card:first-child { margin-left: 0; }
.hand-cards .card:hover, .hand-cards .card:focus-visible { transform: translateY(-22px) scale(1.06); z-index: 5; }
.hand-cards .card.playable { box-shadow: 0 0 0 3px var(--signal), 4px 4px 0 var(--ink); }
.hand-cards .card.dim { filter: saturate(.6); }
.hand-cards .card.dim .card-art img { opacity: .75; }

/* game cards */
.card { position: relative; display: flex; flex-direction: column; gap: 5px; padding: 6px; text-align: center; background: var(--paper); border: 2px solid var(--ink); border-radius: 12px; color: var(--ink); width: 100%; font: inherit; line-height: 1.25; cursor: default; box-shadow: 3px 3px 0 var(--ink); }
button.card { cursor: pointer; }
.card-name { font: 400 11px/1.25 var(--f-display); text-transform: uppercase; padding: 3px 4px; border-radius: 7px; background: var(--paper-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-art { aspect-ratio: 1; border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; overflow: hidden; }
.card-art img { width: 100%; height: 100%; object-fit: cover; }
.card-text { font: 600 10px/1.3 var(--f-ui); padding: 2px 2px 3px; min-height: 48px; display: flex; align-items: center; justify-content: center; text-wrap: pretty; }
.card-text b { font-weight: 800; }
.card.is-event .card-name { background: var(--signal); }
.card.is-reaction .card-name { background: var(--police); color: #fff; }
.card-why { position: absolute; left: 6px; right: 6px; bottom: 6px; background: var(--ink); color: #fff; border-radius: 7px; font: 700 10px/1.25 var(--f-ui); padding: 4px; opacity: 0; transition: opacity .15s; }
.card:hover .card-why, .card:focus-visible .card-why { opacity: 1; }
.card.big { width: 230px; }
.card.big .card-name { font-size: 15px; }
.card.big .card-text { font-size: 13px; min-height: 64px; }
.card.mini { box-shadow: none; }
.card.mini .card-text { display: none; }

/* dice tray, banner, toasts */
.dice-tray { position: absolute; z-index: 4; left: 50%; top: 66px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; padding: 10px 14px; border-radius: var(--r-lg); background: var(--paper); border: var(--bw) solid var(--ink); box-shadow: var(--shadow); border-top: 7px solid var(--pc); max-width: calc(100% - 28px); }
.tray-who { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; width: 100%; justify-content: center; }
.tray-dice { display: flex; gap: 8px; }
.tray-speed { display: flex; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.tray-speed b { font: 400 34px/1 var(--f-display); color: var(--ink); }
.tray-speed em { font-style: normal; color: var(--signal); font-weight: 800; }
.die { width: 44px; height: 44px; border-radius: 10px; background: #fff; border: 2px solid var(--ink); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 6px; box-shadow: 2px 2px 0 var(--ink); }
.die i { display: block; margin: auto; width: 8px; height: 8px; border-radius: 50%; }
.die i.on { background: var(--ink); }
.die[data-v="1"] i.on { background: var(--danger); }
.rolling .die { animation: tumble .42s ease-out; }
@keyframes tumble { 0% { transform: rotate(-200deg) scale(.6); } 70% { transform: rotate(12deg) scale(1.05); } 100% { transform: none; } }
.banner { position: absolute; z-index: 5; left: 50%; top: 40%; display: flex; align-items: center; gap: 12px; padding: 10px 22px 10px 10px; border-radius: 999px; background: var(--paper); border: var(--bw) solid var(--ink); box-shadow: 0 0 0 5px var(--pc), var(--shadow); font-size: 18px; transform: translate(-50%, -50%); opacity: 0; pointer-events: none; }
.banner b { font-family: var(--f-display); font-weight: 400; }
.banner.show { animation: banner 1.8s ease forwards; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.9); } 14%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60%); } }
.played { position: absolute; z-index: 4; right: 330px; top: 66px; display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; border-radius: var(--r-md); background: var(--paper); border: 2px solid var(--ink); box-shadow: var(--shadow-sm); font-size: 13px; font-weight: 700; opacity: 0; pointer-events: none; }
.played .card.mini { width: 66px; padding: 3px; gap: 3px; }
.played .card.mini .card-name { font-size: 8px; }
.played.show { animation: played 3s ease forwards; }
@keyframes played { 0% { opacity: 0; transform: translateY(-10px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.next-bar { position: absolute; z-index: 5; left: 50%; bottom: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 10px; border-radius: 999px; background: var(--paper); border: var(--bw) solid var(--ink); box-shadow: var(--shadow); max-width: calc(100% - 32px); font-weight: 700; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(24, 27, 35, .35); backdrop-filter: blur(2px); overflow-y: auto; }
#modal2 { z-index: 30; }
.modal-box { position: relative; width: 100%; max-width: 580px; max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--paper); border: var(--bw) solid var(--ink); border-radius: var(--r-lg); padding: 20px; box-shadow: 8px 8px 0 var(--ink); animation: pop-in .16s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
.modal.small .modal-box { max-width: 420px; }
.modal.wide .modal-box { max-width: 820px; }
.modal.ask { background: rgba(24, 27, 35, .18); backdrop-filter: none; }
.m-title { margin: 0 0 6px; font: 400 22px/1.15 var(--f-display); text-transform: uppercase; text-wrap: balance; }
.m-text { margin: 0 0 14px; color: var(--ink-2); font-weight: 600; }
.m-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 30px; margin-bottom: 4px; }
.m-who { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 800; padding: 4px 10px 4px 5px; border-radius: 999px; background: color-mix(in srgb, var(--pc) 25%, #fff); border: 2px solid var(--ink); }
.m-collapse { margin-left: auto; border: 2px solid var(--ink); background: var(--paper); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; font-weight: 800; cursor: pointer; }
.m-collapse:hover { background: var(--paper-2); }
.m-pill { display: none; }
.modal.collapsed { background: transparent; backdrop-filter: none; pointer-events: none; place-items: end center; }
.modal.collapsed .modal-box { display: none; }
.modal.collapsed .m-pill { pointer-events: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; padding: 10px 12px 10px 18px; border-radius: 999px; border: var(--bw) solid var(--ink); cursor: pointer; background: var(--paper); box-shadow: var(--shadow); margin-bottom: 8px; max-width: 100%; }
.m-pill b { font-family: var(--f-display); font-weight: 400; text-transform: uppercase; }
.m-pill span { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.m-pill em { font-style: normal; font-weight: 800; background: var(--signal); border: 2px solid var(--ink); border-radius: 999px; padding: 4px 12px; }
.m-body { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 18px; align-items: start; }
.m-card .card { width: 150px; }
.m-main { min-width: 0; }
.m-opts { display: flex; flex-direction: column; gap: 8px; }
.opt { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--r-md); text-align: left; cursor: pointer; background: var(--paper); border: 2px solid var(--ink); box-shadow: var(--shadow-sm); transition: transform .08s, box-shadow .08s, background .1s; }
.opt:hover:not(:disabled), .opt:focus-visible { background: #fff3ea; }
.opt:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.opt:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.opt-txt { display: flex; flex-direction: column; min-width: 0; }
.opt-label { font-weight: 800; }
.opt-sub { color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.m-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.m-actions .hint { margin-right: auto; }
.m-dice { display: flex; align-items: center; gap: 8px; margin: -4px 0 14px; font-weight: 700; color: var(--ink-2); }
.m-dice .die { width: 36px; height: 36px; padding: 5px; }
.m-dice b { font: 400 22px/1 var(--f-display); color: var(--ink); }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 12px; }
.pick-grid .card { transition: transform .12s, box-shadow .12s; }
.pick-grid .card:hover { transform: translateY(-3px); }
.pick-grid .card.picked { box-shadow: 0 0 0 4px var(--danger), 3px 3px 0 var(--ink); transform: translateY(-3px); }
.ev-kicker { margin: 0 0 8px; font: 800 12px/1 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--signal); }
.modal.event .modal-box { max-width: 380px; text-align: center; }
.ev-card { display: flex; justify-content: center; margin-bottom: 14px; }
.modal.event .m-actions { justify-content: center; }
.handoff { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 10px 0; }
.handoff .avatar.xl { margin-bottom: 10px; }
.modal.handoff-wrap { background: rgba(24, 27, 35, .88); }
.modal.handoff-wrap .modal-box { max-width: 420px; }
.modal.win-wrap .modal-box { max-width: 560px; }
.win { display: flex; flex-direction: column; align-items: center; text-align: center; }
.win-art { width: 150px; height: 150px; border-radius: 50%; overflow: hidden; border: 3px solid var(--ink); box-shadow: 0 0 0 6px var(--pc), 6px 6px 0 6px var(--ink); background: var(--rbg); margin: 4px 0 20px; }
.win-art img { width: 100%; height: 100%; object-fit: cover; }
.win-title { margin: 0 0 6px; font: 400 30px/1.1 var(--f-display); text-transform: uppercase; text-wrap: balance; }
.win-list { list-style: none; margin: 4px 0 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; counter-reset: place; }
.win-list li { display: grid; grid-template-columns: 22px 20px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 7px 10px; border-radius: var(--r-sm); background: var(--paper-2); font-size: 13px; counter-increment: place; }
.win-list li::before { content: counter(place); font: 800 13px/1 var(--f-mono); }
.win-list li span { color: var(--ink-2); white-space: nowrap; font-weight: 600; }
.win-list li b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* rules */
.modal.rules-wrap .modal-box { max-width: 1000px; padding: 0; }
.rules-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 16px 20px; background: var(--paper); border-bottom: 2px solid var(--ink); }
.rules-head .m-title { margin: 0; }
.rules-body { padding: 18px 20px 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 28px; }
.rules-body section { min-width: 0; }
.rules-body section.wide { grid-column: 1 / -1; }
.rules-body h4 { margin: 0 0 6px; font: 800 12.5px/1.2 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--signal); }
.rules-body p, .rules-body ol { margin: 0; max-width: 65ch; font-weight: 500; }
.rules-body ol { padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.gloss { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.gl { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; align-items: start; padding: 9px; border-radius: var(--r-md); background: var(--paper-2); font-size: 13px; }
.gl img { width: 52px; height: 52px; object-fit: contain; }
.gl b { display: block; font-size: 14px; font-weight: 800; }
.gl em { display: block; font-style: normal; font: 700 10.5px/1.3 var(--f-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 2px; }
.turn-swatch { width: 52px; height: 52px; border-radius: 10px; border: 2px solid var(--ink); display: grid; place-items: center; font: 400 24px/1 var(--f-display); color: #6ff0ff; -webkit-text-stroke: 1.5px var(--ink); }
.turn-swatch.y { background: #f2cf3c; }
.turn-swatch.r { background: #ef4b3f; }
.rules-racers { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 10px; }

/* tooltip */
.tooltip { position: fixed; z-index: 40; max-width: 270px; pointer-events: none; padding: 9px 11px; border-radius: var(--r-md); background: var(--paper); color: var(--ink); border: 2px solid var(--ink); box-shadow: var(--shadow-sm); font-size: 13px; }
.tt-kind { font: 800 10.5px/1 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--signal); margin-bottom: 3px; }
.tt-kind:empty { display: none; }
.tt-title { font-weight: 800; font-size: 14px; }
.tt-text { margin-top: 3px; line-height: 1.35; font-weight: 500; }

/* 2D board fallback (no WebGL) */
.board-svg { width: 100%; height: 100%; display: block; background: transparent; overflow: visible; }
.turn-num { font: 400 32px/1 var(--f-display); fill: #6ff0ff; stroke: #1a1d20; stroke-width: 7px; paint-order: stroke; text-anchor: middle; pointer-events: none; }
.token { transition: transform .22s cubic-bezier(.3, .7, .3, 1); }
.token.no-anim { transition: none; }
.token-inner { transition: opacity .22s, transform .22s; transform-box: fill-box; transform-origin: center; }
.token.warp .token-inner { opacity: 0; transform: scale(.3); }
.token-halo { opacity: 0; }
.token.current .token-halo { opacity: 1; }
.token.pickable { cursor: pointer; }
.token.pickable .token-halo { opacity: 1; stroke: var(--star); }
.hl { fill: rgba(255, 183, 43, .2); stroke: var(--star); stroke-width: 6px; cursor: pointer; }
.hl-hover { fill: rgba(255, 183, 43, .45); stroke: #fff; }
.pop { font: 400 30px/1 var(--f-display); text-anchor: middle; stroke: #111; stroke-width: 7px; paint-order: stroke; fill: #fff; pointer-events: none; }

/* ---------- track builder ---------- */
.builder { position: fixed; inset: 0; }
.build-panel { position: absolute; z-index: 4; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(1000px, calc(100% - 28px)); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.build-panel p { margin: 0; }
.palette { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; }
.blk { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 4px 7px; border: 2px solid var(--ink); border-radius: var(--r-md); background: var(--paper); box-shadow: var(--shadow-sm); cursor: pointer; font-weight: 800; font-size: 12.5px; line-height: 1.15; text-align: center; }
.blk svg { width: 30px; height: 30px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.blk:hover:not([aria-disabled="true"]) { background: #fff6ef; }
.blk:active:not([aria-disabled="true"]) { transform: translate(3px, 3px); box-shadow: none; }
.blk[aria-disabled="true"] { opacity: .38; cursor: not-allowed; box-shadow: none; }
.blk.fin { background: #fff1cc; }
.blk-left { font: 700 11px/1 var(--f-mono); color: var(--ink-2); }
.blk kbd { position: absolute; top: 4px; right: 5px; font: 800 10px/1 var(--f-mono); color: var(--ink-2); }
.bp-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bp-msg { font-weight: 700; font-size: 13px; color: var(--danger); }
.tile-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tile-row > b { font: 800 13px/1 var(--f-mono); }
.topt { display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px 3px 3px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); cursor: pointer; font-weight: 700; font-size: 13px; }
.topt img { width: 28px; height: 28px; border-radius: 6px; }
.topt small { font: 700 11px/1 var(--f-mono); color: var(--ink-2); }
.topt.on { background: var(--ink); color: var(--paper); }
.topt.on small { color: #c9ced8; }
.topt:disabled { opacity: .38; cursor: not-allowed; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .hand-cards .card { width: 100px; margin-left: -30px; }
  .dash { width: 340px; }
}
@media (max-width: 960px) {
  .menu-ui { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; padding: 16px; gap: 14px; }
  .menu-brand, .head-actions, .menu-col, .trackbar { grid-column: 1; grid-row: auto; }
  .menu-brand { order: 1; }
  .head-actions { justify-self: start; order: 2; }
  .trackbar { order: 3; justify-self: stretch; width: 100%; margin-top: 30vh; position: relative; bottom: auto; }
  .menu-col { order: 4; }
  .wordmark { -webkit-text-stroke-width: 2px; text-shadow: 3px 3px 0 var(--ink); }
  .hud-top { flex-direction: column; align-items: stretch; gap: 8px; top: 8px; left: 8px; right: 8px; }
  .hud-left .wordmark { display: none; }
  .hud-tools { justify-content: flex-start; gap: 6px; }
  .hud-tools #btn-speed, .hud-tools .lang-seg, .hud-tools #btn-rules-game, #cam-in, #cam-out { display: none; }
  .cam-tools .icon-btn { width: 34px; height: 34px; }
  .hand-cards .card .card-text { min-height: 40px; }
  .log-wrap { top: auto; bottom: calc(var(--sheet, 300px) + 10px); left: 8px; width: auto; right: 8px; }
  .hud-right { top: 96px; left: 8px; right: 8px; width: auto; max-height: none; padding: 6px; overflow-x: auto; box-shadow: var(--shadow-sm); }
  .hud-right .side-title { display: none; }
  .standings { flex-direction: row; gap: 6px; }
  .srow { grid-template-columns: auto auto auto; padding: 4px 8px 4px 4px; flex: none; }
  .srow .srank, .srow .sinfo .sbar, .srow .sracer, .srow .schips, .srow .sstats .hp, .srow .ccount { display: none; }
  .srow .sinfo { gap: 1px; }
  .srow .sname { font-size: 12px; max-width: 86px; }
  .srow .sstats .stars .pip { width: 9px; height: 9px; }
  .srow .spos { font-size: 14px; }
  .hud-bottom { left: 0; right: 0; bottom: 0; flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 8px calc(10px + env(safe-area-inset-bottom, 0px)); background: rgba(255, 255, 255, .92); border-top: var(--bw) solid var(--ink); }
  .dash { width: auto; box-shadow: none; border-width: 2px; padding: 10px; }
  .dash-card { grid-template-columns: 44px minmax(0, 1fr); }
  .dash-ability { display: none; }
  .hand { align-items: stretch; }
  .hand .side-title { display: none; }
  .hand-cards { justify-content: flex-start; overflow-x: auto; padding: 6px 4px 6px; }
  .hand-cards .card { width: 124px; margin-left: 8px; transform: none; box-shadow: 2px 2px 0 var(--ink); }
  .hand-cards .card:first-child { margin-left: 0; }
  .hand-cards .card .card-art { display: none; }
  .hand-cards .card .card-text { min-height: 0; font-size: 10.5px; }
  .dash { gap: 8px; padding: 8px 10px; }
  .dash-card { grid-template-columns: 38px minmax(0, 1fr); gap: 8px; }
  .dash-who { display: none; }
  .dash-racer { font-size: 15px; }
  .act-title, .act-hint { display: none; }
  .actions .btn { min-height: 38px; }
  .played .card.mini { display: none; }
  .hand-cards .card:hover { transform: translateY(-4px); }
  .played { right: auto; left: 8px; top: 156px; padding: 6px 10px 6px 6px; }
  .dice-tray { top: 150px; padding: 8px 10px; gap: 10px; }
  .dice-tray .die { width: 34px; height: 34px; padding: 5px; }
  .dice-tray .die i { width: 6px; height: 6px; }
  .tray-speed b { font-size: 26px; }
  .m-body { grid-template-columns: minmax(0, 1fr); }
  .m-card { display: flex; justify-content: center; }
  .m-card .card { width: 130px; }
  .rules-body { grid-template-columns: minmax(0, 1fr); }
  .build-panel { left: 0; right: 0; bottom: 0; transform: none; width: auto; padding: 10px 8px calc(10px + env(safe-area-inset-bottom, 0px)); border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 52vh; overflow-y: auto; }
  .build-panel .hint { font-size: 12px; line-height: 1.35; }
  .palette { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .blk { padding: 6px 2px 5px; font-size: 11.5px; }
  .blk svg { width: 24px; height: 24px; }
  .blk kbd { display: none; }
}
@media (max-width: 560px) {
  .slot { grid-template-columns: minmax(0, 1fr) auto; }
  .slot-racer { grid-column: 1 / -1; justify-self: start; }
  .slot-name { grid-column: 1 / -1; }
  .slot .seg, .slot .tag-remote { justify-self: start; }
  .win-list li { grid-template-columns: 22px 20px minmax(0, 1fr) auto; }
  .win-list li span:last-child { display: none; }
  .cam-tools .icon-btn { width: 32px; height: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
