/* ============================================================================
   RESET & BASE STYLES
   ============================================================================ */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #1a1a2e;
    color: #ffffff;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

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

#gameCanvas {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #2C3E50;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    touch-action: none;
}

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

#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a2e;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-text {
    font-size: 32px;
    font-weight: bold;
    color: #ffffff;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ============================================================================
   SCREENS (MENU, COUNTDOWN, GAME OVER)
   ============================================================================ */

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(10px);
}

.screen.hidden {
    display: none !important;
}

.hidden {
    display: none !important;
}

/* ============================================================================
   MENU SCREEN
   ============================================================================ */

#menu h1 {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 40px;
    text-align: center;
    text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5);
    line-height: 1.2;
    max-width: 90%;
}

/* ============================================================================
   COUNTDOWN SCREEN
   ============================================================================ */

.countdown-text {
    font-size: 120px;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.8);
    animation: countdownPulse 1s ease-in-out;
}

@keyframes countdownPulse {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================================================
   GAME OVER SCREEN
   ============================================================================ */

#gameOver {
    padding: 20px;
}

.game-over-panel {
    background: rgba(44, 62, 80, 0.95);
    border-radius: 15px;
    padding: 20px 15px;
    max-width: 450px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

.game-over-panel h2 {
    font-size: 24px;
    text-align: center;
    margin-bottom: 12px;
    color: #e74c3c;
}

.final-score,
.final-level {
    font-size: 18px;
    text-align: center;
    margin-bottom: 8px;
}

.final-score span,
.final-level span {
    font-weight: bold;
    color: #3498db;
}

/* ============================================================================
   HIGH SCORES LIST
   ============================================================================ */

.high-scores-container {
    margin: 15px 0;
}

.high-scores-container h3 {
    font-size: 18px;
    text-align: center;
    margin-bottom: 10px;
    color: #f39c12;
}

#highScoresList {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 10px;
    max-height: 200px;
    overflow-y: auto;
}

.high-score-entry {
    padding: 6px 8px;
    margin-bottom: 4px;
    font-size: 14px;
    border-radius: 4px;
    transition: background 0.3s;
}

.high-score-entry:hover {
    background: rgba(255, 255, 255, 0.1);
}

.high-score-entry.highlight {
    background: rgba(241, 196, 15, 0.3);
    color: #f1c40f;
    font-weight: bold;
}

.no-scores {
    text-align: center;
    color: #95a5a6;
    padding: 15px;
    font-size: 13px;
    font-style: italic;
}

/* ============================================================================
   NAME INPUT
   ============================================================================ */

#nameInputContainer {
    margin: 15px 0;
    text-align: center;
}

#nameInputContainer label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
    color: #ecf0f1;
}

.name-input-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    max-width: 320px;
    margin: 0 auto;
}

#nameInput {
    flex: 1;
    padding: 8px 10px;
    font-size: 14px;
    text-align: center;
    border: 2px solid #3498db;
    border-radius: 8px;
    background: rgba(52, 152, 219, 0.2);
    color: #ffffff;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#nameInput:focus {
    border-color: #2ecc71;
    background: rgba(46, 204, 113, 0.2);
    animation: inputPulse 0.5s ease-in-out;
}

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

.name-hint {
    margin-top: 6px;
    font-size: 11px;
    color: #95a5a6;
    font-style: italic;
}

/* ============================================================================
   YOUR SCORE DISPLAY
   ============================================================================ */

#yourScoreDisplay {
    margin: 15px 0;
    padding: 10px;
    background: rgba(241, 196, 15, 0.2);
    border-radius: 8px;
    text-align: center;
}

.your-score {
    font-size: 16px;
    color: #f1c40f;
    font-weight: bold;
}

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

.button-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
    flex-wrap: wrap;
}

button {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    min-width: 120px;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #764ba2 0%, #f093fb 100%);
    box-shadow: 0 6px 20px rgba(118, 75, 162, 0.6);
}

.btn-secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.4);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #f5576c 0%, #4facfe 100%);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.6);
}

.btn-submit {
    padding: 8px 14px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    min-width: 45px;
}

.btn-submit:hover {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.btn-submit:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* ============================================================================
   MOBILE JOYSTICK
   ============================================================================ */

#joystick {
    position: fixed;
    width: 150px;
    height: 150px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 2000;
}

.joystick-base {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.05) 100%);
    border: 3px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.joystick-stick {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.8) 0%, rgba(255, 255, 255, 0.4) 100%);
    border: 3px solid rgba(255, 255, 255, 0.6);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    transition: transform 0.05s ease-out;
}

/* ============================================================================
   SCROLLBAR STYLING
   ============================================================================ */

#highScoresList::-webkit-scrollbar {
    width: 8px;
}

#highScoresList::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

#highScoresList::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

#highScoresList::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.game-over-panel::-webkit-scrollbar {
    width: 8px;
}

.game-over-panel::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

.game-over-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
}

.game-over-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

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

@media (max-width: 600px) {
    #menu h1 {
        font-size: 36px;
        margin-bottom: 30px;
    }

    .countdown-text {
        font-size: 80px;
    }

    .game-over-panel {
        padding: 30px 20px;
    }

    .game-over-panel h2 {
        font-size: 28px;
    }

    .final-score,
    .final-level {
        font-size: 20px;
    }

    .high-score-entry {
        font-size: 16px;
    }

    button {
        padding: 12px 20px;
        font-size: 16px;
        min-width: 130px;
    }

    .hud-top {
        padding: 15px;
    }

    .level-label {
        font-size: 22px;
    }

    .score-label {
        font-size: 32px;
    }
}

@media (max-height: 700px) {
    .game-over-panel {
        padding: 20px 15px;
    }

    .game-over-panel h2 {
        font-size: 24px;
        margin-bottom: 10px;
    }

    .final-score,
    .final-level {
        font-size: 18px;
        margin-bottom: 5px;
    }

    .high-scores-container {
        margin: 15px 0;
    }

    #highScoresList {
        max-height: 200px;
    }
}

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

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

.screen:not(.hidden) {
    animation: fadeIn 0.3s ease-out;
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

button:focus-visible {
    outline: 3px solid #3498db;
    outline-offset: 3px;
}

#nameInput:focus-visible {
    outline: 3px solid #2ecc71;
    outline-offset: 2px;
}

/* ============================================================================
   PRINT (DISABLE)
   ============================================================================ */

@media print {
    body {
        display: none;
    }
}
