:root {
  --bg: #0b1026; --panel: #141a3a; --track: #1d2550;
  --ink: #f4f6ff; --muted: #9aa3c7;
  --lime: #c6ff00; --pink: #ff3d81; --orange: #ff9f1c;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
body { min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center; }
.app {
  width: 100%; max-width: 560px; padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

.top { display: flex; align-items: center; justify-content: space-between; }
h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; font-weight: 900; }
h1 span { color: var(--lime); }
.toggle { font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: center; user-select: none; cursor: pointer; }
.toggle input { accent-color: var(--lime); width: 18px; height: 18px; margin: 0; }

.stage { background: var(--panel); border-radius: 20px; padding: 18px 16px 14px; position: relative; overflow: hidden; }
.big { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; text-align: center; align-items: end; }
.big small { display: block; text-transform: uppercase; letter-spacing: .12em; font-size: 11px; color: var(--muted); }
.big strong { display: block; font-size: clamp(40px, 12vw, 64px); line-height: 1; font-weight: 900; font-variant-numeric: tabular-nums; }
.big .level strong { color: var(--lime); font-size: clamp(64px, 20vw, 110px); }
.big em { display: block; font-style: normal; font-size: 12px; color: var(--muted); margin-top: 4px; }

.bar { height: 10px; background: var(--track); border-radius: 99px; margin: 14px 0 10px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--lime); border-radius: 99px; }

.track {
  position: relative; height: 84px; background: var(--track); border-radius: 12px; overflow: hidden;
  background-image: repeating-linear-gradient(90deg, transparent 0 14px, rgba(255,255,255,.18) 14px 24px);
  background-size: 100% 3px; background-position: 0 50%; background-repeat: no-repeat;
}
.line { position: absolute; top: 0; bottom: 0; width: 4px; background: #fff; }
.line-a { left: 24px; } .line-b { right: 24px; }
.cone { position: absolute; bottom: 8px; width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 18px solid var(--orange); }
.cone-a { left: 6px; } .cone-b { right: 6px; }
.runner { position: absolute; top: 50%; left: 24px; font-size: 44px; line-height: 1; transform: translate(-50%, -50%); }
.runner.flip { transform: translate(-50%, -50%) scaleX(-1); }
.runner span { display: inline-block; }
.stage[data-state="running"] .runner span { animation: bob .3s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-3px) } to { transform: translateY(3px) } }

.hint { margin: 12px 0 0; color: var(--muted); font-size: 15px; text-align: center; line-height: 1.4; min-height: 2.8em; font-weight: 600; }
.stage[data-state="running"] .hint { color: var(--ink); }

.countdown {
  position: absolute; inset: 0; background: rgba(11,16,38,.94); z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.countdown[hidden] { display: none; }
.countdown span { font-size: clamp(90px, 35vw, 160px); font-weight: 900; color: var(--lime); line-height: 1; }
.countdown p { margin: 8px 0 0; color: var(--muted); font-weight: 700; font-size: 18px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats div { background: var(--panel); border-radius: 14px; padding: 10px; text-align: center; }
.stats small { display: block; text-transform: uppercase; letter-spacing: .12em; font-size: 10px; color: var(--muted); }
.stats strong { font-size: 20px; font-variant-numeric: tabular-nums; }

.result {
  background: linear-gradient(135deg, #1b2358, #2b1b4e); border-radius: 20px; padding: 20px;
  text-align: center; border: 2px solid var(--lime);
}
.result[hidden] { display: none; }
.result h2 { margin: 0; font-size: 56px; font-weight: 900; line-height: 1; color: var(--lime); }
.result h2 small { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.r-rating { font-size: 24px; font-weight: 800; margin: 12px 0 2px; }
.r-quip { color: var(--muted); margin: 0 0 16px; }
.result dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.result dt { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.result dd { margin: 2px 0 0; font-weight: 800; font-size: 18px; }
.pbflag { display: inline-block; background: var(--pink); color: #fff; font-weight: 900; padding: 6px 12px; border-radius: 99px; font-size: 14px; margin-top: 14px; animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.pbflag[hidden] { display: none; }
@keyframes pop { from { transform: scale(0) } to { transform: scale(1) } }

.buttons { display: flex; gap: 10px; }
.buttons button {
  flex: 1; font: inherit; font-weight: 900; font-size: 20px; padding: 18px; border: 0; border-radius: 16px;
  cursor: pointer; color: var(--bg); transition: transform .08s;
}
.buttons button:active { transform: scale(.97); }
.buttons button[hidden] { display: none; }
.primary { background: var(--lime); }
.danger { background: var(--pink); color: #fff !important; }
.ghost { background: transparent; color: var(--ink) !important; border: 2px solid var(--muted) !important; }

.foot { margin: 0; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.5; }

.confetti { position: fixed; top: -14px; width: 10px; height: 14px; z-index: 9; pointer-events: none; border-radius: 2px; animation: fall 2.8s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .7; } }

@media (prefers-reduced-motion: reduce) {
  .stage[data-state="running"] .runner span, .pbflag, .confetti { animation: none; }
}
