:root {
    --bg-page: #09090b;
    --bg-surface: #111114;
    --bg-elevated: #17171a;
    --bg-overlay: rgba(9,9,11,0.85);

    --ink: #fafafa;
    --ink-muted: #a1a1aa;
    --ink-subtle: #71717a;
    --ink-faint: #52525b;

    --border: rgba(250,250,250,0.08);
    --border-strong: rgba(250,250,250,0.15);

    --accent: #a67c1f;
    --accent-bright: #d4a94c;
    --accent-hover: #8f6b1b;
    --accent-fg: #ffffff;

    --staff-bg: #fafafa;
    --staff-border: #27272a;
    --staff-ink: #09090b;

    --key-white: #fafafa;
    --key-white-border: #27272a;
    --key-white-hover: #e4e4e7;
    --key-white-active: #d4d4d8;
    --key-black: #050506;
    --key-black-active: #0a0a0b;
    --piano-bg: transparent;
    --key-shadow: 0 2px 6px rgba(0,0,0,0.5), 0 0 0 1px rgba(250,250,250,0.05);

    --fx-correct: #10b981;
    --fx-correct-fg: #ffffff;
    --fx-correct-glow: rgba(16,185,129,0.3);
    --fx-wrong: #ef4444;
    --fx-wrong-fg: #ffffff;
    --fx-wrong-glow: rgba(239,68,68,0.3);
    --fx-missed: #d4a94c;
    --fx-missed-fg: #09090b;
    --fx-missed-glow: rgba(212,169,76,0.3);

    --stat-score: var(--ink);
    --stat-streak: var(--ink-muted);
    --stat-lives: #ef4444;
    --stat-lives-soft: rgba(239,68,68,0.3);
    --stat-level: var(--accent-bright);
    --stat-level-soft: rgba(212,169,76,0.2);
    --stat-level-track: rgba(212,169,76,0.12);
}

[data-theme="bright"] {
    --bg-page: #f4f4f5;
    --bg-surface: #ffffff;
    --bg-elevated: #fafafa;
    --bg-overlay: rgba(9,9,11,0.5);

    --ink: #09090b;
    --ink-muted: #52525b;
    --ink-subtle: #71717a;
    --ink-faint: #a1a1aa;

    --border: rgba(9,9,11,0.08);
    --border-strong: rgba(9,9,11,0.15);

    --accent: #a67c1f;
    --accent-bright: #a67c1f;
    --accent-hover: #8f6b1b;
    --accent-fg: #ffffff;

    --staff-bg: #ffffff;
    --staff-border: #e4e4e7;
    --staff-ink: #09090b;

    --key-white: #ffffff;
    --key-white-border: #d4d4d8;
    --key-white-hover: #f4f4f5;
    --key-white-active: #e4e4e7;
    --key-black: #18181b;
    --key-black-active: #27272a;
    --piano-bg: transparent;
    --key-shadow: 0 3px 8px rgba(9,9,11,0.18), 0 0 0 1px rgba(9,9,11,0.06);

    --fx-correct: #059669;
    --fx-correct-fg: #ffffff;
    --fx-correct-glow: rgba(5,150,105,0.3);
    --fx-wrong: #dc2626;
    --fx-wrong-fg: #ffffff;
    --fx-wrong-glow: rgba(220,38,38,0.3);
    --fx-missed: #a67c1f;
    --fx-missed-fg: #ffffff;
    --fx-missed-glow: rgba(166,124,31,0.3);

    --stat-score: var(--ink);
    --stat-streak: var(--ink-muted);
    --stat-lives: #dc2626;
    --stat-lives-soft: rgba(220,38,38,0.3);
    --stat-level: var(--accent);
    --stat-level-soft: rgba(166,124,31,0.2);
    --stat-level-track: rgba(166,124,31,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg-page);
    color: var(--ink);
    height: 100vh;
    height: -webkit-fill-available;
    height: 100dvh;
    overflow: hidden;
    transition: background 300ms ease, color 300ms ease;
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
}
.app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: -webkit-fill-available;
    height: 100dvh;
    overflow: hidden;
    padding-top: env(safe-area-inset-top, 0px);
}

/* ── Top bar ── */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(0.25rem, 0.5vw, 0.5rem) calc(clamp(0.4rem, 1.5vw, 1.5rem) + env(safe-area-inset-right, 0px)) clamp(0.25rem, 0.5vw, 0.5rem) calc(clamp(0.4rem, 1.5vw, 1.5rem) + env(safe-area-inset-left, 0px));
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    gap: 0.3rem;
    flex-shrink: 0;
}

