/* Maths — subject-specific overrides (base loaded from shared/css/subject-base.css) */

:root {
    --primary: #4361ee;
    --primary-light: #eef0ff;
}

/* ---- Topic tag variants (maths-specific) ---- */
.topic-tag.log { background: #e8daef; color: #6c3483; }
.topic-tag.quad { background: #d5f5e3; color: #1e8449; }
.topic-tag.num { background: #fdebd0; color: #b9770e; }
.topic-tag.alg { background: #d6eaf8; color: #2471a3; }
.topic-tag.func { background: #fdebd0; color: #b9770e; }
.topic-tag.crit-b { background: #f5eef8; color: #7d3c98; }
.topic-tag.trig { background: #f72585; color: #fff; }
.topic-tag.ext { background: #00b894; color: #fff; }
.topic-tag.vec { background: #4cc9f0; color: #fff; }
.topic-tag.geo { background: #2ec4b6; color: #fff; }
.topic-tag.prob { background: #ff6b6b; color: #fff; }
.topic-tag.stat { background: #ffa62b; color: #fff; }
.topic-tag.sets { background: #845ec2; color: #fff; }
.topic-tag.mens { background: #00b4d8; color: #fff; }
.topic-tag.pyth { background: #e76f51; color: #fff; }
.topic-tag.sim { background: #2a9d8f; color: #fff; }
.topic-tag.coord { background: #6366f1; color: #fff; }
.topic-tag.fin { background: #16a34a; color: #fff; }
.topic-tag.bear { background: #d97706; color: #fff; }

/* ---- Search Bar (maths custom) ---- */
.search-bar { position: relative; margin-bottom: 20px; }
.search-input {
    width: 100%; padding: 14px 18px; font-size: 1rem; border: 2px solid transparent;
    border-radius: var(--radius); background: var(--card); color: var(--text);
    box-shadow: var(--shadow); outline: none; transition: border-color 0.2s;
    font-family: inherit;
}
.search-input:focus { border-color: var(--primary); }
.search-input::placeholder { color: var(--text-light); opacity: 0.6; }
.search-results {
    display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--card); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    max-height: 340px; overflow-y: auto; z-index: 100; padding: 8px 0;
}
.search-results.show { display: block; }
.search-result {
    padding: 10px 18px; cursor: pointer; display: flex; align-items: center; gap: 10px;
    transition: background 0.15s;
}
.search-result:hover, .search-result.active { background: var(--primary-light); }
.search-result-icon { font-size: 1.1rem; opacity: 0.6; flex-shrink: 0; }
.search-result-text { flex: 1; }
.search-result-title { font-weight: 600; font-size: 0.92rem; color: var(--text); }
.search-result-sub { font-size: 0.78rem; color: var(--text-light); }
.search-result-type {
    font-size: 0.68rem; font-weight: 600; padding: 2px 8px; border-radius: 8px;
    flex-shrink: 0; text-transform: uppercase;
}
.search-result-type.topic { background: var(--primary-light); color: var(--primary); }
.search-result-type.activity { background: var(--success-light); color: var(--success); }
.search-result-type.lesson { background: #fef3c7; color: #b45309; }
.search-level {
    font-size: 0.62rem; font-weight: 700; padding: 2px 6px; border-radius: 6px;
    flex-shrink: 0; text-transform: uppercase; letter-spacing: 0.02em;
}
.search-level.std { background: rgba(67,97,238,0.12); color: #4361ee; }
.search-level.ext { background: rgba(0,184,148,0.12); color: #00b894; }
.topic-card.search-hidden { display: none; }

/* ---- Topic Card Icons ---- */
.topic-card-inner { display: flex; align-items: flex-start; gap: 14px; }
.topic-card-icon { flex-shrink: 0; width: 48px; height: 48px; color: var(--primary); opacity: 0.7; }
.topic-card-icon svg { width: 100%; height: 100%; }
.topic-card-body { flex: 1; min-width: 0; }

/* ---- Topic card (maths overrides) ---- */
.topic-card:hover {
    border-color: var(--primary); transform: translateY(-3px);
    box-shadow: 0 8px 32px rgba(67,97,238,0.15);
}
.topic-card h2 {
    font-size: 1.2rem; font-weight: 700; color: var(--primary);
    margin-bottom: 6px;
}
.topic-card p { font-size: 0.9rem; color: var(--text-light); line-height: 1.5; }
.topic-tag {
    display: inline-block; font-size: 0.72rem; font-weight: 600;
    padding: 3px 10px; border-radius: 12px; margin-top: 10px;
}

/* ---- Score bar (maths layout) ---- */
.score-bar {
    display: flex; justify-content: center; gap: 16px;
    margin-bottom: 24px; flex-wrap: wrap;
}
.score-item {
    background: var(--card); padding: 10px 20px; border-radius: 12px;
    box-shadow: var(--shadow); text-align: center; min-width: 90px;
}
.score-item .label {
    font-size: 0.7rem; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--text-light); margin-bottom: 2px;
}
.score-item .value { font-size: 1.3rem; font-weight: 700; }

/* ---- Question card (maths) ---- */
.question-card {
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 32px; margin-bottom: 20px;
    text-align: center;
}
.rule-tag, .difficulty-tag {
    display: inline-block; font-size: 0.78rem; font-weight: 600;
    padding: 4px 14px; border-radius: 20px; margin-bottom: 14px;
}
.rule-tag { background: var(--primary-light); color: var(--primary); }
.difficulty-tag.easy   { background: var(--success-light); color: #047857; }
.difficulty-tag.medium { background: #fff3cd; color: #856404; }
.difficulty-tag.hard   { background: var(--error-light); color: #be123c; }

.question-text { font-size: 1.15rem; margin-bottom: 4px; line-height: 1.5; }
.question-prompt { font-size: 1.55rem; font-weight: 600; margin: 14px 0 4px; line-height: 2; }
.question-hint { font-size: 0.9rem; color: var(--text-light); margin-bottom: 4px; }
.equation-system { font-size: 1.35rem; line-height: 2.6; margin: 16px 0; }

/* ---- MC (maths option-btn with data-i numbering) ---- */
.options-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 12px; margin-top: 20px;
}
.option-btn {
    background: var(--card); border: 2px solid var(--border); border-radius: 12px;
    padding: 16px 8px 16px 40px; cursor: pointer; font-size: 1.05rem;
    transition: all 0.2s ease; font-family: inherit; line-height: 1.6;
    position: relative; text-align: center;
}
.option-btn::before {
    content: attr(data-i);
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 22px; height: 22px; border-radius: 6px;
    background: #e8e8e8; color: #666; font-size: 0.75rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.option-btn[data-i="0"]::before { content: "1"; }
.option-btn[data-i="1"]::before { content: "2"; }
.option-btn[data-i="2"]::before { content: "3"; }
.option-btn[data-i="3"]::before { content: "4"; }
.option-btn:hover:not(:disabled) {
    border-color: var(--primary); background: var(--primary-light);
    transform: translateY(-2px);
}
.option-btn.selected:not(:disabled) {
    border-color: var(--primary); background: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.3);
}
.option-btn.correct { border-color: var(--success); background: var(--success-light); }
.option-btn.incorrect { border-color: var(--error); background: var(--error-light); }
.option-btn:disabled { cursor: default; opacity: 0.7; }

/* ---- MC Options (linprog, coord, finance, etc.) ---- */
.mc-options { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.mc-option {
    flex: 1; min-width: 180px; padding: 12px 16px; border: 2px solid var(--border);
    border-radius: 12px; background: #fff; cursor: pointer; font-size: 0.95rem;
    font-weight: 500; text-align: center; transition: all 0.2s;
}
.mc-option:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); transform: translateY(-2px); }
.mc-option.correct { border-color: var(--success); background: var(--success-light); font-weight: 700; }
.mc-option.incorrect { border-color: var(--error); background: var(--error-light); }
.mc-option.disabled { opacity: 0.5; }
.mc-option:disabled { cursor: default; }

/* ---- Input area (maths custom) ---- */
.input-area {
    margin-top: 20px; display: flex; flex-direction: column;
    align-items: center; gap: 14px;
}
math-field {
    font-size: 1.4rem; border-radius: 12px; border: 2px solid var(--border);
    padding: 8px 14px;
    --caret-color: var(--primary);
    --selection-background-color: rgba(67,97,238,0.18);
}
math-field:focus-within {
    border-color: var(--primary); outline: none;
    box-shadow: 0 0 0 3px rgba(67,97,238,0.15);
}
.lr-math-field { width: 100%; max-width: 280px; font-size: 1.5rem; padding: 10px 16px; }
.se-math-field { width: 140px; }

/* ---- Buttons (maths overrides) ---- */
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-hint {
    background: none; border: 2px solid var(--border); color: var(--text-light);
    padding: 8px 20px; font-size: 0.88rem;
}
.btn-hint:hover { border-color: #ffc107; color: #856404; background: #fff8e1; }
.hint-box {
    background: #fff8e1; border: 2px solid #ffc107; border-radius: var(--radius);
    padding: 16px 20px; margin-bottom: 20px; text-align: center;
    font-size: 0.95rem; line-height: 1.8; display: none;
    animation: slideIn 0.3s ease;
}
.hint-box.show { display: block; }

/* ---- Feedback (maths custom) ---- */
.feedback {
    border-radius: var(--radius); padding: 20px 24px; margin-bottom: 20px;
    display: none; animation: slideIn 0.3s ease;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.feedback.show { display: block; }
.feedback.correct  { background: var(--success-light); border: 2px solid var(--success); color: #047857; }
.feedback.incorrect { background: var(--error-light); border: 2px solid var(--error); color: #be123c; }
.feedback-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 8px; text-align: center; }
.feedback-explanation { font-size: 0.95rem; line-height: 1.8; }
.solution-step { margin: 4px 0; }

.next-btn { display: none; margin: 0 auto 24px; }
.next-btn.show { display: block; }
body.timed-active .next-btn.show { display: none; }

/* ---- Level selector (maths custom) ---- */
.level-select {
    display: flex; justify-content: center; gap: 8px;
    margin-bottom: 20px; flex-wrap: wrap;
}
.level-btn {
    background: var(--card); color: var(--text); border: 2px solid var(--border);
    border-radius: 20px; padding: 6px 18px; font-size: 0.85rem;
    font-weight: 600; cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.level-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.level-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- Workout space ---- */
.workout-section {
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px;
}
.workout-section h3 {
    font-size: 0.9rem; font-weight: 600; color: var(--primary); margin-bottom: 12px;
}
details.workout-section { padding: 0; }
details.workout-section summary {
    padding: 16px 24px; cursor: pointer; font-weight: 600;
    color: var(--primary); user-select: none; list-style: none;
}
details.workout-section summary::-webkit-details-marker { display: none; }
details.workout-section summary::before { content: '+ '; font-weight: 700; }
details.workout-section[open] summary::before { content: '\2212 '; }
details.workout-section[open] summary { border-bottom: 1px solid #f0f0f0; }
details.workout-section .workout-textarea {
    margin: 16px; width: calc(100% - 32px); min-height: 120px;
}
.workout-textarea {
    width: 100%; min-height: 180px; padding: 16px;
    border: 2px solid var(--border); border-radius: 12px;
    font-family: 'Cascadia Code','Fira Code','SF Mono','Consolas',monospace;
    font-size: 1rem; line-height: 1.8; color: var(--text);
    resize: vertical; background: #fafbfc; transition: border-color 0.2s;
}
.workout-textarea:focus {
    border-color: var(--primary); outline: none;
    box-shadow: 0 0 0 3px rgba(67,97,238,0.15);
}
.workout-textarea::placeholder { color: #b0b8c4; }
.copy-calc-btn {
    display: block; margin: 12px 16px; padding: 10px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; border: none; border-radius: 8px; cursor: pointer;
    font-size: 0.85rem; font-weight: 600; width: calc(100% - 32px);
}
.copy-calc-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.copy-calc-btn:active { transform: translateY(0); }
details.workout-section .copy-calc-btn { margin-bottom: 8px; }
.workout-content {
    width: calc(100% - 32px); min-height: 150px; margin: 0 16px 16px; padding: 16px;
    border: 2px solid var(--border); border-radius: 12px; background: #fafbfc;
    font-family: 'Cascadia Code','Fira Code',monospace; font-size: 1rem;
    line-height: 1.8; overflow-y: auto; max-height: 400px;
}
.workout-content:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(67,97,238,0.15); }
.workout-content:empty::before { content: 'Show your working here...'; color: #b0b8c4; }
.workout-content img { max-width: 100%; border-radius: 8px; margin: 8px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

/* ---- Answer section ---- */
.answer-section {
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px;
    text-align: center;
}
.answer-section h3 {
    font-size: 0.9rem; font-weight: 600; color: var(--primary); margin-bottom: 16px;
}
.answer-row {
    display: flex; justify-content: center; align-items: center;
    gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.answer-label { font-size: 1.3rem; font-weight: 600; min-width: 30px; text-align: right; }
.btn-row { margin-top: 16px; }

/* ---- Rules reference (maths additions) ---- */
.ka-links { padding: 12px 0 0; }
.ka-links a {
    display: inline-block; margin: 4px 6px 4px 0; padding: 5px 14px;
    background: #e8f5e9; color: #2e7d32; border-radius: 20px;
    font-size: 0.82rem; font-weight: 600; text-decoration: none;
    transition: all 0.2s;
}
.ka-links a:hover { background: #c8e6c9; transform: translateY(-1px); }
.rule-name {
    font-weight: 600; color: var(--primary); display: block;
    margin-bottom: 2px; font-size: 0.82rem;
}

/* ---- Lesson view (maths additions) ---- */
.lesson-progress { width: 100%; height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 24px; overflow: hidden; }
.lesson-progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.4s ease; }
.lesson-box { background: var(--primary-light); border-left: 4px solid var(--primary); border-radius: 0 12px 12px 0; padding: 16px 20px; margin: 16px 0; font-size: 1.1rem; line-height: 2; }
.lesson-content { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px; margin-bottom: 20px; line-height: 1.8; }
.lesson-image { text-align: center; margin-bottom: 16px; }
.lesson-image img { max-width: 100%; height: auto; border-radius: 8px; }
.lesson-image svg { max-width: 320px; height: auto; }
.question-diagram { text-align: center; margin: 12px 0; }
.question-diagram svg { max-width: 100%; height: auto; }
.lesson-content h3 { color: var(--primary); margin-bottom: 12px; }
.lesson-content p { margin-bottom: 12px; }
.lesson-step { padding: 12px 16px; margin: 8px 0; border-radius: 12px; background: var(--bg-subtle); border: 1px solid var(--border); opacity: 0; max-height: 0; overflow: hidden; transition: opacity 0.4s ease, max-height 0.4s ease, padding 0.4s ease, margin 0.4s ease; padding: 0 16px; margin: 0; }
.lesson-step.revealed { opacity: 1; max-height: 200px; padding: 12px 16px; margin: 8px 0; }
.lesson-nav { margin: 24px 0; }
.lesson-nav .btn { margin: 0 4px; }
.lesson-btn-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.lesson-score { text-align: center; font-size: 1.1rem; margin: 16px 0; }
.lesson-score strong { color: var(--primary); }
.section-label { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-light); margin: 24px 0 12px; padding-left: 4px; grid-column: 1 / -1; }
.topic-card.lesson-card { border-left: 4px solid var(--primary); }
.topic-tag.lesson { background: var(--primary-light); color: var(--primary); }
.topic-tag.lesson-done { background: var(--success-light); color: var(--success); font-weight: 700; }

/* ---- TTS Reader Bar ---- */
.tts-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 16px; padding: 8px 12px; background: var(--bg-subtle, #f5f6fa); border-radius: 10px; border: 1px solid var(--border); }
.tts-btn { width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--primary); color: #fff; font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.15s, opacity 0.2s; flex-shrink: 0; }
.tts-btn:hover { transform: scale(1.1); }
.tts-btn:active { transform: scale(0.95); }
.tts-speed { background: var(--primary-light, #eef0ff); color: var(--primary); font-weight: 700; font-size: 0.7rem; width: auto; padding: 0 10px; border-radius: 8px; }
.tts-voice-select { border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; font-size: 0.75rem; background: var(--card); color: var(--text); max-width: 140px; cursor: pointer; }
.tts-label { font-size: 0.78rem; color: var(--text-light); margin-left: 4px; }
body.dark-mode .tts-bar { background: rgba(255,255,255,0.06); }
.tts-word { cursor: default; border-radius: 3px; transition: background 0.2s, color 0.2s; }
.tts-word-ready { background: var(--primary-light, #eef0ff); color: var(--primary); cursor: pointer; }
body.dark-mode .tts-word-ready { background: rgba(67,97,238,0.2); }

/* ---- Dashboard (maths grid layout) ---- */
.dash-overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.dash-stat { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 10px; text-align: center; }
.dash-stat-value { font-size: 1.4rem; font-weight: 700; }
.dash-stat-label { font-size: 0.75rem; color: var(--text-light); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.dash-topic { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.dash-topic-header { font-size: 1rem; font-weight: 700; margin-bottom: 12px; color: var(--primary); }
.dash-lesson-count { font-size: 0.78rem; font-weight: 400; color: var(--text-light); margin-left: 8px; }
.dash-row { display: grid; grid-template-columns: 120px 1fr 60px 40px; align-items: center; gap: 8px; padding: 6px 0; }
.dash-row-label { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-row-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.dash-row-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.dash-row-stat { font-size: 0.78rem; color: var(--text-light); text-align: right; }
.dash-row-pct { font-size: 0.78rem; font-weight: 600; text-align: right; }
@media (max-width: 480px) {
    .dash-overview { grid-template-columns: repeat(2, 1fr); }
    .dash-row { grid-template-columns: 90px 1fr 50px 36px; }
}

/* ---- Floating Feedback Widget (maths) ---- */
.fb-float-btn { position: fixed; bottom: 24px; right: 90px; z-index: 900; width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--primary); color: #fff; font-size: 1.2rem; cursor: pointer; box-shadow: 0 4px 16px rgba(67,97,238,0.35); transition: transform 0.2s, box-shadow 0.2s; display: flex; align-items: center; justify-content: center; }
.fb-float-btn:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(67,97,238,0.45); }
.fb-float-btn.hidden { display: none; }
.fb-float-panel { position: fixed; bottom: 80px; right: 90px; z-index: 901; width: 300px; background: var(--card); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.18); display: none; overflow: hidden; }
.fb-float-panel.show { display: block; }
.fb-float-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; background: var(--primary); color: #fff; font-weight: 700; font-size: 0.95rem; }
.fb-float-close { background: none; border: none; color: #fff; font-size: 1.3rem; cursor: pointer; padding: 0; line-height: 1; }
.fb-float-body { padding: 16px; }
.fb-float-body select, .fb-float-body textarea { width: 100%; border: 2px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 0.9rem; font-family: inherit; margin-bottom: 12px; transition: border-color 0.2s; }
.fb-float-body select:focus, .fb-float-body textarea:focus { border-color: var(--primary); outline: none; }
.fb-float-body textarea { min-height: 80px; resize: vertical; }
.fb-confirmation { background: var(--success-light); color: var(--success); border-radius: 10px; padding: 10px 16px; text-align: center; font-weight: 600; margin-top: 8px; display: none; font-size: 0.85rem; }
.fb-confirmation.show { display: block; }
.topic-tag.dash { background: #eef0ff; color: var(--primary); }

/* ---- Settings (maths) ---- */
.settings-dropdown { display: none; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 18px; margin-top: 10px; text-align: left; }
.settings-dropdown.show { display: block; }
.settings-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 0.85rem; flex-wrap: wrap; }
.settings-item span:first-child { font-weight: 600; min-width: 110px; }
#bg-opacity { accent-color: var(--primary); }
#font-selector { padding: 4px 8px; border-radius: 8px; border: 1px solid #ccc; font-size: 0.85rem; background: var(--card); color: var(--text); }
body.font-inter { font-family: 'Inter', sans-serif; }
body.font-poppins { font-family: 'Poppins', sans-serif; }
body.font-dyslexic { font-family: 'OpenDyslexic', sans-serif; }
body.font-mono { font-family: 'JetBrains Mono', monospace; }
.bg-overlay { position: fixed; inset: 0; z-index: -1; background-size: cover; background-position: center; background-attachment: fixed; pointer-events: none; }

/* When custom bg is active, make cards translucent — values driven by JS vars */
body.has-bg .topic-card,
body.has-bg .question-card,
body.has-bg .score-bar,
body.has-bg .feedback,
body.has-bg .hint-box,
body.has-bg .workout-section,
body.has-bg .rules-ref,
body.has-bg .lesson-content,
body.has-bg .dash-topic,
body.has-bg .dash-stat,
body.has-bg .fb-float-body,
body.has-bg .settings-dropdown,
body.has-bg .calc-modal,
body.has-bg .fb-float-panel,
body.has-bg .continue-card,
body.has-bg .search-input,
body.has-bg .search-results,
body.has-bg header { background: rgba(255,255,255,var(--bg-card-alpha,0.85)); backdrop-filter: blur(var(--bg-blur,16px)); -webkit-backdrop-filter: blur(var(--bg-blur,16px)); }
body.has-bg .hub-header { background: rgba(255,255,255,calc(var(--bg-card-alpha,0.85) - 0.05)); backdrop-filter: blur(var(--bg-blur,16px)); -webkit-backdrop-filter: blur(var(--bg-blur,16px)); border-radius: var(--radius); padding: 20px; margin-bottom: 24px; }
body.has-bg .topic-card h2,
body.has-bg .hub-header h1,
body.has-bg header h1 { color: var(--bg-text, var(--primary)); font-weight: var(--bg-text-weight, 700); }
body.has-bg .topic-card p,
body.has-bg .hub-header p { color: var(--bg-text, var(--text-light)); }
body.dark-mode.has-bg .topic-card,
body.dark-mode.has-bg .question-card,
body.dark-mode.has-bg .score-bar,
body.dark-mode.has-bg .feedback,
body.dark-mode.has-bg .hint-box,
body.dark-mode.has-bg .workout-section,
body.dark-mode.has-bg .rules-ref,
body.dark-mode.has-bg .lesson-content,
body.dark-mode.has-bg .dash-topic,
body.dark-mode.has-bg .dash-stat,
body.dark-mode.has-bg .fb-float-body,
body.dark-mode.has-bg .settings-dropdown,
body.dark-mode.has-bg .calc-modal,
body.dark-mode.has-bg .fb-float-panel,
body.dark-mode.has-bg .continue-card,
body.dark-mode.has-bg .search-input,
body.dark-mode.has-bg .search-results,
body.dark-mode.has-bg header { background: rgba(22,33,62,var(--bg-card-alpha,0.85)); }
body.dark-mode.has-bg .hub-header { background: rgba(22,33,62,calc(var(--bg-card-alpha,0.85) - 0.05)); }

/* ---- Continue Prompt (maths) ---- */
.continue-card {
    display: flex; align-items: center; gap: 14px;
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px 20px;
    margin-bottom: 16px; border-left: 4px solid var(--primary);
    animation: slideIn 0.3s ease; position: relative;
}
.continue-left { flex: 1; min-width: 0; }
.continue-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-light); font-weight: 600; margin-bottom: 2px; }
.continue-name { font-size: 1.1rem; font-weight: 700; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-meta { font-size: 0.8rem; color: var(--text-light); margin-top: 2px; }
.continue-go { white-space: nowrap; padding: 10px 24px; font-size: 0.9rem; }
.continue-dismiss { position: absolute; top: 8px; right: 10px; background: none; border: none; font-size: 1.1rem; color: var(--text-light); cursor: pointer; padding: 0; line-height: 1; }
.continue-dismiss:hover { color: var(--error); }
@media (max-width: 480px) {
    .continue-card { flex-direction: column; align-items: stretch; text-align: center; }
    .continue-go { width: 100%; }
}

/* ---- Achievement Toast ---- */
.ach-toast {
    position: fixed; top: -80px; left: 50%; transform: translateX(-50%);
    z-index: 2000; background: var(--card); border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2); padding: 14px 24px;
    display: flex; align-items: center; gap: 14px;
    transition: top 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 2px solid #ffc107; min-width: 260px;
}
.ach-toast.show { top: 24px; }
.ach-toast-icon { font-size: 2rem; }
.ach-toast-text { font-size: 0.9rem; line-height: 1.4; }
.ach-toast-text strong { color: #ffc107; display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- Achievement Grid (Dashboard) ---- */
.ach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ach-card { text-align: center; padding: 14px 8px; border-radius: 12px; background: var(--bg-subtle); border: 1px solid var(--border); transition: transform 0.2s; }
.ach-card:not(.locked):hover { transform: translateY(-2px); }
.ach-card.locked { opacity: 0.45; }
.ach-icon { font-size: 1.8rem; margin-bottom: 4px; }
.ach-name { font-size: 0.82rem; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.ach-desc { font-size: 0.72rem; color: var(--text-light); }
@media (max-width: 480px) { .ach-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---- Timed Challenge (maths) ---- */
.timed-btn { background: linear-gradient(135deg, #ff6b6b, #ee5a24); color: #fff; border: none; border-radius: 20px; padding: 8px 20px; font-size: 0.85rem; font-weight: 700; cursor: pointer; transition: all 0.2s; font-family: inherit; }
.timed-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(238,90,36,0.35); }
.timed-timer { position: fixed; top: 0; left: 0; right: 0; height: 36px; background: var(--border); z-index: 1500; display: flex; align-items: center; }
.timed-timer-fill { height: 100%; background: var(--primary); transition: width 1s linear; border-radius: 0 4px 4px 0; }
.timed-timer-text { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 0.85rem; font-weight: 700; color: var(--text); }
.timed-overlay { display: none; position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,0.6); justify-content: center; align-items: center; }
.timed-results { background: var(--card); border-radius: var(--radius); box-shadow: 0 8px 40px rgba(0,0,0,0.3); padding: 36px 32px; text-align: center; max-width: 400px; width: 90%; animation: slideIn 0.3s ease; }
.timed-results h2 { color: var(--primary); margin-bottom: 20px; font-size: 1.5rem; }
.timed-stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.timed-stat-val { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.timed-stat-lbl { font-size: 0.75rem; color: var(--text-light); margin-top: 2px; text-transform: uppercase; }
.timed-btn-row { display: flex; justify-content: center; gap: 12px; }

/* ---- Mastery Engine ---- */
.mastery-overall { margin-bottom: 24px; text-align: center; }
.mastery-overall-label { font-size: 0.95rem; margin-bottom: 8px; color: var(--text); }
.mastery-overall-bar {
    width: 100%; height: 12px; background: var(--border); border-radius: 6px;
    overflow: hidden;
}
.mastery-overall-fill {
    height: 100%; border-radius: 6px; transition: width 0.5s ease, background 0.5s ease;
}
.mastery-skills-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }
.mastery-skill-tile {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px 20px; cursor: pointer; transition: all 0.2s ease;
    border: 2px solid transparent;
}
.mastery-skill-tile:hover:not(.locked) { border-color: var(--primary); transform: translateY(-2px); }
.mastery-skill-tile.locked { opacity: 0.5; cursor: default; }
.mastery-skill-tile .mastery-skill-name {
    font-weight: 600; font-size: 0.95rem; margin-bottom: 6px;
    display: flex; align-items: center; gap: 8px;
}
.mastery-skill-tile .mastery-skill-bar {
    width: 100%; height: 8px; background: var(--border); border-radius: 4px;
    overflow: hidden; margin-bottom: 4px;
}
.mastery-skill-tile .mastery-skill-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.mastery-skill-tile .mastery-skill-stats {
    font-size: 0.78rem; color: var(--text-light);
    display: flex; justify-content: space-between;
}
.mastery-skill-fill.weak { background: var(--error); }
.mastery-skill-fill.developing { background: #ffc107; }
.mastery-skill-fill.proficient { background: var(--primary); }
.mastery-skill-fill.mastered { background: var(--success); }
.mastery-overall-fill.weak { background: var(--error); }
.mastery-overall-fill.developing { background: #ffc107; }
.mastery-overall-fill.proficient { background: var(--primary); }
.mastery-overall-fill.mastered { background: var(--success); }
.mastery-tier-header {
    font-size: 0.82rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--text-light); margin: 16px 0 8px;
    padding-left: 4px;
}

/* ---- Dark Mode (maths) ---- */
body.dark-mode {
    --bg: #1a1a2e; --card: #16213e; --text: #e0e0e0;
    --text-light: #a0a0b8; --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --primary-light: rgba(67,97,238,0.15);
    --success-light: rgba(6,214,160,0.15); --error-light: rgba(239,71,111,0.15);
}
body.dark-mode .option-btn { background: var(--card); border-color: #2a2a4a; color: var(--text); }
body.dark-mode .option-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); }
body.dark-mode .option-btn.correct { border-color: var(--success); background: var(--success-light); }
body.dark-mode .option-btn.incorrect { border-color: var(--error); background: var(--error-light); }
body.dark-mode .mc-option { background: var(--card); border-color: #2a2a4a; color: var(--text); }
body.dark-mode .mc-option:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); }
body.dark-mode .mc-option.correct { border-color: var(--success); background: var(--success-light); }
body.dark-mode .mc-option.incorrect { border-color: var(--error); background: var(--error-light); }
body.dark-mode .level-btn { background: var(--card); border-color: #2a2a4a; color: var(--text); }
body.dark-mode .level-btn:hover { border-color: var(--primary); background: var(--primary-light); }
body.dark-mode .level-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
body.dark-mode math-field { border-color: #2a2a4a; background: #0f1a30; color: var(--text); }
body.dark-mode math-field:focus-within { border-color: var(--primary); }
body.dark-mode .back-to-hub { background: rgba(22,33,62,0.85); color: var(--primary); }
body.dark-mode .back-to-hub:hover { background: var(--card); }
body.dark-mode .back-btn { background: rgba(22,33,62,0.85); color: var(--primary); }
body.dark-mode .back-btn:hover { background: var(--card); }
body.dark-mode .hint-box { background: rgba(255,193,7,0.1); border-color: #b8860b; }
body.dark-mode .lesson-step { background: #0f1a30; border-color: #2a2a4a; }
body.dark-mode .lesson-box { background: var(--primary-light); }
body.dark-mode .ach-card { background: #0f1a30; border-color: #2a2a4a; }
body.dark-mode .fb-float-body select,
body.dark-mode .fb-float-body textarea { background: #0f1a30; border-color: #2a2a4a; color: var(--text); }
body.dark-mode .fb-float-panel { background: var(--card); }
body.dark-mode .workout-content { background: #0f1a30; border-color: #2a2a4a; color: var(--text); }
body.dark-mode .workout-content:empty::before { color: #555; }
body.dark-mode .btn-hint { border-color: #2a2a4a; color: var(--text-light); }
body.dark-mode .btn-hint:hover { border-color: #ffc107; color: #ffc107; background: rgba(255,193,7,0.1); }
body.dark-mode .settings-dropdown { background: var(--card); }
body.dark-mode .search-input { background: #0f1a30; border-color: #2a2a4a; color: var(--text); }
body.dark-mode .search-input:focus { border-color: var(--primary); }
body.dark-mode .search-results { background: var(--card); box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
body.dark-mode .search-result:hover, body.dark-mode .search-result.active { background: var(--primary-light); }
body.dark-mode .search-result-title { color: var(--text); }
body.dark-mode .rule-item { border-bottom-color: #2a2a4a; }
body.dark-mode .rules-ref { background: var(--card); }
body.dark-mode .timed-results { background: var(--card); }
body.dark-mode .option-btn::before { background: #2a2a4a; color: #888; }
body.dark-mode .difficulty-tag.easy { background: rgba(6,214,160,0.15); }
body.dark-mode .difficulty-tag.medium { background: rgba(255,193,7,0.15); }
body.dark-mode .difficulty-tag.hard { background: rgba(239,71,111,0.15); }

/* ---- Leaderboard (maths) ---- */
.lb-table { width: 100%; border-collapse: collapse; margin-top: 12px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.lb-table th { background: var(--primary); color: #fff; padding: 10px 12px; text-align: left; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.lb-table th:first-child { border-radius: 10px 0 0 0; }
.lb-table th:last-child { border-radius: 0 10px 0 0; }
.lb-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
body.dark-mode .lb-table td { border-bottom-color: #2a2a4a; }
body.has-bg .lb-table { background: rgba(255,255,255,0.92); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
body.dark-mode.has-bg .lb-table { background: rgba(22,33,62,0.92); }
.lb-table tr:last-child td { border-bottom: none; }
.lb-me { background: var(--primary-light); font-weight: 700; }
.lb-avatar { width: 28px; height: 28px; border-radius: 50%; vertical-align: middle; margin-right: 8px; }
.lb-table td:first-child { font-weight: 700; color: var(--text-light); width: 40px; text-align: center; }
.lb-school { font-size: 0.8rem; color: var(--text-light); max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Settings text input ---- */
.settings-text-input { flex:1; padding:8px 14px; border:2px solid transparent; border-radius:var(--radius); font-family:inherit; font-size:0.85rem; background:var(--card); color:var(--text); box-shadow:var(--shadow); outline:none; transition:border-color 0.2s; }
.settings-text-input:focus { border-color:var(--primary); }
body.dark-mode .settings-text-input { background:#0f1a30; border-color:#2a2a4a; }
body.dark-mode .settings-text-input:focus { border-color:var(--primary); }

/* ---- Onboarding Modal ---- */
.onboard-overlay { display:none; position:fixed; inset:0; z-index:9999; background:rgba(0,0,0,0.5); backdrop-filter:blur(6px); -webkit-backdrop-filter:blur(6px); align-items:center; justify-content:center; }
.onboard-overlay.show { display:flex; }
.onboard-modal { background:var(--card); border-radius:20px; box-shadow:0 16px 48px rgba(0,0,0,0.25); padding:32px; max-width:400px; width:90%; text-align:center; }
.onboard-modal h2 { font-size:1.3rem; font-weight:700; margin-bottom:6px; }
.onboard-field { display:flex; flex-direction:column; text-align:left; gap:4px; margin-bottom:14px; }
.onboard-field span { font-size:0.82rem; font-weight:600; color:var(--text-light); }
.onboard-field select, .onboard-field input { padding:12px 16px; border:2px solid transparent; border-radius:var(--radius); font-size:0.95rem; font-family:inherit; background:var(--card); color:var(--text); box-shadow:var(--shadow); outline:none; transition:border-color 0.2s; }
.onboard-field select:focus, .onboard-field input:focus { border-color:var(--primary); }
body.dark-mode .onboard-field select, body.dark-mode .onboard-field input { background:#0f1a30; border-color:#2a2a4a; }
body.dark-mode .onboard-field select:focus, body.dark-mode .onboard-field input:focus { border-color:var(--primary); }
.onboard-skip { display:block; margin:10px auto 0; background:none; border:none; color:var(--text-light); font-size:0.82rem; cursor:pointer; text-decoration:underline; }

/* ---- Practice History (maths grid layout) ---- */
.hist-row { display: grid; grid-template-columns: 1fr 100px 70px 60px; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
body.dark-mode .hist-row { border-bottom-color: #2a2a4a; }
.hist-row:last-child { border-bottom: none; }
.hist-name { font-weight: 600; }
.hist-date { color: var(--text-light); font-size: 0.78rem; }
.hist-score { text-align: center; }
.hist-pct { text-align: right; font-weight: 600; }

/* ---- Loading Screen (maths gradient) ---- */
.loading-screen {
    position: fixed; inset: 0; z-index: 10000;
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a2e 40%, #16213e 70%, #0f3460 100%);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.8s cubic-bezier(.4,0,.2,1), visibility 0.8s;
    overflow: hidden;
}
.loading-pi { animation: pulse-pi 2s ease-in-out infinite; }
@keyframes pulse-pi {
    0%,100% { opacity: 0.7; }
    50% { opacity: 1; }
}
.loading-bar {
    height: 100%; width: 0%; border-radius: 4px;
    background: linear-gradient(90deg, #4361ee, #06d6a0, #f72585);
    background-size: 200% 100%;
    animation: bar-shimmer 1.5s ease-in-out infinite;
    transition: width 0.3s ease;
}

/* ---- Music Button (maths) ---- */
.music-btn {
    position: fixed; bottom: 146px; right: 28px; z-index: 900;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none;
    font-size: 1.3rem; cursor: pointer;
    box-shadow: 0 2px 12px rgba(67,97,238,0.4);
    transition: background 0.2s, transform 0.15s;
    display: flex; align-items: center; justify-content: center;
    opacity: 0.85;
}
.music-btn:hover { transform: scale(1.1); opacity: 1; }
.music-btn.playing { background: #06d6a0; box-shadow: 0 2px 12px rgba(6,214,160,0.4); }
.changelog-btn {
    position: fixed; bottom: 20px; left: 20px; z-index: 900;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--card-bg); color: var(--text); border: 1px solid var(--border);
    font-size: 1.2rem; cursor: pointer; text-decoration: none;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    transition: background 0.2s, transform 0.15s;
    display: flex; align-items: center; justify-content: center;
    opacity: 0.7;
}
.changelog-btn:hover { transform: scale(1.1); opacity: 1; }

/* ---- Streak Toast ---- */
.streak-toast {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-80px);
    z-index: 9998; background: linear-gradient(135deg, #ffc107, #ff6b35);
    color: #fff; padding: 10px 24px; border-radius: 30px;
    font-weight: 700; font-size: 0.95rem; white-space: nowrap;
    box-shadow: 0 4px 20px rgba(255,193,7,0.4);
    animation: toast-in 0.5s cubic-bezier(.34,1.56,.64,1) forwards;
}
.streak-toast.out { animation: toast-out 0.4s ease-in forwards; }
@keyframes toast-in { to { transform: translateX(-50%) translateY(0); } }
@keyframes toast-out { to { transform: translateX(-50%) translateY(-80px); opacity: 0; } }

/* ---- Gem Counter ---- */
.gem-val { color: #a855f7 !important; }

/* ---- Freeze Dots ---- */
.freeze-dots { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: center; }
.freeze-dot {
    width: 14px; height: 14px; border-radius: 50%; border: 2px solid #60a5fa;
    background: transparent; display: inline-block; transition: background 0.3s;
}
.freeze-dot.filled { background: #60a5fa; box-shadow: 0 0 6px rgba(96,165,250,0.5); }

/* ---- Gem Toast ---- */
.gem-toast {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-80px);
    z-index: 9999; background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: #fff; padding: 10px 24px; border-radius: 30px;
    font-weight: 700; font-size: 0.95rem; white-space: nowrap;
    box-shadow: 0 4px 20px rgba(168,85,247,0.4);
    transition: transform 0.5s cubic-bezier(.34,1.56,.64,1), opacity 0.4s;
}
.gem-toast.show { transform: translateX(-50%) translateY(0); }
.gem-toast.out { transform: translateX(-50%) translateY(-80px); opacity: 0; }

/* ---- Streak Reminder Banner ---- */
.streak-reminder {
    position: fixed; top: 0; left: 0; right: 0; z-index: 9990;
    background: linear-gradient(135deg, #f59e0b, #ea580c);
    color: #fff; padding: 12px 48px 12px 20px; text-align: center;
    font-weight: 600; font-size: 0.9rem;
    transform: translateY(-100%); transition: transform 0.4s ease;
}
.streak-reminder.show { transform: translateY(0); }
.streak-reminder-close {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer;
    padding: 4px 8px; opacity: 0.8;
}
.streak-reminder-close:hover { opacity: 1; }

/* ---- Weekly Reward Banner ---- */
.lb-reward-banner {
    position: fixed; top: 0; left: 0; right: 0; z-index: 9991;
    background: linear-gradient(135deg, #f59e0b, #d97706, #b45309);
    color: #fff; padding: 12px 48px 12px 20px; text-align: center;
    font-weight: 600; font-size: 0.9rem;
    transform: translateY(-100%); transition: transform 0.4s ease;
}
.lb-reward-banner.show { transform: translateY(0); }
.lb-reward-close {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer;
    padding: 4px 8px; opacity: 0.8;
}
.lb-reward-close:hover { opacity: 1; }

/* ---- Freeze Dialog ---- */
.freeze-dialog-overlay {
    display: none; position: fixed; inset: 0; z-index: 9000;
    background: rgba(0,0,0,0.5); justify-content: center; align-items: center;
}
.freeze-dialog-overlay.show { display: flex; }
.freeze-dialog {
    background: var(--card); border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0,0,0,0.3); padding: 32px 28px;
    text-align: center; max-width: 360px; width: 90%;
    animation: slideIn 0.3s ease; position: relative;
}
.freeze-dialog h2 { color: #60a5fa; margin-bottom: 8px; font-size: 1.4rem; }
.freeze-dialog-desc { color: var(--text-light); font-size: 0.88rem; margin-bottom: 20px; line-height: 1.5; }
.freeze-dialog-close {
    position: absolute; top: 10px; right: 14px; background: none;
    border: none; font-size: 1.6rem; color: var(--text-light); cursor: pointer; padding: 4px;
}
.freeze-dialog-close:hover { color: var(--error); }
.freeze-dialog-dots { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.freeze-dialog-dots .freeze-dot { width: 28px; height: 28px; border-width: 3px; }
.freeze-dialog-count { font-size: 0.85rem; color: var(--text-light); margin-bottom: 16px; }
.freeze-dialog-balance {
    font-size: 1.1rem; font-weight: 700; margin-bottom: 20px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.freeze-dialog-gem-icon { color: #a855f7; font-size: 1.2rem; }
.freeze-dialog-buy { width: 100%; padding: 14px; font-size: 0.95rem; }
.freeze-dialog-buy:disabled { background: #666; cursor: default; transform: none; }
.freeze-dialog-msg {
    margin-top: 12px; font-size: 0.85rem; font-weight: 600; min-height: 20px;
    transition: opacity 0.3s;
}
.freeze-dialog-msg.error { color: var(--error); }
.freeze-dialog-msg.success { color: var(--success); }
.freeze-dialog-info {
    margin-top: 16px; font-size: 0.78rem; color: var(--text-light);
    line-height: 1.4; border-top: 1px solid rgba(128,128,128,0.2); padding-top: 12px;
}

/* ---- Gem Shop ---- */
.gem-shop-overlay {
    display: none; position: fixed; inset: 0; z-index: 9000;
    background: rgba(0,0,0,0.5); justify-content: center; align-items: center;
}
.gem-shop-overlay.show { display: flex; }
.gem-shop {
    background: var(--card); border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0,0,0,0.3); padding: 28px 24px;
    text-align: center; max-width: 420px; width: 92%;
    max-height: 85vh; overflow-y: auto;
    animation: slideIn 0.3s ease; position: relative;
}
.gem-shop h2 { color: #a855f7; margin-bottom: 4px; font-size: 1.4rem; }
.gem-shop-close {
    position: absolute; top: 10px; right: 14px; background: none;
    border: none; font-size: 1.6rem; color: var(--text-light); cursor: pointer; padding: 4px;
}
.gem-shop-close:hover { color: var(--error); }
.gem-shop-balance {
    font-size: 1.2rem; font-weight: 700; margin-bottom: 16px;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.gem-shop-gem-icon { color: #a855f7; font-size: 1.3rem; }
.gem-shop-section { text-align: left; margin-bottom: 16px; }
.gem-shop-section h3 {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--text-light); margin-bottom: 8px; padding-bottom: 4px;
    border-bottom: 1px solid rgba(128,128,128,0.2);
}
.gem-mission {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 10px; margin-bottom: 6px;
    background: rgba(128,128,128,0.06); transition: background 0.2s;
}
.gem-mission.ready { background: rgba(168,85,247,0.08); }
.gem-mission.claimed { opacity: 0.5; }
.gem-mission-info { flex: 1; min-width: 0; }
.gem-mission-title { font-weight: 600; font-size: 0.9rem; }
.gem-mission-desc { font-size: 0.78rem; color: var(--text-light); }
.gem-mission-reward {
    font-weight: 700; font-size: 0.95rem; color: #a855f7;
    white-space: nowrap; min-width: 32px; text-align: right;
}
.gem-mission-reward::after { content: 'g'; font-size: 0.7rem; margin-left: 1px; }
.gem-mission-claim { white-space: nowrap; padding: 6px 14px !important; font-size: 0.78rem !important; }
.gem-mission-badge {
    font-size: 0.72rem; font-weight: 600; padding: 4px 10px; border-radius: 10px;
    background: var(--success-light); color: var(--success); white-space: nowrap;
}
.gem-mission-badge.pending { background: rgba(128,128,128,0.1); color: var(--text-light); }
.gem-shop-info {
    font-size: 0.78rem; color: var(--text-light); margin-top: 8px;
    border-top: 1px solid rgba(128,128,128,0.2); padding-top: 12px;
}

/* ---- Test Generator ---- */
.topic-tag.tgen { background: linear-gradient(135deg, #7c3aed, #4361ee); color: #fff; }

/* Mode selection */
.tg-mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; }
.tg-mode-card {
    background: var(--card); border: 2px solid var(--border); border-radius: var(--radius);
    padding: 20px; cursor: pointer; transition: all 0.2s; text-align: center;
}
.tg-mode-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.tg-mode-card.selected { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 0 0 3px rgba(67,97,238,0.2); }
.tg-mode-card h3 { font-size: 1.1rem; color: var(--primary); margin-bottom: 4px; }
.tg-mode-card p { font-size: 0.82rem; color: var(--text-light); }

/* Topic checkbox grid */
.tg-topic-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    margin-bottom: 20px; max-height: 340px; overflow-y: auto; padding: 4px;
}
.tg-topic-item {
    display: flex; align-items: center; gap: 8px;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 12px; cursor: pointer; transition: all 0.15s; font-size: 0.88rem;
}
.tg-topic-item:hover { border-color: var(--primary); }
.tg-topic-item input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; flex-shrink: 0; }
.tg-topic-name { flex: 1; font-weight: 500; }
.tg-topic-acc {
    font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 10px;
}
.tg-topic-acc.weak { background: var(--error-light); color: var(--error); }
.tg-topic-acc.ok { background: #fff3cd; color: #856404; }
.tg-topic-acc.strong { background: var(--success-light); color: var(--success); }
.tg-topic-acc.new { background: #e8e8e8; color: #888; }

/* Setup controls */
.tg-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tg-controls .btn { font-size: 0.82rem; padding: 6px 14px; }

/* Length / Difficulty selector */
.tg-length-grid { display: flex; gap: 10px; margin-bottom: 16px; }
.tg-length-btn, .tg-diff-btn {
    flex: 1; padding: 12px; border: 2px solid var(--border); border-radius: 10px;
    background: var(--card); cursor: pointer; text-align: center; transition: all 0.15s;
    font-family: inherit; font-size: 1rem; font-weight: 600; color: var(--text);
}
.tg-length-btn:hover, .tg-diff-btn:hover { border-color: var(--primary); }
.tg-length-btn.selected, .tg-diff-btn.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

/* Timer toggle */
.tg-timer-toggle {
    display: flex; align-items: center; gap: 10px; margin-bottom: 20px;
    font-size: 0.9rem; color: var(--text);
}
.tg-timer-toggle input[type="checkbox"] { accent-color: var(--primary); width: 18px; height: 18px; }

/* Active test: timer bar */
.tg-timer {
    width: 100%; height: 8px; background: var(--border); border-radius: 4px;
    margin-bottom: 12px; position: relative; overflow: hidden;
}
.tg-timer-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 1s linear; }
.tg-timer-text {
    position: absolute; right: 0; top: -22px; font-size: 0.78rem; font-weight: 700; color: var(--text-light);
}

/* Progress bar */
.tg-overall-progress { width: 100%; height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 8px; }
.tg-progress-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s; }
.tg-progress-label { font-size: 0.82rem; color: var(--text-light); margin-bottom: 16px; text-align: center; }

/* Score bar (practice) */
.tg-score-bar {
    display: flex; justify-content: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap;
}

/* Question header inside card */
.tg-q-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tg-q-topic { font-size: 0.78rem; font-weight: 600; color: var(--primary); background: var(--primary-light); padding: 3px 10px; border-radius: 10px; }

/* Active test buttons row */
.tg-btn-row { display: flex; justify-content: center; gap: 12px; margin-top: 16px; }

/* Results */
.tg-results-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
.tg-results-stat {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 18px 12px; text-align: center;
}
.tg-stat-value { font-size: 1.5rem; font-weight: 800; }
.tg-stat-label { font-size: 0.72rem; text-transform: uppercase; color: var(--text-light); margin-top: 4px; letter-spacing: 0.04em; }

.tg-section-title { font-size: 1rem; font-weight: 700; color: var(--primary); margin: 20px 0 12px; }

/* Breakdown bars */
.tg-breakdown-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.tg-breakdown-item { background: var(--card); border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); }
.tg-breakdown-header { display: flex; justify-content: space-between; margin-bottom: 6px; }
.tg-breakdown-name { font-weight: 600; font-size: 0.9rem; }
.tg-breakdown-score { font-size: 0.82rem; color: var(--text-light); font-weight: 600; }
.tg-breakdown-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.tg-breakdown-fill { height: 100%; border-radius: 4px; transition: width 0.5s; }

/* Review items */
.tg-review-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.tg-review-item {
    background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
    border-left: 4px solid #e0e0e0; overflow: hidden;
}
.tg-review-summary {
    padding: 12px 16px; cursor: pointer; display: flex; align-items: center; gap: 8px;
    font-size: 0.88rem; list-style: none;
}
.tg-review-summary::-webkit-details-marker { display: none; }
.tg-review-summary::before { content: '\25B6'; font-size: 0.7rem; color: var(--text-light); transition: transform 0.2s; }
details.tg-review-item[open] > .tg-review-summary::before { transform: rotate(90deg); }
.tg-review-num { font-weight: 700; color: var(--primary); min-width: 30px; }
.tg-review-topic { font-weight: 500; flex: 1; }
.tg-review-time { font-size: 0.75rem; color: var(--text-light); }
.tg-badge { font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.tg-badge.correct { background: var(--success-light); color: var(--success); }
.tg-badge.incorrect { background: var(--error-light); color: var(--error); }
.tg-review-body { padding: 0 16px 16px; }
.tg-review-q { font-size: 0.9rem; margin-bottom: 8px; }
.tg-review-latex { font-size: 1.1rem; margin-bottom: 8px; }
.tg-review-explain { font-size: 0.85rem; color: var(--text-light); padding: 10px; background: var(--primary-light); border-radius: 8px; }

/* History list on setup */
.tg-history-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.tg-history-item:last-child { border-bottom: none; }
.tg-history-left { display: flex; flex-direction: column; gap: 2px; }
.tg-history-mode { font-weight: 600; }
.tg-history-date { font-size: 0.75rem; color: var(--text-light); }
.tg-history-right { display: flex; gap: 12px; align-items: center; }
.tg-history-score { font-weight: 600; }
.tg-history-acc { font-weight: 700; color: var(--primary); }

/* Section label in setup */
.tg-setup-section { font-size: 0.88rem; font-weight: 700; color: var(--text); margin: 16px 0 8px; }

/* Dark mode overrides */
body.dark-mode .tg-mode-card { background: var(--card); border-color: #2a2a4a; }
body.dark-mode .tg-mode-card.selected { border-color: var(--primary); background: var(--primary-light); }
body.dark-mode .tg-topic-item { background: var(--card); border-color: #2a2a4a; }
body.dark-mode .tg-topic-acc.new { background: #2a2a4a; color: #888; }
body.dark-mode .tg-length-btn, body.dark-mode .tg-diff-btn { background: var(--card); border-color: #2a2a4a; color: var(--text); }
body.dark-mode .tg-length-btn.selected, body.dark-mode .tg-diff-btn.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
/* Stopwatch (untimed tests) */
.tg-stopwatch {
    position: fixed; bottom: 200px; right: 24px; background: var(--card);
    border: 2px solid var(--primary); border-radius: 12px; padding: 8px 16px;
    font-size: 1.1rem; font-weight: 700; color: var(--primary);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15); z-index: 90;
    font-variant-numeric: tabular-nums; user-select: none;
}
body.dark-mode .tg-stopwatch { background: var(--card); border-color: var(--primary); }
body.dark-mode .tg-timer { background: #2a2a4a; }
body.dark-mode .tg-overall-progress { background: #2a2a4a; }
body.dark-mode .tg-breakdown-bar { background: #2a2a4a; }
body.dark-mode .tg-history-item { border-bottom-color: #2a2a4a; }
body.dark-mode .tg-review-explain { background: var(--primary-light); }

/* ---- Paper Generator (maths-specific additions) ---- */
.topic-tag.paper { background: linear-gradient(135deg, #6c5ce7, #a29bfe); color: #fff; }

.pg-context-box {
    background: #f0f4ff; border-left: 4px solid #6c5ce7;
    padding: 18px 20px; border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 16px; font-size: 0.92rem; line-height: 1.6;
}
.pg-context-title { font-weight: 700; font-size: 1rem; margin-bottom: 8px; color: #6c5ce7; }
.pg-topic-label {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    background: #6c5ce7; color: #fff; font-size: 0.7rem; font-weight: 700;
    margin-right: 8px; vertical-align: middle;
}

.pg-nav-btn.answered { background: #e8eaf6; border-color: #7986cb; }

.pg-extended-textarea {
    width: 100%; min-height: 100px; padding: 12px; border: 1px solid #ddd;
    border-radius: 8px; font-size: 0.9rem; font-family: inherit; resize: vertical;
}

/* Results card (maths) */
.pg-results-card {
    background: var(--card); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 32px 28px;
}
body.has-bg .pg-results-card { background: rgba(255,255,255,0.85); backdrop-filter: blur(8px); }
body.has-bg.dark-mode .pg-results-card { background: rgba(22,33,62,0.85); }

.pg-grade-circle {
    width: 100px; height: 100px; border-radius: 50%;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    display: inline-flex; flex-direction: column; align-items: center;
    justify-content: center; margin-bottom: 16px;
}

.pg-q-topic {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    background: #6c5ce7; color: #fff; font-size: 0.68rem; font-weight: 700;
}

.pg-mark-icon.partial { color: #ffc107; }
.pg-crit-c-tag { display: inline-block; background: #ff9800; color: #fff; font-size: 0.68rem; font-weight: 700; padding: 1px 5px; border-radius: 4px; vertical-align: middle; margin-right: 2px; }
.pg-model-answer { margin-top: 10px; font-size: 0.85rem; color: var(--text-light); line-height: 1.5; padding: 10px; background: var(--primary-light); border-radius: 8px; }
.tw-crit-c-fb { margin-top: 12px; padding: 10px; background: rgba(255,152,0,0.08); border: 1px solid rgba(255,152,0,0.2); border-radius: 8px; }
.tw-crit-c-title { font-size: 0.82rem; font-weight: 700; margin-bottom: 6px; }

/* Dark mode paper gen (maths extras) */
body.dark-mode .pg-context-box { background: rgba(108,92,231,0.1); border-left-color: #a29bfe; }
body.dark-mode .pg-context-title { color: #a29bfe; }
body.dark-mode .pg-nav-btn.active { background: rgba(67,97,238,0.15); }
body.dark-mode .pg-nav-btn.answered { background: rgba(121,134,203,0.15); border-color: #7986cb; }
body.dark-mode .pg-extended-textarea { background: #1a1a2e; border-color: #444; color: var(--text); }

/* Data tables (statistics contexts) */
.pg-data-table { border-collapse: collapse; margin: 12px 0; font-size: 0.88rem; width: auto; }
.pg-data-table th, .pg-data-table td { border: 1px solid var(--border, #dee2e6); padding: 8px 14px; text-align: center; min-width: 50px; }
.pg-data-table th { background: var(--primary-light); font-weight: 700; color: var(--primary); white-space: nowrap; }
.pg-data-table td { background: var(--card, #fff); }
.pg-data-table tr:nth-child(even) td { background: rgba(99,102,241,0.03); }
body.dark-mode .pg-data-table td { background: var(--card); }
body.dark-mode .pg-data-table tr:nth-child(even) td { background: rgba(99,102,241,0.06); }
body.dark-mode .pg-data-table th { background: rgba(99,102,241,0.15); }

/* Criterion B pattern tables */
.pg-pattern-table { border-collapse: collapse; margin: 12px 0; font-size: 0.9rem; }
.pg-pattern-table th, .pg-pattern-table td { border: 1px solid var(--border, #dee2e6); padding: 6px 14px; text-align: center; }
.pg-pattern-table th { background: var(--primary-light); font-weight: 700; color: var(--primary); }
.pg-pattern-table td { background: var(--card, #fff); }
body.dark-mode .pg-pattern-table td { background: var(--card); }
body.dark-mode .pg-pattern-table th { background: rgba(99,102,241,0.15); }

/* Editable table inputs */
.pg-table-input { width: 60px; padding: 4px 6px; text-align: center; border: 1.5px solid var(--primary); border-radius: 4px; font-size: 0.88rem; font-family: inherit; background: rgba(99,102,241,0.05); color: var(--text); }
.pg-table-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(67,97,238,0.2); }
body.dark-mode .pg-table-input { background: rgba(99,102,241,0.1); border-color: rgba(99,102,241,0.5); color: var(--text); }

/* ---- Working out area (maths overrides for marked working) ---- */
.pg-working-marked { border: 2px solid rgba(99,102,241,0.25); border-radius: 10px; padding: 12px; background: rgba(99,102,241,0.03); }
.pg-working-marked .pg-working-textarea { border-style: solid; min-height: 80px; }
body.dark-mode .pg-working-marked { border-color: rgba(99,102,241,0.3); background: rgba(99,102,241,0.05); }

/* Calculator titlebar actions */
.calc-titlebar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 10px; background: var(--primary); color: #fff;
    cursor: grab; user-select: none; -webkit-user-select: none; flex-shrink: 0;
    font-size: 0.8rem; font-weight: 600;
}
.calc-titlebar:active { cursor: grabbing; }
.calc-close-btn {
    background: none; border: none; color: #fff; font-size: 1.1rem;
    cursor: pointer; padding: 0 4px; line-height: 1; opacity: 0.8;
}
.calc-close-btn:hover { opacity: 1; }
.calc-resize-handle {
    position: absolute; bottom: 0; right: 0; width: 18px; height: 18px;
    cursor: nwse-resize; z-index: 2;
    background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.15) 50%);
    border-radius: 0 0 var(--radius) 0;
}
body.dark-mode .calc-resize-handle { background: linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.15) 50%); }
.calc-modal {
    display: none; position: fixed; bottom: 90px; right: 24px; z-index: 999;
    width: 380px; height: 500px; min-width: 280px; min-height: 300px;
    background: var(--card);
    border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    overflow: hidden; animation: slideUp 0.2s ease;
    flex-direction: column;
}
.calc-modal.show { display: flex; }
.calc-modal .calc-container { width: 100%; flex: 1; touch-action: none; min-height: 0; }
.calc-titlebar-actions { display: flex; align-items: center; gap: 6px; }
.calc-deg-btn { padding: 2px 8px; font-size: 0.72rem; font-weight: 700; border-radius: 4px; border: 1.5px solid rgba(255,255,255,0.5); background: transparent; color: #fff; cursor: pointer; letter-spacing: 0.03em; transition: all 0.2s; }
.calc-deg-btn:hover { background: rgba(255,255,255,0.15); }
.calc-deg-btn.rad-mode { background: rgba(255,255,255,0.2); border-color: #fff; }
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 480px) {
    .calc-modal { width: calc(100vw - 32px); right: 16px; bottom: 80px; height: 440px; min-width: unset; }
    .calc-btn { bottom: 16px; right: 16px; width: 50px; height: 50px; font-size: 1.3rem; }
    .fb-float-btn { bottom: 16px; right: 76px; width: 42px; height: 42px; font-size: 1rem; }
    .fb-float-panel { right: 16px; bottom: 68px; width: calc(100vw - 32px); }
}

/* Glossary tooltips */
.glossary-term { border-bottom: 1px dotted var(--primary); cursor: help; position: relative; }
.glossary-term:hover { color: var(--primary); }
.glossary-term[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
    background: var(--text); color: var(--bg, #fff); padding: 6px 10px; border-radius: 6px;
    font-size: 0.78rem; font-weight: 400; white-space: nowrap; max-width: 280px; white-space: normal;
    z-index: 100; pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    line-height: 1.4; margin-bottom: 4px;
}
.glossary-term[data-tooltip]:hover::before {
    content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
    border: 5px solid transparent; border-top-color: var(--text);
    z-index: 100; pointer-events: none; margin-bottom: -6px;
}
body.dark-mode .glossary-term[data-tooltip]:hover::after { background: var(--border); color: #1a1a2e; }
body.dark-mode .glossary-term[data-tooltip]:hover::before { border-top-color: #e0e0e0; }

/* Desmos Clear All button */
.calc-clear-btn { padding: 4px 12px; font-size: 0.78rem; border-radius: 6px; border: 1.5px solid var(--error); background: transparent; color: var(--error); cursor: pointer; font-weight: 600; margin-left: 8px; transition: all 0.2s; }
.calc-clear-btn:hover { background: var(--error); color: white; }

/* Criterion B SVG diagrams */
.pg-pattern-svg { margin: 12px 0; overflow-x: auto; }
.pg-pattern-svg svg { max-width: 100%; height: auto; display: block; }

/* ---- Level Sections (Standard / Extended) ---- */
.level-section { margin-bottom: 24px; }
.level-section-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px; border-radius: var(--radius);
    cursor: pointer; user-select: none;
    transition: all 0.2s; font-family: inherit;
    background: rgba(67,97,238,0.08); border: 2px solid rgba(67,97,238,0.15);
}
.level-section-header:hover { background: rgba(67,97,238,0.14); }
#section-standard .level-section-header { border-color: rgba(67,97,238,0.2); }
#section-extended .level-section-header {
    background: rgba(0,184,148,0.08); border-color: rgba(0,184,148,0.2);
}
#section-extended .level-section-header:hover { background: rgba(0,184,148,0.14); }
.level-section-header h2 {
    font-size: 1.15rem; font-weight: 700; margin: 0; flex: 1;
    color: var(--primary);
}
#section-extended .level-section-header h2 { color: #00b894; }
.level-count {
    font-size: 0.78rem; font-weight: 600; color: var(--text-light);
    background: rgba(0,0,0,0.05); padding: 3px 10px; border-radius: 10px;
}
.level-chevron {
    font-size: 0.7rem; color: var(--text-light);
    transition: transform 0.3s ease; display: inline-block;
}
.level-section.collapsed .level-chevron { transform: rotate(-90deg); }
.level-section-content {
    overflow: hidden; transition: max-height 0.4s ease, opacity 0.3s ease;
    max-height: 2000px; opacity: 1; padding-top: 16px;
}
.level-section.collapsed .level-section-content {
    max-height: 0; opacity: 0; padding-top: 0;
}

/* Dark mode */
body.dark-mode .level-section-header { background: rgba(67,97,238,0.1); border-color: rgba(67,97,238,0.2); }
body.dark-mode .level-section-header:hover { background: rgba(67,97,238,0.18); }
body.dark-mode #section-extended .level-section-header { background: rgba(0,184,148,0.1); border-color: rgba(0,184,148,0.2); }
body.dark-mode #section-extended .level-section-header:hover { background: rgba(0,184,148,0.18); }
body.dark-mode .level-count { background: rgba(255,255,255,0.08); }

/* Glassmorphism */
body.has-bg .level-section-header {
    background: rgba(255,255,255,var(--bg-card-alpha,0.85));
    backdrop-filter: blur(var(--bg-blur,16px)); -webkit-backdrop-filter: blur(var(--bg-blur,16px));
}
body.dark-mode.has-bg .level-section-header { background: rgba(22,33,62,var(--bg-card-alpha,0.85)); }

/* Dashboard section headers */
.dash-section-header {
    font-size: 0.85rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; padding: 10px 0 6px; margin-top: 16px;
    border-bottom: 2px solid rgba(67,97,238,0.15);
}
.dash-section-header.standard { color: var(--primary); border-bottom-color: rgba(67,97,238,0.2); }
.dash-section-header.extended { color: #00b894; border-bottom-color: rgba(0,184,148,0.2); }

/* Formula Booklet (maths) */
.formula-section { background: var(--card-bg, rgba(255,255,255,0.92)); border-radius: 12px; padding: 16px 20px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.formula-section h3 { color: var(--primary); border-bottom: 2px solid var(--primary); padding-bottom: 4px; margin-bottom: 8px; margin-top: 0; }
.formula-table { width: 100%; border-collapse: collapse; }
.formula-table td { padding: 8px 12px; border-bottom: 1px solid rgba(128,128,128,0.15); }
.formula-table td:first-child { width: 40%; font-weight: 500; }
.formula-table td:last-child { text-align: center; }
.formula-table tr:last-child td { border-bottom: none; }
.formula-table tr:hover { background: rgba(128,128,128,0.05); }
/* Formula FAB */
.formula-fab { position: fixed; bottom: 24px; right: 24px; width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; border: none; font-size: 1.4rem; cursor: pointer; z-index: 999; box-shadow: 0 4px 14px rgba(0,0,0,0.3); display: none; align-items: center; justify-content: center; transition: transform 0.2s; }
.formula-fab:hover { transform: scale(1.1); }

/* Scratchpad FAB + Overlay */
.scratchpad-fab { position: fixed; bottom: 24px; right: 86px; width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; border: none; font-size: 1.4rem; cursor: pointer; z-index: 999; box-shadow: 0 4px 14px rgba(0,0,0,0.3); display: none; align-items: center; justify-content: center; transition: transform 0.2s; }
.scratchpad-fab:hover { transform: scale(1.1); }
.scratchpad-fab.active { background: #e74c3c; }
.scratchpad-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 1100; display: none; flex-direction: column; pointer-events: none; }
.scratchpad-overlay.open { display: flex; pointer-events: auto; }
.scratchpad-toolbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; padding: 6px 12px; background: rgba(22,33,62,0.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 12px; z-index: 1102; box-shadow: 0 4px 16px rgba(0,0,0,0.3); align-items: center; }
.scratchpad-toolbar button { background: rgba(255,255,255,0.12); border: none; color: #fff; font-size: 1.1rem; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.15s; }
.scratchpad-toolbar button:hover { background: rgba(255,255,255,0.25); }
.scratchpad-toolbar button.active { background: var(--primary); }
.scratchpad-toolbar input[type="color"] { width: 32px; height: 32px; border: 2px solid rgba(255,255,255,0.3); border-radius: 8px; cursor: pointer; padding: 0; background: none; }
.scratchpad-toolbar input[type="range"] { width: 60px; accent-color: var(--primary); }
.scratchpad-toolbar .sp-sep { width: 1px; height: 24px; background: rgba(255,255,255,0.2); margin: 0 4px; }
.scratchpad-canvas { flex: 1; cursor: crosshair; touch-action: none; }

/* Formula slide-out panel */
.formula-panel-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.formula-panel-backdrop.open { opacity: 1; pointer-events: auto; }
.formula-panel { position: fixed; top: 0; right: 0; width: 420px; max-width: 90vw; height: 100vh; background: var(--bg, #fff); z-index: 1001; overflow-y: auto; padding: 20px; box-shadow: -4px 0 24px rgba(0,0,0,0.2); transform: translateX(100%); transition: transform 0.3s ease; }
.formula-panel.open { transform: translateX(0); }
.formula-panel .formula-section { box-shadow: none; background: rgba(128,128,128,0.06); }
.formula-panel-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); padding: 4px 10px; border-radius: 8px; margin-bottom: 12px; }
.formula-panel-close:hover { background: rgba(128,128,128,0.1); }

/* Lesson History Modal (maths overrides) */
.lh-modal { background: var(--bg, #fff); }
.lh-bar-wrap { width: 80px; height: 6px; background: var(--border, #e0e0e0); border-radius: 3px; margin-bottom: 4px; margin-left: auto; }
.lh-bar { height: 100%; border-radius: 3px; transition: width 0.3s; }
.lh-pct { font-size: 0.75rem; font-weight: 600; }

/* Paper Generator Folder Nav (maths overrides) */
.pg-nav-folders { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 0; align-items: flex-start; }
.pg-nav-q { display: inline-flex; flex-direction: column; align-items: center; position: relative; }
.pg-nav-qbtn { padding: 6px 12px; border: 1.5px solid var(--border, #e0e0e0); border-radius: 8px; background: var(--bg, #fff); color: var(--text, #1a1a2e); font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.pg-nav-qbtn:hover { border-color: var(--primary, #4361ee); }
.pg-nav-qbtn.active { background: var(--primary, #4361ee); color: #fff; border-color: var(--primary, #4361ee); }
.pg-nav-qbtn.has-answered { border-color: #27ae60; }
.pg-nav-parts { display: none; flex-wrap: wrap; gap: 2px; margin-top: 4px; }
.pg-nav-q.expanded .pg-nav-parts { display: flex; }
.pg-nav-pbtn { padding: 3px 8px; border: 1px solid var(--border, #e0e0e0); border-radius: 6px; background: transparent; color: var(--text, #1a1a2e); font-size: 0.75rem; cursor: pointer; transition: all 0.15s; }
.pg-nav-pbtn:hover { border-color: var(--primary, #4361ee); }
.pg-nav-pbtn.active { background: var(--primary, #4361ee); color: #fff; border-color: var(--primary, #4361ee); }
.pg-nav-pbtn.answered { border-color: #27ae60; color: #27ae60; }
.pg-nav-pbtn.correct { background: rgba(39,174,96,0.1); border-color: #27ae60; color: #27ae60; }
.pg-nav-pbtn.incorrect { background: rgba(231,76,60,0.1); border-color: var(--error); color: var(--error); }
body.dark-mode .pg-nav-qbtn { background: #1a1a2e; border-color: #444; color: #e0e0e0; }
body.dark-mode .pg-nav-pbtn { border-color: #444; color: #e0e0e0; }

@media print {
    body * { visibility: hidden; }
    #view-paper-markscheme, #view-paper-markscheme * { visibility: visible; }
    #view-paper-markscheme { position: absolute; left: 0; top: 0; width: 100%; }
    .pg-ms-topbar, .back-btn, nav, .wallpaper-bg { display: none !important; }
    .pg-ms-question { break-inside: avoid; border: 1px solid #ccc; }
    .pg-ms-answer { background: #f0fdf4 !important; border-left: 4px solid #22c55e; }
    .pg-ms-opt.correct { background: #f0fdf4 !important; }
    * { color: #000 !important; }
}

/* ---- High Contrast ---- */
body.high-contrast .topic-card,
body.high-contrast .question-card,
body.high-contrast .score-bar,
body.high-contrast .search-input,
body.high-contrast .search-results,
body.high-contrast header {
    border: 2px solid var(--text) !important;
    overflow: hidden;
    position: relative;
}
body.high-contrast .topic-tag { border: 1.5px solid currentColor; }
body.high-contrast .btn, body.high-contrast .btn-primary, body.high-contrast .btn-hint {
    border: 2px solid currentColor !important;
}
body.high-contrast .option-btn { border: 2px solid var(--text) !important; }

/* ---- Responsive (maths) ---- */
@media (max-width: 600px) {
    html, body { overflow-x: hidden; }
    body { padding: 12px; }
    .topic-grid { grid-template-columns: 1fr; }
    .topic-card { padding: 20px 16px; }
    .hub-header h1 { font-size: 1.5rem; }
    .daily-streak-bar { gap: 12px; flex-wrap: wrap; }
    .daily-streak-val { font-size: 1.2rem; }
    .tg-mode-grid { grid-template-columns: 1fr; }
    .tg-topic-grid { grid-template-columns: 1fr; }
    .tg-results-summary { grid-template-columns: repeat(2, 1fr); }
    .tg-length-grid { flex-direction: column; }
    .pg-nav-strip { gap: 3px; padding: 8px; }
    .pg-nav-btn { padding: 3px 6px; font-size: 0.65rem; }
    .pg-context-box { padding: 14px 16px; }
    .pg-mode-select { flex-direction: column; align-items: stretch; }
    .pg-option-row { flex-direction: column; gap: 6px; }
    .pg-cw-grid { grid-template-columns: 1fr 1fr; }
    .pg-results-summary { gap: 12px; }
    .pg-bottom-nav { flex-wrap: wrap; }
}
@media (max-width: 480px) {
    .options-grid { grid-template-columns: 1fr; }
    .question-prompt { font-size: 1.25rem; }
    .question-card { padding: 24px 16px; }
    .equation-system { font-size: 1.1rem; }
    .se-math-field { width: 120px; font-size: 1.2rem; }
    .workout-textarea { min-height: 140px; font-size: 0.9rem; }
}

/* ---- Touch & Mobile Improvements ---- */
* { -webkit-tap-highlight-color: transparent; }

.btn-primary:active { filter: brightness(0.9); }
.option-btn:active:not(:disabled) { transform: scale(0.98); }
.topic-card:active { transform: translateY(0); }
.back-btn:active { background: var(--primary-light); }

@media (pointer: coarse) {
    .btn-sm { padding: 10px 18px; font-size: 0.85rem; min-height: 44px; }
    .pg-nav-btn { min-width: 40px; min-height: 36px; padding: 6px 10px; }
    .level-btn, .mode-btn { padding: 10px 20px; min-height: 44px; }
}

@media (hover: none) {
    .topic-card:hover { transform: none; }
    .btn-primary:hover { transform: none; }
}

@media (pointer: coarse) {
    #view-paper-active { position: relative; }
    #view-paper-active::before, #view-paper-active::after {
        content: ''; position: fixed; top: 50%; width: 4px; height: 60px;
        border-radius: 2px; background: var(--primary); opacity: 0.15;
        transform: translateY(-50%); pointer-events: none;
    }
    #view-paper-active::before { left: 4px; }
    #view-paper-active::after { right: 4px; }
}

/* ---- PhET Simulation Embeds ---- */
.lesson-sim-desc {
    color: var(--text-light); font-size: 0.92rem; margin-bottom: 12px; line-height: 1.5;
}
.lesson-sim-container {
    position: relative; width: 100%; border-radius: var(--radius);
    overflow: hidden; margin: 12px 0 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    background: #1a1a2e;
}
.lesson-sim-card {
    padding: 32px 24px; text-align: center; color: #e0e0e0;
}
.lesson-sim-icon { font-size: 2.5rem; margin-bottom: 10px; }
.lesson-sim-card p { font-size: 0.9rem; margin-bottom: 16px; opacity: 0.85; }
.lesson-sim-launch {
    display: inline-block; padding: 10px 24px; font-size: 0.9rem; font-weight: 700;
    border-radius: 10px; text-decoration: none;
}
.lesson-sim-tasks {
    background: rgba(128,128,128,0.06); border-radius: 10px; padding: 14px 18px;
    margin-top: 8px; font-size: 0.88rem; line-height: 1.6;
}
.lesson-sim-tasks strong { color: var(--primary); }
.lesson-sim-tasks ul { margin: 6px 0 0 16px; padding: 0; }
.lesson-sim-tasks li { margin-bottom: 4px; }

.home-icon { flex-shrink: 0; }
