:root {
  --bg: #0b0d10;
  --panel: #151920;
  --panel-2: #1d232c;
  --line: #2a313c;
  --text: #eef1f5;
  --muted: #98a2b3;
  --accent: #ff5a1f;
  --accent-2: #ffb020;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --info: #38bdf8;
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-2); }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; }
.num, .clock { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 12px; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ''; width: 14px; height: 14px; border-radius: 3px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.conn { font-size: .8rem; padding: 3px 10px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.conn.online { color: var(--ok); }
.conn.offline, .conn.connecting { color: var(--warn); }
.conn.invalid { color: var(--bad); }

/* ---- controls ---- */
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; position: relative; overflow: hidden; touch-action: manipulation; }
.btn:hover:not(:disabled) { border-color: #3b4452; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #04210f; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: .9rem; }
.btn.hold::after { content: ''; position: absolute; inset: auto 0 0 0; height: 5px; background: rgba(255,255,255,.85); transform-origin: left; transform: scaleX(var(--hold, 0)); }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; max-width: 100%; }
textarea { width: 100%; min-height: 110px; }
label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tag.ok { background: rgba(34,197,94,.15); color: var(--ok); }
.tag.warn { background: rgba(245,158,11,.15); color: var(--warn); }
.tag.bad { background: rgba(239,68,68,.15); color: var(--bad); }
.tag.info { background: rgba(56,189,248,.15); color: var(--info); }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.table-scroll { overflow-x: auto; }

/* ---- toasts & dialogs ---- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--info); padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.error { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
dialog.pin-dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: min(360px, calc(100vw - 32px)); }
dialog.pin-dialog::backdrop { background: rgba(0,0,0,.6); }
dialog.pin-dialog input { width: 100%; font-size: 1.6rem; text-align: center; letter-spacing: .3em; margin: 8px 0 16px; }
dialog.pin-dialog .row { justify-content: flex-end; }

/* ---- landing ---- */
.hero { padding: 40px 16px; text-align: center; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.4rem); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.tile { display: block; text-decoration: none; color: var(--text); }
.tile h3 { color: var(--accent-2); }

/* ---- admin ---- */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; padding: 12px 14px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; min-height: 44px; }
.tabs button[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.mov-row { display: grid; grid-template-columns: 1fr 140px auto; gap: 8px; margin-bottom: 6px; }
.qr { background: #fff; padding: 6px; border-radius: 8px; width: 120px; height: 120px; }
.qr svg { width: 100%; height: 100%; display: block; }
.link-card { display: grid; grid-template-columns: 132px 1fr; gap: 12px; align-items: start; }
.link-url { font-family: var(--mono); font-size: .8rem; word-break: break-all; color: var(--muted); }

/* ---- zone console ---- */
.console { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 12px; padding: 12px; }
.clock-box { text-align: center; padding: 18px; }
.clock-box .clock { font-size: clamp(3rem, 9vw, 5.5rem); font-weight: 800; line-height: 1; }
.clock-box .phase { margin-top: 6px; }
.phase-countdown .clock { color: var(--accent-2); }
.phase-running .clock { color: var(--ok); }
.phase-finished .clock, .phase-stopped .clock { color: var(--bad); }
.lanes-table td.name { font-weight: 600; }
.alert { padding: 8px 12px; border-radius: 8px; background: rgba(239,68,68,.12); color: #fecaca; border: 1px solid rgba(239,68,68,.35); margin-bottom: 6px; }
.alert.warn { background: rgba(245,158,11,.12); color: #fde68a; border-color: rgba(245,158,11,.35); }
.heat-list { display: grid; gap: 6px; max-height: 360px; overflow: auto; }
.heat-item { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 8px; background: var(--panel-2); }
.heat-item.current { outline: 2px solid var(--accent); }
.heat-item.done { opacity: .55; }

/* ---- judge ---- */
.judge { max-width: 560px; margin: 0 auto; padding: 12px; display: grid; gap: 12px; }
.judge .athlete { font-size: 1.4rem; font-weight: 800; }
.judge .clock { font-size: 3rem; font-weight: 800; text-align: center; }
.mov-now { text-align: center; }
.mov-now .mov-name { font-size: 1.6rem; font-weight: 800; }
.mov-now .mov-count { font-size: 1.1rem; color: var(--muted); }
.big-count { font-size: 4.5rem; font-weight: 900; text-align: center; line-height: 1; }
.rep-btn { width: 100%; min-height: 34vh; font-size: 3rem; font-weight: 900; border-radius: 18px; background: var(--ok); border: 0; color: #03210e; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.rep-btn:active { filter: brightness(1.15); transform: scale(.995); }
.rep-btn:disabled { background: var(--panel-2); color: var(--muted); }
.judge .actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.lane-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; }
.lane-pick .btn { min-height: 90px; font-size: 1.6rem; }
.progress { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; transition: width .2s; }
.mov-list { display: grid; gap: 4px; font-size: .95rem; }
.mov-list .cur { color: var(--accent-2); font-weight: 700; }
.mov-list .done { color: var(--muted); text-decoration: line-through; }
.banner { text-align: center; font-weight: 800; padding: 10px; border-radius: 10px; }
.banner.ok { background: rgba(34,197,94,.15); color: var(--ok); }
.banner.warn { background: rgba(245,158,11,.15); color: var(--warn); }
.pending-badge { font-size: .8rem; color: var(--warn); }

/* ---- big screen ---- */
body.screen { overflow: hidden; }
body.screen.overlay { background: transparent; }
.bs { height: 100vh; display: grid; grid-template-rows: auto 1fr; padding: 2vh 2vw; gap: 2vh; }
.bs-head { display: flex; align-items: center; gap: 2vw; }
.bs-title { font-size: 3.4vh; font-weight: 800; }
.bs-sub { font-size: 2.2vh; color: var(--muted); }
.bs-clock { margin-left: auto; font-size: 9vh; font-weight: 900; line-height: 1; }
.bs-lanes { display: grid; gap: 1vh; align-content: start; }
.bs-lane { display: grid; grid-template-columns: 6vh 7vh 1fr 16vw 14vh; align-items: center; gap: 1.4vw; background: var(--panel); border-radius: 1.2vh; padding: 1.1vh 1.4vw; font-size: 2.8vh; border-left: .8vh solid var(--line); }
.bs-lane.fin { border-left-color: var(--ok); }
.bs-lane .ln { font-weight: 900; color: var(--muted); }
.bs-lane .rk { font-weight: 900; color: var(--accent-2); }
.bs-lane .nm { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bs-lane .nm small { display: block; font-weight: 500; color: var(--muted); font-size: 1.9vh; }
.bs-lane .sc { text-align: right; font-weight: 900; font-size: 3.6vh; }
.bs-lane .progress { height: 1.3vh; }
.bs-lane .mv { font-size: 1.8vh; color: var(--muted); margin-top: .4vh; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bs-idle { display: grid; place-items: center; font-size: 4vh; color: var(--muted); }
.bs-lb { overflow: hidden; position: relative; }
.bs-lb table { font-size: 2.6vh; }
.bs-lb td, .bs-lb th { padding: .9vh 1vw; }

/* ---- leaderboard ---- */
.lb-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.lb-table td.place { font-weight: 900; font-size: 1.1rem; width: 3.5em; }
.lb-table td.total { font-weight: 800; }
.lb-table .ev { white-space: nowrap; }
.lb-table .ev b { display: block; }
.lb-table .ev span { font-size: .8rem; color: var(--muted); }
.lb-table tr.me { background: rgba(255,90,31,.12); }
.lb-cards { display: none; }
.lb-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.lb-card summary { display: flex; gap: 10px; align-items: center; cursor: pointer; list-style: none; min-height: 44px; }
.lb-card summary::-webkit-details-marker { display: none; }
.lb-card .place { font-weight: 900; font-size: 1.2rem; width: 2.2em; }

@media (max-width: 760px) {
  .console { grid-template-columns: 1fr; }
  .lb-table-wrap { display: none; }
  .lb-cards { display: block; }
  .link-card { grid-template-columns: 1fr; }
  .mov-row { grid-template-columns: 1fr 100px auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