.logo {
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 700;
    font-size: clamp(0.75rem, 2.5vw, 1rem);
    color: var(--ink);
    letter-spacing: -0.01em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: clamp(0.2rem, 0.5vw, 0.25rem);
}
.logo-icon {
    width: clamp(0.875rem, 2vw, 1.125rem);
    height: clamp(0.875rem, 2vw, 1.125rem);
    flex-shrink: 0;
}
.top-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
}
.top-right {
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
}
.game-stats {
    display: flex;
    align-items: center;
    gap: 0;
}
.stats-bar {
    display: flex;
    gap: 0;
    align-items: stretch;
}
.stat { text-align: center; width: clamp(28px, 3.5vw, 36px); height: clamp(28px, 3.5vw, 36px); flex-shrink: 0; }
.stat-value {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(0.65rem, 1.5vw + 0.2rem, 1rem);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.stat-value.score { color: var(--stat-score); }
.stat-value.streak { color: var(--stat-streak); }

/* ── Score circle ── */
.score-circle {
    position: relative;
    width: clamp(28px, 3.5vw, 36px);
    height: clamp(28px, 3.5vw, 36px);
    border-radius: 50%;
    border: 1.5px solid var(--border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.score-note-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.score-note-path {
    fill: var(--stat-score);
    opacity: 0.18;
    transition: opacity 0.3s ease;
}
.score-number {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--stat-score);
    line-height: 1;
    overflow: hidden;
    font-variant-numeric: tabular-nums;
}

/* ── Streak circle ── */
.streak-circle {
    position: relative;
    width: clamp(28px, 3.5vw, 36px);
    height: clamp(28px, 3.5vw, 36px);
    border-radius: 50%;
    border: 1.5px solid var(--border-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.streak-flame-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.streak-flame-path {
    fill: var(--stat-streak);
    opacity: 0.2;
    transition: opacity 0.3s ease;
}
.streak-number {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--stat-streak);
    line-height: 1;
    overflow: hidden;
    max-width: clamp(28px, 3.5vw, 36px);
    font-variant-numeric: tabular-nums;
}

/* ── Lives circle ── */
.lives-circle {
    position: relative;
    width: clamp(28px, 3.5vw, 36px);
    height: clamp(28px, 3.5vw, 36px);
    border-radius: 50%;
    border: 1.5px solid var(--stat-lives-soft);
    display: flex;
    align-items: center;
    justify-content: center;
}
.lives-circle.warning { animation: pulse 0.5s infinite; }
.lives-heart-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.lives-heart-path {
    fill: var(--stat-lives);
    opacity: 0.22;
    transition: opacity 0.3s ease;
}
.lives-heart-path.heart-break { animation: heartBreak 0.5s ease-out forwards; }
.lives-number {
    position: relative;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--stat-lives);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
@keyframes heartBreak {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.3); opacity: 0.8; }
    100% { transform: scale(0.3); opacity: 0; }
}

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

/* ── Stat circle pulses (score/lives/level gained feedback) ── */
.score-circle.gained {
    animation: score-gained-pulse 0.4s ease-out;
    will-change: box-shadow;
}
@keyframes score-gained-pulse {
    0% { box-shadow: 0 0 0 0 var(--fx-correct-glow); }
    100% { box-shadow: 0 0 0 10px rgba(16,185,129,0); }
}
.score-circle.gained .score-note-path { opacity: 0.5; }

.lives-circle.life-gained {
    animation: life-gained-pulse 0.5s ease-out;
    will-change: box-shadow;
}
@keyframes life-gained-pulse {
    0% { box-shadow: 0 0 0 0 var(--stat-lives-soft); }
    100% { box-shadow: 0 0 0 14px rgba(239,68,68,0); }
}
.lives-circle.life-gained .lives-heart-path {
    animation: heart-beat 0.5s ease-out;
}
@keyframes heart-beat {
    0% { transform-origin: center; transform: scale(1); opacity: 0.22; }
    40% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 0.22; }
}

.level-circle.level-up {
    animation: level-up-pulse 0.6s ease-out;
    will-change: box-shadow, transform;
}
@keyframes level-up-pulse {
    0% {
        box-shadow: 0 0 0 0 var(--stat-level-soft);
        border-color: var(--stat-level);
    }
    50% {
        box-shadow: 0 0 0 8px var(--stat-level-track);
        border-color: var(--stat-level);
    }
    100% {
        box-shadow: 0 0 0 18px rgba(212,169,76,0);
        border-color: var(--stat-level-soft);
    }
}
.level-circle.level-up .level-number {
    animation: level-number-bounce 0.6s ease-out;
}
@keyframes level-number-bounce {
    0%, 100% { transform: scale(1); }
    40% { transform: scale(1.3); }
}

/* ── Timer bar tier-up flash (speed increase) ── */
.note-timer-bar.tier-up {
    animation: timer-tier-up 0.7s ease-out;
    will-change: box-shadow;
}
@keyframes timer-tier-up {
    0% { box-shadow: 0 0 0 0 var(--stat-level-soft); }
    30% { box-shadow: 0 0 8px 2px var(--stat-level-soft); }
    100% { box-shadow: 0 0 0 0 rgba(212,169,76,0); }
}
.note-timer-bar.tier-up .note-timer-fill {
    animation: timer-fill-flash 0.7s ease-out;
}
@keyframes timer-fill-flash {
    0%, 100% { filter: brightness(1); }
    30% { filter: brightness(1.4); }
}

