/* Math Estimator - Kid-Friendly Styles */

/* Fonts are served from this site (no requests to Google or anyone else).
   Latin subsets of the Google Fonts variable fonts, SIL Open Font License;
   see fonts/Fredoka-OFL.txt and fonts/Nunito-OFL.txt. */
@font-face {
    font-family: 'Fredoka';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('fonts/fredoka-latin.woff2') format('woff2');
}

@font-face {
    font-family: 'Nunito';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('fonts/nunito-latin.woff2') format('woff2');
}

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

:root {
    /* Warm, playful palette - less "vibe code", more kid-friendly */
    --primary: #FF6B6B;          /* Coral red - warm and inviting */
    --primary-dark: #ee5a5a;
    --primary-light: #ff8a8a;
    --secondary: #4ECDC4;        /* Teal - complementary pop */
    --accent: #FFE66D;           /* Sunny yellow */
    --danger: #FF6B6B;
    --purple: #A66CFF;           /* Fun purple accent */
    --background: #FFF9F0;       /* Warm cream background */
    --surface: #ffffff;
    --text: #2D3436;             /* Soft black */
    --text-light: #636E72;
    --border: #E0E0E0;
    --bullseye: #00B894;         /* Mint green - success */
    --close: #0984E3;            /* Ocean blue */
    --neighborhood: #FDCB6E;     /* Golden yellow */
    --far: #E17055;              /* Terracotta */
}

html, body {
    height: 100%;
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--background);
    color: var(--text);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

#app {
    height: 100%;
    max-width: 500px;
    margin: 0 auto;
}

/* Screens */
.screen {
    display: none;
    height: 100%;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
}

/* Form controls don't inherit the page font by default */
button,
input {
    font-family: inherit;
}

/* Visible keyboard focus everywhere */
:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
}

.screen.active {
    display: flex;
}

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

/* ============ START SCREEN ============ */
#start-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: 30px;
    background: linear-gradient(135deg, #FFF5E6 0%, #FFE8E8 50%, #E8F5FF 100%);
}

#start-screen h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    text-shadow: 3px 3px 0 rgba(255, 107, 107, 0.2);
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-light);
    margin-top: -20px;
}

.level-select {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

.level-select h2 {
    font-size: 1rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.level-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--surface);
    border: 2px solid transparent;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.level-btn:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.2);
}

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

.level-icon {
    font-size: 1.8rem;
}

.level-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
}

.level-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-left: auto;
}

.stats-preview {
    display: flex;
    gap: 20px;
    color: var(--text-light);
    font-size: 0.8rem;
}

.stats-preview span {
    font-weight: 600;
    color: var(--primary);
}

/* Timer toggle on mode screen */
.timer-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    cursor: pointer;
    padding: 6px 12px;
    background: var(--surface);
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.toggle-switch input:focus-visible + .toggle-slider {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #cbd5e1;
    border-radius: 22px;
    transition: 0.3s;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--secondary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(18px);
}

.toggle-label {
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 500;
}

/* Timer display in game header */
.timer-display {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    padding: 4px 8px;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.timer-display.hidden {
    display: none;
}

#timer-icon {
    font-size: 1.1rem;
}

#timer-value {
    font-family: 'Courier New', monospace;
    min-width: 48px;
    color: var(--primary);
}

/* "Answers stay on this device" line */
.privacy-note {
    font-size: 0.85rem;
    color: var(--text-light);
    text-align: center;
    max-width: 380px;
    margin: 4px auto;
}

/* Plain text-style button (e.g. "Clear my answers") */
.text-btn {
    display: block;
    min-height: 44px;
    margin: 8px auto 0;
    padding: 8px 16px;
    background: transparent;
    border: none;
    color: var(--text-light);
    font: inherit;
    font-size: 0.9rem;
    text-decoration: underline;
    cursor: pointer;
}

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

/* "For parents and teachers" (collapsed by default) */
.parent-note {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    text-align: left;
    font-size: 0.9rem;
    line-height: 1.5;
}

.parent-note summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

.parent-note p,
.parent-note ul {
    margin: 0 14px 10px;
}

.parent-note ul {
    padding-left: 18px;
}

.parent-note li {
    margin-bottom: 4px;
}

