/**
 * Central theme for all skill popups (LKG, UKG, Grade 1–5, computation).
 * Change --popup-scene-* variables below to retheme every popup at once.
 */
:root {
    --popup-scene-sky-top: #6EC6E8;
    --popup-scene-sky-bottom: #D6F5FF;
    --popup-scene-grass: #8CD867;
    --popup-scene-grass-dark: #6FBF52;
    --popup-scene-sun: #FFD93D;
    --popup-scene-card: #FFFFFF;
    --popup-scene-shadow: rgba(35, 49, 86, 0.18);
    --popup-scene-ink: #233156;
    --popup-scene-accent-red: #FF6B6B;
    --popup-scene-accent-green: #4ECB71;
    --popup-scene-accent-purple: #A78BFA;
    --popup-scene-backdrop: rgba(20, 32, 50, 0.6);

    /* Layout — popup floats over skills content, not header / grade rail */
    --popup-chrome-top: 128px;
    --popup-grade-rail-width: 88px;
    --popup-edge-gap: 12px;

    --popup-scene-background: linear-gradient(
        to bottom,
        var(--popup-scene-sky-top) 0%,
        var(--popup-scene-sky-bottom) 65%,
        var(--popup-scene-grass) 65%,
        var(--popup-scene-grass-dark) 100%
    );
}

@media (max-width: 980px) {
    :root {
        --popup-grade-rail-width: 64px;
    }
}

@media (max-width: 768px) {
    :root {
        --popup-chrome-top: 0;
        --popup-edge-gap: 0;
        --popup-grade-rail-width: 0;
    }
}

/* ---------- Backdrop overlays ---------- */
.quiz-overlay,
.computation-overlay {
    position: fixed;
    top: var(--popup-chrome-top);
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 200;
    background: var(--popup-scene-backdrop);
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: var(--popup-edge-gap);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.18s ease;
}

body[data-page="skills"] .quiz-overlay,
body[data-page="skills"] .computation-overlay {
    left: calc((100vw - min(1300px, 100vw)) / 2 + var(--popup-grade-rail-width));
}

/* Keep grade rail visible and clickable above the backdrop */
body[data-page="skills"] .grade-rail {
    position: sticky;
    z-index: 250;
    background: var(--white, #fff);
}

.quiz-overlay.open,
.computation-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* ---------- Popup panels (shared sky/grass background) ---------- */
.quiz-modal,
.computation-overlay .card,
.balloon-identify-game,
.balloon-identify-fullpage,
.balloon-pop-game,
.balloon-pop-fullpage {
    position: relative;
    background: var(--popup-scene-background);
    overflow: hidden;
}

.quiz-modal {
    width: 100%;
    max-width: none;
    height: 100%;
    border-radius: 20px;
    box-shadow: 0 30px 70px -20px rgba(10, 20, 40, 0.5);
    padding: 30px 34px 34px;
    transform: translateY(10px) scale(0.99);
    transition: transform 0.2s ease;
    max-height: none;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.quiz-modal > .quiz-progress,
.quiz-modal > #quiz-body {
    width: 100%;
    max-width: 560px;
}

.quiz-modal.has-balloon-game > #quiz-body {
    max-width: none;
}

.quiz-overlay.open .quiz-modal {
    transform: translateY(0) scale(1);
}

.computation-overlay .computation-modal {
    position: relative;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.computation-overlay .card {
    width: 100%;
    max-width: 100%;
    height: 100%;
    border-radius: 20px;
    box-shadow: 0 18px 40px -18px rgba(30, 58, 95, 0.25);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.computation-overlay .card .content {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    max-width: 540px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

/* Popups show quiz content only — no in-modal logo / Practice Zone bar */
.computation-overlay .brandHeader,
.quiz-overlay .brandHeader,
.computation-overlay .quiz-brand-header,
.quiz-overlay .quiz-brand-header {
    display: none !important;
}

.computation-overlay #summaryTitle {
    text-align: center;
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--popup-scene-ink);
    margin-bottom: 12px;
}

#quiz-body {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
}

/* ---------- Quiz content sizing (prevent stretched answer buttons) ---------- */
.quiz-modal .quiz-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 12px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.quiz-modal .quiz-opt {
    padding: 12px 10px;
    font-size: 17px;
    min-height: 0;
    height: auto;
}

.quiz-modal .quiz-number-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.quiz-modal .quiz-number-opt {
    width: 64px;
    height: 64px;
    font-size: 24px;
    flex-shrink: 0;
}

