/* ===================================
   MATH FLASH CARDS — styles.css
   =================================== */

:root {
    --bg: #FFF9F0;
    --card: #ffffff;
    --accent: #FF6B35;
    --accent2: #FFD700;
    --text: #2D3748;
    --text-light: #718096;
    --success: #38A169;
    --danger: #E53E3E;
    --shadow: 0 4px 20px rgba(0,0,0,0.08);
    --radius: 18px;
    --font-head: 'Fredoka One', cursive;
    --font-body: 'Nunito', sans-serif;
}

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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 16px;
    transition: background 0.4s, color 0.4s;
}

.container {
    max-width: 540px;
    margin: 0 auto;
    padding-bottom: 40px;
}

/* ---- FIREWORKS ---- */
#fireworks-canvas {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 9998;
    display: none;
}

/* ---- STREAK BANNER (inline, no popup) ---- */
#streak-banner {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 9000;
    pointer-events: none;
    padding: 0 16px;
    animation: bannerSlide 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#streak-banner.show { display: block; }

@keyframes bannerSlide {
    from { transform: translateY(-100%); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

#streak-banner-inner {
    background: linear-gradient(135deg, #FFD700, #FF6B35);
    color: white;
    text-align: center;
    padding: 14px 20px;
    font-family: var(--font-head);
    font-size: clamp(1.4rem, 5vw, 2rem);
    border-radius: 0 0 20px 20px;
    box-shadow: 0 6px 24px rgba(255,107,53,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
#streak-banner-emoji { font-size: 1.8em; animation: bannerBounce 0.4s ease infinite alternate; }
@keyframes bannerBounce { from { transform: scale(1); } to { transform: scale(1.25); } }

@keyframes popIn {
    from { transform: scale(0.5); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-12px); } }

/* ---- QUIT DIALOG ---- */
#quit-overlay {
    display: none;
    visibility: hidden;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
#quit-overlay.show {
    display: flex;
    visibility: visible;
    pointer-events: auto;
}

#quit-content {
    background: var(--card);
    border-radius: 24px;
    padding: 36px 28px;
    text-align: center;
    max-width: 340px;
    width: 90%;
    animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
#quit-emoji { font-size: 3.5rem; margin-bottom: 10px; }
#quit-title {
    font-family: var(--font-head);
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 6px;
}
#quit-subtitle { font-size: 0.95rem; color: var(--text-light); margin-bottom: 20px; }

#quit-confirm-btn, #quit-cert-btn, #quit-print-btn, #quit-cancel-btn {
    display: block; width: 100%;
    padding: 13px;
    border-radius: 12px;
    border: none;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    margin-bottom: 10px;
    transition: transform 0.15s;
}
#quit-confirm-btn:hover, #quit-cert-btn:hover, #quit-print-btn:hover, #quit-cancel-btn:hover { transform: scale(1.02); }
#quit-confirm-btn { background: var(--danger);  color: white; }
#quit-cert-btn    { background: #f6e05e; color: #744210; }
#quit-print-btn   { background: #2D3748; color: white; }
#quit-cancel-btn  { background: var(--success); color: white; margin-bottom: 0; }

/* ---- CERTIFICATE ---- */
#certificate-area {
    display: none;
    position: fixed; inset: 0;
    background: white;
    z-index: 10000;
    padding: 30px 20px;
    overflow-y: auto;
    text-align: center;
    flex-direction: column;
    align-items: center;
}
#certificate-area.show { display: flex; }

#certificate {
    max-width: 600px;
    width: 100%;
    margin: 0 auto 20px;
}
.cert-border {
    border: 12px double #c8a415;
    padding: 40px 30px;
    background: linear-gradient(135deg, #fffdf0, #fff8dc);
    border-radius: 8px;
    box-shadow: 0 4px 30px rgba(200,164,21,0.2);
}
.cert-stars { font-size: 1.8rem; margin: 8px 0; letter-spacing: 6px; }
.cert-title {
    font-family: var(--font-head);
    font-size: 2.4rem;
    color: #b7791f;
    margin: 12px 0 4px;
}
.cert-subtitle { font-size: 1rem; color: #718096; margin-bottom: 8px; }
.cert-name {
    font-family: var(--font-head);
    font-size: 2.8rem;
    color: #2D3748;
    border-bottom: 3px solid #c8a415;
    display: inline-block;
    padding: 0 20px 4px;
    margin: 8px 0 16px;
}
.cert-achievement {
    font-size: 1.15rem;
    color: #4A5568;
    margin-bottom: 16px;
    font-weight: 700;
    line-height: 1.5;
}
.cert-date { font-size: 0.9rem; color: #718096; margin-bottom: 12px; }
.cert-footer {
    font-size: 0.85rem;
    color: #a0aec0;
    margin-top: 20px;
    font-style: italic;
}
.cert-print-btn {
    padding: 14px 32px;
    border-radius: 12px;
    border: none;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    margin: 6px;
    background: var(--accent);
    color: white;
    font-family: var(--font-body);
}
.cert-close-btn { background: #718096 !important; }

/* ---- APP HEADER ---- */
.app-header {
    text-align: center;
    padding: 24px 0 16px;
}
.app-logo {
    font-size: 3.5rem;
    animation: spin 3s linear infinite;
    display: inline-block;
}
@keyframes spin { 0%,100%{transform:rotate(-8deg)} 50%{transform:rotate(8deg)} }

.app-header h1 {
    font-family: var(--font-head);
    font-size: 2.4rem;
    color: var(--accent);
    line-height: 1.1;
    margin-top: 4px;
}
.app-tagline { color: var(--text-light); font-size: 1rem; margin-top: 4px; }

/* ---- SETUP CARDS ---- */
.setup-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}
.setup-card-header {
    font-family: var(--font-head);
    font-size: 1.2rem;
    color: var(--accent);
    margin-bottom: 12px;
}
.setup-hint {
    font-size: 0.88rem;
    color: var(--text-light);
    margin-bottom: 10px;
}
.big-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    font-size: 1.1rem;
    font-family: var(--font-body);
    font-weight: 700;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}
.big-input:focus { outline: none; border-color: var(--accent); }

/* ---- THEME PICKER ---- */
.theme-picker {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
.theme-dot {
    width: 52px; height: 52px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.6rem;
    display: flex; align-items: center; justify-content: center;
    border: 3px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.theme-dot:hover { transform: scale(1.1); }
.theme-dot.active { border-color: var(--accent); transform: scale(1.15); }

/* ---- OPERATION BUTTONS ---- */
.op-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}
.op-btn {
    padding: 14px 10px;
    border-radius: 14px;
    border: 2px solid #e2e8f0;
    background: var(--bg);
    color: var(--text);
    font-size: 1.4rem;
    font-family: var(--font-body);
    font-weight: 800;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}
.op-btn span { font-size: 0.8rem; font-weight: 700; }
.op-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.op-btn:hover:not(.active) { border-color: var(--accent); }

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0 0;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
}
.toggle-switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: #cbd5e0;
    border-radius: 26px;
    transition: 0.3s;
    cursor: pointer;
}
.toggle-slider:before {
    content: "";
    position: absolute;
    height: 20px; width: 20px;
    left: 3px; bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(22px); }

/* ---- NUMBER RANGE PANELS ---- */
.range-panel {
    margin-bottom: 4px;
}
.range-panel-title {
    font-family: var(--font-head);
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 10px;
}
.range-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.range-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.range-field-label {
    font-weight: 800;
    font-size: 0.92rem;
    min-width: 110px;
    line-height: 1.3;
}
.range-term {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
}
.range-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
}
.range-num-input {
    width: 72px;
    padding: 8px 6px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-family: var(--font-body);
    font-weight: 800;
    font-size: 0.95rem;
    text-align: center;
    background: var(--bg);
    color: var(--text);
    -moz-appearance: textfield;
}
.range-num-input::-webkit-inner-spin-button,
.range-num-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.range-num-input:focus { outline: none; border-color: var(--accent); }
.range-dash {
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--text-light);
}

#range-warning {
    margin-top: 12px;
    background: #fff5f5;
    border: 2px solid #fc8181;
    border-radius: 12px;
    padding: 12px 14px;
    font-weight: 700;
    font-size: 0.9rem;
    color: #c53030;
    line-height: 1.5;
}

