/* ===== Ratio Kitchen - Elephant Math Savanna Theme ===== */

:root {
    --savanna-gold: #F5A623;
    --savanna-green: #4CAF50;
    --savanna-brown: #5D4037;
    --text-dark: #2C1810;
    --text-medium: #5D4037;
    --white: #FFFFFF;
    --correct-green: #4CAF50;
    --wrong-red: #E53935;
    --timer-yellow: #FFC107;
    --timer-red: #E53935;
    --card-bg: linear-gradient(180deg, #FFF8E7 0%, #FFF3E0 100%);
    --card-border: #E8C87A;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    --kitchen-warm: #FFF3E0;
    --kitchen-tile: #FFECD2;
}

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

body {
    font-family: 'Quicksand', sans-serif;
    min-height: 100vh;
    background: linear-gradient(180deg, #FFECD2 0%, #FCB69F 30%, #FFF3E0 60%, #FFE0B2 100%);
    color: var(--text-dark);
    overflow-x: hidden;
}

/* ===== Screens ===== */
.screen {
    display: none;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ===== Back Link ===== */
.back-link {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 100;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    color: var(--savanna-brown);
    text-decoration: none;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 12px;
    padding: 8px 16px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}

.back-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ===== START SCREEN ===== */
.start-container {
    max-width: 480px;
    width: 100%;
    text-align: center;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 24px;
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}

.game-logo {
    font-size: 4rem;
    margin-bottom: 8px;
    line-height: 1;
}

.game-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--savanna-brown);
    margin-bottom: 8px;
}

.game-subtitle {
    font-size: 1.1rem;
    color: var(--text-medium);
    margin-bottom: 28px;
    line-height: 1.5;
}

/* Settings Panel */
.settings-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 24px;
}

.setting-group {
    text-align: left;
}

.setting-group label {
    display: block;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--savanna-brown);
    margin-bottom: 8px;
}

.option-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.option-btn {
    flex: 1;
    min-width: 56px;
    padding: 10px 12px;
    font-family: 'Quicksand', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    border: 2px solid var(--card-border);
    border-radius: 12px;
    background: var(--white);
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.2s;
}

.option-btn:hover {
    border-color: var(--savanna-gold);
    background: #FFF8E1;
}

.option-btn.selected {
    border-color: var(--savanna-gold);
    background: var(--savanna-gold);
    color: #2C1810;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(245, 166, 35, 0.4);
}

/* High Score */
.high-score-display {
    background: rgba(245, 166, 35, 0.15);
    border: 2px solid var(--savanna-gold);
    border-radius: 12px;
    padding: 10px 20px;
    margin-bottom: 20px;
    font-family: 'Fredoka', sans-serif;
}

.high-score-label {
    font-size: 0.9rem;
    color: var(--text-medium);
}

.high-score-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #B8700A;
    margin-left: 8px;
}

/* Start Button */
.start-btn {
    display: inline-block;
    padding: 16px 48px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--white);
    background: linear-gradient(135deg, var(--savanna-gold) 0%, #E8941A 100%);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: 0 4px 0 #C07A10, var(--shadow-md);
    transition: all 0.15s;
    margin-bottom: 24px;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #C07A10, var(--shadow-lg);
}

.start-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #C07A10, var(--shadow-sm);
}

/* Instructions */
.instructions {
    font-size: 0.9rem;
    color: var(--text-medium);
    line-height: 1.6;
}

.instructions strong {
    color: var(--savanna-brown);
}

.keyboard-hint {
    margin-top: 8px;
    font-size: 0.85rem;
    opacity: 0.7;
}

kbd {
    display: inline-block;
    padding: 2px 8px;
    font-family: 'Quicksand', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    background: var(--white);
    border: 2px solid var(--card-border);
    border-radius: 6px;
    box-shadow: 0 2px 0 var(--card-border);
}

/* ===== GAME SCREEN ===== */
#game-screen.active {
    justify-content: flex-start;
    padding-top: 0;
    gap: 0;
}

/* Top Bar */
.game-top-bar {
    width: 100%;
    max-width: 600px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 0 12px;
}

.lives-section {
    display: flex;
    gap: 4px;
    align-items: center;
}

.chef-hat {
    font-size: 1.8rem;
    transition: all 0.3s;
    filter: none;
}

.chef-hat.lost {
    filter: grayscale(1) opacity(0.3);
    transform: scale(0.85);
}

.chef-hat.losing {
    animation: hat-fall 0.6s ease forwards;
}

