/**
 * Centralized mobile / Android popup layout for ALL skill quizzes.
 * Edit this file only when fixing phone popup sizing, close button, or action buttons.
 */

/* Lock page scroll while a full-screen popup is open on phones */
@media (max-width: 768px) {
    body.quiz-popup-open {
        overflow: hidden;
        touch-action: none;
    }
}

/* ---------- Phone / touch full-screen shell (≤768px) ---------- */
@media (max-width: 768px) {
    .quiz-overlay,
    .computation-overlay {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        align-items: stretch !important;
        justify-content: stretch !important;
        /* Above site header (1000+) and mobile nav (3000+) */
        z-index: 4100 !important;
    }

    body[data-page="skills"] .quiz-overlay,
    body[data-page="skills"] .computation-overlay {
        left: 0 !important;
    }

    .quiz-overlay .quiz-modal,
    .computation-overlay .computation-modal {
        width: 100%;
        height: 100%;
        min-height: 100dvh;
        max-height: 100dvh;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        transform: none !important;
    }

    /* Fixed close — always visible, not clipped by header or scroll */
    .quiz-overlay.open .quiz-close,
    .computation-overlay.open .computation-close {
        position: fixed;
        top: max(8px, env(safe-area-inset-top, 0px));
        right: max(8px, env(safe-area-inset-right, 0px));
        z-index: 4200;
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        font-size: 28px;
        line-height: 1;
        border: 2px solid rgba(30, 58, 95, 0.12);
        background: #fff;
        color: #233156;
        box-shadow: 0 4px 14px rgba(20, 32, 50, 0.22);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* Hide decorative sun on phones — keeps top area clear for close */
    .quiz-modal::before,
    .computation-overlay .card::before {
        display: none !important;
    }

    /* Scrollable quiz body */
    .computation-overlay .card,
    .quiz-overlay .quiz-modal > .card,
    .quiz-overlay .quiz-modal > #quiz-body {
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
        max-width: none;
        border-radius: 0 !important;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding:
            calc(env(safe-area-inset-top, 0px) + 56px)
            max(14px, env(safe-area-inset-right, 0px))
            max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px))
            max(14px, env(safe-area-inset-left, 0px));
    }

    .computation-overlay .card .content {
        flex: none;
        overflow: visible;
        min-height: 0;
        max-width: none;
        width: 100%;
        margin: 0;
        padding: 0 0 12px;
    }

    /* Sticky action buttons — stay visible after answering (word problems, blocks, etc.) */
    .computation-overlay #nextBtn,
    .computation-overlay #yesBtn,
    .computation-overlay #noBtn,
    .quiz-overlay #nextBtn,
    .quiz-overlay .bq-next-btn,
    .quiz-overlay #compareNextBtn,
    .quiz-overlay .bq-check-btn,
    .quiz-overlay .quiz-btn,
    .quiz-overlay .quiz-next-row {
        position: sticky;
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        z-index: 12;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .computation-overlay #nextBtn,
    .quiz-overlay .bq-next-btn,
    .quiz-overlay #compareNextBtn {
        min-height: 48px;
        width: 100%;
        max-width: 360px;
        margin-left: auto;
        margin-right: auto;
        padding: 14px 18px;
        font-size: 16px;
        box-shadow: 0 4px 14px rgba(20, 32, 50, 0.15);
    }

    .quiz-overlay .bq-check-btn {
        min-height: 48px;
        min-width: 100px;
        padding: 14px 20px;
        font-size: 16px;
    }

    .quiz-overlay .quiz-next-row {
        text-align: center;
        padding-top: 8px;
        margin-top: 12px;
        background: linear-gradient(to top, rgba(214, 245, 255, 0.95) 70%, transparent);
    }

    .computation-overlay .summary-buttons {
        position: sticky;
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        z-index: 12;
        flex-direction: column;
        gap: 10px;
        padding-top: 8px;
        background: linear-gradient(to top, rgba(214, 245, 255, 0.95) 70%, transparent);
    }

    .computation-overlay .summary-buttons button,
    .quiz-overlay .bq-summary-buttons {
        width: 100%;
    }

    .quiz-overlay .bq-summary-buttons {
        position: sticky;
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding-top: 8px;
        background: linear-gradient(to top, rgba(214, 245, 255, 0.95) 70%, transparent);
    }

    .quiz-overlay .bq-summary-buttons .bq-btn {
        width: 100%;
        min-height: 48px;
    }
}

