*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #070c18;
    --panel: rgba(16, 24, 46, 0.96);
    --line: #2b3c66;
    --text: #eaf2ff;
    --muted: #8fa4cc;
    --accent: #59c2ff;
    --gold: #ffd76a;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

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

/* ===== HUD ===== */
.hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding:
        max(8px, env(safe-area-inset-top))
        max(10px, env(safe-area-inset-right)) 0
        max(10px, env(safe-area-inset-left));
    pointer-events: none;
}

.hud-row { display: flex; align-items: center; gap: 8px; padding-right: 46px; }

.badge {
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(6, 12, 26, 0.7);
    font-size: 0.76rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
}

.badge-mid { flex: 1; text-align: center; background: transparent; font-size: 0.9rem; color: var(--muted); }

.powers { display: flex; gap: 4px; flex-wrap: wrap; }

.power {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    border-radius: 7px;
    background: rgba(6, 12, 26, 0.75);
    font-size: 0.62rem;
    font-weight: 700;
}

.power b { font-size: 0.7rem; }

.p-wide { color: #6ee7a8; } .p-multi { color: #ffd76a; } .p-slow { color: #8fb6ff; }
.p-laser { color: #ff7a9c; } .p-catch { color: #c79bff; } .p-life { color: #ff9e6b; }

.pause-btn {
    position: absolute;
    top: max(26px, calc(env(safe-area-inset-top) + 18px));
    right: max(10px, env(safe-area-inset-right));
    width: 38px; height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(6, 12, 26, 0.8);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    z-index: 5;
}

.pause-btn:active { transform: scale(0.94); }

/* ===== Overlays ===== */
.overlay {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center; padding: 18px;
    background: rgba(3, 6, 14, 0.88);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    z-index: 10;
}

.overlay.is-open { display: flex; }

.panel {
    width: 100%; max-width: 340px; max-height: 100%; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
    padding: 22px 18px;
    border: 1px solid var(--line); border-radius: 20px;
    background: var(--panel);
    text-align: center;
    animation: pop 0.22s ease;
}

@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }

.title {
    font-size: clamp(1.9rem, 9vw, 2.5rem);
    font-weight: 800;
    letter-spacing: 0.16em;
    background: linear-gradient(135deg, var(--accent), #a56bff 60%, var(--gold));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}

.panel-title { font-size: 1.5rem; font-weight: 800; letter-spacing: 0.08em; color: var(--gold); }
.subtitle { color: var(--muted); font-size: 0.85rem; line-height: 1.65; }

.btn {
    min-height: 48px; padding: 13px 20px;
    border: 1px solid var(--line); border-radius: 14px;
    background: rgba(255, 255, 255, 0.06); color: var(--text);
    font-family: inherit; font-size: 0.94rem; font-weight: 700; letter-spacing: 0.05em;
    text-decoration: none; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform 0.12s ease;
}

.btn:active { transform: scale(0.96); }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, var(--accent), #2b7fff); color: #04121f; }
.btn-secondary { border-color: #7a4dd8; background: rgba(122, 77, 216, 0.16); color: #e2d2ff; }

.legend { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); text-align: left; }
.legend h3 { margin-bottom: 7px; font-size: 0.68rem; letter-spacing: 0.14em; color: var(--muted); text-align: center; }
.legend-row { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; font-size: 0.76rem; color: var(--muted); }
.legend-row b { width: 20px; text-align: center; font-size: 0.9rem; }

.best-line { font-size: 0.8rem; color: var(--muted); }
.best-line b { color: var(--gold); font-variant-numeric: tabular-nums; }

.toolbar { display: flex; justify-content: center; gap: 8px; margin-top: 2px; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; height: 34px; padding: 0 10px;
    border: 1px solid var(--line); border-radius: 10px;
    background: rgba(255, 255, 255, 0.06); color: var(--text);
    font-family: inherit; font-size: 0.9rem; text-decoration: none; cursor: pointer;
}

.icon-btn-text { font-size: 0.76rem; font-weight: 700; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat { padding: 9px 6px; border-radius: 11px; background: rgba(255, 255, 255, 0.06); }
.stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.64rem; color: var(--muted); }

@media (max-height: 620px) {
    .legend { display: none; }
    .btn { min-height: 44px; padding: 11px 18px; }
}

@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }
