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

/* ===== GAME SCREEN ===== */
#game-screen.active {
    justify-content: flex-start;
    padding-top: 0;
    gap: 0;
    position: fixed;
    inset: 0;
    overflow: hidden;
    padding: 12px 20px;
}

/* Top Bar */
.game-top-bar {
    width: 100%;
    max-width: 600px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0 8px;
    z-index: 10;
}

/* Lives */
.lives-section {
    display: flex;
    gap: 4px;
    font-size: 1.6rem;
}

.life-balloon {
    transition: all 0.3s;
    display: inline-block;
}

.life-balloon.lost {
    opacity: 0.25;
    filter: grayscale(1);
    transform: scale(0.7);
}

.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;
    margin-left: auto;
}

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

/* ===== Scenario Card ===== */
.scenario-card {
    width: 100%;
    max-width: 600px;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 20px;
    padding: 20px 24px;
    box-shadow: var(--shadow-md);
    text-align: center;
    z-index: 10;
    margin-bottom: 12px;
}

.scenario-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--savanna-brown);
    margin-bottom: 12px;
    line-height: 1.5;
}

/* ===== Context Visuals ===== */
.context-visual {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60px;
}

/* Bag of marbles */
.marble-bag {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    align-items: center;
    background: rgba(139, 90, 43, 0.15);
    border: 2px dashed #8B5A2B;
    border-radius: 16px;
    padding: 12px 16px;
    max-width: 220px;
}

.marble {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    box-shadow: inset -3px -3px 6px rgba(0,0,0,0.2), inset 3px 3px 6px rgba(255,255,255,0.3);
}

