/* ===== Reset & base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #07070f;
    --panel: rgba(16, 16, 34, 0.96);
    --border: #2c2c58;
    --text: #e8e8ff;
    --muted: #8c8cba;
    --accent: #00e0ff;
    --xp: #4ea8ff;
    --hp: #ff5566;
    --gold: #ffcc44;
}

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;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding:
        max(8px, env(safe-area-inset-top))
        max(10px, env(safe-area-inset-right))
        max(10px, env(safe-area-inset-bottom))
        max(10px, env(safe-area-inset-left));
    pointer-events: none;
}

.hud-top { display: flex; flex-direction: column; gap: 5px; }

.xp-bar, .hp-bar {
    height: 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.xp-fill, .hp-fill {
    display: block;
    height: 100%;
    width: 0%;
    border-radius: 999px;
    transition: width 0.16s ease;
}

.xp-fill { background: linear-gradient(90deg, var(--xp), #9ad4ff); }
.hp-fill { background: linear-gradient(90deg, var(--hp), #ff9aa4); width: 100%; }

/* Right padding keeps the kill counter clear of the pause button, which is
   positioned over this row. */
.hud-line { display: flex; align-items: center; gap: 8px; padding-right: 46px; }

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

.hud-timer {
    flex: 1;
    text-align: center;
    font-size: 1.25rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}

.hud-bottom { display: flex; flex-direction: column; gap: 6px; }

.weapon-strip { display: flex; gap: 5px; flex-wrap: wrap; }

.weapon-pip {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px 7px;
    border-radius: 8px;
    background: rgba(10, 10, 26, 0.75);
    font-size: 0.66rem;
    font-weight: 700;
}

.weapon-pip i { font-style: normal; font-size: 0.8rem; }
.weapon-pip b { color: var(--gold); font-variant-numeric: tabular-nums; }

.pause-btn {
    position: absolute;
    top: max(30px, calc(env(safe-area-inset-top) + 22px));
    right: max(10px, env(safe-area-inset-right));
    width: 38px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(10, 10, 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(4, 4, 12, 0.86);
    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: 11px;
    padding: 22px 18px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--panel);
    text-align: center;
    animation: pop 0.2s ease;
}

.panel-wide { max-width: 420px; }

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

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

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

.btn {
    min-height: 48px;
    padding: 13px 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(30, 30, 62, 0.9);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    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), #0090ff); color: #041018; }
.btn-secondary { border-color: #7a4dd8; background: rgba(122, 77, 216, 0.16); color: #e2d2ff; }

.rows { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }

.row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.78rem;
    color: var(--muted);
}

.row span:first-child { color: var(--accent); font-weight: 700; }

.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: 4px; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(30, 30, 62, 0.8);
    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; }
.icon-btn:active { border-color: var(--accent); }

/* ===== Level-up cards ===== */
.cards { display: flex; flex-direction: column; gap: 9px; }

.card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: rgba(28, 28, 60, 0.92);
    color: var(--text);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.card:active { transform: scale(0.98); border-color: var(--accent); }
.card-icon { flex: 0 0 auto; font-size: 1.6rem; width: 34px; text-align: center; }
.card-body { flex: 1; min-width: 0; }
.card-name { display: block; font-size: 0.95rem; font-weight: 700; }
.card-name b { color: var(--gold); font-size: 0.76rem; margin-left: 6px; }
.card-desc { display: block; margin-top: 2px; font-size: 0.75rem; color: var(--muted); line-height: 1.5; }

/* ===== Stats ===== */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }

.stat {
    padding: 9px 6px;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.055);
}

.stat b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.66rem; color: var(--muted); }

@media (max-height: 620px) {
    .panel { padding: 16px 14px; gap: 9px; }
    .rows { display: none; }
    .card { padding: 10px 12px; }
    .btn { min-height: 44px; padding: 11px 18px; }
}

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