/* ============================================
   DUNGEON ESCAPE - STYLE SYSTEM
   (Matched to Flappy Wojak vibe)
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Inter:wght@400;600;700;900&display=swap');

:root {
    --bg-dark: #04080f;
    --bg-card: rgba(12, 26, 46, 0.85);
    --ton-blue: #0098EA;
    --ton-light: #2AABEE;
    --ton-glow: rgba(0, 152, 234, 0.4);
    --ton-dim: rgba(0, 152, 234, 0.15);
    --dungeon-amber: #f59e0b;
    --dungeon-glow: rgba(245, 158, 11, 0.4);
    --dungeon-dim: rgba(245, 158, 11, 0.15);
    --neon-pink: #ff2d78;
    --neon-yellow: #ffd600;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --glass: rgba(245, 158, 11, 0.05);
    --glass-border: rgba(245, 158, 11, 0.15);
    --font-pixel: 'Press Start 2P', monospace;
    --font-ui: 'Inter', sans-serif;
}

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

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    font-family: var(--font-ui);
    color: var(--text-primary);
    touch-action: manipulation;
}

/* ============================================
   CANVAS
   ============================================ */

#game-canvas {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
}
#game-canvas canvas { display: block; width: 100%; height: 100%; }

/* ============================================
   SCREENS (overlays)
   ============================================ */

.screen {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 20;
    background: rgba(5, 5, 15, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: fadeIn 0.3s ease;
    transition: opacity 0.4s ease;
}
.screen.hidden {
    opacity: 0; pointer-events: none;
}
.screen-content {
    text-align: center;
    padding: 25px 20px;
    max-width: 340px;
    width: 90%;
}

/* ============================================
   START SCREEN
   ============================================ */

.game-title {
    font-family: var(--font-pixel);
    font-size: 22px;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-shadow: 0 0 20px var(--dungeon-glow);
    letter-spacing: 2px;
}
.title-accent {
    font-size: 32px;
    color: var(--dungeon-amber);
    text-shadow: 0 0 30px var(--dungeon-amber), 0 0 60px var(--dungeon-glow);
    display: block;
}
#start-character {
    width: 90px; height: 90px;
    object-fit: contain;
    border-radius: 50%;
    margin: 12px auto;
    display: block;
    animation: float 2s ease-in-out infinite;
    filter: drop-shadow(0 0 20px var(--dungeon-glow));
}
.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.6;
    font-weight: 600;
}

/* How to Play Tips */
.how-to-play {
    display: flex;
    gap: 8px;
    margin: 12px 0 16px;
    justify-content: center;
}
.htp-tip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 600;
    animation: fadeInUp 0.4s ease backwards;
}
.htp-tip:nth-child(1) { animation-delay: 0.1s; }
.htp-tip:nth-child(2) { animation-delay: 0.2s; }
.htp-tip:nth-child(3) { animation-delay: 0.3s; }
.htp-icon { font-size: 20px; }

.best-score-card {
    background: var(--bg-card);
    border: 2px solid rgba(245, 158, 11, 0.2);
    border-radius: 12px;
    padding: 12px 20px;
    margin-bottom: 16px;
    width: 100%;
    max-width: 250px;
    display: inline-block;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.best-score-card.hidden { display: none; }
.bsc-label {
    font-family: var(--font-pixel);
    font-size: 7px;
    color: var(--text-secondary);
    letter-spacing: 2px;
    display: block;
    margin-bottom: 6px;
}
.bsc-value {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--font-pixel);
    font-size: 28px;
    font-weight: 900;
    color: var(--dungeon-amber);
    text-shadow: 0 0 15px var(--dungeon-glow);
}

/* ============================================
   BUTTONS
   ============================================ */

.btn-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 36px;
    font-family: var(--font-pixel);
    font-size: 13px;
    color: var(--bg-dark);
    background: linear-gradient(135deg, var(--dungeon-amber), #d97706);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px var(--dungeon-glow), inset 0 1px 0 rgba(255,255,255,0.2);
    width: 100%;
    letter-spacing: 1px;
}
.btn-play:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(245,158,11,0.2);
}
.btn-play.pulse {
    animation: btnPulse 2s ease-in-out infinite;
}
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--text-primary);
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    cursor: pointer;
    margin-top: 10px;
    width: 100%;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    letter-spacing: 1px;
}
.btn-secondary:active {
    background: rgba(255,255,255,0.1);
    transform: scale(0.97);
}

/* ============================================
   HUD (matches Flappy exactly)
   ============================================ */

#hud {
    position: fixed; top: 0; left: 0; right: 0;
    z-index: 10;
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 16px 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.6) 0%, transparent 100%);
    pointer-events: none;
    transition: opacity 0.3s;
}
#hud.hidden { opacity: 0; pointer-events: none; }