/* ---- NUMBER FOCUS CHIPS ---- */
.multi-select {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-top: 6px;
}
.num-chip {
    padding: 10px 4px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    background: var(--bg);
    color: var(--text);
    font-weight: 800;
    font-size: 0.95rem;
    transition: all 0.15s;
    font-family: var(--font-body);
}
.num-chip.selected { background: var(--accent) !important; color: white !important; border-color: var(--accent) !important; }
.num-chip:hover:not(.selected) { border-color: var(--accent); }

/* ---- SETTINGS ROWS ---- */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
}
.settings-row:last-of-type { border-bottom: none; }
.settings-row label { font-weight: 700; font-size: 0.95rem; }
.small-select, .small-input {
    padding: 8px 12px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.95rem;
    background: var(--bg);
    color: var(--text);
    min-width: 110px;
}
.time-row { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.tiny-input {
    width: 54px;
    padding: 8px;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-family: var(--font-body);
    font-weight: 800;
    text-align: center;
    font-size: 0.95rem;
    background: var(--bg);
    color: var(--text);
}

/* ---- START BUTTON ---- */
.start-btn {
    width: 100%;
    padding: 20px;
    border-radius: 18px;
    border: none;
    background: linear-gradient(135deg, var(--accent), #ff8c42);
    color: white;
    font-family: var(--font-head);
    font-size: 1.6rem;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255,107,53,0.4);
    transition: transform 0.15s, box-shadow 0.15s;
    margin-bottom: 12px;
}
.start-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(255,107,53,0.5); }
.start-btn:active { transform: translateY(0); }

.secondary-action-btn {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    margin-bottom: 10px;
    transition: background 0.2s;
}
.secondary-action-btn:hover { background: rgba(255,107,53,0.08); }

.ghost-btn {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text-light);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 4px;
}

/* ===== GAME SCREEN ===== */
#hud {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
}
.hud-pill {
    flex: 1;
    text-align: center;
    background: var(--card);
    border-radius: 12px;
    padding: 10px 8px;
    font-weight: 800;
    font-size: 0.95rem;
    box-shadow: var(--shadow);
}

#problem-card {
    background: var(--card);
    border-radius: 24px;
    padding: 24px 12px 20px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    position: relative;
    overflow: visible;
}
#problem-card::before {
    content: '';
    position: absolute;
    top: -30px; right: -30px;
    width: 100px; height: 100px;
    background: var(--accent);
    opacity: 0.08;
    border-radius: 50%;
}
#problem-text {
    font-family: var(--font-head);
    font-size: clamp(3.5rem, 15vw, 6rem);
    color: var(--text);
    line-height: 1;
}
#problem-op-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-light);
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#feedback-text {
    min-height: 44px;
    font-size: 1.3rem;
    font-weight: 800;
    text-align: center;
    padding: 8px;
    border-radius: 12px;
    transition: all 0.3s;
    margin-bottom: 12px;
}
#feedback-text.correct { background: rgba(56,161,105,0.1); color: var(--success); }
#feedback-text.wrong   { background: rgba(229,62,62,0.1);  color: var(--danger);  }
#feedback-text.streak  { background: rgba(255,215,0,0.15); color: #c05621; }
#feedback-text.big-streak {
    font-size: 1.7rem;
    padding: 12px;
    font-family: var(--font-head);
    animation: pulseFeedback 0.4s ease;
}
@keyframes pulseFeedback {
    0%   { transform: scale(0.9); }
    60%  { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.answer-area {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}
#answer-input {
    flex: 1;
    padding: 18px;
    border-radius: 16px;
    border: 3px solid #e2e8f0;
    font-family: var(--font-head);
    font-size: 2.5rem;
    text-align: center;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.2s;
    -moz-appearance: textfield;
}
#answer-input::-webkit-inner-spin-button,
#answer-input::-webkit-outer-spin-button { -webkit-appearance: none; }
#answer-input:focus { outline: none; border-color: var(--accent); }

#submit-btn {
    width: 80px;
    border-radius: 16px;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 2rem;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255,107,53,0.35);
    transition: transform 0.1s;
}
#submit-btn:active { transform: scale(0.95); }