@keyframes hat-fall {
    0% { transform: scale(1) rotate(0); opacity: 1; }
    50% { transform: scale(1.2) rotate(-15deg); opacity: 0.7; }
    100% { transform: scale(0.85) rotate(0); opacity: 0.3; filter: grayscale(1); }
}

.score-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 12px;
    padding: 6px 16px;
    min-width: 80px;
}

.score-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.score-value {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: #B8700A;
}

/* Streak Display */
.streak-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
    opacity: 0.5;
    transition: all 0.3s;
}

.streak-display.on-fire {
    background: linear-gradient(135deg, #FF6B35 0%, #F7931A 100%);
    color: var(--white);
    opacity: 1;
    box-shadow: 0 0 20px rgba(255, 107, 53, 0.4);
    animation: fire-glow 1s ease-in-out infinite alternate;
}

@keyframes fire-glow {
    0% { box-shadow: 0 0 20px rgba(255, 107, 53, 0.4); }
    100% { box-shadow: 0 0 30px rgba(255, 107, 53, 0.7); }
}

.streak-count {
    font-size: 1.3rem;
}

.streak-label {
    font-size: 0.85rem;
    font-weight: 600;
}

/* ===== Order Ticket ===== */
.order-ticket {
    width: 100%;
    max-width: 600px;
    background: #FFFFF0;
    border: 2px dashed #C8A96E;
    border-radius: 4px;
    padding: 20px 24px 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md), inset 0 0 20px rgba(200, 169, 110, 0.1);
    position: relative;
}

.order-ticket::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20px;
    right: 20px;
    height: 3px;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 4px,
        #C8A96E 4px,
        #C8A96E 8px
    );
}

.ticket-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed #D4B896;
}

.ticket-number {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--savanna-brown);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.ticket-icon {
    font-size: 1.4rem;
}

.ticket-context {
    font-family: 'Quicksand', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-medium);
    margin-bottom: 12px;
    font-style: italic;
}

.ticket-question {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-dark);
    line-height: 1.5;
    margin-bottom: 16px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Per-question timer bar */
.per-question-timer {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.pq-timer-fill {
    height: 100%;
    width: 100%;
    background: var(--savanna-green);
    border-radius: 3px;
    transition: width 0.1s linear, background-color 0.3s;
}

.pq-timer-fill.warning {
    background: var(--timer-yellow);
}

.pq-timer-fill.danger {
    background: var(--timer-red);
}

/* ===== Answer Input Area ===== */
.answer-area {
    width: 100%;
    max-width: 600px;
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.answer-input {
    width: 100%;
    padding: 16px 60px 16px 20px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 1.4rem;
    color: var(--text-dark);
    background: var(--white);
    border: 3px solid var(--card-border);
    border-radius: 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: var(--shadow-sm);
}

.answer-input:focus {
    border-color: var(--savanna-gold);
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.3), var(--shadow-md);
}

.answer-input.correct {
    border-color: var(--correct-green);
    background: #E8F5E9;
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3);
}

.answer-input.wrong {
    border-color: var(--wrong-red);
    background: #FFEBEE;
    box-shadow: 0 0 0 3px rgba(229, 57, 53, 0.3);
    animation: wrong-shake 0.4s ease;
}

@keyframes wrong-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    50% { transform: translateX(8px); }
    75% { transform: translateX(-4px); }
}

.answer-unit {
    position: absolute;
    right: 16px;
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-medium);
    opacity: 0.6;
    pointer-events: none;
}

.submit-btn {
    padding: 16px 24px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--white);
    background: linear-gradient(135deg, var(--savanna-green) 0%, #388E3C 100%);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    box-shadow: 0 4px 0 #2E7D32, var(--shadow-sm);
    transition: all 0.15s;
    white-space: nowrap;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #2E7D32, var(--shadow-md);
}

.submit-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #2E7D32;
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

/* Feedback overlay */
.feedback-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Fredoka', sans-serif;
    font-size: 3rem;
    font-weight: 700;
    pointer-events: none;
    opacity: 0;
    z-index: 50;
}

.feedback-overlay.show-correct {
    color: var(--correct-green);
    opacity: 1;
    animation: feedback-pop 0.6s ease forwards;
}

.feedback-overlay.show-wrong {
    color: var(--wrong-red);
    opacity: 1;
    animation: feedback-pop 0.6s ease forwards;
}

@keyframes feedback-pop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

/* Correct answer display */
.correct-answer-display {
    width: 100%;
    max-width: 600px;
    text-align: center;
    padding: 10px;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--wrong-red);
    opacity: 0;
    transition: opacity 0.3s;
}

