body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 1rem;
    background: radial-gradient(circle at top right, #1e1b4b, var(--background));
    overflow-x: hidden;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    width: 100%;
    max-width: 800px;
    margin: 0 auto 1.25rem auto;
}

.back-btn {
    background: transparent;
    border: none;
    padding: 0.3rem 0;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s;
}
.back-btn:hover { color: var(--text); }

.hud {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    background: var(--surface-glass);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--surface-border);
    font-weight: 700;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}
.hud-score  { color: #3b82f6; }
.hud-lives  { color: #ef4444; }
.hud-best   { color: #f59e0b; }

.game-container {
    flex: 1;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    animation: fadeIn 0.4s ease forwards;
}
.screen.active { display: flex; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

h1 {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.4rem;
    text-align: center;
    line-height: 1.1;
}
h1 .title-emoji {
    -webkit-text-fill-color: initial;
    background: none;
}
.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
    text-align: center;
}

/* ── Mode menu (fallback when no ?mode= in URL) ── */
.mode-groups {
    width: 100%;
    max-width: 720px;
}

.mode-group-title {
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin: 1.25rem 0 0.6rem 0;
}
.mode-group-title:first-of-type { margin-top: 0; }

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.85rem;
    margin-bottom: 0.5rem;
}

.mode-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.1rem 1rem;
    cursor: pointer;
    text-align: left;
    color: var(--text);
    font-family: var(--font-ui);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    transition: all 0.2s ease;
}
.mode-card:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: 0 10px 24px rgba(139, 92, 246, 0.18);
}
.mode-card .mode-title {
    font-size: 1.02rem;
    font-weight: 800;
}
.mode-card .mode-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}
.mode-card .mode-best {
    margin-top: 0.3rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: #f59e0b;
    font-variant-numeric: tabular-nums;
}
.mode-card.mode-beginner     { border-left: 4px solid #10b981; }
.mode-card.mode-intermediate { border-left: 4px solid #f59e0b; }
.mode-card.mode-advanced     { border-left: 4px solid #ef4444; }

.controls-hint {
    margin-top: 1.75rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-align: center;
}

/* ── Prompt banner (above road) ── */
.prompt-banner {
    width: 100%;
    max-width: 480px;
    background: var(--surface-glass);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: 0.85rem 1.1rem;
    text-align: center;
    margin-bottom: 0.85rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}

.prompt-context {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.2rem;
}

.prompt-main {
    font-family: var(--font-kr);
    font-size: 2rem;
    font-weight: 900;
    color: var(--text);
    line-height: 1.1;
}

/* ── Lane previews (stationary readable row above the road) ── */
.lane-previews {
    display: flex;
    width: 100%;
    max-width: 480px;
    gap: 6px;
    margin: 0 auto 0.5rem auto;
}

.lane-preview {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--surface-border);
    border-bottom: 4px solid var(--accent);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding: 0.7rem 0.4rem;
    text-align: center;
    font-family: var(--font-kr);
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text);
    word-break: keep-all;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.lane-preview.hit-correct {
    background: rgba(16, 185, 129, 0.25);
    border-bottom-color: #10b981;
    color: #10b981;
}
.lane-preview.hit-wrong {
    background: rgba(239, 68, 68, 0.25);
    border-bottom-color: #ef4444;
    color: #ef4444;
}
.lane-preview.show-correct {
    background: rgba(16, 185, 129, 0.15);
    border-bottom-color: #10b981;
    color: #10b981;
}

/* ── Road ── */
.road {
    position: relative;
    width: 100%;
    max-width: 480px;
    height: 580px;
    background:
        repeating-linear-gradient(
            180deg,
            #16161f 0px,
            #16161f 40px,
            #1a1a24 40px,
            #1a1a24 80px
        );
    background-size: 100% 80px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: var(--radius-lg);
    border: 2px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.6);
    touch-action: none;
    user-select: none;
}

/* Lane divider lines — dashed, scrolling */
.road-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.road-lines::before,
.road-lines::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 5px;
    background-image: repeating-linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.55) 0,
        rgba(255, 255, 255, 0.55) 28px,
        transparent 28px,
        transparent 56px
    );
    animation: scrollDash 0.85s linear infinite;
}
.road-lines::before { left: calc(33.333% - 2.5px); }
.road-lines::after  { left: calc(66.666% - 2.5px); }