.pause-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    width: clamp(44px, 5vw, 48px);
    height: clamp(44px, 5vw, 48px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.1s;
    font-size: clamp(0.75rem, 1.4vw, 0.9rem);
    color: var(--ink-muted);
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}
.pause-btn:hover { border-color: var(--accent); color: var(--ink); }
.pause-btn:active {
    transform: scale(0.94);
    background: var(--bg-surface);
    border-color: var(--accent);
    color: var(--ink);
}

/* ── Toggle switch ── */
.toggle {
    position: relative;
    width: 48px;
    height: 32px;
    flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-elevated);
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.3s, border-color 0.3s;
    border: 1px solid var(--border-strong);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 22px;
    height: 22px;
    background: var(--ink-subtle);
    border-radius: 50%;
    transition: transform 0.3s, background 0.3s;
    -webkit-transform: translateX(0);
    transform: translateX(0);
}
.toggle input:checked + .toggle-slider {
    background: rgba(166,124,31,0.25);
    border-color: var(--accent);
}
.toggle input:checked + .toggle-slider::before {
    -webkit-transform: translateX(18px);
    transform: translateX(18px);
    background: var(--accent);
}

/* ── Main game area ── */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(0.3rem, 1.5vw, 1rem) clamp(0.3rem, 2vw, 0.5rem) clamp(0.1rem, 0.5vw, 0.2rem) clamp(0.3rem, 2vw, 0.5rem);
    gap: clamp(0.3rem, 1vw, 0.8rem);
    flex: 1;
    min-height: 0;
    justify-content: center;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

/* ── Staff ── */
.staff-wrapper {
    position: relative;
    background: var(--staff-bg);
    border: 1px solid var(--staff-border);
    border-radius: 6px;
    padding: 1.5rem 2rem;
    transition: border-color 0.3s, box-shadow 0.3s;
    flex: 1.3;
    min-height: 0;
    max-height: 500px;
    aspect-ratio: 340 / 160;
    width: auto;
    align-self: center;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    contain: layout paint;
    -webkit-touch-callout: none;
}
.staff-wrapper.dual {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    gap: 12px;
    aspect-ratio: 680 / 160;
}
.staff-wrapper > svg {
    width: 100%;
    height: auto;
    max-height: 100%;
    display: block;
}

.staff-dual {
    flex: 1;
    min-width: 0;
    min-height: 0;
    background: var(--staff-bg);
    border: 1px solid var(--staff-border);
    border-radius: 6px;
    padding: 1rem 1.2rem;
    transition: border-color 0.3s, box-shadow 0.3s;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    contain: layout paint;
}
.staff-dual > svg {
    width: 100%;
    height: 100%;
    display: block;
}
.staff-wrapper.correct {
    box-shadow: 0 0 0 2px var(--fx-correct-glow);
}
.staff-wrapper.correct .staff-dual {
    box-shadow: 0 0 0 2px var(--fx-correct-glow);
}
.staff-wrapper.wrong {
    animation: shake 0.4s ease;
    box-shadow: 0 0 0 2px var(--fx-wrong-glow);
    will-change: transform;
}
.staff-wrapper.wrong .staff-dual {
    box-shadow: 0 0 0 2px var(--fx-wrong-glow);
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-12px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-8px); }
    80% { transform: translateX(6px); }
}