/* Per-mode estimation tip on the level screen */
.level-tip {
    max-width: 300px;
    margin: -8px 0 16px;
    padding: 10px 14px;
    background: #fef9c3;
    border-radius: 10px;
    color: #713f12;
    font-size: 0.95rem;
    line-height: 1.4;
}

.level-tip:empty {
    display: none;
}

.credits {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: center;
}

.credits p {
    margin: 2px 0;
}

.credits a {
    color: var(--primary);
    text-decoration: none;
}

.credits a:hover {
    text-decoration: underline;
}

/* ============ GAME SCREEN ============ */
#game-screen {
    gap: 8px;
    background: var(--background);
    overflow: hidden;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.icon-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: none;
    border-radius: 12px;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.icon-btn:hover {
    background: #f1f5f9;
}

.score-display {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
}

.streak-display {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 1.1rem;
    font-weight: 600;
}

#streak-icon {
    font-size: 1.3rem;
}

#streak-icon.fire {
    animation: pulse 0.5s ease infinite;
}

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

/* Problem Display */
.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    overflow-y: auto;
    padding-bottom: 10px;
}

.problem-container {
    text-align: center;
    padding: 16px;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.problem-type {
    font-size: 0.85rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.problem {
    font-family: 'Fredoka', sans-serif;
    font-size: 2rem;
    font-weight: 600;
    color: var(--text);
}

.problem-visual {
    font-size: 1.2rem;
    line-height: 1.4;
    margin-top: 12px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 12px;
    white-space: pre-wrap;
    letter-spacing: 2px;
}

.problem-visual:empty {
    display: none;
}

.problem-visual.mono {
    font-family: ui-monospace, Menlo, Consolas, 'Courier New', monospace;
    letter-spacing: 0;
    line-height: 1.25;
}

/* Number Line */
.number-line-container {
    padding: 10px 8px;
}

.number-line-labels {
    display: flex;
    justify-content: space-between;
    padding: 0 16px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 500;
}

.number-line {
    position: relative;
    padding: 20px 16px;
    cursor: pointer;
    touch-action: pan-y;
}

.number-line-track {
    position: relative;
    height: 14px;
    background: linear-gradient(90deg, #FFE0E0, #FFD0B0, #FFF0C0, #D0F0E0, #D0E8FF);
    border-radius: 7px;
    cursor: pointer;
    border: 2px solid rgba(255, 107, 107, 0.2);
}

.slider-thumb {
    touch-action: none;
    position: absolute;
    top: 50%;
    left: 0%; /* Start at 0, JS will set random position */
    transform: translate(-50%, -50%);
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: 4px solid var(--surface);
    border-radius: 50%;
    box-shadow: 0 3px 12px rgba(255, 107, 107, 0.4);
    cursor: grab;
    transition: box-shadow 0.2s; /* Remove transform transition for snappier feel */
    z-index: 2;
}

.slider-thumb:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

.slider-thumb:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 3px;
}

.slider-thumb.active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.5);
}

.answer-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 28px;
    background: var(--secondary);
    border-radius: 4px;
    z-index: 1;
    transition: opacity 0.3s;
}

.answer-marker.hidden {
    opacity: 0;
}

.answer-marker::after {
    content: '✓';
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1rem;
    color: var(--secondary);
}

.tick-marks {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}

.tick {
    width: 2px;
    height: 8px;
    background: #cbd5e1;
    border-radius: 1px;
}

.estimate-display {
    text-align: center;
    font-size: 1.1rem;
    color: var(--text);
    margin-top: 8px;
}

#estimate-value {
    font-weight: 700;
    color: var(--primary);
    font-size: 1.3rem;
}

/* Feedback */
.feedback {
    text-align: center;
    padding: 20px;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    animation: slideIn 0.3s ease;
}

