/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg: #1a1a2e;
    --color-surface: #16213e;
    --color-primary: #e94560;
    --color-primary-hover: #d63050;
    --color-success: #4ade80;
    --color-error: #f87171;
    --color-text: #ffffff;
    --color-text-muted: #9ca3af;
    --color-streak: #fbbf24;
    --transition-speed: 0.3s;
    --border-radius: 12px;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Screen management */
.screen {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    padding-top: env(safe-area-inset-top, 20px);
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

.screen.active {
    display: flex;
}

/* Menu Screen */
.menu-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 32px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.logo {
    text-align: center;
}

.logo-emoji {
    font-size: 64px;
    display: block;
    margin-bottom: 8px;
}

.logo h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 4px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-streak));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--color-text-muted);
    font-size: 1rem;
    margin-top: 4px;
}

.highscore-box {
    background: var(--color-surface);
    padding: 16px 24px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 600;
}

.trophy {
    font-size: 1.5rem;
}

.difficulty-selector {
    width: 100%;
    text-align: center;
}

.difficulty-label {
    color: var(--color-text-muted);
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.difficulty-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.btn-difficulty {
    padding: 12px 20px;
    border: 2px solid var(--color-surface);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-difficulty.active {
    border-color: var(--color-primary);
    background: rgba(233, 69, 96, 0.2);
    color: var(--color-primary);
}

.btn-difficulty:hover {
    border-color: var(--color-primary);
}

/* Buttons */
.btn-primary {
    width: 100%;
    max-width: 300px;
    padding: 18px 32px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
}

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

.btn-secondary {
    width: 100%;
    max-width: 300px;
    padding: 16px 32px;
    background: transparent;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-secondary:hover {
    background: rgba(233, 69, 96, 0.1);
}

.btn-text {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 12px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-text:hover {
    color: var(--color-text);
}

/* Game Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--color-surface);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

.stat {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 4px;
}

.stat-streak .stat-value {
    color: var(--color-streak);
}

.fire {
    display: inline-block;
    transition: transform 0.2s;
}

.fire.pulse {
    animation: pulse 0.3s ease-in-out;
}

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

/* Flag container */
.flag-container {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--color-surface);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 24px;
    min-height: 180px;
    position: relative;
    overflow: hidden;
}

.flag-image {
    max-width: 100%;
    max-height: 140px;
    width: auto;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: opacity var(--transition-speed);
}

.flag-image.loading {
    opacity: 0;
}

.flag-loading {
    position: absolute;
    display: none;
}

.flag-loading.active {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--color-surface);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.flag-fallback {
    font-size: 80px;
    display: none;
}

.flag-fallback.active {
    display: flex;
}

/* Options */
.options-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    justify-content: flex-start;
}

.option-btn {
    width: 100%;
    min-height: 56px;
    padding: 16px 20px;
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.option-btn:hover:not(:disabled) {
    border-color: var(--color-primary);
    background: rgba(233, 69, 96, 0.1);
}

.option-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.option-btn:disabled {
    cursor: not-allowed;
    opacity: 0.8;
}

.option-btn.correct {
    background: var(--color-success);
    color: #000;
    border-color: var(--color-success);
}

.option-btn.incorrect {
    background: var(--color-error);
    color: #000;
    border-color: var(--color-error);
}

.option-btn.show-correct {
    border-color: var(--color-success);
    background: rgba(74, 222, 128, 0.2);
}

/* Result Screen */
.result-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.result-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--color-primary);
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    width: 100%;
    background: var(--color-surface);
    padding: 24px;
    border-radius: var(--border-radius);
}

.result-stat {
    text-align: center;
}

.result-stat-value {
    display: block;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--color-text);
}

.result-stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.new-record {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--color-streak);
    animation: bounce 0.5s ease-in-out infinite alternate;
}

.new-record.hidden {
    display: none;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-5px); }
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: center;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Responsive */
@media (min-width: 768px) {
    .menu-content {
        gap: 40px;
    }

    .logo-emoji {
        font-size: 80px;
    }

    .logo h1 {
        font-size: 3rem;
    }

    .flag-container {
        min-height: 220px;
        padding: 30px;
    }

    .flag-image {
        max-height: 180px;
    }

    .options-container {
        max-width: 500px;
        margin: 0 auto;
    }

    .result-stats {
        gap: 48px;
    }

    .result-stat-value {
        font-size: 2.2rem;
    }
}

/* Landscape mode adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    .screen {
        padding: 10px 20px;
    }

    .menu-content {
        gap: 16px;
    }

    .logo-emoji {
        font-size: 40px;
    }

    .logo h1 {
        font-size: 1.8rem;
    }

    .flag-container {
        min-height: 120px;
        padding: 10px;
    }

    .flag-image {
        max-height: 100px;
    }

    .option-btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 1rem;
    }

    .options-container {
        gap: 8px;
    }
}