/* ── Floating +points ── */
.float-points {
    position: absolute;
    top: 0.4rem;
    right: 0.6rem;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(0.7rem, 1.4vw + 0.2rem, 0.9rem);
    font-weight: 700;
    pointer-events: none;
    animation: floatUp 0.5s ease-out forwards;
    z-index: 10;
    will-change: transform, opacity;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.float-points.positive { color: var(--fx-correct); }
@keyframes floatUp {
    0% { opacity: 0; transform: translate(0, 4px); }
    20% { opacity: 0.95; transform: translate(0, 0); }
    100% { opacity: 0; transform: translate(10px, -14px); }
}

.pressed-note {
    animation: pressedNoteFade 1.2s ease-out forwards;
}
@keyframes pressedNoteFade {
    0% { opacity: 0.6; }
    100% { opacity: 0; }
}

/* ── Note name reveal (timeout) ── */
.note-name-reveal {
    position: absolute;
    top: 50%;
    left: 50%;
    opacity: 0;
    transform: translate(-50%, -50%);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(1.4rem, 4.5vw, 2.4rem);
    font-weight: 700;
    color: var(--accent);
    pointer-events: none;
    animation: noteNameReveal 1100ms ease-out forwards;
    z-index: 10;
    letter-spacing: 0.02em;
    white-space: nowrap;
    will-change: transform, opacity;
}
@keyframes noteNameReveal {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
    15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
    30%  { opacity: 1; transform: translate(-50%, -50%) scale(1);    }
    80%  { opacity: 1; transform: translate(-50%, -52%) scale(1);    }
    100% { opacity: 0; transform: translate(-50%, -58%) scale(0.95); }
}

/* ── History panel ── */
.history-section {
    margin-top: 1.5rem;
    width: 100%;
    max-width: min(700px, 95vw);
}
.history-columns {
    display: flex;
    gap: 1.5rem;
    width: 100%;
}
.history-column {
    flex: 1;
    min-width: 0;
}
.history-title {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 500;
    color: var(--ink-subtle);
    margin-bottom: 0.8rem;
    text-align: center;
}
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.history-entry {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: clamp(0.5rem, 0.8vw, 0.6rem) clamp(0.6rem, 1vw, 0.8rem);
    transition: background 0.2s, border-color 0.2s;
}
.history-entry:hover {
    background: var(--bg-surface);
    border-color: var(--border-strong);
}
.history-entry.last-play {
    background: linear-gradient(135deg, rgba(212, 169, 76, 0.20), rgba(212, 169, 76, 0.06));
    border-color: var(--accent-bright);
    box-shadow: 0 0 18px rgba(212, 169, 76, 0.28), 0 0 36px rgba(212, 169, 76, 0.14);
    animation: last-play-glow 1.4s ease-in-out 3;
}
[data-theme="bright"] .history-entry.last-play {
    background: linear-gradient(135deg, rgba(166, 124, 31, 0.18), rgba(166, 124, 31, 0.06));
    box-shadow: 0 0 18px rgba(166, 124, 31, 0.28), 0 0 36px rgba(166, 124, 31, 0.14);
}
@keyframes last-play-glow {
    0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(212, 169, 76, 0), 0 0 0 0 rgba(212, 169, 76, 0); }
    50%  { transform: scale(1.03); box-shadow: 0 0 32px 8px rgba(212, 169, 76, 0.55), 0 0 60px 12px rgba(212, 169, 76, 0.30); }
    100% { transform: scale(1);    box-shadow: 0 0 18px rgba(212, 169, 76, 0.28), 0 0 36px rgba(212, 169, 76, 0.14); }
}
@media (prefers-reduced-motion: reduce) {
    .history-entry.last-play {
        animation: none;
    }
}
.history-rank {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.history-rank.gold { color: #d4a94c; }
.history-rank.silver { color: #d4d4d8; }
.history-rank.bronze { color: #a67c1f; }
.history-rank.other { color: var(--ink-faint); }
.history-grade {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 1rem;
    font-weight: 700;
    width: 36px;
    text-align: center;
    flex-shrink: 0;
}
.history-info {
    flex: 1;
    min-width: 0;
}
.history-score-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.history-score {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(0.85rem, 1.5vw, 0.95rem);
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.history-options {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.history-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 0.3rem;
    font-family: 'Noto Music', 'Inter', system-ui, sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1;
    color: var(--ink-muted);
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    letter-spacing: 0;
}
.history-option.acc {
    color: var(--accent);
    background: var(--bg-surface);
    border-color: var(--accent);
}
.history-mode-tag {
    font-size: 0.55rem;
    background: var(--accent);
    color: var(--accent-fg);
    padding: 1px 5px;
    border-radius: 4px;
    letter-spacing: 0.05em;
    vertical-align: middle;
    margin-left: 4px;
}
.history-meta {
    font-size: clamp(0.55rem, 1vw, 0.65rem);
    color: var(--ink-faint);
    letter-spacing: 0.03em;
}
.history-empty {
    text-align: center;
    color: var(--ink-faint);
    font-size: 0.8rem;
    padding: 1rem;
}

/* ── Start screen settings ── */
/* ── PWA install button (Android/Chrome) ── */
.pwa-install-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.7rem 1.6rem;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-fg);
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: background 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}
.pwa-install-btn:hover {
    background: var(--accent-hover);
}
.pwa-install-btn.hidden { display: none; }
.pwa-install-icon {
    font-size: 1rem;
    line-height: 1;
}

/* ── PWA prompt (iOS Safari fallback) ── */
.pwa-prompt {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 0.6rem 1.2rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    max-width: 560px;
    width: 100%;
}
.pwa-prompt.hidden { display: none; }
.pwa-prompt-text {
    font-size: 0.8rem;
    color: var(--ink-muted);
    margin-bottom: 0.4rem;
}
.pwa-prompt-steps {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.pwa-step {
    font-size: 0.85rem;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.pwa-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--accent);
}

.start-settings {
    display: flex;
    flex-direction: column;
    gap: clamp(0.3rem, 1vw, 1rem);
    margin-bottom: clamp(0.5rem, 1.5vw, 1.2rem);
    width: 100%;
    max-width: min(560px, 95vw);
}
.start-settings-section {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.start-settings-title {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 500;
    color: var(--ink-subtle);
    padding-left: 0.3rem;
}
.start-settings-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}
.start-setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: clamp(0.3rem, 0.8vw, 0.55rem) clamp(0.5rem, 1vw, 0.8rem);
}
.start-setting-row--full {
    grid-column: 1 / -1;
}
.start-setting-label {
    font-size: clamp(0.7rem, 1.5vw, 0.85rem);
    color: var(--ink);
}

/* ── Piano ── */
.piano-container {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    touch-action: manipulation;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: var(--piano-bg);
    flex: 1;
    min-height: 0;
    contain: layout;
    -webkit-touch-callout: none;
}
.piano {
    display: flex;
    position: relative;
    height: var(--piano-h, 140px);
    margin: 0 auto;
    width: fit-content;
    max-width: 100%;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.key {
    position: relative;
    cursor: pointer;
    transition: background 0.1s;
    border-radius: 0 0 4px 4px;
    flex-shrink: 0;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    contain: layout paint style;
}
.key-white {
    width: var(--key-white-w, 32px);
    height: var(--piano-h, 140px);
    background: var(--key-white);
    border: 1px solid var(--key-white-border);
    border-top: none;
    z-index: 1;
    margin: 0 0.5px;
    box-shadow: var(--key-shadow);
}
.key-white:hover {
    background: var(--key-white-hover);
}
.key-white:active, .key-white.pressed {
    background: var(--key-white-active);
}
.key-white .key-label {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(0.4rem, 0.8vw, 0.5rem);
    font-weight: 500;
    color: var(--accent);
    opacity: 0.55;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    pointer-events: none;
    white-space: nowrap;
}
.key-black {
    width: var(--key-black-w, 22px);
    height: var(--piano-black-h, 88px);
    background: var(--key-black);
    border: 1px solid var(--key-black);
    border-top: none;
    z-index: 2;
    margin: 0 calc(var(--key-black-w, 22px) / -2);
    box-shadow: var(--key-shadow);
}
.key-black:active, .key-black.pressed {
    background: var(--key-black-active);
    height: calc(var(--piano-black-h, 88px) - 2px);
}
.key-black .key-label {
    display: none;
}
.key-white.flash-correct {
    background: var(--fx-correct) !important;
    box-shadow: 0 0 20px var(--fx-correct-glow);
}
.key-white.flash-wrong {
    background: var(--fx-wrong) !important;
    box-shadow: 0 0 20px var(--fx-wrong-glow);
}
.key-black.flash-correct {
    background: var(--fx-correct) !important;
    box-shadow: 0 0 20px var(--fx-correct-glow);
}
.key-black.flash-wrong {
    background: var(--fx-wrong) !important;
    box-shadow: 0 0 20px var(--fx-wrong-glow);
}
.key-white.flash-missed {
    background: var(--fx-missed) !important;
    box-shadow: 0 0 20px var(--fx-missed-glow);
    animation: keyMissedPulse 800ms ease-out;
}
.key-black.flash-missed {
    background: var(--fx-missed) !important;
    box-shadow: 0 0 20px var(--fx-missed-glow);
    animation: keyMissedPulse 800ms ease-out;
}
@keyframes keyMissedPulse {
    0%   { filter: brightness(0.95); }
    20%  { filter: brightness(1.15); }
    100% { filter: brightness(1); }
}

.key-white.disabled {
    background: var(--key-white-hover) !important;
    opacity: 0.4;
    pointer-events: none;
}
.key-black.disabled {
    background: var(--key-black-active) !important;
    opacity: 0.4;
    pointer-events: none;
}

/* ── Start / End screens ── */
.overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    z-index: 100;
    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);
}
@supports (backdrop-filter: blur(4px)) {
    .overlay {
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
}
.overlay-scroll {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}
.overlay-content {
    margin: auto 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
}
.overlay.hidden { display: none; }

.overlay-title {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(1.3rem, 5vw + 0.5rem, 3rem);
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.02em;
    text-transform: uppercase;
    margin-bottom: clamp(0.15rem, 0.5vw, 0.5rem);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.overlay-title .logo-icon {
    width: clamp(1.5rem, 4vw, 3rem);
    height: clamp(1.5rem, 4vw, 3rem);
    flex-shrink: 0;
}
.overlay-subtitle {
    color: var(--ink-muted);
    font-size: clamp(0.75rem, 2.5vw, 1rem);
    margin-bottom: clamp(0.5rem, 2vw, 2rem);
}
.start-btn {
    padding: clamp(0.65rem, 1.5vw + 0.3rem, 1.1rem) clamp(2rem, 5vw, 3rem);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(0.85rem, 2.5vw, 1.1rem);
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-fg);
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: background 0.2s, opacity 0.3s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 48px;
}
.start-btn:hover {
    background: var(--accent-hover);
}
.start-btn.disabled,
.start-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--accent);
}