#progress-bar-wrap {
    height: 10px;
    background: #e2e8f0;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 16px;
}
#progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 5px;
    transition: width 0.5s ease;
    width: 0%;
}

.game-actions {
    display: flex;
    gap: 8px;
}
.game-action-btn {
    flex: 1;
    padding: 12px 6px;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    background: var(--card);
    color: var(--text);
    font-family: var(--font-body);
    font-weight: 800;
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.2s;
}
.game-action-btn:hover { border-color: var(--accent); }

/* ===== RESULTS SCREEN ===== */
#results-trophy {
    font-size: 5rem;
    text-align: center;
    animation: bounce 0.8s ease infinite alternate;
    display: block;
    margin: 16px 0 8px;
}
#summary-title {
    font-family: var(--font-head);
    font-size: 2rem;
    text-align: center;
    color: var(--accent);
    margin-bottom: 16px;
}
#stat-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--card);
    border-radius: 16px;
    padding: 14px 8px;
    text-align: center;
    box-shadow: var(--shadow);
    font-weight: 800;
    font-size: 0.85rem;
}
.stat-card .stat-num {
    font-family: var(--font-head);
    font-size: 2rem;
    color: var(--accent);
    display: block;
}

#review-list {
    background: var(--card);
    border-radius: 16px;
    padding: 16px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.review-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    font-weight: 700;
    flex-wrap: wrap;
}
.review-item:last-child { border-bottom: none; }
.review-problem { flex: 1; min-width: 100px; }
.review-answer  { font-size: 0.9rem; white-space: nowrap; }
.correct-answer { color: var(--success); }
.wrong-answer   { color: var(--danger); background: rgba(229,62,62,0.08); padding: 2px 8px; border-radius: 6px; }

.results-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.result-btn {
    padding: 14px;
    border-radius: 14px;
    border: none;
    font-family: var(--font-body);
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.15s;
}
.result-btn:hover { transform: scale(1.02); }
.primary-btn { background: var(--accent); color: white; }
.success-btn { background: #f6e05e; color: #744210; }
.gray-btn    { background: #e2e8f0; color: var(--text); }
.dark-btn    { background: #2D3748; color: white; }

/* ===== PROGRESS HISTORY ===== */
#progress-screen h2 {
    font-family: var(--font-head);
    font-size: 1.8rem;
    color: var(--accent);
    margin: 16px 0;
    text-align: center;
}
#progress-summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
#progress-list {
    background: var(--card);
    border-radius: 16px;
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.progress-entry {
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}
.progress-entry:last-child { border-bottom: none; }
.progress-entry-header {
    display: flex;
    justify-content: space-between;
    font-weight: 800;
    margin-bottom: 4px;
}
.progress-entry-stats { font-size: 0.88rem; color: var(--text-light); font-weight: 600; }

/* ===== PRINT STYLES ===== */
@media print {
    /* Hide everything that should never print */
    #fireworks-canvas,
    #streak-banner,
    #quit-overlay,
    .game-actions,
    .results-btns,
    .cert-print-btn,
    .cert-close-btn { display: none !important; }

    /* ---- Printing RESULTS (default when Print button clicked) ---- */
    #setup-menu,
    #game-area,
    #progress-screen,
    #certificate-area { display: none !important; }

    #results {
        display: block !important;
    }
    #review-list {
        max-height: none !important;
        overflow: visible !important;
    }

    /* ---- Printing CERTIFICATE (body gets .print-cert class) ---- */
    body.print-cert #results,
    body.print-cert .container { display: none !important; }
    body.print-cert #certificate-area {
        display: flex !important;
        position: static !important;
    }
}

/* ===== RESPONSIVE & MOBILE KEYBOARD FIX ===== */

/*
 * On mobile, the game screen is a fixed viewport-height layout.
 * This prevents the keyboard from pushing the problem off screen.
 * The JS visualViewport listener will update --game-height dynamically.
 */

:root { --game-height: 100dvh; }

