:root{--brand-primary:#a41617;--text-main:#334155;--text-heading:#172033;--text-muted:#596579;--surface:#fff;--surface-alt:#f1f5f9;--page-bg:#f8fafc;--border:#cbd5e1;--input-bg:#fff;--chart-line:#a41617;--chart-fill:#a4161720}
[data-theme="dark"]{color-scheme:dark;--brand-primary:#ff9298;--text-main:#e2e8f0;--text-heading:#f8fafc;--text-muted:#b4c0d2;--surface:#1e293b;--surface-alt:#273449;--page-bg:#111827;--border:#526077;--input-bg:#172033;--chart-line:#ff9298;--chart-fill:#ff929825}
.tuklas-logo{display:inline-block;width:48px;height:48px;max-width:100%;object-fit:contain;flex-shrink:0;background:transparent;border:0;border-radius:0}.student-topbar .tuklas-logo{width:42px;height:42px}.auth-login-logo .tuklas-logo{width:76px;height:76px}.hero-mascot .tuklas-logo{width:clamp(140px,18vw,210px);height:auto}.theme-toggle{min-width:42px;min-height:42px}
body:not(.reader-body){background:var(--page-bg);color:var(--text-main)}
[data-theme="dark"] :is(.panel-card,.story-card,.stat-pill,.quiz-card,.quiz-choice,.matching-row,.editor-section,.question-card,.question-group,.student-topbar,.topbar,.sidebar,.auth-card,.asset-item,.student-detail-item,.modal-content,.dropdown-menu){background:var(--surface)!important;color:var(--text-main);border-color:var(--border)!important}
[data-theme="dark"] :is(.bg-white,.bg-light,.quiz-choice-letter,.quiz-type-heading,.quiz-type-instructions,.question-type-help,[class*="builder-panel"],[class*="builder-toolbar"]){background:var(--surface-alt)!important;color:var(--text-main)!important}
[data-theme="dark"] :is(.form-control,.form-select,.input-group-text){background-color:var(--input-bg)!important;color:var(--text-main)!important;border-color:var(--border)!important}
[data-theme="dark"] :is(.text-dark,.quiz-question-text,.story-card-title,.pill-value,.sidebar-brand-text,.sidebar-link,.panel-card-title,.auth-heading){color:var(--text-heading)!important}
[data-theme="dark"] :is(.text-muted,.story-card-meta,.sidebar-user-name,.sidebar-section-label){color:var(--text-muted)!important}
[data-theme="dark"] :is(table,.data-table){--bs-table-bg:var(--surface);--bs-table-color:var(--text-main);color:var(--text-main)}
[data-theme="dark"] :is(.data-table td,.data-table th){background:var(--surface);color:var(--text-main);border-color:var(--border)}
[data-theme="dark"] :is(.quiz-choice.selected,.quiz-choice:hover){background:var(--surface-alt)!important;border-color:var(--brand-primary)!important}
[data-theme="dark"] .btn-brand{background:#a41617;color:#fff!important}[data-theme="dark"] .btn-outline-brand{color:#ff9298;border-color:#ff9298}
:focus-visible{outline:3px solid var(--brand-primary);outline-offset:3px}
.image-choices{display:grid!important;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px}.image-choices .quiz-choice{flex-direction:column;min-height:150px}.choice-picture{width:100%;max-width:230px;height:140px;object-fit:contain}.image-option-preview{width:100px;height:80px;object-fit:contain}.add-question-footer button{flex:0 0 auto!important;width:auto!important}
.term-columns{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:24px}.term-column{min-width:0}.term-track{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;gap:16px;scrollbar-width:thin}.term-track>.story-card{flex:0 0 100%;scroll-snap-align:start}.term-controls{display:flex;align-items:center;justify-content:space-between;margin:10px 0}@media(max-width:991px){.term-columns{grid-template-columns:1fr}}

.reader-body{--surface:#1e293b;--surface-alt:#273449;--text-main:#e2e8f0;--text-heading:#f8fafc;--text-muted:#b4c0d2;--border:#526077;--input-bg:#172033}.reader-body .modal-content{background:var(--surface);color:var(--text-main)}

[data-theme=dark]{--system-canvas:var(--page-bg);--system-surface:var(--surface);--system-border:var(--border);--system-ink:var(--text-main);--system-muted:var(--text-muted);--text-body:var(--text-main);--card-bg:var(--surface);--content-bg:var(--page-bg);--bs-link-color:var(--brand-primary)}
[data-theme=dark] :is(.student-section-title,.auth-subheading,.form-label,.question-type-group-header,.question-type-badge){color:var(--text-heading)!important}
[data-theme=dark] :is(.question-type-group-header,.question-type-help,.question-group-body,.editor-section,.auth-form-panel){background:var(--surface)!important}
[data-theme=dark] a:not(.btn):not(.sidebar-link):not(.sidebar-brand):not(.student-topbar-brand){color:var(--brand-primary)}
[data-theme=dark] .text-primary{color:var(--brand-primary)!important}[data-theme=dark] .text-success{color:#75d9a2!important}[data-theme=dark] .text-danger{color:#ff9298!important}[data-theme=dark] .text-warning{color:#ffd36b!important}
[data-theme=dark] .btn-primary{background:#a41617;border-color:#a41617;color:#fff!important}

[data-theme="dark"] .btn-outline-primary{color:var(--brand-primary)!important;border-color:var(--brand-primary)!important;background:transparent!important}
[data-theme="dark"] .btn-outline-primary:hover{background:#a41617!important;color:#fff!important}
[data-theme="dark"] .btn-outline-secondary{color:#cbd5e1;border-color:#7b899e}
[data-theme="dark"] .badge-new{background:#42341a!important;color:#ffd36b!important}[data-theme="dark"] .badge-reading{background:#223c5c!important;color:#b2d6ff!important}[data-theme="dark"] .badge-completed{background:#163c2e!important;color:#91efbd!important}
[data-theme="dark"] .image-option{border-color:var(--border)!important}
.student-topbar :is(.theme-toggle,.student-settings-toggle){color:#fff!important;border-color:#fff!important;background:#a41617!important}
[data-theme="light"] .btn-outline-secondary{color:#596579;border-color:#596579}
[data-theme="light"] .btn-outline-secondary:hover{background:#596579;color:#fff}

/* Shared dark-mode foregrounds: soft text and restrained, readable icons. */
[data-theme="dark"] {
    --text-main: #dde3ec;
    --text-heading: #edf1f7;
    --text-muted: #aeb9ca;
    --icon-default: #bdc9da;
    --icon-brand: #f2a1a8;
    --icon-success: #86cdaa;
    --icon-warning: #e6c184;
    --icon-info: #9dbfe8;
    --icon-purple: #c2ace4;
    --adaptive-heading: var(--text-heading);
    --adaptive-text: var(--text-main);
    --adaptive-muted: var(--text-muted);
    --adaptive-brand: var(--icon-brand);
    --adaptive-success: var(--icon-success);
    --adaptive-warning: var(--icon-warning);
    --adaptive-info: var(--icon-info);
    --adaptive-surface: var(--surface);
    --brand-pink: var(--icon-brand);
    --brand-blue: var(--icon-info);
    --brand-secondary: var(--icon-warning);
    --student-primary: var(--icon-brand);
    --student-green: var(--icon-success);
    --student-orange: var(--icon-warning);
    --bs-body-color: var(--text-main);
    --bs-heading-color: var(--text-heading);
    --bs-secondary-color: var(--text-muted);
    --bs-emphasis-color: var(--text-heading);
    --bs-link-color: var(--icon-brand);
    --bs-link-hover-color: #f6bbc0;
}

[data-theme="dark"] :is(h1,h2,h3,h4,h5,h6,.card-title,.stat-value,.stat-number,.quiz-question-text) {
    color: var(--text-heading);
}
[data-theme="dark"] :is(.text-body,.text-body-emphasis,.text-black,.text-dark,.dropdown-item,.form-label,.form-check-label,.accordion-button) {
    color: var(--text-main) !important;
}
[data-theme="dark"] :is(.text-secondary,.text-body-secondary,.text-body-tertiary,.stat-label,.sidebar-brand-sub,.sidebar-user-role,.sidebar-logout,.form-text,.auth-footer,.auth-security,.student-empty p) {
    color: var(--text-muted) !important;
}
[data-theme="dark"] :is(.stat-card,.student-empty,.card,.list-group-item,.accordion-item,.accordion-button,.offcanvas,.toast,.popover) {
    background-color: var(--surface);
    color: var(--text-main);
    border-color: var(--border);
}
[data-theme="dark"] :is(.form-control,.form-select)::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* Inherit the surrounding control's color on buttons and semantic messages. */
[data-theme="dark"] :is(.bi,svg.icon,svg.bi,[data-lucide]) {
    color: var(--icon-color, var(--icon-default)) !important;
}
[data-theme="dark"] :is(.btn,button,.badge,.alert,.text-white,.text-bg-primary,.text-bg-success,.text-bg-danger,.text-bg-warning,.text-bg-info,.quiz-header,.student-hero,.auth-hero) {
    --icon-color: currentColor;
}
[data-theme="dark"] :is(.text-primary,.text-purple,.text-brand) { color: var(--icon-brand) !important; --icon-color: var(--icon-brand); }
[data-theme="dark"] .text-success { color: var(--icon-success) !important; --icon-color: var(--icon-success); }
[data-theme="dark"] .text-danger { color: var(--icon-brand) !important; --icon-color: var(--icon-brand); }
[data-theme="dark"] .text-warning { color: var(--icon-warning) !important; --icon-color: var(--icon-warning); }
[data-theme="dark"] .text-info { color: var(--icon-info) !important; --icon-color: var(--icon-info); }
[data-theme="dark"] :is(.text-muted,.text-secondary,.input-group-text) { --icon-color: var(--text-muted); }
[data-theme="dark"] .input-group-text { color: var(--text-muted) !important; }

[data-theme="dark"] .stat-icon { background: #2b384b; }
[data-theme="dark"] .stat-icon.purple { color: var(--icon-purple); --icon-color: var(--icon-purple); }
[data-theme="dark"] .stat-icon.pink { color: var(--icon-brand); --icon-color: var(--icon-brand); }
[data-theme="dark"] .stat-icon.orange { color: var(--icon-warning); --icon-color: var(--icon-warning); }
[data-theme="dark"] .stat-icon.green { color: var(--icon-success); --icon-color: var(--icon-success); }
[data-theme="dark"] .stat-icon.teal { color: var(--icon-info); --icon-color: var(--icon-info); }
[data-theme="dark"] .panel-icon-wrap { background: #2b384b !important; color: var(--icon-info) !important; --icon-color: var(--icon-info); }
[data-theme="dark"] .sidebar { background-image: none; }
[data-theme="dark"] .sidebar-link { --icon-color: var(--icon-default); }
[data-theme="dark"] .sidebar-link.active { --icon-color: var(--icon-brand); }
[data-theme="dark"] .sidebar-link:hover { --icon-color: var(--text-heading); }

[data-theme="dark"] :is(.badge-role-teacher,.badge-new) { background: #403622 !important; color: var(--icon-warning) !important; }
[data-theme="dark"] :is(.badge-role-student,.badge-status-published,.student-detail-status.is-active) { background: #203b32 !important; color: var(--icon-success) !important; }
[data-theme="dark"] :is(.badge-role-admin,.badge-status-archived,.student-detail-status.is-inactive) { background: #442c35 !important; color: var(--icon-brand) !important; }
[data-theme="dark"] .badge-status-draft { background: #303b4c !important; color: var(--text-muted) !important; }
[data-theme="dark"] :is(.btn-outline-danger) { color: var(--icon-brand); border-color: var(--icon-brand); }
[data-theme="dark"] :is(.btn-outline-success) { color: var(--icon-success); border-color: var(--icon-success); }
[data-theme="dark"] :is(.btn-outline-warning) { color: var(--icon-warning); border-color: var(--icon-warning); }
[data-theme="dark"] :is(.btn-outline-info) { color: var(--icon-info); border-color: var(--icon-info); }
[data-theme="dark"] :is(.question-type-badge,.question-type-group-header) { --question-accent: var(--icon-brand); }
[data-theme="dark"] :is(.mission-modal-card,.quiz-matching-row) { background: var(--surface); color: var(--text-main); }
[data-theme="dark"] :is(.mission-modal-message,.mission-modal-card p,.quiz-matching-left,.quiz-answer-help) { color: var(--text-muted); }
[data-theme="dark"] :is(.quiz-text-response,.quiz-matching-select) { background: var(--input-bg); color: var(--text-main); border-color: var(--border); }
[data-theme="dark"] :is(.btn-outline-brand,.btn-outline-primary) { color: var(--icon-brand) !important; border-color: var(--icon-brand) !important; }
[data-theme="dark"] :is(.btn-outline-brand,.btn-outline-primary):is(:hover,:focus-visible) { color: var(--text-heading) !important; background: #703039 !important; }
[data-theme="dark"] .btn-outline-danger:hover { background-color: #703039; color: var(--text-heading); }
[data-theme="dark"] .btn-outline-success:hover { background-color: #265341; color: var(--text-heading); }
[data-theme="dark"] .btn-outline-warning:hover { background-color: #59472b; color: var(--text-heading); }
[data-theme="dark"] .btn-outline-info:hover { background-color: #2c4d73; color: var(--text-heading); }
[data-theme="dark"] svg text { fill: var(--text-main); }
[data-theme="dark"] .circular-chart > circle { stroke: var(--border); }
[data-theme="dark"] .circle-green { stroke: var(--icon-success); }
[data-theme="dark"] .circle-blue { stroke: var(--icon-info); }
[data-theme="dark"] .circle-orange { stroke: var(--icon-warning); }
[data-theme="dark"] :is(.text-black-50,.text-white-50) { color: var(--text-muted) !important; }
[data-theme="dark"] :is(.dropdown-item.active,.dropdown-item:active) { background-color: #38495f !important; color: var(--text-heading) !important; }