/* ── End screen — summary card ── */
.end-grade-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    margin-block: clamp(0.8rem, 2vw, 1.5rem);
}
.end-grade {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(3rem, 6vw + 1rem, 4.5rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
}
.end-grade-scale {
    display: inline-flex;
    gap: 0.35rem;
    justify-content: center;
    flex-wrap: wrap;
}
.end-grade-pill {
    padding: 0.25rem 0.55rem;
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 600;
    font-size: clamp(0.6rem, 1.5vw, 0.75rem);
    letter-spacing: 0.05em;
    border-radius: 6px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--ink-faint);
    transition: background 0.3s, border-color 0.3s, color 0.3s;
}

.end-hero-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: clamp(0.8rem, 2vw, 1.2rem) clamp(1.2rem, 3vw, 2rem);
    margin: clamp(0.5rem, 1.5vw, 1rem) 0;
    text-align: center;
    width: min(360px, 92vw);
}
.end-hero-label {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 500;
    color: var(--ink-subtle);
}
.end-hero-value {
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw + 0.5rem, 3rem);
    line-height: 1;
    color: var(--accent-bright);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}
.end-hero-delta {
    font-size: clamp(0.7rem, 1.5vw, 0.85rem);
    font-weight: 600;
    min-height: 1.2em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.03em;
}

