* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-main: #0b0f19;
    --lane-bg: rgba(15, 23, 42, 0.9);
    --tile-color: linear-gradient(180deg, #1e293b, #0f172a);
    --tile-border: #38bdf8;
    --accent: #38bdf8;
    --accent-gradient: linear-gradient(135deg, #0ea5e9, #a855f7);
    --gold: #fbbf24;
    --text: #f8fafc;
    --text-muted: #94a3b8;
}

body {
    background: radial-gradient(circle at 50% 15%, #1e1b4b, var(--bg-main) 70%);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    padding-bottom: 75px; /* Space for bottom banner ad */
}

/* Header & HUD */
header {
    width: 100%;
    max-width: 480px;
    padding: 8px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    z-index: 50;
}

.title-group h1 {
    font-size: 1.15rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hud-stats {
    display: flex;
    gap: 8px;
}

.stat-chip {
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 3px 8px;
    text-align: center;
    min-width: 50px;
}

.stat-label {
    display: block;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat-value {
    font-size: 0.9rem;
    font-weight: 800;
    color: #38bdf8;
    font-variant-numeric: tabular-nums;
}

/* Song Progress Bar */
.song-progress-container {
    width: 100%;
    max-width: 480px;
    height: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.song-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    transition: width 0.1s linear;
}

/* Toolbar & Song Selector */
.toolbar {
    width: 100%;
    max-width: 480px;
    padding: 6px 12px 2px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bar-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.pill-btn {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-muted);
    padding: 5px 10px;
    border-radius: 16px;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pill-btn:hover {
    color: #fff;
    background: rgba(56, 189, 248, 0.2);
    border-color: #38bdf8;
}

.pill-btn.active {
    background: var(--accent-gradient);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.4);
}

/* Combo Banner */
#combo-banner {
    height: 20px;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--gold);
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
    display: none;
    text-align: center;
}

.pop-anim {
    animation: popBounce 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popBounce {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* 4-Lane Piano Highway */
.piano-viewport {
    flex: 1;
    width: 100%;
    max-width: 440px;
    height: 480px;
    max-height: 65vh;
    margin: 8px auto;
    position: relative;
    background: var(--lane-bg);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.6);
    display: flex;
}

.piano-lane {
    flex: 1;
    height: 100%;
    position: relative;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

.piano-lane:last-child {
    border-right: none;
}

.piano-lane.flash-red {
    background: rgba(239, 68, 68, 0.4) !important;
    animation: redFlash 0.3s ease;
}

@keyframes redFlash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Falling Black Tile */
.piano-tile {
    position: absolute;
    left: 4px;
    right: 4px;
    background: linear-gradient(180deg, #38bdf8, #2563eb);
    border: 2px solid #7dd3fc;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.4);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.1s ease;
}

.piano-tile::after {
    content: '🎵';
    font-size: 1.2rem;
    opacity: 0.85;
}

.piano-tile.hit {
    background: rgba(255, 255, 255, 0.8) !important;
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.15s ease-out;
}

/* Start Overlay */
.start-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 40;
    cursor: pointer;
}

.start-overlay h2 {
    font-size: 1.6rem;
    color: #fff;
    margin-bottom: 8px;
}

.start-overlay p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.tap-indicator {
    font-size: 2.5rem;
    margin-top: 12px;
    animation: pulseTap 1.2s infinite ease-in-out;
}

@keyframes pulseTap {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-box {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 28px 24px;
    text-align: center;
    max-width: 360px;
    width: 100%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-box h2 {
    font-size: 1.8rem;
    margin-bottom: 6px;
}

.win-title {
    color: var(--gold);
    text-shadow: 0 0 15px rgba(251, 191, 36, 0.5);
}

.lose-title {
    color: #f87171;
}

.stars-row {
    font-size: 2rem;
    margin: 10px 0 14px;
    letter-spacing: 4px;
}

.results-grid {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.res-item span {
    display: block;
}

.res-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.res-val {
    font-size: 1.05rem;
    font-weight: 800;
    color: #38bdf8;
}

.action-btn {
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(14, 165, 233, 0.4);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    width: 100%;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.6);
}

.action-btn:active {
    transform: translateY(1px);
}