.correct-answer-display.visible {
    opacity: 1;
}

/* ===== RESULTS SCREEN ===== */
.results-container {
    max-width: 480px;
    width: 100%;
    text-align: center;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 24px;
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}

.results-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--savanna-brown);
    margin-bottom: 16px;
}

/* Star rating */
.star-rating {
    margin-bottom: 20px;
}

.star {
    font-size: 3rem;
    color: #D5D5D5;
    transition: color 0.3s, transform 0.3s;
    display: inline-block;
}

.star.earned {
    color: var(--savanna-gold);
    animation: star-pop 0.5s ease;
}

@keyframes star-pop {
    0% { transform: scale(0); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Results Score */
.results-score {
    margin-bottom: 24px;
}

.results-score-label {
    display: block;
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    color: var(--text-medium);
    margin-bottom: 4px;
}

.results-score-value {
    font-family: 'Fredoka', sans-serif;
    font-size: 3.5rem;
    font-weight: 700;
    color: #B8700A;
}

/* Stats Grid */
.results-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    padding: 12px 8px;
}

.stat-value {
    display: block;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--savanna-brown);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-medium);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* XP Display */
.xp-earned-display {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #FFD700 0%, #FFA000 100%);
    border-radius: 16px;
    margin-bottom: 16px;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
    animation: xp-glow 1.5s ease-in-out infinite alternate;
}

@keyframes xp-glow {
    0% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.4); }
    100% { box-shadow: 0 0 30px rgba(255, 215, 0, 0.7); }
}

.xp-icon {
    font-size: 1.5rem;
}

.xp-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--white);
}

/* New High Score */
.new-high-score {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: #B8700A;
    margin-bottom: 20px;
    animation: high-score-bounce 0.8s ease infinite alternate;
}

@keyframes high-score-bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-6px); }
}

/* Actions */
.results-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    margin-top: 8px;
}

.secondary-btn {
    display: inline-block;
    padding: 12px 32px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    color: var(--savanna-brown);
    background: var(--white);
    border: 2px solid var(--card-border);
    border-radius: 12px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    border-color: var(--savanna-gold);
    background: #FFF8E1;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 600px) {
    .screen {
        padding: 12px;
    }

    .back-link {
        top: 8px;
        left: 8px;
        font-size: 0.85rem;
        padding: 6px 12px;
    }

    .start-container,
    .results-container {
        padding: 24px 16px;
        border-radius: 20px;
    }

    .game-title {
        font-size: 2rem;
    }

    .game-subtitle {
        font-size: 1rem;
    }

    .ticket-question {
        font-size: 1.1rem;
    }

    .answer-input {
        font-size: 1.2rem;
        padding: 14px 50px 14px 16px;
    }

    .submit-btn {
        padding: 14px 18px;
        font-size: 1rem;
    }

    .answer-area {
        flex-direction: column;
    }

    .game-top-bar {
        padding: 12px 0 8px;
    }

    .chef-hat {
        font-size: 1.5rem;
    }

    .score-value {
        font-size: 1.2rem;
    }

    .keyboard-hint {
        display: none;
    }

    .results-score-value {
        font-size: 2.8rem;
    }

    .star {
        font-size: 2.4rem;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .option-btn {
        min-width: 48px;
        padding: 8px 8px;
        font-size: 0.85rem;
    }
}

/* Touch optimization */
.answer-input,
.submit-btn {
    -webkit-tap-highlight-color: rgba(245, 166, 35, 0.3);
    touch-action: manipulation;
}

/* Prevent iOS bounce scroll during gameplay */
#game-screen {
    overscroll-behavior: none;
}

#game-screen.active {
    overflow: hidden;
    position: fixed;
    inset: 0;
    padding: 12px 20px;
}

/* Landscape mobile: tighter layout */
@media (max-height: 500px) and (orientation: landscape) {
    .order-ticket {
        padding: 12px 16px 8px;
        margin-bottom: 8px;
    }

    .ticket-question {
        font-size: 1.1rem;
        min-height: 40px;
        margin-bottom: 8px;
    }

    .answer-input {
        padding: 10px 50px 10px 14px;
        font-size: 1.1rem;
    }

    .submit-btn {
        padding: 10px 16px;
        font-size: 0.95rem;
    }

    .game-top-bar {
        padding: 8px 0 4px;
    }

    .streak-display {
        margin-bottom: 6px;
    }
}

/* Skip link (accessibility) */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--savanna-gold);
    color: var(--white);
    padding: 8px;
    z-index: 200;
}

.skip-link:focus {
    top: 0;
}