.end-breakdown {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: min(360px, 92vw);
    margin-bottom: clamp(0.8rem, 2vw, 1.2rem);
}
.end-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0.75rem;
    padding: clamp(0.5rem, 1.2vw, 0.7rem) clamp(0.8rem, 2vw, 1rem);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.end-row-label {
    font-size: clamp(0.7rem, 1.5vw, 0.85rem);
    color: var(--ink-muted);
}
.end-row-value {
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 600;
    font-size: clamp(0.85rem, 2vw, 1rem);
    color: var(--ink);
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.end-row-delta {
    font-size: clamp(0.6rem, 1.3vw, 0.7rem);
    font-weight: 600;
    min-width: 4.5rem;
    text-align: right;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.2rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.03em;
}

.end-row-delta.improved,
.end-hero-delta.improved {
    color: var(--fx-correct);
}
.end-row-delta.equal,
.end-hero-delta.equal {
    color: var(--ink-faint);
}
.end-row-delta.worse,
.end-hero-delta.worse {
    color: var(--fx-wrong);
}
.end-row-delta.empty {
    color: var(--ink-faint);
}
.end-hero-delta.empty {
    visibility: hidden;
}

.end-row-delta.new-best,
.end-hero-delta.new-best {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: var(--accent-fg);
    padding: 0.15rem 0.55rem;
    border-radius: 6px;
}

.end-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
}
.share-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.6rem;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}
.share-btn:hover {
    border-color: var(--accent);
    color: var(--ink);
    background: var(--bg-elevated);
}
.share-btn.hidden { display: none; }

/* ── Note timer bar ── */
.note-timer-bar {
    flex: 1;
    min-width: 0;
    height: clamp(6px, 1.5vw, 14px);
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    contain: layout paint;
}
.note-timer-fill {
    position: relative;
    height: 100%;
    width: 100%;
    background: var(--accent-bright);
    border-radius: 3px;
    transform-origin: left;
    transform: scaleX(1);
    will-change: transform;
}
.note-timer-fill.running {
    animation: note-timer-countdown var(--timer-duration, 5s) linear forwards;
}
.note-timer-fill.warning {
    background: var(--fx-wrong);
}
.note-timer-fill.warning::before {
    content: '';
    position: absolute;
    inset: 0;
    background: inherit;
    border-radius: inherit;
    animation: pulse 0.5s infinite;
    pointer-events: none;
    will-change: opacity;
}
@keyframes note-timer-countdown {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
    .staff-wrapper {
        padding: 1rem 0.8rem;
        border-radius: 6px;
    }
    .staff-wrapper.dual {
        padding: 0;
    }
    .staff-dual {
        border-radius: 6px;
        padding: 0.6rem 0.8rem;
    }
    .start-settings {
        max-width: 320px;
    }
    .start-settings-grid {
        grid-template-columns: 1fr 1fr;
    }
    .history-columns {
        flex-direction: column;
        gap: 1rem;
    }
    .top-right {
        justify-content: flex-end;
    }
    .stats-bar {
        flex: 1;
        justify-content: center;
    }
    .stat#statScore, .stat#statStreak {
        flex-shrink: 1;
    }
    .top-center {
        flex: 1;
        min-width: 0;
    }
    .note-timer-bar {
        height: 8px;
    }
}
@media (max-width: 480px), (max-height: 480px) {
    .staff-wrapper {
        padding: 0.5rem 0.8rem;
        border-radius: 6px;
    }
    .staff-dual {
        border-radius: 6px;
        padding: 0;
    }
    .overlay-title {
        margin-bottom: 0.15rem;
    }
    .overlay-subtitle {
        padding: 0 1rem;
    }
    .overlay-scroll {
        justify-content: flex-start;
        padding-block: 1rem;
        padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    }
    .note-timer-bar {
        height: 6px;
        border-radius: 3px;
    }
    .level-circle {
        width: clamp(24px, 3.5vw, 28px);
        height: clamp(24px, 3.5vw, 28px);
    }
    .level-number {
        font-size: 0.6rem;
    }
    .start-settings-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-height: 340px) {
    .top-center {
        display: none;
    }
    .history-section {
        display: none;
    }
    .start-settings-title {
        display: none;
    }
}