/* Game screen fills the visible viewport on mobile */
@media (max-width: 600px) {

    body {
        padding: 8px;
        /* prevent body scroll during game — only setup/results scroll */
        overflow-x: hidden;
    }

    /* When game is active, lock body scroll */
    body.game-active {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }

    /* Game area: fixed compact layout that fits above keyboard */
    #game-area {
        position: fixed;
        top: 0; left: 0; right: 0;
        height: var(--game-height);
        padding: 10px 12px 8px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        overflow: hidden;
        background: var(--bg);
        z-index: 100;
        box-sizing: border-box;
    }

    /* Compact HUD */
    #hud {
        margin-bottom: 8px;
        flex-shrink: 0;
    }
    .hud-pill {
        padding: 7px 4px;
        font-size: 0.82rem;
    }

    /* Problem card — smaller padding, smaller font on mobile */
    #problem-card {
        padding: 14px 16px 12px;
        margin-bottom: 8px;
        border-radius: 18px;
        flex-shrink: 0;
    }
    #problem-text {
        font-size: clamp(2.4rem, 12vw, 3.8rem);
        line-height: 1;
    }
    #problem-op-label {
        font-size: 0.78rem;
        margin-top: 4px;
    }

    /* Feedback — compact */
    #feedback-text {
        min-height: 36px;
        font-size: 1.05rem;
        padding: 6px 8px;
        margin-bottom: 8px;
        flex-shrink: 0;
    }
    #feedback-text.big-streak {
        font-size: 1.25rem;
        padding: 8px;
    }

    /* Answer area — slightly smaller but still easy to tap */
    .answer-area {
        margin-bottom: 8px;
        flex-shrink: 0;
    }
    #answer-input {
        padding: 12px;
        font-size: 2rem;
        border-radius: 14px;
    }
    #submit-btn {
        width: 68px;
        font-size: 1.7rem;
        border-radius: 14px;
    }

    /* Progress bar */
    #progress-bar-wrap {
        height: 8px;
        margin-bottom: 8px;
        flex-shrink: 0;
    }

    /* Game action buttons — compact row at bottom */
    .game-actions {
        margin-top: auto;
        flex-shrink: 0;
    }
    .game-action-btn {
        padding: 9px 4px;
        font-size: 0.78rem;
        border-radius: 10px;
    }

    /* Setup and results screens scroll normally */
    #setup-menu, #results, #progress-screen {
        position: relative;
        height: auto;
    }

    /* Smaller stat cards on mobile */
    #stat-cards { grid-template-columns: repeat(3, 1fr); }
    .stat-card { padding: 10px 4px; font-size: 0.75rem; }
    .stat-card .stat-num { font-size: 1.5rem; }

    /* Results buttons stack 2x2 */
    .results-btns { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 380px) {
    .op-grid { grid-template-columns: 1fr 1fr; }
    .results-btns { grid-template-columns: 1fr; }
    #problem-text { font-size: clamp(2rem, 11vw, 3rem); }
}


/* ===== DISPLAY MODE SETUP CARD ===== */
.display-mode-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.display-mode-btn {
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    background: var(--bg);
    cursor: pointer;
    padding: 10px 8px;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.display-mode-btn.active {
    border-color: var(--accent);
    background: rgba(255,107,53,0.08);
}
.display-mode-btn:hover:not(.active) { border-color: var(--accent); }
.display-mode-preview {
    font-family: var(--font-head);
    font-size: 1.3rem;
    color: var(--text);
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.display-mode-label {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--text-light);
}
.display-mode-btn.active .display-mode-label { color: var(--accent); }

/* stacked mini-preview in setup card */
.stacked-preview {
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    font-size: 1rem;
    padding: 2px 8px;
}
.sp-row { line-height: 1.3; }
.sp-op  { margin-right: 3px; color: var(--accent); }
.sp-line {
    width: 100%;
    border-top: 2px solid var(--text);
    margin: 2px 0;
}
.sp-boxes { display: flex; gap: 3px; justify-content: flex-end; margin-bottom: 1px; }
.sp-box {
    width: 13px; height: 13px;
    border: 1.5px solid var(--accent);
    border-radius: 3px;
    display: inline-block;
}

/* ===== STACKED PROBLEM VIEW ===== */
#problem-stacked {
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: visible;
}
#stacked-container {
    font-family: var(--font-head);
    font-size: clamp(2.4rem, 10vw, 4.2rem);
    line-height: 1.2;
    display: inline-block;
    text-align: right;
    overflow: visible;
}
.stacked-row {
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    gap: 0;
    white-space: nowrap;
}
.stacked-op-symbol {
    margin-right: 6px;
    color: var(--accent);
    min-width: 1ch;
    display: inline-block;
}
.stacked-divider {
    border: none;
    border-top: 3px solid var(--text);
    width: 100%;
    margin: 4px 0;
}

