/* ---------- theme tokens: light is the default ---------- */
:root {
  color-scheme: light;
  --font: "Sora", system-ui, sans-serif;
  --font-display: "Sora", system-ui, sans-serif;

  --bg: #eef0f5;
  --bg-grid: rgba(20, 30, 70, .045);
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --line: #e0e3ec;
  --line-2: #c8cedb;
  --text: #11142a;
  --muted: #5b6380;
  --dim: #8990a8;
  --accent: #0b8fd0;
  --accent-ink: #ffffff;
  --gold: #a87a00;
  --bad: #d63250;
  --good: #16a05c;
  --opp: #d9711c;
  --overlay: rgba(238, 240, 245, .7);
  --shadow: 0 10px 30px rgba(20, 30, 70, .12);
  /* chart (validated: light surface) */
  --bar: #d0742a;
  --bar-you: #0b7fb0;
  /* reaction test */
  --react-wait: #c8304a;
  --react-go: #149a55;
  --react-ink: #ffffff;

  /* canvas */
  --cv-bg: #ffffff;
  --cv-grid: rgba(20, 30, 70, .05);
  --cv-circle: #a3a8ba;
  --cv-hit: #e0364f;
  --cv-me: #0f1428;
  --cv-meGlow: #0b8fd0;
  --cv-opp: #e0751f;
  --cv-text: #11142a;
  --cv-muted: #5b6380;
  --cv-soft: rgba(17, 20, 42, .7);
  --cv-gold: #a87a00;
  --cv-lifeEmpty: rgba(91, 99, 128, .45);
  --cv-reactWait: var(--react-wait);
  --cv-reactGo: var(--react-go);
  --cv-reactInk: var(--react-ink);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07080f;
  --bg-grid: rgba(140, 150, 200, .035);
  --surface: #0d1020;
  --surface-2: #141a30;
  --line: #222944;
  --line-2: #323a5c;
  --text: #e6e9f5;
  --muted: #8a92b2;
  --dim: #5d6585;
  --accent: #4dd9ff;
  --accent-ink: #03141c;
  --gold: #ffd23f;
  --bad: #ff4d6d;
  --good: #5ee6a0;
  --opp: #ff9f43;
  --overlay: rgba(7, 8, 15, .6);
  --shadow: 0 16px 50px rgba(0, 0, 0, .5);
  /* chart (validated: dark surface) */
  --bar: #c27426;
  --bar-you: #1f9cc9;
  --react-wait: #a82a40;
  --react-go: #17914f;
  --react-ink: #ffffff;

  --cv-bg: #0b0d18;
  --cv-grid: rgba(140, 150, 200, .06);
  --cv-circle: #8d93ad;
  --cv-hit: #ff4d6d;
  --cv-me: #e8faff;
  --cv-meGlow: #4dd9ff;
  --cv-opp: #ff9f43;
  --cv-text: #e6e9f5;
  --cv-muted: #8a92b2;
  --cv-soft: rgba(230, 233, 245, .8);
  --cv-gold: #ffd23f;
  --cv-lifeEmpty: rgba(138, 146, 178, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: linear-gradient(var(--bg-grid) 1px, transparent 1px),
                    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}
a { color: var(--accent); }
[hidden] { display: none !important; }
code { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; }
.small { font-size: 12px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: stretch; gap: 28px;
  height: 54px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.logo {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font: 800 17px/1 var(--font-display); letter-spacing: 1px;
}
.logo b { color: var(--accent); font-weight: 800; }
.logo .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
#nav { display: flex; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; }
#nav a { flex: none; }
#nav a {
  display: flex; align-items: center; gap: 7px; padding: 0 16px;
  color: var(--muted); text-decoration: none;
  font: 700 12px/1 var(--font-display); letter-spacing: 1.2px; text-transform: uppercase;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
#nav a:hover { color: var(--text); }
#nav a.on { color: var(--text); border-bottom-color: var(--accent); }
.top .spacer { flex: 1; }
.top-tools { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  appearance: none; cursor: pointer; display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line-2);
}
.icon-btn:hover { border-color: var(--muted); }

/* ---------- layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 56px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
aside { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font: 800 22px/1 var(--font-display); letter-spacing: 1px; text-transform: uppercase; }
.page-head .seg { min-width: 420px; }

@media (max-width: 900px) {
  .layout, .grid2 { grid-template-columns: 1fr; }
  .page-head .seg { min-width: 0; width: 100%; }
  .top { gap: 8px; padding: 0 12px; }
  #nav a { padding: 0 8px; }
  .logo { font-size: 0; gap: 0; }
  .logo .dot { width: 12px; height: 12px; }
  }

/* ---------- stage ---------- */
.stage { position: relative; border: 1px solid var(--line-2); background: var(--surface); }
.stage canvas { display: block; width: 100%; aspect-ratio: 550 / 450; touch-action: none; cursor: crosshair; user-select: none; }
.stage canvas.playing { cursor: none; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); padding: 14px 16px; }
section.panel { margin-bottom: 16px; }
.grid2 > .panel { margin-bottom: 0; }
.panel h3 {
  margin: 0 0 12px; color: var(--muted);
  font: 700 11px/1.2 var(--font-display); letter-spacing: 1.5px; text-transform: uppercase;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-head h3 { margin-bottom: 8px; }
.summary { margin: 0 0 16px; color: var(--muted); }
.summary b { color: var(--text); }
.how { color: var(--muted); font-size: 13px; }
.rules { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.rules b { color: var(--text); }
.note-panel { font-size: 13px; color: var(--muted); border-left: 2px solid var(--accent); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.note { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.note b { color: var(--text); }
.empty { color: var(--dim); margin: 0; font-size: 13px; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; }

/* ---------- tiles ---------- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 1px; background: var(--line); border: 1px solid var(--line);
}
.tiles:empty { display: none; }
.tiles:has(.empty) { background: transparent; border: 0; }
.tile { background: var(--surface); padding: 10px 12px; }
.tile .v { font: 700 22px/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font: 600 10px/1.2 var(--font-display); letter-spacing: 1px; text-transform: uppercase; margin-top: 5px; }

/* ---------- lists & tables ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list li { display: grid; grid-template-columns: 1fr auto 56px; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list li:last-child { border-bottom: 0; }
.list li .num { text-align: right; }
.list li.empty { display: block; border: 0; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font: 600 10px/1 var(--font-display); letter-spacing: 1px; text-transform: uppercase; padding: 0 8px 8px 0; border-bottom: 1px solid var(--line-2); }
.tbl td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
.tbl .r { text-align: right; }
.tbl tr.me td { color: var(--bar-you); font-weight: 700; }

/* ---------- controls ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line-2); background: var(--surface); }
.seg button {
  all: unset; cursor: pointer; text-align: center; padding: 8px 4px;
  color: var(--muted); font: 700 11px/1 var(--font-display); letter-spacing: .8px; text-transform: uppercase;
  border-right: 1px solid var(--line-2);
}
.seg button:last-child { border-right: 0; }
.seg button:hover:not(.on) { color: var(--text); background: var(--surface-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, .col:focus-visible, .opt:focus-visible, .switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  appearance: none; cursor: pointer;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line-2);
  font: 700 12px/1 var(--font-display); letter-spacing: 1px; text-transform: uppercase;
  padding: 11px 16px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.small { padding: 8px 10px; font-size: 10px; }
.btn.block { display: block; width: 100%; }
.btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

input[type=text], input[type=password] {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--line-2); padding: 10px 12px; font: 15px var(--font);
}
.field { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); font: 600 11px/1 var(--font-display); letter-spacing: 1px; text-transform: uppercase; }
.err { color: var(--bad); font-size: 13px; margin: 10px 0 0; min-height: 1em; }
.err:empty { display: none; }

.led { display: inline-block; width: 7px; height: 7px; background: var(--dim); margin-right: 7px; vertical-align: 1px; }
.led.on { background: var(--good); box-shadow: 0 0 6px var(--good); }
.led.off { background: var(--bad); }
.conn { font-size: 13px; color: var(--muted); }
.conn b { color: var(--text); }
.who-big { font: 800 28px/1.1 var(--font-display); margin-bottom: 6px; }

/* ---------- settings drawer ---------- */
.drawer {
  position: fixed; top: 54px; right: 0; z-index: 20;
  width: min(320px, 100%); max-height: calc(100vh - 54px); overflow: auto;
  background: var(--surface); border-left: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2);
  box-shadow: var(--shadow); padding: 16px;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.drawer-head h3 { margin: 0; color: var(--muted); font: 700 11px/1 var(--font-display); letter-spacing: 1.5px; text-transform: uppercase; }
.drawer h4 { margin: 18px 0 8px; color: var(--muted); font: 700 11px/1 var(--font-display); letter-spacing: 1.5px; text-transform: uppercase; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; font-size: 14px; }
.set-row + input[type=range] { margin: 8px 0 18px; }
input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.switch {
  appearance: none; cursor: pointer; position: relative; width: 40px; height: 22px; padding: 0;
  background: var(--surface-2); border: 1px solid var(--line-2);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px;
  background: var(--dim); transition: transform .15s, background .15s;
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(18px); background: var(--accent-ink); }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.opt {
  appearance: none; cursor: pointer; display: flex; align-items: center; gap: 8px; text-align: left;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); padding: 7px 8px;
  font: 600 13px var(--font-display);
}
.opt:hover { border-color: var(--line-2); }
.opt.on { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.opt .play { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--line-2); font-size: 8px; color: var(--accent); flex: none; }


/* ---------- admin ---------- */
.admin-login { max-width: 360px; margin: 40px auto; }
.admin-totals { margin-bottom: 16px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.table-wrap { overflow-x: auto; }
.table-wrap .tbl td, .table-wrap .tbl th { white-space: nowrap; }
.mt { margin-top: 12px; }
.flag { color: var(--bad); font-weight: 700; cursor: help; }
a.btn { text-decoration: none; display: inline-block; }

/* ---------- reaction test ---------- */
.react-box {
  aspect-ratio: 550 / 450; display: grid; place-content: center; gap: 10px; text-align: center;
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  background: var(--surface); color: var(--text);
}
.react-big { font: 800 clamp(26px, 6vw, 44px)/1.1 var(--font-display); padding: 0 12px; }
.react-small { font-size: 15px; opacity: .8; min-height: 1.2em; }
.react-box.is-wait { background: var(--react-wait); color: var(--react-ink); }
.react-box.is-go { background: var(--react-go); color: var(--react-ink); }
.react-box.is-result .react-big { font-size: clamp(36px, 10vw, 64px); }
.react-box.is-early .react-big { color: var(--bad); }

/* ---------- top score today ---------- */
.today { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.today-score { font-size: 26px; font-weight: 800; line-height: 1; }
.today-name { color: var(--muted); font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.today-name.mine { color: var(--accent); }

/* ---------- arena overlay ---------- */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: var(--overlay); }
.overlay.hidden { display: none; }
.card { width: min(380px, 92%); background: var(--surface); border: 1px solid var(--line-2); padding: 22px; box-shadow: var(--shadow); }
.card.center { text-align: center; }
.card h2 { margin: 6px 0 16px; font: 800 19px/1.3 var(--font-display); }
.card > p { margin: 0 0 16px; font-size: 13px; }
.card .card-title { margin: 0 0 6px; font-size: 22px; }
.card .mode-seg { margin-bottom: 16px; }
.card #vsDiff, .card #vsLives { margin-bottom: 12px; }
.card .seg { margin-bottom: 12px; }
.kicker { color: var(--accent); font: 700 10px/1 var(--font-display); letter-spacing: 2px; text-transform: uppercase; }
.field-label { color: var(--muted); font: 600 10px/1 var(--font-display); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--dim); font: 600 10px/1 var(--font-display); letter-spacing: 1px; text-transform: uppercase; margin: 16px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 8px; }
.join-row input { font: 700 16px/1 var(--font-display); letter-spacing: 4px; text-transform: uppercase; }
.code { font: 800 44px/1 var(--font-display); letter-spacing: 10px; margin: 14px 0 12px; padding-left: 10px; color: var(--text); }
.dots::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.result { font-size: 30px !important; letter-spacing: 1px; text-transform: uppercase; }
.result.win { color: var(--gold); }
.result.lose { color: var(--bad); }
.vs-scores { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); margin-bottom: 14px; }
.vs-scores > div { background: var(--surface); padding: 10px; display: grid; gap: 4px; }
.vs-scores .who { font: 700 10px/1 var(--font-display); letter-spacing: 1px; text-transform: uppercase; }
.vs-scores .who.you { color: var(--accent); }
.vs-scores .who.opp { color: var(--opp); }
.vs-scores .num { font-size: 24px; font-weight: 800; }

/* ---------- stats charts ---------- */
.chart { display: grid; grid-template-columns: 38px 1fr; grid-template-rows: 200px auto; margin-top: 18px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; padding-right: 8px; margin: -6px 0; color: var(--dim); font: 10px/12px var(--font-display); }
.chart-plot { position: relative; display: grid; grid-template-columns: repeat(var(--n), 1fr); border-bottom: 1px solid var(--line-2); }
.chart-plot .gl { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); pointer-events: none; }
.col { position: relative; display: flex; align-items: flex-end; justify-content: center; padding: 0 1px; outline: none; }
.col:hover, .col:focus-visible { background: var(--surface-2); }
.bar { width: 100%; max-width: 30px; min-height: 0; background: var(--bar); border-radius: 2px 2px 0 0; }
.col.is-you .bar { background: var(--bar-you); }
.col.is-you .bar[style="height:0%"] { height: 2px !important; }
.you-tag {
  position: absolute; left: 50%; transform: translateX(-50%);
  color: var(--bar-you); font: 800 10px/1 var(--font-display); letter-spacing: 1px; white-space: nowrap;
}
.col.is-you { box-shadow: inset 0 0 0 1px var(--bar-you); }
.chart-x { display: grid; grid-template-columns: repeat(var(--n), 1fr); color: var(--dim); font: 10px/1 var(--font-display); padding-top: 6px; }
.chart-x span { justify-self: start; transform: translateX(-50%); } /* labels mark bucket edges */
.axis-title { color: var(--dim); font-size: 12px; margin: 10px 0 0 38px; }
.tip {
  position: absolute; top: 8px; transform: translateX(-50%); z-index: 2; pointer-events: none;
  background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; display: grid; gap: 3px;
}
.tip b { color: var(--text); font-family: var(--font-display); }
.tip .num { color: var(--text); }
.tip-you { color: var(--bar-you); font-weight: 700; }
.stats-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
