* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

:root {
    --bg: #2a1608;
    --ink: #f6e9d4;
    --gold: #ffc24a;
    --muted: #b79a76;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
}

.wrap { position: relative; width: 100%; height: 100dvh; }

#stage {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* ---------- hud ---------- */
.hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
    pointer-events: none;
}
.hud > * { pointer-events: auto; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 36px;
    padding: 0 8px;
    border: 1px solid rgba(255, 194, 74, 0.3);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--ink);
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    flex: 0 0 auto;
}
.icon-btn-text { font-size: 13px; }

.score-block { display: flex; flex-direction: column; line-height: 1.1; }
.score {
    font-size: 30px;
    font-weight: 800;
    color: var(--gold);
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
    font-variant-numeric: tabular-nums;
}
.best { font-size: 11px; color: var(--muted); }
.best b { color: var(--ink); }

.hud-right { flex: 1; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.lives { display: flex; gap: 4px; }
.life {
    width: 18px; height: 18px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ff8a6b, #c62f1e);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.life.spent { background: rgba(255, 255, 255, 0.12); box-shadow: none; }
.clock {
    padding: 2px 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.35);
    font-size: 16px;
    font-weight: 800;
    color: var(--gold);
    font-variant-numeric: tabular-nums;
}
.clock.low { color: #ff7a6a; }

.combo {
    position: absolute;
    top: 34%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.7);
    font-size: 30px;
    font-weight: 900;
    color: var(--gold);
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
    letter-spacing: 2px;
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
}
.combo.show { animation: burst 1s ease forwards; }
@keyframes burst {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6) rotate(-6deg); }
    22% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(2deg); }
    70% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* ---------- overlays ---------- */
.overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(20, 9, 3, 0.9);
    z-index: 20;
}
.overlay.is-open { display: flex; }
.overlay-card {
    width: 100%;
    max-width: 330px;
    padding: 26px 20px;
    border-radius: 20px;
    background: linear-gradient(180deg, #4a2a12, #331a09);
    border: 1px solid rgba(255, 194, 74, 0.28);
    text-align: center;
}
.title {
    font-size: 33px;
    letter-spacing: 5px;
    color: var(--gold);
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}
.subtitle { margin: 8px 0 20px; font-size: 13px; color: var(--muted); }
.tip { margin-top: 14px; font-size: 11px; color: var(--muted); }

.mode {
    display: block;
    width: 100%;
    margin-bottom: 9px;
    padding: 12px 16px;
    border: 1px solid rgba(255, 194, 74, 0.3);
    border-radius: 13px;
    background: rgba(0, 0, 0, 0.24);
    color: var(--ink);
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    min-height: 56px;
}
.mode:active { background: rgba(0, 0, 0, 0.4); }
.mode b { display: block; font-size: 17px; color: var(--gold); }
.mode span { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }

.btn {
    min-height: 48px;
    width: 100%;
    margin-top: 9px;
    padding: 0 18px;
    border: 1px solid rgba(255, 194, 74, 0.35);
    border-radius: 13px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
}
.btn-primary {
    background: linear-gradient(180deg, #ffcb63, #e2942a);
    border-color: #ffd98a;
    color: #3a2205;
}
.over-title { font-size: 27px; color: var(--gold); letter-spacing: 3px; }
.over-sub { margin: 6px 0 14px; font-size: 13px; color: var(--muted); min-height: 18px; }
.result-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 4px;
    font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