/* ── Very small phones (iPhone SE 1st gen, iPhone 5) ── */
@media (max-width: 375px) {
    .start-settings-grid {
        grid-template-columns: 1fr 1fr;
    }
    .start-settings {
        max-width: 280px;
    }
    .start-setting-row {
        padding: 0.25rem 0.4rem;
    }
    .start-setting-label {
        font-size: 0.65rem;
    }
    .overlay-title {
        font-size: clamp(1.1rem, 5vw, 1.6rem);
    }
    .overlay-title .logo-icon {
        width: 1.2rem;
        height: 1.2rem;
    }
    .end-hero-stat,
    .end-breakdown {
        width: min(300px, 92vw);
    }
    .end-hero-stat {
        padding: 0.7rem 1rem;
    }
    .history-entry {
        padding: 0.35rem 0.5rem;
        gap: 0.5rem;
    }
    .history-rank {
        font-size: 0.9rem;
        width: 22px;
    }
    .history-grade {
        font-size: 0.85rem;
        width: 28px;
    }
    .history-score {
        font-size: 0.75rem;
    }
    .history-meta {
        font-size: 0.5rem;
    }
    .staff-wrapper {
        padding: 0.4rem 0.5rem;
        border-radius: 6px;
    }
    .staff-dual {
        padding: 0;
        border-radius: 6px;
    }
}

/* ── Ultra-small phones (Galaxy Fold folded, 280-320px) ── */
@media (max-width: 320px) {
    .start-settings-grid {
        grid-template-columns: 1fr;
    }
    .start-settings {
        max-width: 260px;
    }
    .start-setting-row {
        padding: 0.2rem 0.35rem;
    }
    .start-setting-label {
        font-size: 0.6rem;
    }
    .overlay-title {
        font-size: clamp(1rem, 5vw, 1.3rem);
    }
    .overlay-subtitle {
        font-size: 0.65rem;
    }
    .end-hero-stat,
    .end-breakdown {
        width: min(260px, 94vw);
    }
    .end-hero-stat {
        padding: 0.6rem 0.9rem;
    }
    .end-row {
        padding: 0.45rem 0.7rem;
        gap: 0.5rem;
    }
    .overlay-scroll {
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
    }
}

/* ── Landscape phones ── */
@media (orientation: landscape) and (max-height: 500px) {
    .top-bar {
        padding-top: 0.2rem;
        padding-bottom: 0.2rem;
        padding-left: max(0.4rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.4rem, env(safe-area-inset-right, 0px));
    }
    .game-area {
        padding: 0.2rem 0.5rem;
        gap: 0.2rem;
    }
    .staff-wrapper {
        padding: 0.3rem 0.6rem;
        border-radius: 6px;
    }
    .staff-dual {
        padding: 0.2rem 0.4rem;
        border-radius: 6px;
    }
    .overlay-title {
        font-size: clamp(1rem, 4vw, 2rem);
        margin-bottom: 0.1rem;
    }
    .overlay-subtitle {
        margin-bottom: 0.3rem;
    }
    .start-settings {
        gap: 0.2rem;
        margin-bottom: 0.25rem;
        max-width: 420px;
    }
    .start-settings-title {
        display: none;
    }
    .start-settings-section + .start-settings-section {
        margin-top: 0.2rem;
    }
    .start-settings-grid {
        gap: 0.3rem;
    }
    .start-setting-row {
        padding: 0.28rem 0.7rem;
    }
    .start-btn {
        padding: 0.5rem 2.2rem;
        font-size: 0.9rem;
    }
    .end-grade-block {
        margin-block: 0.4rem;
        gap: 0.4rem;
    }
    .end-grade {
        font-size: clamp(2rem, 5vw, 3rem);
    }
    .end-hero-stat {
        margin: 0.35rem 0;
        padding: 0.55rem 1rem;
    }
    .end-hero-value {
        font-size: clamp(1.5rem, 4vw, 2.2rem);
    }
    .end-breakdown {
        margin-bottom: 0.4rem;
    }
    .end-row {
        padding: 0.35rem 0.7rem;
    }
}

/* ── Landscape tablets / large phones ── */
@media (min-width: 768px) and (orientation: landscape) {
    .staff-wrapper {
        padding: 1rem 1.5rem;
    }
}