/* Digit cells used in both stacked and workout */
.digit-cell {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    min-width: 0.6em;
}

/* ===== WORKOUT MODE ===== */
/* Regroup box above each digit of the top number */
.regroup-box {
    width: 32px;
    height: 28px;
    border: 2px solid var(--accent);
    border-radius: 4px;
    background: var(--card);
    font-size: 0.85rem;
    font-family: var(--font-body);
    font-weight: 800;
    text-align: center;
    color: var(--accent);
    caret-color: var(--accent);
    outline: none;
    transition: border-color 0.2s;
    padding: 0 2px;
    display: block;
    -moz-appearance: textfield;
}
.regroup-box::-webkit-inner-spin-button,
.regroup-box::-webkit-outer-spin-button { -webkit-appearance: none; }
.regroup-box:focus { border-color: var(--text); box-shadow: 0 0 0 2px rgba(255,107,53,0.2); }

/* Clickable digit — pointer cursor, subtle hover */
.digit-clickable {
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
}
.digit-clickable:hover { background: rgba(255,107,53,0.12); }

/* Tip toast */
#workout-tip-toast {
    background: rgba(45,55,72,0.88);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
    padding: 8px 16px;
    border-radius: 10px;
    margin-bottom: 8px;
    animation: fadeInOut 4s ease forwards;
}
@keyframes fadeInOut {
    0%   { opacity: 0; }
    10%  { opacity: 1; }
    75%  { opacity: 1; }
    100% { opacity: 0; }
}

/* Slash-through on a digit that has been crossed out */
.digit-crossed {
    position: relative;
    display: inline-block;
}
.digit-crossed::after {
    content: '';
    position: absolute;
    left: -5%;
    top: 50%;
    width: 110%;
    height: 3px;
    background: var(--danger);
    transform: rotate(-12deg);
    border-radius: 2px;
    pointer-events: none;
}

/* Workout answer digit boxes at the bottom */
#workout-answer-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}
.workout-ans-box {
    width: 52px;
    height: 62px;
    border: 3px solid #e2e8f0;
    border-radius: 12px;
    font-family: var(--font-head);
    font-size: 2rem;
    text-align: center;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.2s;
    -moz-appearance: textfield;
    padding: 0;
    cursor: text;
}
.workout-ans-box::-webkit-inner-spin-button,
.workout-ans-box::-webkit-outer-spin-button { -webkit-appearance: none; }
.workout-ans-box:focus { outline: none; border-color: var(--accent); }
.workout-ans-box.correct-col { border-color: var(--success); background: rgba(56,161,105,0.1); }
.workout-ans-box.wrong-col   { border-color: var(--danger);  background: rgba(229,62,62,0.1); }

#workout-submit-btn {
    display: block;
    width: 100%;
    padding: 16px;
    border-radius: 16px;
    border: none;
    background: var(--accent);
    color: white;
    font-family: var(--font-head);
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255,107,53,0.35);
    transition: transform 0.1s;
}
#workout-submit-btn:active { transform: scale(0.97); }

/* HUD mode toggle pill */
.hud-mode-pill {
    cursor: pointer;
    flex: 0 0 auto;
    min-width: 44px;
    font-size: 1.1rem;
    transition: background 0.2s;
}
.hud-mode-pill:hover { background: var(--accent); color: white; }

/* Mobile tweaks for workout */
@media (max-width: 600px) {
    .workout-ans-box { width: 42px; height: 52px; font-size: 1.6rem; border-radius: 10px; }
    #stacked-container { font-size: clamp(2.2rem, 10vw, 3.8rem); }
    .regroup-box { width: 0.8em; height: 0.6em; }
}

#division-workout-warning {
    margin-top: 10px;
    background: #fffbeb;
    border: 2px solid #f6ad55;
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 0.88rem;
    font-weight: 600;
    color: #7b341e;
    line-height: 1.5;
}

