:root {
    --bg: #05060f;
    --panel: rgba(11, 16, 40, 0.92);
    --line: rgba(120, 160, 255, 0.22);
    --text: #e8f1ff;
    --muted: #8ea3c8;
    --cyan: #3fd0ff;
    --rose: #ff5fb0;
    --gold: #ffd36b;
    --danger: #c46bff;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overscroll-behavior: none;
}

body {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

#app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 14px 4px;
}

.hud-block { min-width: 0; }

.hud-label {
    font-size: 10px;
    letter-spacing: 0.18em;
    color: var(--muted);
    font-weight: 700;
}

.score {
    font-size: clamp(22px, 6vw, 34px);
    font-weight: 900;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 18px rgba(63, 208, 255, 0.5);
}

.hud-center { text-align: center; }

.phase {
    font-size: 11px;
    letter-spacing: 0.22em;
    font-weight: 800;
    color: var(--gold);
}

.timer {
    font-size: clamp(18px, 5vw, 26px);
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.timer-sub { font-size: 12px; color: var(--muted); margin-left: 2px; }

.hud-right { text-align: right; }

.chain-row { display: flex; gap: 6px; justify-content: flex-end; align-items: baseline; }

.chain-value { font-size: 18px; font-weight: 900; color: var(--cyan); font-variant-numeric: tabular-nums; }

.partner {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    font-size: 10px;
    letter-spacing: 0.14em;
    color: var(--muted);
    font-weight: 700;
    margin-top: 2px;
}

.partner .dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #58e08a;
    box-shadow: 0 0 8px #58e08a;
}

.partner.warn { color: var(--gold); }
.partner.warn .dot { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.partner.bad { color: var(--danger); }
.partner.bad .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

.beat { font-size: 10px; letter-spacing: 0.12em; color: var(--gold); font-weight: 800; margin-top: 2px; }

/* ---------- Stage ---------- */
#stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }

#board {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

/* ---------- Overlays ---------- */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    pointer-events: none;
}

.panel {
    pointer-events: auto;
    width: min(430px, 94%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 22px 22px 20px;
    text-align: center;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    max-height: 92%;
    overflow-y: auto;
}

.brand {
    font-size: clamp(26px, 8vw, 40px);
    font-weight: 900;
    letter-spacing: 0.08em;
}
.brand span { color: var(--gold); }
.brand.small { font-size: 22px; }

.tagline {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
    letter-spacing: 0.06em;
}

.howto { margin: 16px 0 6px; text-align: left; }

.howto-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #cfdcf5;
    margin: 7px 0;
}

.chip { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto; }
.chip-you { background: var(--cyan); box-shadow: 0 0 12px var(--cyan); }
.chip-them { background: var(--rose); box-shadow: 0 0 12px var(--rose); }

.howto-note { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 10px 0 0; }
.howto-note b { color: #dfeaff; }
.howto-note b.s { color: #bfeaff; }
.howto-note b.t { color: var(--gold); }
.howto-note b.h { color: var(--danger); }
.howto-note b.d { color: #ffbf7a; }

.lobby-hint { font-size: 11px; color: var(--muted); margin: 14px 0 4px; }

.btn {
    appearance: none;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 13px 18px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
    touch-action: manipulation;
}

.btn:hover { background: rgba(255, 255, 255, 0.09); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn.primary {
    background: linear-gradient(135deg, #2a6dff, #8a3dff);
    border-color: transparent;
    box-shadow: 0 8px 26px rgba(80, 80, 255, 0.4);
}
.btn.primary:hover { filter: brightness(1.08); }

.btn.ghost { background: transparent; }
.btn.tiny { padding: 7px 11px; font-size: 11px; border-radius: 9px; }

#playBtn { width: 100%; margin-top: 12px; }

/* ---------- Result ---------- */
.result-kicker { font-size: 11px; letter-spacing: 0.22em; color: var(--muted); font-weight: 800; }
.result-tier { font-size: 22px; font-weight: 900; color: var(--gold); margin: 6px 0 2px; letter-spacing: 0.04em; }

.result-score {
    font-size: clamp(46px, 14vw, 70px);
    font-weight: 900;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 28px rgba(63, 208, 255, 0.5);
}

.result-contrib { margin-top: 8px; font-size: 13px; color: #cfdcf5; }
.result-contrib b { color: var(--gold); }

.result-beat { margin-top: 10px; font-size: 12px; color: var(--muted); letter-spacing: 0.05em; }
.result-beat.record { color: var(--gold); font-weight: 800; }
.result-beat span { color: var(--text); font-weight: 900; }

.stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 16px 0;
}

.stat {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(120, 160, 255, 0.12);
    border-radius: 12px;
    padding: 10px 6px;
}

.stat .v { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 9.5px; letter-spacing: 0.14em; color: var(--muted); font-weight: 700; margin-top: 2px; }

.result-actions { display: flex; flex-direction: column; gap: 8px; }
.result-wait { margin-top: 12px; font-size: 12px; color: var(--muted); }

.dots i { animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink { 0%, 60%, 100% { opacity: 0.2; } 30% { opacity: 1; } }

.goodbye-msg { color: var(--muted); font-size: 14px; margin: 16px 0; line-height: 1.5; }

/* ---------- Waiting banner ---------- */
.wait-banner {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(11, 16, 40, 0.9);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 10px 8px 14px;
    font-size: 12px;
    color: #cfdcf5;
    max-width: 92%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.wb-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--cyan);
    box-shadow: 0 0 10px var(--cyan);
    animation: pulse 1.1s infinite;
}

@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---------- Countdown ---------- */
.countdown {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.countdown .pop {
    font-size: clamp(40px, 16vw, 96px);
    font-weight: 900;
    letter-spacing: 0.06em;
    color: var(--text);
    text-shadow: 0 0 40px rgba(63, 208, 255, 0.8);
    animation: pop 0.5s ease-out;
}

.countdown.go .pop { color: var(--gold); text-shadow: 0 0 46px rgba(255, 211, 107, 0.9); }

@keyframes pop {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* ---------- Controls ---------- */
#controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 14px calc(8px + env(safe-area-inset-bottom));
}

.reactions { display: flex; gap: 6px; flex-wrap: wrap; }

.reaction {
    appearance: none;
    border: 1px solid rgba(120, 160, 255, 0.16);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    font-size: 18px;
    line-height: 1;
    padding: 7px 8px;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.15s ease;
    touch-action: manipulation;
}

.reaction:hover { background: rgba(255, 255, 255, 0.1); }
.reaction:active { transform: scale(0.9); }

@media (max-width: 520px) {
    .hud-label { font-size: 9px; }
    .howto-row { font-size: 12px; }
    .panel { padding: 18px 16px 16px; }
}
