:root {
  --ink: #e8f0fa;
  --ink-dim: #9fb2c8;
  --panel: rgba(8, 13, 22, 0.62);
  --panel-line: rgba(160, 200, 255, 0.18);
  --gold: #ffcc57;
  --cyan: #7fd6ff;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05070c;
  color: var(--ink);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: default;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
}
#stage canvas { display: block; width: 100%; height: 100%; }

.hidden { display: none !important; }
body.hide-ui .hud, body.hide-ui .screen { display: none !important; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud > * { position: absolute; }

.hud-standings {
  top: 12px; left: 12px;
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px 10px; min-width: 150px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  font-size: 12px;
}
.row { display: grid; grid-template-columns: 10px 1fr 44px; align-items: center; gap: 7px; }
.row .dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.row .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.me .nm { color: var(--gold); font-weight: 700; }
.row .pg { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.row .pg i { display: block; height: 100%; width: 0; background: currentColor; }

.hud-center { top: 10px; left: 50%; transform: translateX(-50%); text-align: center; text-shadow: 0 2px 14px rgba(0,0,0,.7); }
.hud-place { font-size: clamp(28px, 5.4vw, 52px); font-weight: 800; letter-spacing: 0.02em; line-height: 1; }
.hud-time { margin-top: 4px; font-size: 14px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

.hud-stage {
  top: 12px; right: 12px; padding: 7px 12px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 999px; color: var(--ink-dim);
}

.lives { top: 50px; right: 12px; display: flex; gap: 6px; align-items: center; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-dim); }
.lives:empty { display: none; }
.life { width: 14px; height: 18px; background: var(--cyan); border-radius: 50% 50% 55% 55% / 65% 65% 40% 40%; box-shadow: 0 0 10px rgba(127, 214, 255, 0.5); }
.life.gone { background: rgba(255, 255, 255, 0.14); box-shadow: none; }
.row.dead { opacity: 0.4; text-decoration: line-through; }

.hud-meters { left: 12px; bottom: 12px; display: flex; gap: 10px; }
.meter {
  width: clamp(110px, 18vw, 170px); padding: 7px 10px;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px; font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-dim);
}
.bar { margin-top: 5px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 50%; background: var(--cyan); transition: width 0.12s linear; }
#clingBar { background: var(--gold); }
#clingBar.low { background: #ff7a5c; }

.chain {
  top: 26%; right: 4%; min-width: 130px; text-align: right; opacity: 0; transition: opacity 0.15s;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
}
.chain.on { opacity: 1; }
.chain b { display: block; font-size: clamp(22px, 4vw, 40px); font-weight: 900; color: var(--gold); letter-spacing: 0.04em; transform-origin: right center; }
.chain.pop b { animation: chainpop 0.22s ease-out; }
@keyframes chainpop { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }
.chain .bar { margin-top: 4px; }
.chain .bar i { background: linear-gradient(90deg, #ffcc57, #fff1b0); transition: none; }

.ups { right: 12px; bottom: 12px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 46vw; }
.up-chip {
  padding: 4px 9px; font-size: 11px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-line); color: var(--ink-dim);
}
body.touch-ui .ups { bottom: 108px; }

.banner {
  top: 21%; left: 50%; transform: translate(-50%, 0); padding: 9px 18px; max-width: 90vw; text-align: center;
  font-size: clamp(14px, 2.4vw, 22px); font-weight: 700; border-radius: 999px;
  background: rgba(8, 13, 22, 0.72); border: 1px solid var(--panel-line);
  opacity: 0; transition: opacity 0.18s;
}
.banner.on { opacity: 1; }
.banner.warn { color: #ffd98a; border-color: rgba(255, 200, 100, 0.5); }
.banner.bad { color: #ff9c8a; }
.banner.good { color: #9bffc0; }

.countdown {
  top: 38%; left: 50%; transform: translate(-50%, -50%); font-size: clamp(64px, 14vw, 150px); font-weight: 900;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.7); opacity: 0; letter-spacing: 0.04em;
}
.countdown.pop { animation: pop 0.9s ease-out; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
}

.hint {
  bottom: 62px; left: 50%; transform: translateX(-50%); padding: 7px 14px; font-size: 13px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 999px; opacity: 0; transition: opacity 0.4s;
  white-space: nowrap;
}
.hint.on { opacity: 1; }

.touch { left: 0; right: 0; bottom: 0; display: none; justify-content: space-between; align-items: flex-end; padding: 0 14px 14px; pointer-events: none; }
body.touch-ui .touch { display: flex; }
body.touch-ui .hud-meters { bottom: 96px; }
body.touch-ui .hint { bottom: 150px; }
.tbtn {
  pointer-events: auto; width: 74px; height: 74px; border-radius: 50%; border: 1px solid var(--panel-line);
  background: rgba(20, 30, 46, 0.55); color: var(--ink); font: 700 14px var(--font); touch-action: none;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.tbtn:active { background: rgba(80, 120, 170, 0.6); }
.tcling { width: 92px; height: 92px; background: rgba(120, 90, 20, 0.5); letter-spacing: 0.08em; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto;
  background: radial-gradient(ellipse at 30% 20%, rgba(5, 10, 22, 0.35), rgba(3, 5, 10, 0.78));
}
.screen-card { width: min(920px, 100%); margin: auto; padding: 4px; }
.logo { font-size: clamp(30px, 7vw, 76px); font-weight: 900; letter-spacing: 0.02em; line-height: 0.95; margin: 0; text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6); }
.logo span { color: var(--cyan); }
.tag { max-width: 560px; margin: 10px 0 18px; font-size: clamp(13px, 1.9vw, 18px); color: var(--ink-dim); line-height: 1.4; }

.stages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stage-card {
  text-align: left; padding: 11px 12px; border-radius: 14px; border: 1px solid var(--panel-line); background: var(--panel);
  color: var(--ink); font: inherit; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.stage-card.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset, 0 0 24px rgba(255, 204, 87, 0.15); }
.stage-card h3 { margin: 0 0 4px; font-size: 15px; }
.stage-card p { margin: 0 0 7px; font-size: 12px; color: var(--ink-dim); line-height: 1.35; }
.stage-card .meta { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--cyan); }
.drops { letter-spacing: 3px; color: var(--cyan); }

.cup-line { font-size: 13px; color: var(--gold); letter-spacing: 0.04em; }
.pick-title { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-dim); margin: 6px 0 8px; }
.stage-card.up { border-color: rgba(127, 214, 255, 0.35); }
.stage-card.up h3 { color: var(--cyan); }
.stage-card.up:hover, .stage-card.up:focus-visible { border-color: var(--gold); }
.stage-card:hover { border-color: rgba(255, 204, 87, 0.55); }
.result-big.small { font-size: clamp(30px, 6vw, 60px); }

.go-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.btn {
  font: 800 16px var(--font); letter-spacing: 0.1em; padding: 13px 34px; border-radius: 999px; border: 0;
  background: linear-gradient(180deg, #ffd978, #f2a93a); color: #1a1205; box-shadow: 0 6px 28px rgba(242, 169, 58, 0.35);
}
.btn:hover { filter: brightness(1.08); }
.btn.alt { background: linear-gradient(180deg, #9fe3ff, #4aa9e0); color: #04121c; box-shadow: 0 6px 28px rgba(74, 169, 224, 0.35); }
.mode-lines { display: flex; flex-direction: column; gap: 2px; }
.btn.ghost { background: var(--panel); color: var(--ink); border: 1px solid var(--panel-line); box-shadow: none; padding: 11px 20px; font-size: 13px; }
.btn:focus-visible, .stage-card:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.how { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 22px; margin: 0 0 8px; padding: 0; list-style: none; font-size: 13px; color: var(--ink-dim); }
.how b { color: var(--ink); margin-right: 6px; }
.keys { font-size: 12px; color: var(--ink-dim); opacity: 0.8; }

.result-big { font-size: clamp(44px, 11vw, 120px); font-weight: 900; line-height: 0.95; margin: 0; }
.result-sub { font-size: clamp(15px, 2.6vw, 24px); color: var(--ink-dim); margin: 6px 0 18px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.stat { padding: 10px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-line); min-width: 110px; }
.stat small { display: block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-dim); }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat.new b { color: var(--gold); }
.result-list { margin: 0 0 18px; padding: 0; list-style: none; font-size: 13px; color: var(--ink-dim); }
.result-list li { display: flex; gap: 8px; align-items: center; padding: 2px 0; }
.result-list .dot { width: 9px; height: 9px; border-radius: 50%; }
.result-list .me { color: var(--gold); font-weight: 700; }

.pause-card { text-align: center; }
.go-row.center { justify-content: center; margin-top: 18px; }
.pause-card h2 { font-size: clamp(30px, 6vw, 56px); margin: 0 0 6px; }
.pause-card p { color: var(--ink-dim); margin: 0; }

@media (max-width: 700px) {
  .stages { grid-template-columns: 1fr; gap: 6px; }
  .stage-card p { display: none; }
  .how { grid-template-columns: 1fr; }
  .hud-standings { min-width: 0; font-size: 11px; padding: 6px 8px; }
  .hud-standings .pg { display: none; }
  .row { grid-template-columns: 9px 1fr; }
  .hud-stage { display: none; }
}
@media (max-height: 460px) {
  .how, .keys { display: none; }
  .tag { margin-bottom: 10px; }
  .screen { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .countdown.pop { animation: none; opacity: 1; }
}
