:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel-2: #1f2732;
  --ink: #e8edf4;
  --muted: #8b97a8;
  --accent: #4dd6a0;
  --accent-2: #4da3ff;
  --danger: #ff5c6c;
  --gold: #f2c14e;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0,0,0,.35);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 700px at 70% -10%, #1a2330 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 920px; margin: 0 auto; padding: 24px 18px 60px; }

header.top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
header.top h1 { font-size: 1.5rem; margin: 0; letter-spacing: .3px; }
header.top .dot { color: var(--accent); }
header.top p { margin: 0; color: var(--muted); font-size: .9rem; }

.namebar { display: flex; gap: 10px; align-items: center; margin: 16px 0; flex-wrap: wrap; }
.namebar label { color: var(--muted); font-size: .85rem; }
input[type=text] {
  background: var(--panel-2); border: 1px solid #2b3543; color: var(--ink);
  border-radius: 10px; padding: 9px 12px; font-size: .95rem; min-width: 180px; outline: none;
}
input[type=text]:focus { border-color: var(--accent-2); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
  background: var(--panel); border: 1px solid #262f3b; color: var(--ink);
  padding: 10px 14px; border-radius: 12px; cursor: pointer; font-size: .92rem;
  display: flex; align-items: center; gap: 8px; transition: .15s;
}
.tab:hover { border-color: #3a475a; }
.tab.active { background: linear-gradient(180deg, #21303f, #1a2330); border-color: var(--accent-2); }
.tab small { color: var(--muted); font-size: .72rem; }

.stage {
  position: relative; background: var(--panel); border: 1px solid #232c38;
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-height: 340px; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 28px; overflow: hidden; user-select: none;
  transition: background .05s;
}
.stage.state-wait { background: #202a1c; }
.stage.state-go   { background: #12351f; }
.stage.state-flash{ background: #eef2f7; }
.stage.state-early{ background: #3a1520; }
.stage .big { font-size: clamp(1.4rem, 5vw, 2.6rem); font-weight: 700; line-height: 1.2; }
.stage .sub { color: var(--muted); margin-top: 10px; font-size: .95rem; }
.stage.state-flash .big, .stage.state-flash .sub { color: #0e1116; }

.flashdot {
  position: absolute; width: 42vmin; height: 42vmin; max-width: 340px; max-height: 340px;
  border-radius: 50%; background: radial-gradient(circle, #fff 0%, #ffd34d 55%, #ff8a3d 100%);
  opacity: 0; transform: scale(.2); pointer-events: none;
}
.flashdot.on { animation: pop .5s ease-out forwards; }
@keyframes pop { 0%{opacity:1;transform:scale(.2);} 100%{opacity:1;transform:scale(1);} }

.cam {
  position: absolute; right: 12px; bottom: 12px; width: 150px; height: 112px;
  border-radius: 12px; overflow: hidden; border: 1px solid #2b3543;
  background: #000; display: none;
}
.cam.show { display: block; }
.cam video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam .eye {
  position: absolute; left: 8px; top: 8px; font-size: .7rem; color: #fff;
  background: rgba(0,0,0,.45); padding: 2px 6px; border-radius: 6px;
}
.cam .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); width: 0%; }

.controls { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; align-items: center; }
button.btn {
  background: linear-gradient(180deg, #2b8f6b, #1f6f52); color: #fff; border: 0;
  padding: 12px 20px; border-radius: 12px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
button.btn:hover { filter: brightness(1.08); }
button.btn.ghost { background: var(--panel-2); color: var(--ink); border: 1px solid #2b3543; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

.readout { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.stat {
  background: var(--panel); border: 1px solid #232c38; border-radius: 14px;
  padding: 14px 18px; flex: 1; min-width: 130px;
}
.stat .k { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 1.7rem; font-weight: 700; margin-top: 4px; }
.stat .v small { font-size: .9rem; color: var(--muted); font-weight: 400; }
.v.good { color: var(--accent); } .v.mid { color: var(--gold); } .v.bad { color: var(--danger); }

.board { margin-top: 26px; }
.board h2 { font-size: 1.05rem; margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #212a35; }
th { color: var(--muted); font-weight: 500; font-size: .8rem; }
td.rank { color: var(--muted); width: 40px; }
tr:first-child td .medal { margin-right: 4px; }
.msg { color: var(--muted); font-size: .85rem; margin-top: 10px; min-height: 1.2em; }
.err { color: var(--danger); }
footer { margin-top: 40px; color: var(--muted); font-size: .8rem; text-align: center; }
.hist { margin-top: 10px; display: flex; gap: 4px; align-items: flex-end; height: 40px; }
.hist i { width: 8px; background: var(--accent-2); border-radius: 2px 2px 0 0; opacity: .8; cursor: pointer; transition: .1s; }
.hist i:hover { opacity: 1; background: var(--gold); transform: scaleX(1.6); }
#histLabel { font-variant-numeric: tabular-nums; }