.feedback.hidden {
    display: none;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback-emoji {
    font-size: 3rem;
    margin-bottom: 8px;
}

.feedback-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.feedback.bullseye .feedback-text { color: var(--bullseye); }
.feedback.close .feedback-text { color: var(--close); }
.feedback.neighborhood .feedback-text { color: var(--neighborhood); }
.feedback.far .feedback-text { color: var(--far); }

.feedback-details {
    font-size: 0.9rem;
    color: var(--text-light);
}

.feedback-details span {
    font-weight: 600;
    color: var(--text);
}

/* One-line "how far off" summary */
.feedback-miss {
    margin-top: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.feedback-miss:empty {
    display: none;
}

/* Explanation in feedback - for showing formulas and visual breakdowns */
.feedback-explanation {
    margin-top: 10px;
    padding: 14px;
    background: linear-gradient(135deg, rgba(78, 205, 196, 0.1) 0%, rgba(255, 230, 109, 0.1) 100%);
    border-radius: 12px;
    border: 1px solid rgba(78, 205, 196, 0.2);
    font-size: 1.05rem;
    color: var(--text);
    text-align: left;
    white-space: pre-line;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

.feedback-explanation.hidden {
    display: none;
}

.feedback-explanation a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.feedback-explanation a:hover {
    color: var(--primary-dark, #4f46e5);
    text-decoration: underline;
}

/* Time info in feedback */
.time-info {
    margin-top: 10px;
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 500;
}

.time-info.hidden {
    display: none;
}

/* Credits reminder in feedback */
.credits-reminder {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
    font-size: 0.8rem;
    color: var(--text-light);
}

.credits-reminder.hidden {
    display: none;
}

.credits-reminder a {
    color: var(--primary);
    text-decoration: none;
}

.credits-reminder a:hover {
    text-decoration: underline;
}

/* Footer */
.game-footer {
    padding: 8px 0;
    flex-shrink: 0;
}

.primary-btn {
    width: 100%;
    padding: 16px 28px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 16px;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.35);
}

/* Direct number input (for advanced modes) */
.number-input-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px;
}

.number-input-container.hidden {
    display: none;
}

.number-input-help {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-light, #475569);
    text-align: center;
}

.number-input {
    width: 100%;
    max-width: 260px;
    padding: 16px 20px;
    font-size: 1.8rem;
    font-weight: 700;
    text-align: center;
    border: 3px solid #e2e8f0;
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s;
}

.number-input:focus {
    outline: none;
    border-color: var(--primary);
}

.number-input::placeholder {
    color: #64748b;
    font-size: 1.2rem;
}

/* Hint button (any mode) */
.hint-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.hint-btn {
    min-height: 44px;
    padding: 8px 16px;
    background: #fef3c7;
    border: 2px solid #fcd34d;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #92400e;
    cursor: pointer;
    transition: all 0.2s;
}

.hint-btn:hover {
    background: #fde68a;
    transform: translateY(-1px);
}

.hint-btn.hidden {
    display: none;
}

.hint-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hint-display {
    text-align: center;
    padding: 10px 16px;
    background: #fef9c3;
    border-radius: 10px;
    font-size: 0.9rem;
    color: #92400e;
    margin-top: 8px;
}

.hint-display.hidden {
    display: none;
}

.primary-btn:hover {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.45);
}

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

.primary-btn.hidden {
    display: none;
}

/* Responsive */
@media (max-height: 600px) {
    .problem {
        font-size: 1.6rem;
    }

    .problem-container {
        padding: 16px;
    }

    .feedback-emoji {
        font-size: 2rem;
    }

    .game-main {
        gap: 16px;
    }
}

@media (min-width: 500px) {
    #start-screen h1 {
        font-size: 3rem;
    }

    .problem {
        font-size: 2.4rem;
    }
}

