/* ===== Percentage Panic - 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);
}

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

body {
    font-family: 'Quicksand', sans-serif;
    min-height: 100vh;
    background: linear-gradient(180deg, #87CEEB 0%, #E0F4FF 30%, #C4E5B4 60%, #A8D08D 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;
    gap: 16px;
    padding: 16px 0 12px;
}

.timer-section {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.timer-bar-container {
    flex: 1;
    height: 16px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--card-border);
}

.timer-bar {
    height: 100%;
    width: 100%;
    background: var(--savanna-green);
    border-radius: 6px;
    transition: width 0.1s linear;
}

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

.timer-bar.danger {
    background: var(--timer-red);
    animation: pulse-timer 0.5s ease-in-out infinite;
}

@keyframes pulse-timer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.timer-text {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--savanna-brown);
    min-width: 36px;
    text-align: right;
}

.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;
}

/* Game Status Row (reputation + streak) */
.game-status-row {
    width: 100%;
    max-width: 600px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

/* Reputation Stars (Lives) */
.reputation-display {
    display: flex;
    gap: 6px;
}

.rep-star {
    font-size: 2rem;
    color: #D5D5D5;
    transition: all 0.3s;
    display: inline-block;
}

.rep-star.active {
    color: var(--savanna-gold);
}

.rep-star.losing {
    animation: star-lose 0.5s ease forwards;
}

@keyframes star-lose {
    0% { transform: scale(1); color: var(--savanna-gold); }
    50% { transform: scale(1.4) rotate(15deg); color: var(--wrong-red); }
    100% { transform: scale(0.8); color: #D5D5D5; }
}

/* 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);
    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;
}

/* ===== Customer Area ===== */
.customer-area {
    width: 100%;
    max-width: 600px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 8px;
}

.customer-face {
    font-size: 3.5rem;
    line-height: 1;
    flex-shrink: 0;
    transition: all 0.3s;
}

.customer-face.happy {
    animation: customer-happy 0.5s ease;
}

.customer-face.angry {
    animation: customer-angry 0.5s ease;
}

@keyframes customer-happy {
    0% { transform: scale(1); }
    50% { transform: scale(1.2) rotate(-5deg); }
    100% { transform: scale(1); }
}

@keyframes customer-angry {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px) rotate(-5deg); }
    40% { transform: translateX(6px) rotate(5deg); }
    60% { transform: translateX(-4px) rotate(-3deg); }
    80% { transform: translateX(4px) rotate(3deg); }
}

.speech-bubble {
    position: relative;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 20px;
    padding: 20px 24px;
    box-shadow: var(--shadow-md);
    flex: 1;
}

.speech-bubble::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 20px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 12px solid var(--card-border);
}

.speech-bubble::after {
    content: '';
    position: absolute;
    left: -9px;
    top: 22px;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 10px solid #FFF8E7;
}

.question-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--savanna-brown);
    line-height: 1.4;
}

/* Price Tag */
.price-tag {
    width: 100%;
    max-width: 600px;
    text-align: center;
    margin-bottom: 8px;
}

.price-tag-text {
    display: inline-block;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-medium);
    background: rgba(255, 255, 255, 0.6);
    padding: 6px 16px;
    border-radius: 10px;
    border: 1px dashed var(--card-border);
}

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

.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-input-area {
    width: 100%;
    max-width: 600px;
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--white);
    border: 3px solid var(--card-border);
    border-radius: 16px;
    overflow: hidden;
    transition: border-color 0.2s;
}

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

.currency-prefix {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-medium);
    padding: 0 4px 0 16px;
    user-select: none;
}

.answer-input {
    flex: 1;
    border: none;
    outline: none;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--savanna-brown);
    padding: 16px 16px 16px 4px;
    background: transparent;
    width: 100%;
    min-width: 0;
}

.answer-input::placeholder {
    color: #C4A872;
    font-weight: 500;
    font-size: 1rem;
}

.answer-input.correct {
    color: var(--correct-green);
}

.answer-input.wrong {
    color: var(--wrong-red);
}

.submit-btn {
    padding: 16px 28px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 1.2rem;
    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-sm);
    transition: all 0.15s;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(245, 166, 35, 0.3);
}

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

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

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

/* Correct/Wrong input wrapper feedback */
.input-wrapper.correct {
    border-color: var(--correct-green);
    animation: correct-pulse 0.4s ease;
}

.input-wrapper.wrong {
    border-color: var(--wrong-red);
    animation: wrong-shake 0.4s ease;
}

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

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

/* 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 reveal */
.correct-answer-reveal {
    width: 100%;
    max-width: 600px;
    text-align: center;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--correct-green);
    padding: 8px;
    opacity: 0;
    transition: opacity 0.3s;
}

.correct-answer-reveal.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;
    }

    .customer-face {
        font-size: 2.8rem;
    }

    .question-text {
        font-size: 1.2rem;
    }

    .speech-bubble {
        padding: 14px 16px;
    }

    .answer-input {
        font-size: 1.2rem;
        padding: 12px 12px 12px 4px;
    }

    .currency-prefix {
        font-size: 1.2rem;
    }

    .submit-btn {
        padding: 12px 20px;
        font-size: 1rem;
    }

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

    .timer-text {
        font-size: 1.2rem;
    }

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

    .rep-star {
        font-size: 1.6rem;
    }

    .keyboard-hint {
        display: none;
    }

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

    .star {
        font-size: 2.4rem;
    }

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

    .price-tag-text {
        font-size: 0.85rem;
    }
}

/* Touch optimization */
.submit-btn,
.answer-input {
    -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) {
    .customer-area {
        margin-bottom: 4px;
    }

    .customer-face {
        font-size: 2.4rem;
    }

    .speech-bubble {
        padding: 10px 14px;
    }

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

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

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

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

    .game-status-row {
        margin-bottom: 6px;
    }

    .rep-star {
        font-size: 1.4rem;
    }

    .price-tag {
        margin-bottom: 4px;
    }

    .per-question-timer {
        margin-bottom: 8px;
    }
}

/* 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;
}
