/* ========================================
   Super Mario - Theme & Base Styles
   ======================================== */

:root {
    --sky-blue: #5c94fc;
    --sky-dark: #1a1a2e;
    --ground-brown: #c84c0c;
    --ground-dark: #6b3000;
    --brick-color: #c86800;
    --brick-dark: #7c3800;
    --question-yellow: #faa005;
    --question-dark: #c87000;
    --pipe-green: #00a800;
    --pipe-dark: #005800;
    --coin-gold: #ffd700;
    --mario-red: #e52521;
    --mario-blue: #049cd8;
    --luigi-green: #43b047;
    --text-white: #fcfcfc;
    --text-shadow: rgba(0,0,0,0.6);
    --ui-bg: rgba(0,0,0,0.85);
    --ui-border: rgba(255,255,255,0.15);
    --ui-accent: #e52521;
    --ui-accent-hover: #ff3d38;
    --ui-success: #43b047;
    --ui-warning: #faa005;
    --glow-red: 0 0 20px rgba(229, 37, 33, 0.5);
    --glow-gold: 0 0 20px rgba(255, 215, 0, 0.5);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
    --font-pixel: 'Courier New', 'Consolas', monospace;
    --border-radius: 8px;
    --border-radius-lg: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: var(--font-pixel);
    color: var(--text-white);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    max-width: 1280px;
    max-height: 720px;
    overflow: hidden;
    background: #000;
    border-radius: 4px;
    box-shadow: 0 0 60px rgba(92, 148, 252, 0.3);
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ========================================
   HUD (Heads-Up Display)
   ======================================== */

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#hud {
    display: flex;
    justify-content: space-between;
    padding: 12px 24px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.4), transparent);
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-label {
    font-size: 11px;
    letter-spacing: 2px;
    color: rgba(255,255,255,0.7);
    text-transform: uppercase;
}

.hud-value {
    font-size: 18px;
    font-weight: bold;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.5);
    letter-spacing: 1px;
}

/* ========================================
   Menu Screens
   ======================================== */

.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    background: var(--ui-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn var(--transition-normal) ease;
}

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

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

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

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

@keyframes slideDown {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes bounceIn {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.05); }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes shimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

@keyframes coinSpin {
    0% { transform: scaleX(1); }
    25% { transform: scaleX(0); }
    50% { transform: scaleX(1); }
    75% { transform: scaleX(0); }
    100% { transform: scaleX(1); }
}

.menu-content {
    text-align: center;
    animation: slideUp 0.5s ease;
    max-width: 500px;
    width: 90%;
}

.menu-content.compact {
    max-width: 400px;
}

.menu-content h2 {
    font-size: 28px;
    margin-bottom: 30px;
    text-shadow: 3px 3px 0 rgba(0,0,0,0.5);
    letter-spacing: 3px;
}

/* ========================================
   Game Logo
   ======================================== */

.game-logo {
    margin-bottom: 50px;
    animation: bounceIn 0.8s ease;
}

.game-logo h1 {
    font-size: 64px;
    font-weight: 900;
    line-height: 1;
    color: var(--mario-red);
    text-shadow:
        4px 4px 0 #7a1200,
        6px 6px 0 rgba(0,0,0,0.3);
    letter-spacing: 6px;
    background: linear-gradient(
        135deg,
        var(--mario-red) 0%,
        #ff6b68 30%,
        var(--mario-red) 60%,
        #c41e1a 100%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(4px 4px 0 #7a1200) drop-shadow(6px 6px 0 rgba(0,0,0,0.3));
}

.logo-subtitle {
    margin-top: 12px;
    font-size: 14px;
    color: rgba(255,255,255,0.6);
    letter-spacing: 6px;
    text-transform: uppercase;
}

/* ========================================
   Menu Buttons
   ======================================== */

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.menu-btn {
    display: block;
    width: 260px;
    padding: 14px 24px;
    background: rgba(255,255,255,0.08);
    border: 2px solid var(--ui-border);
    border-radius: var(--border-radius);
    color: var(--text-white);
    font-family: var(--font-pixel);
    font-size: 16px;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: left 0.5s ease;
}

.menu-btn:hover::before {
    left: 100%;
}

.menu-btn:hover,
.menu-btn.active {
    background: var(--ui-accent);
    border-color: var(--ui-accent);
    transform: scale(1.03);
    box-shadow: var(--glow-red);
}

.menu-btn:active {
    transform: scale(0.97);
}

/* ========================================
   Settings
   ======================================== */

.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 30px;
    padding: 0 20px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--ui-border);
}

.setting-row label {
    font-size: 15px;
    letter-spacing: 1px;
}

.toggle-switch {
    width: 52px;
    height: 28px;
    background: rgba(255,255,255,0.15);
    border-radius: 14px;
    cursor: pointer;
    position: relative;
    transition: background var(--transition-fast);
    pointer-events: auto;
}

.toggle-switch:hover {
    background: rgba(255,255,255,0.25);
}

.toggle-thumb {
    width: 22px;
    height: 22px;
    background: rgba(255,255,255,0.5);
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: all var(--transition-fast);
}

.toggle-thumb.active {
    left: 27px;
    background: var(--ui-success);
    box-shadow: 0 0 10px rgba(67, 176, 71, 0.5);
}

/* ========================================
   Game Over & Level Complete
   ======================================== */

