/* ==========================================
   CSS Variables & Design System
   ========================================== */
:root {
    --bg-dark: #0b0f19;
    --bg-card: rgba(18, 26, 44, 0.65);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(0, 242, 254, 0.2);
    
    /* Neon Accent Colors */
    --neon-blue: #00f2fe;
    --neon-purple: #9b51e0;
    --neon-cyan: #00e5ff;
    --neon-pink: #ff007f;
    --neon-green: #39ff14;
    --neon-gold: #ffd700;
    --neon-red: #ff3366;
    
    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
    --gradient-accent: linear-gradient(135deg, #b92b27 0%, #1565c0 100%);
    --gradient-dark: linear-gradient(180deg, #0b0f19 0%, #05070c 100%);
    --gradient-purple: linear-gradient(135deg, #9b51e0 0%, #ff007f 100%);
    
    /* Fonts */
    --font-primary: 'Outfit', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
    
    /* Shadows */
    --shadow-neon: 0 0 15px rgba(0, 242, 254, 0.4);
    --shadow-neon-pink: 0 0 15px rgba(255, 0, 127, 0.4);
    --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* ==========================================
   Reset & Base Styles
   ========================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-dark);
    background-image: var(--gradient-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/* Background Atmosphere Orbs */
.city-skyline {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 35vh;
    background: linear-gradient(to top, rgba(11, 15, 25, 0.95) 20%, rgba(11, 15, 25, 0) 100%);
    z-index: -1;
    pointer-events: none;
}

.glow-orb {
    position: absolute;
    width: 450px;
    height: 450px;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.15;
    z-index: -2;
    pointer-events: none;
}

#orb-1 {
    top: -10%;
    left: -10%;
    background: var(--neon-blue);
    animation: orbFloat 20s infinite alternate;
}

#orb-2 {
    bottom: -10%;
    right: -10%;
    background: var(--neon-purple);
    animation: orbFloat 25s infinite alternate-reverse;
}

@keyframes orbFloat {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 80px) scale(1.1); }
}

/* ==========================================
   App Container & Screen Routing
   ========================================== */
#app-container {
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.screen {
    display: none;
    width: 100%;
    max-width: 800px;
    animation: fadeIn 0.4s ease-out forwards;
}

.screen.active {
    display: block;
}

/* Center canvas-based screens differently */
#game-screen.screen.active {
    display: flex;
    justify-content: center;
    max-width: 1000px;
}

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

/* ==========================================
   UI Components (Glassmorphism & Neon)
   ========================================== */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: 24px;
    padding: 40px;
    box-shadow: var(--shadow-card);
    transition: border-color 0.3s ease;
}

.glass-panel:hover {
    border-color: var(--border-glow);
}

/* Title Header */
.logo-container {
    text-align: center;
    margin-bottom: 35px;
}