.marble.red { background: #E53935; }
.marble.blue { background: #1E88E5; }
.marble.green { background: #43A047; }
.marble.yellow { background: #FDD835; }
.marble.purple { background: #8E24AA; }
.marble.orange { background: #FB8C00; }
.marble.white { background: #F5F5F5; border: 1px solid #CCC; }

/* Spinner */
.spinner-visual {
    position: relative;
    width: 100px;
    height: 100px;
}

.spinner-visual svg {
    width: 100%;
    height: 100%;
}

/* Dice */
.dice-visual {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.die {
    width: 48px;
    height: 48px;
    background: var(--white);
    border: 2px solid #999;
    border-radius: 8px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.die-dot {
    width: 8px;
    height: 8px;
    background: #333;
    border-radius: 50%;
    align-self: center;
    justify-self: center;
}

/* Cards visual */
.cards-visual {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
}

.card-item {
    width: 32px;
    height: 42px;
    background: var(--white);
    border: 2px solid #999;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card-item.vowel { color: #E53935; border-color: #E53935; }
.card-item.consonant { color: #1E88E5; border-color: #1E88E5; }

/* Coins visual */
.coins-visual {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.coin {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FFD700, #DAA520);
    border: 2px solid #B8860B;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 0.7rem;
    color: #5D4037;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* ===== Balloon Arena ===== */
.balloon-arena {
    position: relative;
    width: 100%;
    max-width: 600px;
    flex: 1;
    overflow: hidden;
    z-index: 5;
}

/* ===== Balloons ===== */
.balloon {
    position: absolute;
    width: 90px;
    height: 110px;
    cursor: pointer;
    animation: float-up var(--float-duration, 12s) linear forwards;
    z-index: 5;
    -webkit-tap-highlight-color: rgba(245, 166, 35, 0.3);
    touch-action: manipulation;
    user-select: none;
}

.balloon-body {
    width: 90px;
    height: 100px;
    border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: inset -8px -8px 20px rgba(0,0,0,0.15), inset 8px 8px 20px rgba(255,255,255,0.25);
    transition: transform 0.1s;
}

.balloon-body::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 10px solid inherit;
}

.balloon-text {
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--white);
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    text-align: center;
    line-height: 1.2;
    padding: 4px;
    pointer-events: none;
}

/* Balloon colors */
.balloon-red .balloon-body {
    background: linear-gradient(135deg, #EF5350, #C62828);
}
.balloon-red .balloon-body::after {
    border-top-color: #C62828;
}

.balloon-blue .balloon-body {
    background: linear-gradient(135deg, #42A5F5, #1565C0);
}
.balloon-blue .balloon-body::after {
    border-top-color: #1565C0;
}

.balloon-green .balloon-body {
    background: linear-gradient(135deg, #66BB6A, #2E7D32);
}
.balloon-green .balloon-body::after {
    border-top-color: #2E7D32;
}

.balloon-yellow .balloon-body {
    background: linear-gradient(135deg, #FFCA28, #F9A825);
}
.balloon-yellow .balloon-body::after {
    border-top-color: #F9A825;
}
.balloon-yellow .balloon-text {
    color: var(--text-dark);
    text-shadow: 0 1px 2px rgba(255,255,255,0.4);
}

/* String beneath balloon */
.balloon-string {
    width: 2px;
    height: 30px;
    background: #999;
    margin: 0 auto;
    position: relative;
}

/* Wobble animation */
@keyframes float-up {
    0% {
        bottom: -140px;
        opacity: 1;
    }
    3% {
        opacity: 1;
    }
    95% {
        opacity: 1;
    }
    100% {
        bottom: 110%;
        opacity: 0;
    }
}

.balloon {
    animation: float-up var(--float-duration, 12s) linear forwards,
               wobble 2.5s ease-in-out infinite;
}

@keyframes wobble {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* Pop animation - correct */
.balloon.pop-correct {
    animation: pop-burst 0.4s ease forwards !important;
    pointer-events: none;
}

@keyframes pop-burst {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

/* Pop animation - wrong */
.balloon.pop-wrong {
    animation: pop-explode 0.5s ease forwards !important;
    pointer-events: none;
}

@keyframes pop-explode {
    0% { transform: scale(1); opacity: 1; }
    20% { transform: scale(1.2); opacity: 1; }
    40% { transform: scale(0.8) rotate(10deg); opacity: 0.8; }
    60% { transform: scale(0.5) rotate(-10deg); opacity: 0.5; }
    100% { transform: scale(0) rotate(20deg); opacity: 0; }
}

/* Wrong X overlay on balloon */
.balloon.pop-wrong .balloon-body::before {
    content: '\2716';
    position: absolute;
    font-size: 2.5rem;
    color: var(--wrong-red);
    z-index: 10;
    text-shadow: 0 0 6px rgba(0,0,0,0.5);
}

/* Missed balloons fade */
.balloon.missed {
    animation: none !important;
    opacity: 0;
    transition: opacity 0.3s;
}

/* ===== Confetti ===== */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 1;
    animation: confetti-fall 1s ease-out forwards;
}

@keyframes confetti-fall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(200px) rotate(720deg) scale(0.3);
    }
}

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

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

    .scenario-text {
        font-size: 1rem;
    }

    .scenario-card {
        padding: 14px 16px;
        border-radius: 16px;
    }

    .balloon {
        width: 76px;
        height: 95px;
    }

    .balloon-body {
        width: 76px;
        height: 85px;
    }

    .balloon-text {
        font-size: 0.95rem;
    }

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

    .lives-section {
        font-size: 1.3rem;
    }

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

    .marble {
        width: 20px;
        height: 20px;
    }

    .die {
        width: 40px;
        height: 40px;
        padding: 4px;
    }

    .die-dot {
        width: 6px;
        height: 6px;
    }

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

    .star {
        font-size: 2.4rem;
    }

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

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

    .scenario-text {
        font-size: 0.95rem;
        margin-bottom: 6px;
    }

    .context-visual {
        min-height: 40px;
    }

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

    .balloon {
        width: 70px;
        height: 88px;
    }

    .balloon-body {
        width: 70px;
        height: 78px;
    }

    .balloon-text {
        font-size: 0.85rem;
    }
}

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

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