.game-over-title {
    font-size: 48px !important;
    color: var(--mario-red);
    animation: pulse 1.5s ease infinite;
    text-shadow:
        3px 3px 0 #7a1200,
        0 0 30px rgba(229, 37, 33, 0.5) !important;
}

.final-score {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 20px 0 30px;
    font-size: 18px;
}

.final-score span:last-child {
    font-size: 36px;
    color: var(--coin-gold);
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.level-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0 30px;
    padding: 0 40px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    padding: 6px 0;
    border-bottom: 1px solid var(--ui-border);
}

.stat-row span:last-child {
    color: var(--coin-gold);
    font-weight: bold;
}

/* ========================================
   Touch Controls
   ======================================== */

#touch-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 50;
    pointer-events: none;
}

#touch-controls.hidden {
    display: none;
}

.touch-dpad, .touch-actions {
    display: flex;
    gap: 10px;
    pointer-events: auto;
}

.touch-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: all var(--transition-fast);
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.touch-btn:active {
    background: rgba(255,255,255,0.4);
    transform: scale(0.9);
}

.touch-jump {
    width: 72px;
    height: 72px;
    background: rgba(229, 37, 33, 0.3);
    border-color: rgba(229, 37, 33, 0.5);
    font-size: 24px;
}

.touch-run {
    width: 56px;
    height: 56px;
    background: rgba(4, 156, 216, 0.3);
    border-color: rgba(4, 156, 216, 0.5);
    margin-bottom: 8px;
}

/* ========================================
   Loading Screen
   ======================================== */

#loading-screen {
    background: #000;
    z-index: 200;
}

.loading-content {
    text-align: center;
    animation: slideUp 0.5s ease;
}

.loading-bar-container {
    width: 300px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 16px;
}

.loading-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--mario-red), var(--coin-gold));
    border-radius: 3px;
    transition: width 0.3s ease;
}

#loading-text {
    font-size: 14px;
    color: rgba(255,255,255,0.5);
    letter-spacing: 3px;
}

/* ========================================
   FPS Counter
   ======================================== */

#fps-counter {
    position: absolute;
    top: 50px;
    right: 10px;
    font-size: 12px;
    color: rgba(255,255,255,0.5);
    pointer-events: none;
    z-index: 15;
}

/* ========================================
   Score Popup Animation
   ======================================== */

.score-popup {
    position: absolute;
    font-size: 14px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.8);
    pointer-events: none;
    animation: scoreFloat 1s ease forwards;
    z-index: 20;
}

@keyframes scoreFloat {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(-40px); opacity: 0; }
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    .game-logo h1 {
        font-size: 42px;
    }

    .logo-subtitle {
        font-size: 11px;
        letter-spacing: 4px;
    }

    .menu-btn {
        width: 220px;
        padding: 12px 20px;
        font-size: 14px;
    }

    .hud-label {
        font-size: 9px;
    }

    .hud-value {
        font-size: 14px;
    }

    #hud {
        padding: 8px 12px;
    }

    .menu-content h2 {
        font-size: 22px;
    }

    .game-over-title {
        font-size: 36px !important;
    }
}

@media (max-width: 480px) {
    .game-logo h1 {
        font-size: 32px;
    }

    .menu-btn {
        width: 200px;
        padding: 10px 16px;
        font-size: 13px;
    }

    .hud-item:nth-child(4),
    .hud-item:nth-child(5) {
        display: none;
    }

    .touch-btn {
        width: 50px;
        height: 50px;
        font-size: 16px;
    }

    .touch-jump {
        width: 62px;
        height: 62px;
    }
}

/* ========================================
   How To Play
   ======================================== */

.howto-sections {
    text-align: left;
    max-height: 340px;
    overflow-y: auto;
    padding: 0 10px;
}

.howto-section {
    margin-bottom: 20px;
}

.howto-section h4 {
    font-size: 14px;
    color: var(--coin-gold);
    margin-bottom: 10px;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--ui-border);
    padding-bottom: 6px;
}

.howto-row {
    font-size: 13px;
    color: rgba(255,255,255,0.75);
    padding: 5px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    line-height: 1.5;
}

.howto-row b {
    color: var(--text-white);
}

/* ========================================
   Bestiary (Monster Gallery)
   ======================================== */

.bestiary-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    padding: 10px;
    max-height: 320px;
    overflow-y: auto;
}

.bestiary-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    transition: all var(--transition-fast);
}

.bestiary-card.locked {
    filter: grayscale(1) brightness(0.3);
}

.bestiary-card.unlocked {
    border-color: rgba(255,215,0,0.3);
    background: rgba(255,215,0,0.05);
}

.bestiary-card:hover:not(.locked) {
    transform: scale(1.05);
    border-color: var(--coin-gold);
}

.bestiary-sprite {
    width: 48px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bestiary-sprite canvas {
    image-rendering: pixelated;
}

.bestiary-name {
    font-size: 10px;
    color: rgba(255,255,255,0.6);
    text-align: center;
    letter-spacing: 1px;
}

.bestiary-card.unlocked .bestiary-name {
    color: var(--coin-gold);
}

.bestiary-desc {
    font-size: 9px;
    color: rgba(255,255,255,0.4);
    text-align: center;
    line-height: 1.3;
}

@media (max-width: 768px) {
    .bestiary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ========================================
   Scrollbar Styling
   ======================================== */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.3);
}