.quiz-modal .quiz-count-box,
.quiz-modal .quiz-enough-box,
.quiz-modal .quiz-shape-box {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.quiz-modal .quiz-shape-options {
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}

.computation-overlay #options {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.computation-overlay .option {
    padding: 12px 10px;
    font-size: 18px;
    min-height: 0;
    height: auto;
}

/* Decorative sun (matches B.1 Identify numbers) */
.quiz-modal::before,
.computation-overlay .card::before {
    content: "";
    position: absolute;
    top: 14px;
    left: 14px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #FFF1A8, var(--popup-scene-sun));
    box-shadow: 0 0 22px 4px rgba(255, 217, 61, 0.45);
    pointer-events: none;
    z-index: 0;
    opacity: 0.9;
}

.quiz-modal > *,
.computation-overlay .card > * {
    position: relative;
    z-index: 1;
}

/* ---------- Close buttons ---------- */
.quiz-close,
.computation-overlay .computation-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 30;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--popup-scene-card, #fff);
    color: var(--popup-scene-ink, #233156);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s ease, transform 0.12s ease;
    box-shadow: 0 2px 8px rgba(30, 58, 95, 0.15);
}

.quiz-close:hover,
.computation-overlay .computation-close:hover {
    background: rgba(255, 255, 255, 0.85);
    transform: scale(1.06);
}

/* Balloon game embedded in quiz modal — avoid double background */
.quiz-modal .balloon-identify-game {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
}

.quiz-modal.has-balloon-game {
    max-width: none;
    padding: 48px 14px 18px;
}

.quiz-modal.has-balloon-game #quiz-body {
    padding: 0;
    display: flex;
    flex-direction: column;
}

.quiz-modal.has-balloon-game .balloon-identify-game,
.quiz-modal.has-balloon-game .balloon-pop-game {
    flex: 1 1 auto;
    min-height: 0;
}

.quiz-modal.has-balloon-game .balloon-identify-stage,
.quiz-modal.has-balloon-game .bap-stage {
    min-height: 100%;
    height: 100%;
}

/* Avoid duplicate scenery when balloon game sits inside themed modal */
.quiz-modal .balloon-identify-game .bni-sun,
.quiz-modal .balloon-identify-game .bni-cloud,
.quiz-modal .balloon-pop-game .bap-sun,
.quiz-modal .balloon-pop-game .bap-cloud {
    display: none;
}

/* Balloon addition game embedded in quiz modal — avoid double background */
.quiz-modal .balloon-pop-game {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
}

.pageWrapper > .card {
    position: relative;
    background: var(--popup-scene-background);
    overflow: hidden;
}

.pageWrapper > .card::before {
    content: "";
    position: absolute;
    top: 14px;
    left: 14px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #FFF1A8, var(--popup-scene-sun));
    box-shadow: 0 0 22px 4px rgba(255, 217, 61, 0.45);
    pointer-events: none;
    z-index: 0;
    opacity: 0.9;
}

.pageWrapper > .card > * {
    position: relative;
    z-index: 1;
}

.quiz-modal .quiz-count-box,
.quiz-modal .quiz-enough-group,
.quiz-modal .quiz-shape-box,
.quiz-modal .quiz-opt,
.quiz-modal .quiz-number-opt,
.quiz-modal .quiz-shape-opt,
.quiz-modal .quiz-classify-item,
.quiz-modal .quiz-classify-frame,
.quiz-modal .bni-prompt-card,
.quiz-modal .bni-pill,
.quiz-modal .bni-modal-card,
.quiz-modal .bap-pill,
.quiz-modal .bap-levelup-card {
    background-color: var(--popup-scene-card);
}

.computation-overlay .option,
.pageWrapper > .card .option {
    background-color: var(--popup-scene-card);
}

@media (max-width: 640px) {
    .quiz-modal.has-balloon-game {
        padding:
            max(52px, calc(env(safe-area-inset-top, 0px) + 44px))
            max(12px, env(safe-area-inset-right, 0px))
            max(16px, env(safe-area-inset-bottom, 0px))
            max(12px, env(safe-area-inset-left, 0px));
    }

    .quiz-modal.has-balloon-game .balloon-identify-stage,
    .quiz-modal.has-balloon-game .bap-stage {
        min-height: 0;
        flex: 1 1 auto;
    }
}

@media (max-width: 400px) {
    .quiz-modal.has-balloon-game .balloon-identify-stage,
    .quiz-modal.has-balloon-game .bap-stage {
        min-height: 0;
    }
}