@keyframes scrollDash {
    from { background-position-y: 0; }
    to   { background-position-y: 56px; }
}

/* Subtle scoring line where collision happens */
.scoring-line {
    position: absolute;
    left: 0;
    right: 0;
    top: 380px; /* matches SCORING_LINE_Y in JS approximately */
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.35), transparent);
    pointer-events: none;
}

/* ── Gates ── */
.gates-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.gate {
    position: absolute;
    top: 0;
    width: 33.333%;
    height: 70px;
    background: linear-gradient(180deg, rgba(139, 92, 246, 0.25), rgba(139, 92, 246, 0.05));
    border-top: 4px solid var(--accent);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-family: var(--font-kr);
    font-size: 1.05rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 6px;
    box-sizing: border-box;
    word-break: keep-all;
    will-change: transform;
    transition: background-color 0.15s, border-color 0.15s;
}

.gate.hit-correct {
    background: rgba(16, 185, 129, 0.45);
    border-top-color: #10b981;
    color: #10b981;
    animation: hitPulse 0.4s ease;
}

.gate.hit-wrong {
    background: rgba(239, 68, 68, 0.45);
    border-top-color: #ef4444;
    color: #ef4444;
    animation: hitShake 0.4s ease;
}

.gate.show-correct {
    background: rgba(16, 185, 129, 0.25);
    border-top-color: #10b981;
    color: #10b981;
}

@keyframes hitPulse {
    0% { transform: var(--tx) scale(1); }
    40% { transform: var(--tx) scale(1.12); }
    100% { transform: var(--tx) scale(1); }
}

@keyframes hitShake {
    0%, 100% { transform: var(--tx) translateX(0); }
    25%      { transform: var(--tx) translateX(-4px); }
    75%      { transform: var(--tx) translateX(4px); }
}

/* ── Car ── */
.car {
    position: absolute;
    bottom: 24px;
    width: 56px;
    height: 86px;
    margin-left: -28px; /* center within lane */
    background: linear-gradient(180deg, #f59e0b 0%, #ea580c 80%, #c2410c 100%);
    border-radius: 14px 14px 18px 18px;
    box-shadow:
        0 8px 22px rgba(0, 0, 0, 0.5),
        inset 0 -6px 8px rgba(0, 0, 0, 0.3),
        inset 0 4px 4px rgba(255, 255, 255, 0.15);
    transition: left 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
    will-change: left;
    z-index: 5;
}

/* Front windshield */
.car::before {
    content: '';
    position: absolute;
    top: 14px;
    left: 7px;
    right: 7px;
    height: 26px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(255, 255, 255, 0.05));
    border-radius: 7px 7px 4px 4px;
}

/* Rear windshield */
.car::after {
    content: '';
    position: absolute;
    bottom: 14px;
    left: 7px;
    right: 7px;
    height: 18px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px 4px 6px 6px;
}

/* Touch zones (mobile) */
.touch-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%;
    z-index: 10;
}
.touch-left  { left: 0; }
.touch-right { right: 0; }

/* ── Game over ── */
#screen-gameover { padding-top: 3rem; text-align: center; align-items: center; }
.gameover-icon {
    font-size: 5rem;
    margin-bottom: 0.5rem;
}
#gameover-title {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}
#gameover-message {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}
.gameover-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.primary-btn, .secondary-btn {
    border: none;
    padding: 0.85rem 1.75rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius-full);
    cursor: pointer;
    font-family: var(--font-ui);
    transition: transform 0.2s, background 0.2s;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:hover { transform: scale(1.05); background: var(--accent); }
.secondary-btn {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--surface-border);
}
.secondary-btn:hover { background: rgba(255, 255, 255, 0.06); }

@media (max-width: 480px) {
    h1 { font-size: 2.2rem; }
    .prompt-main { font-size: 1.6rem; }
    .lane-preview { font-size: 1rem; padding: 0.55rem 0.3rem; min-height: 46px; }
    .gate { font-size: 0.92rem; height: 64px; }
    .road { height: 520px; }
    .scoring-line { top: 340px; }
    .car { width: 48px; height: 74px; margin-left: -24px; bottom: 16px; }
}