.logo-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 242, 254, 0.1);
    border: 1px solid rgba(0, 242, 254, 0.3);
    color: var(--neon-blue);
    padding: 6px 14px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.game-title {
    font-size: 3.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, #ffffff 30%, var(--neon-blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
    margin-bottom: 8px;
    text-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

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

/* ==========================================
   Interactive Buttons
   ========================================== */
button {
    font-family: var(--font-primary);
    cursor: pointer;
    border: none;
    outline: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.primary-btn {
    background: var(--gradient-primary);
    color: var(--bg-dark);
    font-size: 1.25rem;
    font-weight: 800;
    padding: 16px 36px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: var(--shadow-neon);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(0, 242, 254, 0.7);
    filter: brightness(1.1);
}

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

.secondary-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-glass);
    color: var(--text-primary);
    font-size: 1.15rem;
    font-weight: 600;
    padding: 16px 36px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.danger-btn {
    background: rgba(255, 51, 102, 0.1);
    border: 1px solid rgba(255, 51, 102, 0.3);
    color: var(--neon-red);
    font-size: 1.15rem;
    font-weight: 600;
    padding: 16px 36px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.danger-btn:hover {
    background: rgba(255, 51, 102, 0.2);
    border-color: var(--neon-red);
    box-shadow: 0 0 15px rgba(255, 51, 102, 0.4);
    transform: translateY(-2px);
}

.action-buttons {
    display: flex;
    gap: 18px;
    margin-top: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

.pulse-animation {
    animation: buttonPulse 2s infinite;
}

@keyframes buttonPulse {
    0% { box-shadow: 0 0 12px rgba(0, 242, 254, 0.4); }
    50% { box-shadow: 0 0 25px rgba(0, 242, 254, 0.8); }
    100% { box-shadow: 0 0 12px rgba(0, 242, 254, 0.4); }
}

/* ==========================================
   Start Screen Configurations
   ========================================== */
#start-screen {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: 24px;
    padding: 45px;
    box-shadow: var(--shadow-card);
}

/* Mode Selection Cards */
.mode-selection {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
    margin-bottom: 30px;
}

.mode-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid rgba(255, 255, 255, 0.05);
    border-radius: 18px;
    padding: 20px;
    display: flex;
    text-align: left;
    gap: 15px;
    align-items: center;
}

.mode-btn .mode-icon {
    font-size: 2rem;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.mode-btn .mode-title {
    display: block;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.mode-btn .mode-desc {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Mode Button Active States */
.mode-btn#btn-easy-mode.active {
    border-color: var(--neon-cyan);
    background: rgba(0, 229, 255, 0.05);
}
.mode-btn#btn-easy-mode.active .mode-icon {
    color: var(--neon-cyan);
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.5);
}

.mode-btn#btn-medium-mode.active {
    border-color: var(--neon-gold);
    background: rgba(255, 215, 0, 0.05);
}
.mode-btn#btn-medium-mode.active .mode-icon {
    color: var(--neon-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.mode-btn#btn-hard-mode.active {
    border-color: var(--neon-pink);
    background: rgba(255, 0, 127, 0.05);
}
.mode-btn#btn-hard-mode.active .mode-icon {
    color: var(--neon-pink);
    text-shadow: 0 0 10px rgba(255, 0, 127, 0.5);
}

/* Instructions Card */
.instructions-card {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.instructions-card h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--neon-blue);
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls-guide {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-key-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.key-cap {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
    padding: 0 8px;
}

/* ==========================================
   Game Play Layout
   ========================================== */
.game-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 30px;
    width: 100%;
}

/* Sidebar Panel */
.stats-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: 18px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--shadow-card);
}

.stat-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.stat-value {
    font-size: 2.2rem;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
    letter-spacing: 1px;
}

#stat-score {
    color: var(--neon-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

#stat-speed {
    color: var(--neon-cyan);
    text-shadow: 0 0 10px rgba(0, 229, 255, 0.3);
}

.unit {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Speed Bar Indicator */
.speed-bar {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 5px;
}

#speed-indicator {
    height: 100%;
    background: linear-gradient(90deg, var(--neon-cyan), var(--neon-purple));
    border-radius: 10px;
    transition: width 0.15s ease-out;
}

/* Hearts Container */
.hearts-container {
    display: flex;
    gap: 8px;
    font-size: 1.5rem;
    margin-top: 5px;
}

.fa-heart.active {
    color: var(--neon-red);
    filter: drop-shadow(0 0 5px rgba(255, 51, 102, 0.6));
    animation: heartPulse 1.5s infinite alternate;
}

.fa-heart.empty {
    color: rgba(255, 255, 255, 0.15);
}

@keyframes heartPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

.game-controls-helper {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.5;
    margin-top: 10px;
}

/* Canvas Center Area */
.canvas-wrapper {
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(255, 255, 255, 0.05);
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameCanvas {
    display: block;
    background-color: #222;
}

/* Canvas Overlays (Pause, Game Over) */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    animation: fadeIn 0.3s ease-out;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    max-width: 320px;
}

.overlay-content h2 {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--neon-blue);
    text-shadow: var(--shadow-neon);
}

.overlay-content p {
    color: var(--text-secondary);
}

/* ==========================================
   Game Over Screen Configurations
   ========================================== */
