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

:root {
    --bg: #06120c;
    --panel: rgba(10, 30, 20, 0.96);
    --line: #235c40;
    --text: #e8fff2;
    --muted: #8fc4a8;
    --accent: #5fe39b;
    --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 {
    position: absolute; top: 0; left: 0; right: 0;
    display: flex; align-items: center; gap: 8px;
    padding:
        max(8px, env(safe-area-inset-top))
        calc(max(10px, env(safe-area-inset-right)) + 46px) 0
        max(10px, env(safe-area-inset-left));
    pointer-events: none;
}

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

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

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

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

.overlay {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center; padding: 18px;
    background: rgba(2, 8, 5, 0.9);
    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), #4cc6ff 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.7; }

.modes { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

.mode {
    display: flex; align-items: center; justify-content: space-between;
    padding: 13px 16px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.95rem; font-weight: 700; cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.mode small { font-size: 0.68rem; font-weight: 500; color: var(--muted); }
.mode:active { transform: scale(0.98); border-color: var(--accent); }

.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), #21b073); color: #032313; }
.btn-secondary { border-color: #7a4dd8; background: rgba(122, 77, 216, 0.16); color: #e2d2ff; }

.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 (prefers-reduced-motion: reduce) { .panel { animation: none; } }