/* ── Very tall phones (iPhone 14 Pro Max, Pixel 7 Pro, etc.) ── */
@media (min-height: 850px) and (max-width: 500px) and (orientation: portrait) {
    .game-area {
        gap: clamp(0.5rem, 2vw, 1.5rem);
        padding-block: clamp(0.5rem, 2vw, 1.5rem);
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Portrait overlay ── */
.portrait-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-page);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.portrait-overlay.visible {
    display: flex;
}
.portrait-icon {
    font-size: 3rem;
}
.portrait-text {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ink);
    text-align: center;
    letter-spacing: -0.01em;
}
.portrait-sub {
    font-size: 0.85rem;
    color: var(--ink-muted);
}
.portrait-dismiss {
    margin-top: 1rem;
    padding: 0.7rem 2rem;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--ink);
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: border-color 0.3s, background 0.3s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}
.portrait-dismiss:hover {
    border-color: var(--accent);
    background: var(--bg-surface);
}

.app.paused .game-area {
    filter: blur(10px) saturate(0.6);
    pointer-events: none;
    transition: filter 200ms ease;
}
.app.paused .top-bar {
    pointer-events: none;
}

.pause-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: safe center;
    justify-content: safe center;
    background: var(--bg-overlay);
    padding:
        calc(env(safe-area-inset-top, 0px) + 0.6rem)
        calc(env(safe-area-inset-right, 0px) + 0.6rem)
        calc(env(safe-area-inset-bottom, 0px) + 0.6rem)
        calc(env(safe-area-inset-left, 0px) + 0.6rem);
    animation: pause-overlay-in 180ms ease-out;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.pause-overlay.hidden { display: none; }
@supports (backdrop-filter: blur(6px)) {
    .pause-overlay {
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
}
@keyframes pause-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.pause-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(0.5rem, 1.4vw, 1rem);
    padding: clamp(0.9rem, 2.4vw, 1.4rem) clamp(1rem, 2.6vw, 1.5rem);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    max-width: min(340px, 92vw);
    width: 100%;
    flex-shrink: 0;
    animation: pause-content-in 200ms ease-out;
}
@keyframes pause-content-in {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}
.pause-overlay-title {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(1rem, 3vw, 1.4rem);
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--ink);
    text-transform: uppercase;
    margin: 0;
}
.pause-settings {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    width: 100%;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}
.pause-settings .start-setting-row {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.7rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.pause-settings .start-setting-label {
    font-size: 0.8rem;
    color: var(--ink);
}
.pause-overlay-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    width: 100%;
}
.pause-menu-btn {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: clamp(0.75rem, 2vw, 0.9rem);
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: clamp(0.5rem, 1.2vw, 0.7rem) 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 40px;
    width: 100%;
}
.pause-menu-btn.primary {
    border: none;
    background: var(--accent);
    color: var(--accent-fg);
}
.pause-menu-btn.primary:hover {
    background: var(--accent-hover);
}
.pause-menu-btn.secondary {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--ink);
}
.pause-menu-btn.secondary:hover {
    border-color: var(--accent);
    background: var(--bg-surface);
}
.pause-menu-btn.tertiary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--fx-wrong);
}
.pause-menu-btn.tertiary:hover {
    border-color: var(--fx-wrong);
    background: var(--bg-surface);
}

.small-screen-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-page);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.small-screen-overlay.visible {
    display: flex;
}
.small-screen-icon {
    font-size: 3rem;
}
.small-screen-text {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ink);
    text-align: center;
    letter-spacing: -0.01em;
}
.small-screen-sub {
    font-size: 0.85rem;
    color: var(--ink-muted);
    text-align: center;
    padding: 0 1rem;
}

/* ── Update-available banner ── */
.update-banner {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    padding: 0.55rem 0.75rem 0.55rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--ink);
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    animation: banner-slide-in 0.3s ease-out;
    max-width: calc(100vw - 2rem);
}
.update-banner.hidden { display: none; }
.update-banner-text {
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.update-banner-btn {
    padding: 0.4rem 0.9rem;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-fg);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 32px;
    transition: background 0.2s;
}
.update-banner-btn:hover { background: var(--accent-hover); }
@keyframes banner-slide-in {
    from { transform: translate(-50%, -120%); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* ── Offline indicator ── */
.offline-indicator {
    position: fixed;
    bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 9998;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--stat-lives);
    border-radius: 6px;
    font-size: 0.7rem;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
}
.offline-indicator.hidden { display: none; }
.offline-indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--stat-lives);
    animation: offline-pulse 1.5s ease-in-out infinite;
}
@keyframes offline-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Level progress ring ── */
.level-circle {
    position: relative;
    width: clamp(28px, 3.5vw, 36px);
    height: clamp(28px, 3.5vw, 36px);
    border-radius: 50%;
    border: 1.5px solid var(--stat-level-soft);
    display: flex;
    align-items: center;
    justify-content: center;
}
.level-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.level-ring-bg {
    fill: none;
    stroke: var(--stat-level-track);
    stroke-width: 2.5;
}
.level-ring-fill {
    fill: none;
    stroke: var(--stat-level);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-dasharray: 80.11;
    stroke-dashoffset: 80.11;
    transition: stroke-dashoffset 0.4s ease;
}
.level-number {
    position: relative;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--stat-level);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
