body {
    margin: 0;
    padding: 0;
    color: rgba(255, 255, 255, 0.92);
    background-color: #0f172a;
    font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

#app {
    width: 100%;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at 50% 20%, #1e1b4b 0%, #0f172a 70%);
}

#game-container {
    width: 100%;
    height: 100%;
    position: relative;
}

canvas {
    display: block;
}

#hud {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

/* ---- Overlays ---- */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    pointer-events: auto;
    background: rgba(8, 12, 30, 0.72);
    backdrop-filter: blur(6px);
    text-align: center;
    padding: 24px;
    box-sizing: border-box;
}

.overlay.menu {
    background: rgba(8, 12, 30, 0.55);
}

/* ---- Menu ---- */
.title {
    font-size: 44px;
    line-height: 1.02;
    margin: 0;
    letter-spacing: 1px;
    font-weight: 900;
    text-shadow: 0 4px 18px rgba(99, 102, 241, 0.55);
}
.title span { color: #fbbf24; }

.subtitle {
    margin: 2px 0 6px;
    color: #cbd5e1;
    font-size: 15px;
}

.best-chip {
    background: rgba(30, 27, 75, 0.85);
    border: 1px solid #6366f1;
    color: #c7d2fe;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 13px;
}
.best-chip b { color: #fbbf24; }

.diff-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(320px, 90%);
}

.diff-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 56px;
    padding: 12px 18px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}
.diff-btn .diff-grid { font-weight: 500; font-size: 13px; color: #cbd5e1; }
.diff-btn:hover { background: rgba(255, 255, 255, 0.16); }
.diff-btn.active {
    border-color: #fbbf24;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    box-shadow: 0 4px 18px rgba(99, 102, 241, 0.5);
}
.diff-btn.active .diff-grid { color: #e0e7ff; }

.play-btn,
.resume-btn {
    min-height: 60px;
    width: min(320px, 90%);
    border: none;
    border-radius: 18px;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1e1b4b;
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 1px;
    cursor: pointer;
    box-shadow: 0 6px 22px rgba(245, 158, 11, 0.45);
    transition: transform 0.12s, box-shadow 0.12s;
}
.play-btn:hover { transform: translateY(-2px); }
.play-btn:active { transform: translateY(1px); box-shadow: 0 3px 12px rgba(245, 158, 11, 0.4); }

.ghost-btn {
    min-height: 48px;
    width: min(320px, 90%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 14px;
    background: transparent;
    color: #e2e8f0;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.1); }

.hint {
    color: #94a3b8;
    font-size: 12px;
    margin: 0;
}

/* ---- HUD bar ---- */
.hud-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 30;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 22px 16px 0;
    pointer-events: none;
}

.hud-timer {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 76px;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 6px 10px;
}
.hud-label { font-size: 10px; color: #94a3b8; letter-spacing: 1px; }
.hud-value { font-size: 24px; font-weight: 900; color: #fbbf24; }

.hud-mid { display: flex; flex-direction: column; align-items: center; margin-top: 4px; }
.hud-score { font-size: 18px; font-weight: 800; color: #e0e7ff; }
.hud-score b { color: #fff; font-size: 22px; }
.hud-sub { display: flex; gap: 14px; font-size: 12px; color: #94a3b8; }

.hud-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: auto;
}
.combo-pill {
    background: linear-gradient(135deg, #f59e0b, #f43f5e);
    color: #fff;
    font-weight: 900;
    font-size: 13px;
    padding: 5px 12px;
    border-radius: 999px;
    box-shadow: 0 3px 12px rgba(244, 63, 94, 0.5);
    animation: pop 0.25s ease;
}
@keyframes pop { 0% { transform: scale(0.5); } 100% { transform: scale(1); } }

.icon-btn {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(15, 23, 42, 0.75);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---- Countdown ---- */
.countdown-banner {
    position: absolute;
    top: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(99, 102, 241, 0.9);
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    padding: 10px 22px;
    border-radius: 999px;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
    z-index: 20;
    pointer-events: none;
    animation: bannerFade 1.6s ease forwards;
}
@keyframes bannerFade { 0% { opacity: 0; transform: translateX(-50%) translateY(-8px); } 20% { opacity: 1; transform: translateX(-50%); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---- Pause ---- */
.overlay.pause h2 { font-size: 40px; margin: 0; letter-spacing: 4px; color: #fff; }

/* ---- Finish ---- */
.win-title { font-size: 34px; margin: 0; color: #fbbf24; text-shadow: 0 4px 18px rgba(245, 158, 11, 0.5); }
.stars { font-size: 52px; line-height: 1; letter-spacing: 8px; }
.star { color: #334155; text-shadow: none; }
.star.lit { color: #fbbf24; text-shadow: 0 0 18px rgba(251, 191, 36, 0.8); animation: pop 0.4s ease; }

.high-badge {
    background: linear-gradient(135deg, #f43f5e, #f59e0b);
    color: #fff;
    font-weight: 900;
    padding: 8px 18px;
    border-radius: 999px;
    font-size: 15px;
    box-shadow: 0 4px 16px rgba(244, 63, 94, 0.5);
    animation: pop 0.4s ease;
}

.final-panel {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    padding: 14px 22px;
    width: min(320px, 90%);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.final-row { display: flex; justify-content: space-between; font-size: 14px; color: #cbd5e1; }
.final-row b { color: #fff; font-size: 15px; }

@media (max-height: 700px) {
    .title { font-size: 34px; }
    .stars { font-size: 42px; }
    .overlay { gap: 12px; }
}