.back-btn {
    pointer-events: all;
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 10px;
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    transition: all 0.2s ease;
    letter-spacing: 1px;
}
.back-btn:active {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}

#score-display, #best-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.score-label {
    font-family: var(--font-pixel);
    font-size: 8px;
    color: var(--text-secondary);
    letter-spacing: 2px;
}
.score-value {
    font-family: var(--font-pixel);
    font-size: 24px;
    color: var(--text-primary);
    text-shadow: 0 0 10px var(--dungeon-amber), 0 2px 4px rgba(0,0,0,0.5);
}
#best-display .score-value {
    color: var(--neon-yellow);
    text-shadow: 0 0 10px var(--neon-yellow), 0 2px 4px rgba(0,0,0,0.5);
}

#hud-speed {
    position: fixed; top: 56px; left: 16px; right: 16px;
    height: 3px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
    overflow: hidden;
    z-index: 10;
}
#hud-speed.hidden { display: none; }
#speed-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--dungeon-amber), #ef4444);
    border-radius: 2px;
    transition: width 0.3s;
}

/* ============================================
   GAME OVER (matches Flappy Wojak exactly)
   ============================================ */

#gameover-screen {
    background: rgba(5, 5, 15, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.gameover-title {
    font-family: var(--font-pixel);
    font-size: 28px;
    color: var(--neon-pink);
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255, 45, 120, 0.5);
    animation: shake 0.5s ease;
}
.gameover-stats {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}
.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 12px 14px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    min-width: 80px;
}
.stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}
.stat-value {
    font-family: var(--font-pixel);
    font-size: 18px;
    color: var(--dungeon-amber);
    white-space: nowrap;
}
.stat-value.best-value {
    color: var(--neon-yellow);
    text-shadow: 0 0 10px rgba(255, 214, 0, 0.4);
}
.stat-value.coins-value {
    color: var(--neon-yellow);
    text-shadow: 0 0 10px rgba(255, 214, 0, 0.4);
}
.achievement-banner {
    background: linear-gradient(135deg, rgba(255, 214, 0, 0.15), rgba(255, 214, 0, 0.05));
    border: 1px solid rgba(255, 214, 0, 0.3);
    padding: 10px 20px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--neon-yellow);
    animation: achievementPop 0.5s ease;
}
.achievement-banner.hidden { display: none; }
.welcome-user {
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--dungeon-amber);
    margin-bottom: 8px;
    letter-spacing: 1px;
}
.gameover-wojak {
    margin-bottom: 10px;
    animation: shake 0.5s ease;
}
.gameover-wojak-img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    filter: drop-shadow(0 0 15px rgba(255, 45, 120, 0.5));
}
.total-coins-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(255, 214, 0, 0.08);
    border: 1px solid rgba(255, 214, 0, 0.2);
    border-radius: 10px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-top: 10px;
    margin-bottom: 16px;
}
.total-coins-value {
    font-family: var(--font-pixel);
    font-size: 14px;
    color: var(--neon-yellow);
    text-shadow: 0 0 8px rgba(255, 214, 0, 0.3);
}

/* ============================================
   LOADING
   ============================================ */

#loading-screen {
    background: var(--bg-dark);
    z-index: 1000;
}
.loader {
    width: 48px; height: 48px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--dungeon-amber);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}
.loading-text {
    font-family: var(--font-pixel);
    font-size: 10px;
    color: var(--dungeon-amber);
    letter-spacing: 2px;
}

/* ============================================
   EFFECTS
   ============================================ */

.shake { animation: shake 0.3s ease-out; }
#flash-overlay {
    position: fixed; inset: 0;
    background: #ef4444;
    opacity: 0;
    pointer-events: none;
    z-index: 4;
    transition: opacity 0.1s;
}

/* Sound toggle */
#sound-toggle {
    position: fixed;
    bottom: 16px; right: 16px;
    z-index: 15;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}
#sound-toggle:active {
    transform: scale(0.9);
    background: rgba(255,255,255,0.1);
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; } to { opacity: 1; }
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes btnPulse {
    0%, 100% { box-shadow: 0 4px 20px var(--dungeon-glow); }
    50% { box-shadow: 0 4px 30px rgba(245,158,11,0.6), 0 0 40px rgba(245,158,11,0.2); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-3px); }
}
@keyframes achievementPop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-height: 600px) {
    .game-title { font-size: 18px; }
    .title-accent { font-size: 26px; }
    #start-character { width: 60px; height: 60px; margin: 8px auto; }
    .btn-play { padding: 12px 28px; font-size: 11px; }
    .gameover-title { font-size: 22px; }
}
@media (max-height: 500px) {
    #start-character { display: none; }
    .how-to-play { margin: 8px 0 12px; }
}