/* Small phone screens */
@media (max-width: 380px) {
    .screen {
        padding: 12px;
    }

    #mode-screen {
        gap: 16px;
    }

    #mode-screen h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 1rem;
        margin-top: -10px;
    }

    .mode-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        max-width: 100%;
        padding: 0 5px;
    }

    .mode-card {
        padding: 12px 8px;
        border-radius: 12px;
        min-height: 85px;
    }

    .mode-card-icon {
        font-size: 1.8rem;
    }

    .mode-card-name {
        font-size: 0.85rem;
    }

    .mode-card-desc {
        font-size: 0.72rem;
    }

    .stats-preview {
        gap: 16px;
        font-size: 0.8rem;
    }

    .timer-toggle {
        padding: 6px 12px;
        gap: 8px;
    }

    .toggle-label {
        font-size: 0.85rem;
    }

    .credits {
        font-size: 0.8rem;
        margin-top: 12px;
    }

    /* Game screen adjustments */
    .problem-container {
        padding: 12px;
        border-radius: 14px;
    }

    .problem {
        font-size: 1.3rem;
    }

    .problem-visual {
        font-size: 1rem;
        letter-spacing: 1px;
        padding: 6px 8px;
    }

    .problem-type {
        font-size: 0.75rem;
    }

    .number-line-container {
        padding: 10px 4px;
    }

    .number-line-labels {
        font-size: 0.8rem;
        padding: 0 8px;
    }

    .slider-thumb {
        width: 30px;
        height: 30px;
        border-width: 3px;
    }

    .estimate-display {
        font-size: 0.95rem;
    }

    #estimate-value {
        font-size: 1.1rem;
    }

    .feedback {
        padding: 14px;
        border-radius: 12px;
    }

    .feedback-emoji {
        font-size: 2rem;
        margin-bottom: 4px;
    }

    .feedback-text {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    .feedback-details {
        font-size: 0.8rem;
    }

    .game-header {
        padding: 4px 0;
    }

    .timer-display {
        font-size: 0.85rem;
        padding: 3px 6px;
    }

    .score-display {
        font-size: 1rem;
    }

    .streak-display {
        font-size: 0.95rem;
    }

    .primary-btn {
        padding: 14px 24px;
        font-size: 1rem;
        border-radius: 12px;
    }

    .game-main {
        gap: 12px;
    }

    /* Shopping items on small screens */
    .shopping-item {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .item-emoji {
        font-size: 1.2rem;
    }

    .item-price {
        padding: 1px 6px;
        font-size: 0.8rem;
    }

    /* Level screen */
    .level-btn {
        padding: 12px 14px;
    }

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

    .level-name {
        font-size: 1rem;
    }

    .level-desc {
        font-size: 0.75rem;
    }
}

/* ============ MODE CARDS (Stage 1) ============ */
#mode-screen {
    position: relative;
    justify-content: flex-start;
    align-items: center;
    text-align: center;
    gap: 12px;
    padding-top: 15px;
    background: linear-gradient(135deg, #FFF5E6 0%, #FFE8E8 50%, #E8F5FF 100%);
    overflow-y: auto;
}

#mode-screen h1 {
    font-family: 'Fredoka', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    color: var(--primary);
    text-shadow: 2px 2px 0 rgba(255, 107, 107, 0.15);
}

#mode-screen .subtitle {
    margin-top: -5px;
    font-size: 1rem;
}

.mode-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 380px;
    padding: 0 10px;
}

.mode-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 10px 8px;
    background: var(--surface);
    border: 3px solid #f0f0f0;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    min-height: 75px;
}

.mode-card:hover {
    border-color: var(--primary);
    transform: translateY(-4px) rotate(-1deg);
    box-shadow: 0 8px 24px rgba(255, 107, 107, 0.25);
}

.mode-card:active {
    transform: translateY(-2px) rotate(0deg);
}

.mode-card-icon {
    font-size: 1.8rem;
}

.mode-card-name {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    text-align: center;
}

.mode-card-desc {
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: center;
}

