:root {
  --bg: #12101f; --panel: #1d1a31; --panel2: #272342; --line: #37325a;
  --ink: #f5f3ff; --muted: #a39fc4; --accent: #ffd23f; --accent-ink: #1a1500;
  --good: #5fd35f; --bad: #ff5d5d; --blue: #4da3ff;
  --r: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: manipulation; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; max-width: 620px; margin: 0 auto; }
#bar { display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
#brand { font-weight: 900; letter-spacing: 0.06em; font-size: 14px; color: var(--muted); }
#brand b { color: var(--accent); margin-left: 3px; }
#stageLabel { flex: 1; text-align: center; font-weight: 700; font-size: 14px; }
#clock { min-width: 58px; text-align: right; font-weight: 900; font-size: 20px; font-variant-numeric: tabular-nums; }
#clock.low { color: var(--bad); }
#banner { margin: 0 16px 8px; padding: 10px 14px; border-radius: 12px; background: #2b2550; border: 1px solid var(--line); font-size: 14px; display: flex; gap: 10px; align-items: center; }
#banner button { margin-left: auto; }
#view { flex: 1; overflow-y: auto; padding: 6px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }

h1 { font-size: 34px; line-height: 1.05; margin: 8px 0 0; font-weight: 900; letter-spacing: -0.02em; text-wrap: balance; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 6px 0 -4px; font-weight: 800; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; margin: auto; }
.lead { font-size: 18px; color: #dcd8f5; }
.kicker { font-weight: 800; color: var(--accent); font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.btn { border: 0; border-radius: 14px; padding: 15px 18px; font-weight: 800; font-size: 18px; background: var(--accent); color: var(--accent-ink); cursor: pointer; width: 100%; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); }
.btn.on { background: var(--good); color: #062006; }
.btn.slim { padding: 8px 12px; font-size: 14px; width: auto; border-radius: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }

input[type=text], textarea { width: 100%; background: #0f0d1c; border: 2px solid var(--line); border-radius: 14px; padding: 14px; font-size: 18px; outline: none; }
input[type=text]:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 150px; resize: none; line-height: 1.35; }

.players { display: flex; flex-direction: column; gap: 6px; }
.player { display: flex; align-items: center; gap: 10px; background: var(--panel2); border-radius: 12px; padding: 9px 12px; font-weight: 700; }
.player.off { opacity: 0.45; }
.player.me { outline: 2px solid rgba(255,255,255,0.55); }
.dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.player .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .score { font-variant-numeric: tabular-nums; font-weight: 900; min-width: 30px; text-align: right; }
.tag { font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 99px; background: #3a3562; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.tag.good { background: #1f4a25; color: #a8f0a8; }
.tag.bad { background: #55202a; color: #ffb3b3; }
.tag.gold { background: #54440d; color: var(--accent); }
.rank { width: 22px; text-align: center; color: var(--muted); font-weight: 900; }

.steps { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.steps li { display: flex; gap: 10px; align-items: baseline; font-size: 15px; color: #d6d2ee; }
.steps b { color: var(--accent); flex: none; width: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--panel2); border-radius: 99px; padding: 7px 12px; font-size: 14px; cursor: pointer; }
.count { font-size: 13px; color: var(--muted); text-align: right; margin-top: -6px; }

.gametitle { font-size: 40px; font-weight: 900; line-height: 1; letter-spacing: -0.02em; text-wrap: balance; }
.bigcount { font-size: 64px; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; color: var(--accent); line-height: 1; }
.controls { display: grid; gap: 6px; font-size: 15px; }
.controls div { display: flex; gap: 8px; }
.controls b { min-width: 74px; color: var(--accent); }

.vgame { display: flex; flex-direction: column; gap: 8px; }
.vgame .t { font-weight: 800; font-size: 18px; }
.vbtns { display: flex; gap: 8px; }
.vbtn { flex: 1; border: 2px solid var(--line); background: transparent; border-radius: 12px; padding: 11px 6px; font-weight: 800; cursor: pointer; }
.vbtn:disabled { opacity: 0.3; cursor: default; }
.vbtn.up.sel { background: var(--good); border-color: var(--good); color: #062006; }
.vbtn.down.sel { background: var(--bad); border-color: var(--bad); color: #2a0505; }
.net { font-weight: 900; font-size: 22px; min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.strike { text-decoration: line-through; opacity: 0.6; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; margin: 6px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- minigame stage ---- */
#stage { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: #07060d; display: flex; flex-direction: column; z-index: 10; }
#stageBar { height: calc(42px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0; display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; color: var(--muted); }
#stageInfo { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#brokenBtn { border: 1px solid #6b3340; background: #2a1820; color: #ffb3b3; border-radius: 10px; padding: 6px 10px; font-weight: 800; font-size: 13px; cursor: pointer; white-space: nowrap; }
#brokenBtn.on { background: var(--bad); color: #2a0505; border-color: var(--bad); }
#brokenBtn:disabled { opacity: 0.7; cursor: default; }
#frameWrap { flex: 1; min-height: 0; position: relative; }
#frameWrap iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; display: block; background: #0b0b12; }
#resultCard { position: absolute; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(92vw, 480px); background: rgba(24,21,44,0.97); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 12px 40px rgba(0,0,0,0.6); max-height: 62vh; overflow-y: auto; }
#resultCard .headline { font-size: 22px; font-weight: 900; }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
#resultCard .players { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
#resultCard .player { padding: 6px 9px; font-size: 14px; gap: 7px; }
#resultCard .player .dot { width: 12px; height: 12px; }
#resultCard .rank { width: 14px; font-size: 12px; }
.microw { margin-top: -4px; min-height: 36px; }
.microw .count { margin-top: 0; white-space: nowrap; }
.mic { white-space: nowrap; }
.mic.rec { background: var(--bad); border-color: var(--bad); color: #2a0505; animation: micpulse 1.2s ease-in-out infinite; }
@keyframes micpulse { 50% { opacity: 0.6; } }
textarea[readonly] { border-color: var(--bad); }