/* ---------- Content sizing (phones ≤640px) ---------- */
@media (max-width: 640px) {
    #question,
    .computation-overlay #question {
        font-size: 18px;
        line-height: 1.45;
        margin-bottom: 16px;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    #progress {
        font-size: 12px;
        margin-bottom: 10px;
    }

    #slotTracker {
        padding: 0 2px;
        margin-bottom: 14px;
    }

    .slot-dot {
        width: 26px;
        height: 26px;
        font-size: 11px;
    }

    #starTracker {
        padding: 10px 8px;
        gap: 6px;
        margin-bottom: 14px;
    }

    .starSlot {
        font-size: 24px;
    }

    #options {
        gap: 10px;
    }

    .option {
        padding: 14px 12px;
        font-size: 17px;
        min-height: 48px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .answer-box {
        width: 32px;
        height: 32px;
        margin: 0 4px;
    }

    #feedback {
        font-size: 16px;
        margin-top: 14px;
        min-height: 28px;
        max-height: 40vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #nextBtn,
    .computation-overlay #nextBtn,
    .computation-overlay .summary-buttons button,
    #yesBtn,
    #noBtn {
        min-height: 48px;
        padding: 14px 18px;
        font-size: 16px;
        margin-top: 16px;
    }

    #stars {
        font-size: 34px;
        letter-spacing: 5px;
    }

    #scoreText {
        font-size: 16px;
    }

    #rewardMessage {
        font-size: 18px;
        padding: 12px 16px;
    }

    .quiz-question {
        font-size: 18px;
        line-height: 1.35;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .quiz-eyebrow {
        font-size: 12px;
    }

    .quiz-options {
        gap: 10px;
    }

    .quiz-opt {
        font-size: 16px;
        padding: 14px 12px;
        min-height: 48px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .quiz-shape-box {
        width: 160px;
        height: 160px;
        margin-bottom: 16px;
    }

    .quiz-shape-box svg {
        width: 110px;
        height: 110px;
    }

    .quiz-shape-options {
        gap: 12px;
    }

    .quiz-shape-opt {
        width: 130px;
        height: 130px;
    }

    .quiz-shape-opt svg {
        width: 85px;
        height: 85px;
    }

    .quiz-represent-opt {
        width: 150px;
        height: 150px;
    }

    .quiz-count-box {
        min-height: 140px;
        padding: 14px;
        gap: 10px;
    }

    .quiz-count-box svg {
        width: 52px;
        height: 52px;
    }

    .quiz-number-opt {
        width: 60px;
        height: 60px;
        min-width: 60px;
        min-height: 60px;
        font-size: 24px;
        touch-action: manipulation;
    }

    .quiz-number-options {
        gap: 12px;
    }

    .quiz-enough-icons svg {
        width: 36px;
        height: 36px;
    }

    .quiz-classify-item {
        width: 68px;
        height: 68px;
    }

    .quiz-classify-item svg {
        width: 44px;
        height: 44px;
    }

    .quiz-classify-frame {
        width: 130px;
        min-height: 100px;
    }

    .quiz-classify-frame-slots svg {
        width: 36px;
        height: 36px;
    }

    .quiz-feedback {
        font-size: 15px;
    }

    .quiz-btn {
        font-size: 16px;
        padding: 14px 24px;
        min-height: 48px;
        min-width: 120px;
    }

    .quiz-overlay .cn-opt-btn {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px;
        min-height: 56px;
        font-size: 26px !important;
        touch-action: manipulation;
    }

    .quiz-result h3 {
        font-size: 22px;
    }

    .quiz-result .quiz-score-emoji {
        font-size: 44px;
    }

    .bq-feedback {
        max-height: 30vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 400px) {
    #question,
    .computation-overlay #question,
    .quiz-question {
        font-size: 16px;
    }

    #options,
    .quiz-options {
        grid-template-columns: 1fr;
    }

    .quiz-shape-opt {
        width: 110px;
        height: 110px;
    }

    .quiz-shape-opt svg {
        width: 70px;
        height: 70px;
    }

    .quiz-represent-opt {
        width: 120px;
        height: 120px;
    }

    .quiz-shape-box {
        width: 140px;
        height: 140px;
    }

    .quiz-shape-box svg {
        width: 95px;
        height: 95px;
    }

    .slot-dot {
        width: 22px;
        height: 22px;
        font-size: 10px;
    }

    #slotTracker::before {
        left: 12px;
        right: 12px;
    }

    .quiz-btn.ghost {
        margin-left: 0;
        margin-top: 8px;
    }

    .quiz-overlay .cn-opt-btn {
        width: 52px !important;
        height: 52px !important;
        min-width: 52px;
        min-height: 52px;
        font-size: 22px !important;
    }
}
