* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html { scrollbar-gutter: stable; }

:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-tertiary: #1a1a2e;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --accent: #a855f7;
    --accent-glow: rgba(168, 85, 247, 0.4);
    --accent-gold: #ffd700;
    --accent-cyan: #00d4ff;
    --accent-pink: #ff6b9d;
    --accent-orange: #ff8c00;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--text-primary);
    overflow: hidden;
}

/* Background Effects */
.bg-effects {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.3;
    animation: float 15s ease-in-out infinite;
}

.bg-orb:nth-child(1) {
    width: 400px; height: 400px;
    background: var(--accent);
    top: -100px; left: -100px;
}

.bg-orb:nth-child(2) {
    width: 350px; height: 350px;
    background: var(--accent-cyan);
    bottom: -50px; right: -100px;
    animation-delay: -7s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.05); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* Layout */
.container {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}

header {
    width: 100%;
    text-align: center;
    padding: 10px 20px;
}

.header-top {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 5px;
}

.back-btn {
    position: absolute;
    left: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-secondary);
    text-decoration: none;
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s;
    min-width: 44px;
    min-height: 44px;
}

.back-btn:hover {
    color: var(--accent-gold);
    background: rgba(255, 255, 255, 0.1);
}

.back-btn svg { width: 20px; height: 20px; }

h1 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Game Container */
.game-container {
    width: 100%;
    display: flex;
    justify-content: center;
}

#gameWrapper {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 16 / 9;
    background: #1a1a2e;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.05), 0 20px 40px rgba(0,0,0,0.4);
    touch-action: none;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
}

/* HUD */
.hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
    pointer-events: none;
    z-index: 10;
}

.hud.hidden { display: none; }

.hud-left {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 80px;
}

.hud-heart {
    font-size: 1.1rem;
    line-height: 1;
    filter: drop-shadow(0 0 4px rgba(239,68,68,0.6));
}

.hud-heart.empty {
    filter: grayscale(1) opacity(0.4);
}

.hud-center {
    font-family: 'Jua', sans-serif;
    font-size: 0.85rem;
    color: var(--accent-gold);
    text-shadow: 0 0 8px rgba(255,215,0,0.5);
    text-align: center;
}

.hud-right {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'Jua', sans-serif;
    font-size: 0.85rem;
    color: var(--accent-gold);
    min-width: 80px;
    justify-content: flex-end;
}

.hud-coin-icon {
    font-size: 1rem;
    filter: drop-shadow(0 0 4px rgba(255,215,0,0.5));
}

.hud-coin-count {
    text-shadow: 0 0 6px rgba(255,215,0,0.4);
}

/* Overlay Screens */
.overlay-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 26, 0.88);
    backdrop-filter: blur(4px);
    z-index: 20;
}

.overlay-screen.hidden { display: none; }

/* Start Screen */
.start-content {
    text-align: center;
    padding: 30px 40px;
}

.game-logo {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.8rem;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--accent), var(--accent-cyan), var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 20px rgba(168,85,247,0.4));
}

.start-sub {
    font-family: 'Jua', sans-serif;
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 24px;
}

.start-btn {
    font-family: 'Jua', sans-serif;
    padding: 14px 44px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px var(--accent-glow);
    min-height: 48px;
    pointer-events: all;
}

.start-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 24px var(--accent-glow);
}

.start-btn:active { transform: translateY(0) scale(0.98); }

/* Stage Clear Screen */
.clear-content {
    text-align: center;
    padding: 30px;
    background: var(--bg-secondary);
    border-radius: 20px;
    border: 1px solid rgba(34,197,94,0.3);
    box-shadow: 0 0 30px rgba(34,197,94,0.15), 0 20px 60px rgba(0,0,0,0.5);
    width: 85%;
    max-width: 360px;
}

.clear-title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2rem;
    color: var(--accent-green);
    text-shadow: 0 0 20px rgba(34,197,94,0.4);
    margin-bottom: 16px;
}

.clear-stats {
    margin-bottom: 20px;
}

/* Game Over / Victory */
.gameover-content {
    text-align: center;
    padding: 30px;
    background: var(--bg-secondary);
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    width: 85%;
    max-width: 360px;
}