.finish-icon {
    font-size: 4rem;
    background: linear-gradient(135deg, #fff, var(--text-muted));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 15px;
    animation: finishRotate 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes finishRotate {
    0% { transform: scale(0) rotate(-45deg); opacity: 0; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

.finish-title {
    font-size: 2.8rem;
    font-weight: 900;
    color: #fff;
    margin-bottom: 10px;
}

.final-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin: 25px 0;
}

.final-stat-item {
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 18px;
}

.final-stat-item .label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.final-stat-item .value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--neon-gold);
}

.final-stat-item .value-mode {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--neon-cyan);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Entry Form */
.entry-form {
    background: rgba(0, 242, 254, 0.03);
    border: 1px dashed rgba(0, 242, 254, 0.2);
    border-radius: 18px;
    padding: 24px;
    margin-top: 10px;
}

.entry-form h3 {
    font-size: 1rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.input-group {
    display: flex;
    gap: 10px;
}

#player-name-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    padding: 14px 20px;
    font-size: 1.1rem;
    color: #fff;
    outline: none;
    font-family: var(--font-primary);
    transition: all 0.3s;
}

#player-name-input:focus {
    border-color: var(--neon-blue);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
    background: rgba(0, 0, 0, 0.5);
}

.submit-btn {
    background: var(--gradient-primary);
    color: var(--bg-dark);
    font-weight: 800;
    font-size: 1.1rem;
    border-radius: 12px;
    padding: 0 25px;
}

.submit-btn:hover {
    filter: brightness(1.1);
    box-shadow: var(--shadow-neon);
}

/* ==========================================
   Leaderboard Screen Configurations
   ========================================== */
.leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
}

.leaderboard-header .header-icon {
    font-size: 2.5rem;
}

.leaderboard-header h2 {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fff 40%, var(--neon-gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Tab styling */
.leaderboard-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    padding: 6px;
    border-radius: 14px;
    margin-bottom: 20px;
    border: 1px solid var(--border-glass);
}

.tab-btn {
    flex: 1;
    background: transparent;
    color: var(--text-secondary);
    padding: 12px;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: 700;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}

/* Table layout */
.leaderboard-table-container {
    background: rgba(0,0,0,0.15);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    overflow: hidden;
    min-height: 250px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.leaderboard-table th, 
.leaderboard-table td {
    padding: 14px 20px;
}

.leaderboard-table th {
    background: rgba(0, 0, 0, 0.25);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-glass);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.leaderboard-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    transition: background 0.2s;
}

.leaderboard-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.leaderboard-table tbody tr:last-child {
    border-bottom: none;
}

.rank-col { width: 12%; text-align: center; }
.name-col { width: 38%; }
.score-col { width: 25%; font-weight: 800; }
.date-col { width: 25%; color: var(--text-muted); font-size: 0.9rem; }

/* Podium Highlights for ranks 1, 2, 3 */
.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.9rem;
}

.rank-1 .rank-badge {
    background: radial-gradient(circle, #fff3a8 0%, var(--neon-gold) 100%);
    color: #5a3e00;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.rank-2 .rank-badge {
    background: radial-gradient(circle, #f0f0f0 0%, #a8a8a8 100%);
    color: #333;
}

.rank-3 .rank-badge {
    background: radial-gradient(circle, #ffd4b8 0%, #c47640 100%);
    color: #4a2300;
}

.rank-other {
    color: var(--text-secondary);
}

.no-scores {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 50px 20px;
    color: var(--text-muted);
    font-size: 1.1rem;
}

.no-scores i {
    font-size: 2.5rem;
}

/* ==========================================
   Helper / Structural Classes
   ========================================== */
.text-center { text-align: center; }
.text-gold { color: var(--neon-gold); }
.text-cyan { color: var(--neon-cyan); }
.text-red { color: var(--neon-red); }
.hidden { display: none !important; }
.margin-top-md { margin-top: 20px; }
.margin-top-lg { margin-top: 35px; }
.justify-center { justify-content: center; }

/* ==========================================
   Responsive adjustments
   ========================================== */
@media (max-width: 768px) {
    .game-layout {
        grid-template-columns: 1fr;
    }
    
    .stats-panel {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .stat-card {
        flex: 1;
        min-width: 140px;
        padding: 12px;
    }
    
    .stat-value {
        font-size: 1.6rem;
    }
    
    .canvas-wrapper {
        order: 2;
    }
    
    .logo-container h1 {
        font-size: 2.5rem;
    }
    
    .mode-selection {
        grid-template-columns: 1fr;
    }
}