/* ===== FEEDBACK CARD ===== */
.fb-link-btn {
    display: block;
    width: 100%;
    padding: 16px;
    border-radius: 14px;
    background: var(--accent);
    color: white;
    font-family: var(--font-body);
    font-size: 1.05rem;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 14px rgba(255,107,53,0.35);
    margin-top: 4px;
}
.fb-link-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(255,107,53,0.45);
}
.fb-link-btn:active { transform: translateY(0); }

/* ===== MULTIPLICATION WORKOUT ===== */
.mul-carry-row { margin-bottom: 2px; }

.mul-partial-row { margin: 3px 0; }

.mul-partial-box {
    width: 32px;
    height: 36px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-family: var(--font-head);
    font-size: 1.1rem;
    text-align: center;
    background: var(--card);
    color: var(--text);
    padding: 0;
    transition: border-color 0.2s;
    display: block;
}
.mul-partial-box:focus  { outline: none; border-color: var(--accent); }
.mul-partial-box::placeholder { color: #cbd5e0; }
.mul-partial-box.correct-col { border-color: var(--success); background: rgba(56,161,105,0.1); }
.mul-partial-box.wrong-col   { border-color: var(--danger);  background: rgba(229,62,62,0.1);  }

.mul-shift-spacer { opacity: 0; pointer-events: none; width: 32px; display: inline-block; }

.mul-ans-row { margin-top: 2px; }
.mul-ans-box {
    width: 32px;
    height: 36px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-family: var(--font-head);
    font-size: 1.1rem;
    text-align: center;
    background: var(--card);
    color: var(--text);
    padding: 0;
    transition: border-color 0.2s;
    display: block;
}
.mul-ans-box:focus { outline: none; border-color: var(--accent); }
.mul-ans-box.correct-col { border-color: var(--success); background: rgba(56,161,105,0.1); }
.mul-ans-box.wrong-col   { border-color: var(--danger);  background: rgba(229,62,62,0.1);  }

/* ===== DIVISION HOUSE LAYOUT ===== */
.division-quotient-row {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-bottom: 2px;
    padding-right: 4px;
}
.division-quot-spacer {
    display: inline-block;
    width: 52px;
}
.division-quot-box {
    width: 52px;
    height: 56px;
    border: 3px solid var(--accent);
    border-radius: 10px;
    font-family: var(--font-head);
    font-size: 1.8rem;
    text-align: center;
    background: var(--card);
    color: var(--text);
    -moz-appearance: textfield;
    padding: 0;
    transition: border-color 0.2s;
}
.division-quot-box::-webkit-inner-spin-button,
.division-quot-box::-webkit-outer-spin-button { -webkit-appearance: none; }
.division-quot-box:focus { outline: none; border-color: var(--text); }
.division-quot-box.correct-col { border-color: var(--success); background: rgba(56,161,105,0.1); }
.division-quot-box.wrong-col   { border-color: var(--danger);  background: rgba(229,62,62,0.1);  }

.division-top-bar {
    border-top: 3px solid var(--text);
    margin-bottom: 0;
    margin-left: 2.2em; /* indent past divisor */
}

.division-house-row {
    display: flex;
    align-items: stretch;
    font-family: var(--font-head);
    font-size: clamp(2.4rem, 10vw, 4rem);
    line-height: 1.2;
}
.division-divisor {
    display: flex;
    align-items: center;
    padding-right: 6px;
    color: var(--text);
}
.division-bracket {
    display: inline-block;
    width: 18px;
    border-top: 3px solid var(--text);
    border-left: 3px solid var(--text);
    align-self: stretch;
    flex-shrink: 0;
    margin-right: 4px;
}
.division-dividend {
    display: flex;
    align-items: center;
    gap: 0;
    letter-spacing: 0.05em;
}

@media (max-width: 600px) {
    .division-quot-box { width: 40px; height: 46px; font-size: 1.5rem; }
    .division-quot-spacer { width: 40px; }
    .division-bracket { width: 14px; }
}

/* ===== DARK THEME HELPERS ===== */
body.dark-mode input,
body.dark-mode select {
    background: #2d2d2d;
    color: #fff;
    border-color: #555;
}