/* Baby mode card special style */
.mode-card[data-mode="baby"] {
    background: linear-gradient(135deg, #FFF3E0 0%, #FFE0B2 100%);
    border-color: #FFB74D;
}

.mode-card[data-mode="baby"]:hover {
    border-color: #FF9800;
}

/* College mode card special style */
.mode-card[data-mode="college"] {
    background: linear-gradient(135deg, #E8F5E9 0%, #C8E6C9 100%);
    border-color: #81C784;
}

.mode-card[data-mode="college"]:hover {
    border-color: #4CAF50;
}

/* College button variant */
.college-btn {
    border-left: 4px solid #3b82f6;
}

.college-btn:hover {
    border-color: #3b82f6;
    border-left: 4px solid #3b82f6;
}

/* College mode number line colors */
.college-mode .number-line-track {
    background: linear-gradient(90deg, #dbeafe, #bfdbfe, #93c5fd);
}

/* ============ LEVEL SCREEN (Stage 2) ============ */
#level-screen {
    padding-top: 20px;
    align-items: center;
    background: linear-gradient(135deg, #FFF5E6 0%, #FFE8E8 50%, #E8F5FF 100%);
}

#level-screen .level-header {
    align-self: stretch;
}

.level-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.level-header h2 {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text);
}

/* Shopping button variant */
.shopping-btn {
    border-left: 4px solid var(--accent);
}

.shopping-btn:hover {
    border-color: var(--accent);
    border-left: 4px solid var(--accent);
}

/* Real World button variant */
.realworld-btn {
    border-left: 4px solid #10b981;
}

.realworld-btn:hover {
    border-color: #10b981;
    border-left: 4px solid #10b981;
}

/* Time Detective button variant */
.time-btn {
    border-left: 4px solid #f59e0b;
}

.time-btn:hover {
    border-color: #f59e0b;
    border-left: 4px solid #f59e0b;
}

/* Magnitude button variant */
.magnitude-btn {
    border-left: 4px solid #8b5cf6;
}

.magnitude-btn:hover {
    border-color: #8b5cf6;
    border-left: 4px solid #8b5cf6;
}

/* Friends Math button variant */
.friends-btn {
    border-left: 4px solid #ec4899;
}

.friends-btn:hover {
    border-color: #ec4899;
    border-left: 4px solid #ec4899;
}

/* About Me card special style */
.aboutme-card {
    background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
    border: 2px solid #818cf8;
}

/* ============ ABOUT ME SETUP SCREEN ============ */
#aboutme-setup-screen {
    padding: 20px;
    background: linear-gradient(135deg, #FFF5E6 0%, #FFE8E8 50%, #E8F5FF 100%);
}

.aboutme-form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 400px;
    margin: 20px auto;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.form-group input {
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1.2rem;
    text-align: center;
    background: var(--surface);
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group input::placeholder {
    color: #cbd5e1;
}

@media (max-width: 400px) {
    .aboutme-form {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .form-group input {
        padding: 10px;
        font-size: 1.1rem;
    }
}

/* ============ SHOPPING DISPLAY ============ */
.shopping-display {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.shopping-display.hidden {
    display: none;
}

.shopping-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.shopping-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #fefce8 0%, #fef9c3 100%);
    border: 1px solid #fde047;
    border-radius: 10px;
    font-size: 0.9rem;
}

.item-emoji {
    font-size: 1.4rem;
}

.item-name {
    color: var(--text);
    font-weight: 500;
}

.item-price {
    font-weight: 700;
    color: #b45309;
    background: white;
    padding: 2px 8px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
}

.item-discount {
    font-size: 0.75rem;
    font-weight: 600;
    color: #dc2626;
    background: #fef2f2;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #fecaca;
}

.shopping-item.has-discount {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    border-color: #fca5a5;
}

/* Problem text with line breaks */
.problem {
    white-space: pre-line;
    line-height: 1.4;
}

/* Smaller problem text for shopping */
.problem-container:has(+ .shopping-display:not(.hidden)) .problem {
    font-size: 1.5rem;
}

/* Shopping mode number line colors */
.shopping-mode .number-line-track {
    background: linear-gradient(90deg, #fef3c7, #fde68a, #fcd34d);
}

/* ============ BABY MODE ============ */
#baby-screen {
    background: linear-gradient(135deg, #FFF8E1 0%, #FCE4EC 50%, #E3F2FD 100%);
    padding: 16px;
}

.baby-stars {
    font-size: 1.8rem;
    letter-spacing: 4px;
}

.baby-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px;
}

.baby-problem {
    background: var(--surface);
    border-radius: 20px;
    padding: 24px 30px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.baby-visual {
    font-size: 3rem;
    line-height: 1.6;
    letter-spacing: 6px;
    margin-bottom: 16px;
    white-space: pre-line;
}

.baby-question {
    font-family: 'Fredoka', sans-serif;
    font-size: 2.5rem;
    color: var(--text-light);
    font-weight: 500;
    margin-top: 8px;
}

.baby-choices {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    width: 100%;
    max-width: 320px;
}

.baby-choice-btn {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    background: var(--surface);
    border: 4px solid #e2e8f0;
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    color: var(--text);
    padding: 8px;
    word-break: break-word;
    line-height: 1.2;
}

/* Visual choices (emoji groups) - smaller font, wrap */
.baby-choice-btn.visual-choice {
    font-size: 1.8rem;
    letter-spacing: 2px;
}

/* Numeral choices - big bold numbers */
.baby-choice-btn.numeral-choice {
    font-size: 3.5rem;
}

.baby-choice-btn:hover {
    transform: scale(1.05);
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.2);
}

.baby-choice-btn:active {
    transform: scale(0.98);
}

.baby-choice-btn.correct {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border-color: var(--secondary);
    animation: correctPulse 0.5s ease;
}

.baby-choice-btn.wrong {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-color: var(--danger);
    animation: shake 0.4s ease;
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-8px); }
    80% { transform: translateX(8px); }
}

.baby-feedback {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 100;
    animation: feedbackIn 0.3s ease;
}

.baby-feedback.correct {
    background: rgba(76, 175, 80, 0.95);
}

.baby-feedback.wrong {
    background: rgba(244, 67, 54, 0.9);
}

.baby-feedback.hidden {
    display: none;
}

@keyframes feedbackIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.baby-feedback-emoji {
    font-size: 8rem;
    animation: bounce 0.6s ease infinite;
}

.baby-feedback-text {
    font-size: 2.5rem;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

/* Responsive for smaller screens */
@media (max-height: 650px) {
    .baby-main {
        gap: 20px;
    }

    .baby-problem {
        padding: 20px 24px;
    }

    .baby-visual {
        font-size: 2.5rem;
        letter-spacing: 4px;
        margin-bottom: 10px;
    }
}

@media (max-height: 580px) {
    .baby-main {
        gap: 16px;
    }

    .baby-visual {
        font-size: 2rem;
        letter-spacing: 3px;
        margin-bottom: 8px;
    }

    .baby-choice-btn {
        font-size: 2rem;
    }

    .baby-choice-btn.visual-choice {
        font-size: 1.4rem;
    }

    .baby-problem {
        padding: 14px 18px;
        border-radius: 16px;
    }

    .baby-feedback-emoji {
        font-size: 5rem;
    }

    .baby-question {
        font-size: 2rem;
    }

    .baby-choices {
        gap: 12px;
        max-width: 280px;
    }
}

@media (max-height: 500px) {
    .baby-main {
        gap: 12px;
    }

    .baby-problem {
        padding: 12px 16px;
    }

    .baby-visual {
        font-size: 1.6rem;
        letter-spacing: 2px;
        margin-bottom: 6px;
    }

    .baby-question {
        font-size: 1.8rem;
    }

    .baby-choice-btn {
        font-size: 1.6rem;
        border-radius: 16px;
        border-width: 3px;
    }

    .baby-choice-btn.visual-choice {
        font-size: 1.2rem;
    }

    .baby-choice-btn.numeral-choice {
        font-size: 2rem;
    }

    .baby-choices {
        gap: 10px;
        max-width: 240px;
    }

    .baby-feedback-emoji {
        font-size: 4rem;
    }
}

/* Larger screens - bigger buttons */
@media (min-width: 400px) and (min-height: 600px) {
    .baby-choices {
        max-width: 360px;
        gap: 20px;
    }

    .baby-choice-btn.numeral-choice {
        font-size: 4rem;
    }

    .baby-choice-btn.visual-choice {
        font-size: 2rem;
    }
}

/* ============ CARTOONY ANIMATIONS & DECORATIONS ============ */

/* Bouncy title animation */
#mode-screen h1 {
    animation: bounceIn 0.8s ease-out;
}

@keyframes bounceIn {
    0% { transform: scale(0.5); opacity: 0; }
    60% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); }
}

