* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background: #f0f4fc;
    display: flex;
    justify-content: center;
    padding: 2rem 1.5rem;
}

.app {
    max-width: 1100px;
    width: 100%;
    background: #ffffff;
    border-radius: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(15, 43, 122, 0.25);
    padding: 2rem 2.5rem 1.5rem;
    position: relative;
    overflow: visible;
}

#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid #e6edf8;
    padding-bottom: 1.25rem;
    margin-bottom: 2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.logo {
    font-size: 1.8rem;
    font-weight: 800;
    color: #0F2B7A;
    letter-spacing: -0.5px;
    user-select: none;
    transition: opacity 0.2s;
}
.logo.clickable {
    cursor: pointer;
}
.logo.clickable:hover { opacity: 0.7; }
.logo.disabled {
    cursor: default;
    opacity: 1;
}
.logo span { color: #FFB800; }

.slogan {
    font-size: 1.1rem;
    font-weight: 500;
    color: #1e3a6f;
    background: #eef4ff;
    padding: 0.25rem 1rem;
    border-radius: 40px;
    border-left: 4px solid #FFB800;
    white-space: nowrap;
    cursor: pointer;
}
.slogan:hover {
    background: #e2ebf6;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.timer-display {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.3rem;
    font-weight: 700;
    background: #eef4ff;
    color: #0F2B7A;
    padding: 0.25rem 1.2rem;
    border-radius: 60px;
    min-width: 120px;
    justify-content: center;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
    box-shadow: inset 0 0 0 1px rgba(15, 43, 122, 0.1);
    transition: opacity 0.3s ease, background 0.3s ease, color 0.3s ease;
    line-height: 1.4;
}
.timer-display .state-icon { font-size: 1rem; opacity: 0.7; }

.timer-display.stopped:not(.warning) {
    opacity: 0.95;
    background: #e8ecf4;
    color: #7a8aa5;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.timer-display.stopped:not(.warning) .state-icon { opacity: 0.95; }

.timer-display.warning {
    background: #fde8e8;
    color: #b22222;
    animation: pulse 1s infinite;
}
.timer-display.warning .state-icon { animation: none; }
.timer-display.warning.stopped { opacity: 1; }

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.streak-badge {
    background: #0F2B7A;
    color: #fff;
    padding: 0.25rem 1.2rem;
    border-radius: 60px;
    font-size: 1.3rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    box-shadow: 0 4px 8px rgba(15, 43, 122, 0.2);
    white-space: nowrap;
    line-height: 1.4;
    height: auto;
    vertical-align: middle;
}

.main-grid {
    display: flex;
    gap: 2rem;
}

.questions-area {
    flex: 7;
    min-width: 0;
}

.section-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin: 1rem 0;
}
.section-card {
    background: #f9fbff;
    border: 2px solid #e2ebf6;
    border-radius: 1.5rem;
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: 0.2s;
    position: relative;
}
.section-card:hover {
    border-color: #0F2B7A;
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(15, 43, 122, 0.1);
}
.section-card .icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.5rem;
    line-height: 1;
}
.section-card h3 {
    font-size: 1.3rem;
    color: #0F2B7A;
    margin-bottom: 0.3rem;
}
.section-card p {
    font-size: 0.85rem;
    color: #4a5f7a;
}
.section-card .diff-badge {
    margin-top: 0.6rem;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.section-card .diff-badge span {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.8rem;
    border-radius: 30px;
}
.diff-easy { background: #d4edda; color: #0b5e2e; }
.diff-medium { background: #fff3cd; color: #856404; }
.diff-hard { background: #f8dddd; color: #9e1f1f; }

.section-card .status-badge {
    display: inline-block;
    margin-top: 0.8rem;
    padding: 0.2rem 1rem;
    border-radius: 30px;
    font-size: 0.8rem;
    font-weight: 700;
}
.status-badge.done { background: #c8f0d0; color: #0b5e2e; }
.status-badge.partial { background: #fff3cd; color: #856404; }
.status-badge.pending { background: #e6edf8; color: #4a5f7a; }
.section-card.complete {
    border-color: #1d8b3e;
    background: #f2faf5;
}

.question-view {
    display: none;
    flex-direction: column;
    gap: 1.2rem;
}
.question-view.active { display: flex; }

.q-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #0F2B7A;
    font-size: 0.9rem;
}
.q-header .dots {
    display: flex;
    gap: 0.5rem;
}
.q-header .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #d0dff0;
    transition: 0.2s;
    border: 2px solid transparent;
}
.q-header .dot.active {
    background: #0F2B7A;
    border-color: #FFB800;
    transform: scale(1.2);
}
.q-header .dot.completed { background: #1d8b3e; }
.q-header .dot.wrong { background: #b22222; }

.q-card-single {
    background: #ffffff;
    border-radius: 1.5rem;
    padding: 1.8rem 2rem;
    border: 1px solid #e2ebf6;
    box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}
.q-card-single .q-text {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e2a3a;
    margin-bottom: 1.2rem;
    line-height: 1.6;
}
.q-card-single .options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem 1rem;
}
.q-card-single .option {
    background: #f5f9ff;
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    border: 2px solid transparent;
    transition: 0.1s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.q-card-single .option:hover:not(.disabled) {
    background: #e6effa;
    border-color: #b3c9e6;
}
.q-card-single .option .letter {
    font-weight: 700;
    color: #0F2B7A;
    min-width: 1.4rem;
}
.q-card-single .option.selected {
    background: #d0e0ff;
    border-color: #0F2B7A;
}
.q-card-single .option.correct-reveal {
    background: #c8f0d0;
    border-color: #1d8b3e;
}
.q-card-single .option.wrong-reveal {
    background: #fcd0d0;
    border-color: #b22222;
}
.q-card-single .option.correct-answer-reveal {
    background: #c8f0d0;
    border-color: #1d8b3e;
}
.q-card-single .option.disabled {
    cursor: default;
    opacity: 0.85;
    pointer-events: none;
}
.q-card-single .option.disabled:hover {
    background: #f5f9ff;
    border-color: transparent;
}

.explanation-box {
    display: none;
    margin-top: 1.2rem;
    padding: 1rem 1.2rem;
    background: #f5f9ff;
    border-radius: 12px;
    border-left: 4px solid #FFB800;
    font-size: 0.9rem;
    color: #1e3a6f;
    line-height: 1.6;
    overflow: scroll;
}
.explanation-box.visible { display: block; }
.explanation-box strong { color: #0F2B7A; }
.explanation-box .distractor {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: #4a5f7a;
}
.explanation-box .time-spent {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #0F2B7A;
    font-weight: 500;
}

.desmos-solution {
    margin-top: 0.8rem;
    padding: 0.6rem 0.8rem;
    background: #ecf7f0;
    border-left: 4px solid #2b8c4a;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #1e3a6f;
}
.desmos-solution strong {
    color: #0F2B7A;
}

.q-actions-single {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}
.actions-left {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    align-items: center;
}
.actions-right {
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

.btn-check, .btn-next, .btn-back {
    border: none;
    padding: 0.6rem 1.8rem;
    border-radius: 60px;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: 0.15s;
}
.btn-check {
    background: #0F2B7A;
    color: #fff;
    box-shadow: 0 4px 12px rgba(15, 43, 122, 0.25);
}
.btn-check:hover:not(:disabled) {
    background: #1a3b8f;
    transform: scale(1.02);
}
.btn-check:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}
.btn-next {
    background: #e6edf8;
    color: #0F2B7A;
}
.btn-next:hover:not(:disabled) {
    background: #d0dff0;
}
.btn-next:disabled {
    opacity: 0.4;
    cursor: default;
}
.btn-next.hidden {
    display: none;
}
.btn-next.fade-in {
    animation: fadeIn 0.25s ease forwards;
}
@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(4px); }
    100% { opacity: 1; transform: translateY(0); }
}

.btn-back {
    background: transparent;
    color: #4a5f7a;
    border: 1px solid #d0dff0;
    font-weight: 500;
}
.btn-back:hover {
    background: #eef4ff;
    color: #0F2B7A;
}

.like-btn, .dislike-btn {
    background: none;
    border: 2px solid #d0dff0;
    border-radius: 30px;
    padding: 0.2rem 0.6rem;
    font-size: 1.2rem;
    cursor: pointer;
    transition: 0.15s;
    line-height: 1.4;
    background: #f5f9ff;
    min-width: 2.4rem;
    text-align: center;
}
.like-btn:hover:not(:disabled):not(.active),
.dislike-btn:hover:not(:disabled):not(.active) {
    background: #e6effa;
    border-color: #b3c9e6;
}
.like-btn.active,
.dislike-btn.active {
    cursor: pointer;
}
.like-btn.active:hover,
.dislike-btn.active:hover {
    background: inherit;
    border-color: inherit;
}
.like-btn.active {
    background: #c8e6ff;
    border-color: #0F2B7A;
}
.dislike-btn.active {
    background: #ffe0e0;
    border-color: #b22222;
}
.like-btn:disabled, .dislike-btn:disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
    border-color: #e2ebf6;
    background: #f5f7fc;
}

.section-complete {
    display: none;
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: #f9fbff;
    border-radius: 1.5rem;
    border: 2px solid #0F2B7A;
    position: relative;
    overflow: hidden;
}
.section-complete.active { display: block; }
.section-complete .big-icon {
    font-size: 4rem;
    margin-bottom: 0.5rem;
    line-height: 1;
}
.section-complete h2 {
    color: #0F2B7A;
    font-size: 1.8rem;
}
.section-complete .score-big {
    font-size: 3rem;
    font-weight: 800;
    color: #FFB800;
    margin: 0.5rem 0;
}
.section-complete .sub-text {
    color: #4a5f7a;
    font-size: 1rem;
}
.section-complete .action-row {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.stats-sidebar {
    flex: 3;
    min-width: 200px;
    background: #0F2B7A;
    border-radius: 1.8rem;
    padding: 1.8rem 1.5rem;
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    box-shadow: 0 8px 24px rgba(15, 43, 122, 0.25);
    height: fit-content;
    position: sticky;
    top: 2rem;
}
.stats-sidebar h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
    font-weight: 500;
    margin-bottom: 0.1rem;
}
.stat-item {
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 1rem;
}
.stat-item:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}
.stat-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.1;
}
.stat-value small {
    font-size: 1rem;
    font-weight: 400;
    opacity: 0.6;
    margin-left: 0.3rem;
}
.stat-label {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-top: 0.1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.progress-ring {
    background: rgba(255,255,255,0.12);
    border-radius: 60px;
    height: 6px;
    width: 100%;
    margin-top: 0.4rem;
}
.progress-ring .fill {
    height: 100%;
    border-radius: 60px;
    background: #FFB800;
    transition: width 0.5s;
}

.badge-free {
    margin-top: auto;
    background: rgba(255,184,0,0.15);
    border: 1px solid rgba(255,184,0,0.3);
    border-radius: 60px;
    padding: 0.5rem 1rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #FFB800;
}
.badge-free span {
    display: block;
    font-weight: 400;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.6);
    margin-top: 0.1rem;
}

/* ─── Footer ─── */
.footer {
    margin-top: 2.5rem;
    padding-top: 1.2rem;
    border-top: 1px solid #e6edf8;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #3d5675;
    gap: 0.8rem;
}

.footer .trust {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.footer .trust .pill {
    background: #ecf3fa;
    padding: 0.2rem 1rem;
    border-radius: 30px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    cursor: pointer;
}
.footer .trust .pill:hover {
    background: #dde6f2;
}

.footer .copy {
    white-space: nowrap;
}

.loader {
    text-align: center;
    padding: 3rem;
    color: #4a5f7a;
    font-size: 1.2rem;
}
.loader .spinner {
    border: 4px solid #eef4ff;
    border-top: 4px solid #0F2B7A;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ─── Welcome Modal ─── */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 43, 122, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1.5rem;
}

.modal-content {
    background: #ffffff;
    max-width: 540px;
    width: 100%;
    border-radius: 2rem;
    padding: 2.5rem 2.5rem 2rem;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
    position: relative;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    0% { opacity: 0; transform: scale(0.95) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    color: #7a8aa5;
    cursor: pointer;
    transition: color 0.2s;
}
.modal-close:hover {
    color: #0F2B7A;
}

.modal-icon {
    font-size: 3.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.modal-content h2 {
    font-size: 1.8rem;
    font-weight: 800;
    color: #0F2B7A;
    text-align: center;
    margin-bottom: 0.3rem;
}

.modal-brand {
    font-size: inherit;
    font-weight: 800;
    color: #0F2B7A;
}
.modal-brand span {
    color: #FFB800;
}

.modal-sub {
    text-align: center;
    color: #4a5f7a;
    font-size: 1rem;
    margin-bottom: 1.5rem;
}

.modal-features {
    list-style: none;
    padding: 0;
    margin: 0 0 1.8rem 0;
}

.modal-features li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.5rem 0;
    font-size: 0.95rem;
    color: #1e2a3a;
    line-height: 1.5;
    border-bottom: 1px solid #f0f4fc;
}
.modal-features li:last-child {
    border-bottom: none;
}

.modal-features li span {
    font-size: 1.2rem;
    min-width: 1.6rem;
    text-align: center;
}

.modal-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 0.75rem;
    font-size: 1.1rem;
    margin-top: 0.25rem;
}

/* ─── MathJax inline fix ─── */
.mjx-chtml { display: inline-block; }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .app { padding: 1.5rem; }
    .main-grid { flex-direction: column; }
    .stats-sidebar {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 1rem;
        padding: 1.5rem;
    }
    .stats-sidebar .stat-item { flex: 1; min-width: 100px; border-bottom: none; padding-bottom: 0; }
    .badge-free { margin-top: 0; flex-basis: 100%; }
    .slogan { font-size: 0.95rem; padding: 0.2rem 0.8rem; }
    .streak-badge { font-size: 1.1rem; padding: 0.2rem 0.9rem; }
    .timer-display { font-size: 1.1rem; padding: 0.2rem 0.9rem; min-width: 100px; }
}

@media (max-width: 700px) {
    .section-selector { grid-template-columns: 1fr; }
    .q-card-single .options-grid { grid-template-columns: 1fr; }
    .header { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
    .header-right { width: 100%; justify-content: space-between; }
    .brand { width: 100%; }
    .timer-display { font-size: 0.95rem; padding: 0.15rem 0.6rem; min-width: 70px; }
    .streak-badge { font-size: 0.95rem; padding: 0.15rem 0.6rem; }
    .slogan { font-size: 0.85rem; padding: 0.15rem 0.6rem; }
    .q-actions-single { flex-direction: column; align-items: stretch; }
    .actions-left { justify-content: center; }
    .actions-right { justify-content: center; }
}

/* ─── Tablet / iPad footer fix (900px) ─── */
@media (max-width: 900px) {
    .footer {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.8rem;
    }
    .footer .trust {
        justify-content: center;
        gap: 0.8rem;
        flex-wrap: wrap;
    }
    .footer .trust .pill {
        font-size: 0.75rem;
        padding: 0.15rem 0.8rem;
    }
    .footer .copy {
        white-space: normal;
        font-size: 0.75rem;
    }
}

/* ─── Mobile footer (600px) ─── */
@media (max-width: 600px) {
    .footer {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 0.6rem;
        padding-top: 1rem;
        margin-top: 2rem;
    }
    .footer .trust {
        justify-content: center;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    .footer .trust .pill {
        padding: 0.15rem 0.8rem;
        font-size: 0.7rem;
        white-space: nowrap;
    }
    .footer .copy {
        font-size: 0.7rem;
        white-space: normal;
        text-align: center;
    }

    .modal-content {
        padding: 1.8rem 1.5rem 1.5rem;
    }
    .modal-content h2 {
        font-size: 1.5rem;
    }
    .modal-features li {
        font-size: 0.9rem;
    }
    .modal-btn {
        font-size: 1rem;
        padding: 0.6rem;
    }
}

/* ─── English / Reading & Writing styles ─── */
.passage-block {
    margin-bottom: 1rem;
    padding: 0.8rem 1rem;
    background: #f8faff;
    border-radius: 8px;
    border-left: 3px solid #0F2B7A;
}
.passage-block:last-of-type {
    margin-bottom: 0.8rem;
}
.passage-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #0F2B7A;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}
.passage-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #1e2a3a;
}
.question-stem {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e2a3a;
    margin: 0.8rem 0 1rem 0;
    padding: 0.6rem 0.8rem;
    background: #f0f4fc;
    border-radius: 6px;
    border-left: 4px solid #FFB800;
}

.visual-container {
    display: flex;
    justify-content: center;
    margin: 0.5rem 0 1rem 0;
}
.visual-container img {
    max-width: 100%;
    max-height: 300px;
    border: 1px solid #e2ebf6;
    border-radius: 8px;
}

/* ─── Fade transition for question area ─── */
.questions-area {
    transition: opacity 0.1s ease;
}
.questions-area.fading-out {
    opacity: 0;
    transition: opacity 0.1s ease;
}

/* ─── Clickable dots in review mode ─── */
.dot[role="button"] {
    cursor: pointer;
    /*transition: all 0.15s ease;*/
}
.dot[role="button"]:hover {
    outline: 2px solid #0F2B7A;
    outline-offset: 2px;
    /*transform: scale(1.15);*/
    /*background: #ffffff;*/
    color: #0F2B7A;
}

/* ─── Free‑response input ─── */
.free-response-input {
    width: 100%;
    max-width: 200px;
    padding: 0.6rem 0.8rem;
    font-size: 1rem;
    border: 2px solid #d0dff0;
    border-radius: 10px;
    background: #f5f9ff;
    color: #1e2a3a;
    transition: border-color 0.2s;
    font-family: 'Courier New', monospace;
}
.free-response-input:focus {
    border-color: #0F2B7A;
    outline: none;
}
.free-response-input:disabled {
    opacity: 0.6;
    background: #eef3fc;
    cursor: not-allowed;
}

/* ─── Border color feedback ─── */
.q-card-single.correct-border {
    border: 2px solid #1d8b3e !important;
    transition: border 0.3s ease;
}
.q-card-single.incorrect-border {
    border: 2px solid #b22222 !important;
    transition: border 0.3s ease;
}