.gameover-content.victory {
    border-color: rgba(255,215,0,0.3);
    box-shadow: 0 0 30px rgba(255,215,0,0.15), 0 20px 60px rgba(0,0,0,0.5);
}

.gameover-title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2rem;
    color: var(--accent-red);
    margin-bottom: 16px;
}

.victory-title {
    color: var(--accent-gold);
    text-shadow: 0 0 20px rgba(255,215,0,0.4);
}

.victory-sub {
    font-family: 'Jua', sans-serif;
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 16px;
}

.gameover-stats {
    margin-bottom: 16px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.stat-row span:last-child {
    color: var(--text-primary);
}

.gameover-score {
    margin: 16px 0 20px;
    font-family: 'Black Han Sans', sans-serif;
}

.gameover-score span:first-child {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}

.gameover-score span:last-child {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Mobile Controls */
.mobile-controls {
    display: none;
    width: 100%;
    max-width: 800px;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    gap: 12px;
}

.ctrl-left,
.ctrl-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ctrl-btn {
    width: 52px;
    height: 52px;
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 26, 0.75);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.1s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.ctrl-btn:active,
.ctrl-btn.pressed {
    background: rgba(168, 85, 247, 0.35);
    border-color: var(--accent);
    transform: scale(0.93);
}

.ctrl-jump {
    background: rgba(168, 85, 247, 0.2);
    border-color: rgba(168, 85, 247, 0.5);
}

.ctrl-jump:active,
.ctrl-jump.pressed {
    background: rgba(168, 85, 247, 0.5);
    box-shadow: 0 0 12px var(--accent-glow);
}

.ctrl-action {
    background: rgba(255, 215, 0, 0.15);
    border-color: rgba(255, 215, 0, 0.4);
    color: var(--accent-gold);
}

.ctrl-action:active,
.ctrl-action.pressed {
    background: rgba(255, 215, 0, 0.35);
    box-shadow: 0 0 12px rgba(255,215,0,0.4);
}

/* Game Content Article */
.game-content {
    width: 100%;
    margin-top: 20px;
    padding: 25px 20px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.1);
}

.game-content h2 {
    font-family: 'Jua', sans-serif;
    font-size: 1.2rem;
    color: var(--accent-gold);
    margin-bottom: 15px;
}

.game-content p {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.tip-box {
    background: rgba(168, 85, 247, 0.1);
    border-left: 3px solid var(--accent);
    padding: 15px;
    border-radius: 0 8px 8px 0;
}

.tip-box p { margin-bottom: 10px; }
.tip-box p:last-child { margin-bottom: 0; }

footer {
    width: 100%;
    text-align: center;
    padding: 20px;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

footer a {
    color: var(--accent-cyan);
    text-decoration: none;
    transition: color 0.3s;
}

footer a:hover { color: var(--accent-gold); }

/* Responsive - Mobile */
@media (max-width: 768px) {
    body { overflow: auto; }
    header { padding: 8px 12px; }
    h1 { font-size: 1.5rem; }
    .back-btn span { display: none; }
    .game-logo { font-size: 2.2rem; }

    #gameWrapper {
        border-radius: 0;
    }

    .mobile-controls {
        display: flex;
    }

    .instructions,
    .game-content,
    footer { display: none; }
}

@media (max-width: 480px) {
    .game-logo { font-size: 1.8rem; }
    .ctrl-btn { width: 48px; height: 48px; font-size: 1rem; }
}

/* Landscape mobile - maximize game area */
@media (max-height: 500px) and (orientation: landscape) {
    header { display: none; }
    .mobile-controls {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 9999;
        background: rgba(10, 10, 26, 0.85);
        padding: 6px 16px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    }
    body { padding-bottom: 72px; }
    #gameWrapper {
        border-radius: 0;
        max-width: none;
    }
    .game-content, footer { display: none; }
}

/* Fullscreen */
body.fullscreen-active .container { max-width: none; }
body.fullscreen-active header,
body.fullscreen-active .game-content,
body.fullscreen-active footer { display: none; }
body.fullscreen-active #gameWrapper {
    max-width: none;
    border-radius: 0;
    aspect-ratio: auto;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}
body.fullscreen-active .mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    background: rgba(10, 10, 26, 0.85);
    padding: 8px 16px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}