/* Floating animation for mode card icons */
.mode-card-icon {
    animation: float 3s ease-in-out infinite;
}

.mode-card:nth-child(2n) .mode-card-icon {
    animation-delay: 0.5s;
}

.mode-card:nth-child(3n) .mode-card-icon {
    animation-delay: 1s;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Wiggle animation for mode cards on hover */
.mode-card:hover .mode-card-icon {
    animation: wiggle 0.5s ease-in-out;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

/* Pop animation for buttons */
.primary-btn:active {
    animation: pop 0.2s ease;
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* Sparkle effect for correct answers */
.feedback.bullseye {
    position: relative;
    overflow: visible;
}

.feedback.bullseye::before,
.feedback.bullseye::after {
    content: '✨';
    position: absolute;
    animation: sparkle 1s ease-in-out infinite;
}

.feedback.bullseye::before {
    top: -10px;
    left: 10%;
    animation-delay: 0.2s;
}

.feedback.bullseye::after {
    top: -10px;
    right: 10%;
    animation-delay: 0.5s;
}

@keyframes sparkle {
    0%, 100% { opacity: 0; transform: scale(0.5) rotate(0deg); }
    50% { opacity: 1; transform: scale(1.2) rotate(180deg); }
}

/* Fun score counter animation */
#current-score {
    display: inline-block;
    transition: transform 0.2s ease;
}

.score-display:hover #current-score {
    animation: scoreJump 0.3s ease;
}

@keyframes scoreJump {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Rainbow streak effect */
.streak-display #streak-icon.fire {
    animation: fireGlow 0.5s ease infinite alternate;
}

@keyframes fireGlow {
    0% { filter: brightness(1) drop-shadow(0 0 2px #f59e0b); }
    100% { filter: brightness(1.2) drop-shadow(0 0 8px #ef4444); }
}

/* Confetti-style celebration for big wins */
@keyframes confetti {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(-100px) rotate(720deg); opacity: 0; }
}

.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.confetti-container.hidden {
    display: none;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    animation: confettiFall 3s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* Achievement toast notification */
.achievement-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, #FFE66D, #FFD93D);
    color: #2D3436;
    padding: 14px 28px;
    border-radius: 50px;
    box-shadow: 0 4px 24px rgba(255, 230, 109, 0.5);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1001;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    font-family: 'Fredoka', sans-serif;
}

.achievement-toast.show {
    transform: translateX(-50%) translateY(0);
}

.achievement-toast.hidden {
    display: none;
}

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

.achievement-text {
    font-weight: 600;
    font-size: 1rem;
}

/* Slider thumb pulse when ready */
.slider-thumb {
    animation: thumbPulse 2s ease-in-out infinite;
}

.slider-thumb.active {
    animation: none;
}

@keyframes thumbPulse {
    0%, 100% { box-shadow: 0 2px 10px rgba(255, 107, 107, 0.4); }
    50% { box-shadow: 0 2px 20px rgba(255, 107, 107, 0.6); }
}

/* Fun background pattern for mode screen */
#mode-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(255, 107, 107, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(78, 205, 196, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(255, 230, 109, 0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

#mode-screen > * {
    position: relative;
    z-index: 1;
}

/* Number input bounce in */
.number-input-container {
    animation: slideUp 0.3s ease-out;
}

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

/* Hint button wiggle to draw attention */
.hint-btn:not(:disabled) {
    animation: hintWiggle 2s ease-in-out infinite;
    animation-delay: 3s;
}

@keyframes hintWiggle {
    0%, 90%, 100% { transform: rotate(0deg); }
    92%, 96% { transform: rotate(-5deg); }
    94%, 98% { transform: rotate(5deg); }
}

/* ============ SHORT SCREENS AND LANDSCAPE PHONES ============ */
@media (max-height: 500px) {
    .screen {
        padding: 10px 16px;
    }

    #game-screen {
        gap: 4px;
    }

    .game-header {
        padding: 2px 0;
    }

    .problem-container {
        padding: 8px 12px;
    }

    .problem {
        font-size: 1.3rem;
    }

    .problem-visual {
        font-size: 0.95rem;
        max-height: 40vh;
        overflow-y: auto;
    }

    .game-footer {
        padding: 4px 0;
    }

    .primary-btn {
        padding: 10px 20px;
    }

    .level-header {
        margin-bottom: 12px;
    }
}

/* Landscape phone: question on the left, answer controls on the right */
@media (orientation: landscape) and (max-height: 500px) {
    #app {
        max-width: 860px;
    }

    .game-main {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 16px;
        align-content: start;
    }

    .game-main > .problem-container {
        grid-column: 1;
        grid-row: 1 / span 5;
    }

    .game-main > :not(.problem-container) {
        grid-column: 2;
    }

    .mode-cards {
        grid-template-columns: repeat(4, 1fr);
        max-width: 820px;
    }

    .level-select {
        max-width: 560px;
    }
}

/* ============ REDUCED MOTION ============ */
/* Kids (and adults) who get dizzy or distracted can turn animation off in
   their device settings; the game then keeps everything still. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
