/* Platform palette: the reader and administrative surfaces share one preference. */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #fbfbfc; --surface: #ffffff; --surface-soft: #f0f1f4;
  --text: #24262d; --muted: #626570; --line: #d7d9df;
  --accent: #2855bd; --accent-strong: #21499f; --accent-soft: #e5ecff;
  --danger: #a42f32; --danger-soft: #fbe8e9; --success: #21613b;
  --success-soft: #e4f3e9; --amber: #785009; --warning-soft: #fff2d8;
  --shadow: none;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #202124; --surface: #2b2d31; --surface-soft: #35373d;
  --text: #ededf0; --muted: #b0b2bc; --line: #484b54;
  --accent: #a6bdff; --accent-strong: #c4d2ff; --accent-soft: #303e60;
  --danger: #ffb3b6; --danger-soft: #512c33; --success: #9cddaf;
  --success-soft: #263f32; --amber: #f2cf83; --warning-soft: #453b25;
}
body { background: var(--bg); color: var(--text); }
.app, .auth-page, .auth-panel, .main, .admin-shell { background: var(--bg); color: var(--text); }
.app-header, .is-learning .app-header {
  display: flex; align-items: center; gap: 24px; background: var(--bg);
  border-bottom: 1px solid var(--line); box-shadow: none; backdrop-filter: none;
}
.header-actions { margin-left: auto; flex-shrink: 0; }
.header-stats { flex: 1; }
.brand-home-button, .brand-lockup, .user-chip, .user-chip strong { color: var(--text); }
.theme-toggle, .avatar-upload { width: 42px; height: 42px; min-width: 42px; border-radius: 10px; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; background: var(--surface); color: var(--text); font-size: 20px; }
.theme-toggle:hover { background: var(--surface-soft); }
.auth-theme-toggle { position: absolute; top: 24px; right: 24px; z-index: 2; }
.avatar-upload { position: relative; overflow: hidden; cursor: pointer; font-size: 13px; }
.avatar-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.avatar-upload:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }
.avatar-upload img { width: 100%; height: 100%; object-fit: cover; }
.panel, .modal, .confirm-dialog, .report-drawer-panel, .notifications-popover,
.custom-select-menu, .inline-picker-popover, .admin-side-nav, .admin-workspace-head,
.home-metrics article, .home-next-card, .profile-progress-card, .achievement-card,
.course-card, .test-card, .library-card, .deadline-card, .admin-block, .question-item,
.question-group-panel, .content-block-editor, .completion-rule-card, .report-mini-card,
.question-analytics-card, .attempt-answer-card, .user-card-row, .access-check-card,
.group-picker-card, .block-palette, .assignment-summary, .assignment-user,
.learning-deadline-item, .notification-item, .profile-section-list article, .section-button,
.calendar-item, .course-detail-meta, .course-detail-tests, .material-block, .material-frame,
.option-line, .answer-button, .admin-tabs, .admin-list-row, .report-table-wrap,
.attempt-row-card, .report-tabs, .matrix-cell, .attempt-review-button, .user-attempt-item,
.quiz-footer-actions, .linked-test-block, .correct-toggle, .profile-tabs button {
  background: var(--surface); color: var(--text); border-color: var(--line); box-shadow: none;
}
.field input, .field textarea, .field select, .custom-select-trigger,
.admin-filters input, .admin-filters select, .report-filter-field input, .report-filter-field select,
.user-profile-grid input, .user-profile-grid select, .users-table input, .users-table select,
.rich-question-input, .exercise-editor input, .exercise-editor textarea, .exercise-editor select,
.compact-empty, .check-row, .user-chip, .notification-bell, .search-field,
.library-search, .library-search:focus-within, .question-nav button,
.block-insert-button, .course-chapter-tabs button, .course-chapter-pager button {
  background: var(--surface); color: var(--text); border-color: var(--line); box-shadow: none;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.btn, .tab, .nav-button, .admin-side-nav nav small { box-shadow: none; }
.btn.primary { background: var(--text); color: var(--bg); border-color: transparent; }
.btn.primary:hover:not(:disabled) { background: var(--text); opacity: .86; }
.btn.secondary, .btn.ghost, .link-button { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled, button:disabled { cursor: not-allowed; }
.pill, .badge, .question-chip { background: var(--surface-soft); color: var(--muted); border-color: var(--line); }
.tab.active, .nav-button.active, .admin-tabs .active, .profile-tabs .active,
.course-chapter-tabs .active, .report-tabs .active, .question-nav button.active,
.option-line.selected, .answer-button.selected { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.alert.success, .pill.success { background: var(--success-soft); color: var(--success); }
.alert.warning { background: var(--warning-soft); color: var(--amber); }
table, th, td, .section-head, .panel-head, .admin-side-nav, .modal-header, .modal-footer { border-color: var(--line); }
thead, th { background: var(--surface-soft); color: var(--muted); }
tbody tr:hover, .notification-item:hover, .admin-list-row:hover { background: var(--surface-soft); }
.home-next-card p, .course-card p, .test-card p, .material-block p, .rich-content,
.question-item p, .option-line, .answer-button, .admin-workspace-head h2 { color: var(--text); }
.home-metric-label, .field > label, .muted, .form-hint, .field-hint,
.exercise-editor-help, .course-card small, .test-card small, .admin-side-nav nav small { color: var(--muted); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.home-hero, .home-stat-card, .learning-hero, .learning-next-card, .profile-hero,
.profile-summary-grid div, .course-chapter-empty, .chapter-editor-card,
.block-insert-zone.empty, .block-insert-zone.empty .block-insert-button.plus-only,
.privacy-settings, .assignment-grid, .completion-rules, .completion-empty,
.course-detail-head, .course-detail-aside, .course-player-nav, .course-chapter-head,
.course-nav-summary, .sticky-save-bar, .user-detail-panel, .user-detail-placeholder,
.achievement-card.earned, .empty-state, .chapter-fallback-note, .block-type-card,
.admin-side-note, .compact-editor, .nav-rail, .nav-rail:hover, .nav-rail:focus-within {
  background: var(--surface); color: var(--text); border-color: var(--line); box-shadow: none; backdrop-filter: none;
}
.nav-rail-button { color: var(--muted); }
.nav-rail-button.active, .section-button.active, .admin-side-nav button.active,
.course-chapter-tabs button.active, .course-player-nav button.active {
  background: var(--accent-soft); color: var(--accent); border-color: var(--accent);
}
.nav-rail-button:hover, .nav-rail-button:focus-visible,
.user-menu-button:hover, .user-menu-button:focus-visible, .block-type-card:hover {
  background: var(--surface-soft); color: var(--text);
}
.rich-editor-tools, .course-detail-back span, .course-chapter-pager span,
.material-block-number, .progress-track, .quiz-stage .quiz-question-title,
.achievement-card code { background: var(--surface-soft); color: var(--text); border-color: var(--line); }
.rich-tool { color: var(--text); }
.rich-tool:hover { background: var(--accent-soft); color: var(--accent); }
.field label, .quiz-stat { color: var(--muted); }
.learning-deadline-item.soon, .calendar-item.soon, .notification-item.deadline,
.deadline-card.soon, .version-warning, .note-block { background: var(--warning-soft); color: var(--amber); border-color: var(--line); }
.version-warning span, .attempt-answer-title em.pending, .answer-chips b.pending { color: var(--amber); }
.learning-deadline-item.overdue, .calendar-item.overdue, .deadline-card.overdue { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.field.has-error input, .field.has-error textarea, .field.has-error select,
.field.has-error .custom-select-trigger, .rich-question-input.invalid { background: var(--danger-soft); border-color: var(--danger); }
.toast { background: var(--text); color: var(--bg); }
.help-button, .user-avatar, .correct-toggle input:checked + span,
.report-tabs button.active { background: var(--accent); color: var(--bg); }

/* Reader: quiet curriculum at the edge, a measured column for the lesson. */
.is-learning .main { max-width: none; margin: 0; padding: 24px 5vw 80px; }
.learning-topline { margin-bottom: 28px; justify-content: space-between; }
.course-author-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.learning-layout { grid-template-columns: minmax(220px, 22vw) minmax(0, 760px); gap: clamp(28px, 4vw, 72px); }
.learning-sidebar { top: 110px; }
.learning-curriculum summary { font-size: 16px; }
.learning-step { min-height: 60px; }
.learning-step strong { font-size: 14px; line-height: 1.6; }
.learning-breadcrumb { color: var(--muted); font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; margin: 6px 0 18px; }
.learning-breadcrumb > span { padding: 0 8px; }
.topic-segments { display: flex; gap: 6px; margin-bottom: 36px; }
.topic-segments span { height: 5px; flex: 1; border-radius: 4px; background: var(--line); }
.topic-segments .is-done { background: var(--text); }
.topic-segments .is-current { background: var(--accent); outline: 1px solid var(--accent); outline-offset: 2px; }
.learning-progress-label { color: var(--muted); font-size: 12px; line-height: 1.5; }
.learning-lesson-heading h1 { font-size: clamp(28px, 3.1vw, 42px); font-weight: 650; line-height: 1.22; letter-spacing: -.025em; margin: 0; overflow-wrap: anywhere; scroll-margin-top: 120px; }
.learning-content .material-block { background: transparent; }
.learning-checkpoint { display: flex; justify-content: flex-end; padding: 20px 0 32px; }
.player-block { position: relative; min-width: 0; }
.is-authoring .player-block { border: 1px dashed var(--line); border-radius: 12px; margin: 12px 0; padding: 28px 20px 12px; }
.is-authoring .player-block > [inert] { pointer-events: none; }
.block-edit-pencil { position: absolute; z-index: 1; top: 4px; right: 4px; width: 44px; height: 44px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); color: var(--text); font-size: 22px; }
.block-edit-pencil:hover { background: var(--accent-soft); color: var(--accent); }
.inline-insert { text-align: center; padding: 4px 0; }
.inline-block-editor { padding: 24px 0 12px; min-width: 0; }
.inline-fields { display: grid; gap: 18px; }
.inline-fields .field { display: grid; gap: 8px; }
.inline-fields .field input, .inline-fields .field select, .inline-fields .field textarea { width: 100%; min-height: 44px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.inline-fields textarea { min-height: 140px; resize: vertical; }
.inline-fields .rich-question-input { min-height: 160px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; }
.inline-image-preview { max-width: 100%; max-height: 320px; object-fit: contain; }
.inline-editor-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.inline-block-preview { padding: 12px 0; }
.learner-dialog { display: flex; align-items: flex-end; justify-content: flex-end; gap: 12px; margin: 32px 0 40px; }
.learner-dialog-content { max-width: min(88%, 640px); text-align: right; }
.learner-dialog-name { display: block; color: var(--muted); font-size: 13px; margin: 0 4px 8px; }
.learner-dialog p { display: inline-block; margin: 0; padding: 14px 20px; border-radius: 20px 20px 4px 20px; background: #2461db; color: #fff; font-size: 17px; line-height: 1.6; text-align: left; overflow-wrap: anywhere; }
.learner-dialog > img, .dialog-initials { width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%; object-fit: cover; }
.dialog-initials { display: grid; place-items: center; background: var(--surface-soft); color: var(--text); font-size: 13px; }
.exercise-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.exercise-option { font-size: 16px; line-height: 1.6; }
.learning-exercise, .learning-exercise.is-complete { background: transparent; border: 1px solid var(--line); padding: 28px; border-radius: 14px; }
.learning-exercise h3 { margin-top: 0; }
.exercise-option { position: relative; border-color: transparent; background: transparent; }
.exercise-option.is-selected { border-color: var(--lesson-accent); background: var(--lesson-selected); }
.exercise-option.is-correct, .exercise-option.is-wrong { background: transparent; border-color: transparent; }
.exercise-option.is-correct::before, .exercise-option.is-wrong::before { content: ''; position: absolute; left: -29px; top: 12px; bottom: 12px; width: 3px; background: var(--success); }
.exercise-option.is-wrong::before { background: var(--danger); }
.exercise-option.is-correct input, .exercise-option.is-wrong input { appearance: none; position: relative; background: var(--success); border: 1px solid var(--success); border-radius: 50%; width: 22px; height: 22px; flex: 0 0 22px; opacity: 1; }
.exercise-option.is-wrong input { background: #cf3b45; border-color: #cf3b45; }
.exercise-option.is-correct input::after, .exercise-option.is-wrong input::after { content: '✓'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--bg); font-size: 15px; font-weight: 750; }
.exercise-option.is-wrong input::after { content: '×'; color: #fff; }
.exercise-option:has(input:disabled), .matching-item:disabled { opacity: 1; cursor: default; }
.matching-item.is-correct { border-color: var(--success); color: var(--success); }
.matching-item.is-wrong { border-color: var(--danger); color: var(--danger); }
.exercise-feedback:empty { display: none; }
.is-revealed { animation: lesson-reveal 380ms cubic-bezier(.16,1,.3,1); }
@keyframes lesson-reveal { from { clip-path: inset(0 0 30% 0); opacity: .35; transform: translateY(8px); } to { clip-path: inset(0); opacity: 1; transform: none; } }
@media (max-width: 1100px) {
  .app-header { gap: 14px; }
  .header-stats { display: none; }
  .learning-layout { grid-template-columns: 220px minmax(0, 1fr); gap: 32px; }
}
@media (max-width: 760px) {
  .app-header, .is-learning .app-header { padding: 12px 16px; gap: 8px; }
  .header-actions, .is-learning .header-actions { gap: 6px; }
  .brand-home-button > span:last-child, .compact-user > strong, .compact-user > span { display: none; }
  .compact-user, .is-learning .compact-user { display: inline-grid; place-items: center; width: 38px; min-width: 38px; max-width: 38px; height: 38px; min-height: 38px; padding: 0; }
  .compact-user::before { content: '◎'; font-size: 24px; }
  .brand-mark { width: 36px; height: 36px; }
  .header-actions .btn, .notification-bell, .theme-toggle, .avatar-upload { width: 38px; min-width: 38px; height: 38px; min-height: 38px; padding: 6px; }
  .is-learning .main { padding: 16px 20px 48px; }
  .learning-topline { align-items: flex-start; gap: 12px; margin-bottom: 24px; }
  .course-author-actions { gap: 8px; }
  .course-author-actions .btn { padding: 8px 10px; font-size: 12px; }
  .learning-layout { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .learning-sidebar { position: static; }
  .learning-curriculum summary { padding-bottom: 14px; }
  .learning-breadcrumb { font-size: 13px; }
  .topic-segments { margin-bottom: 28px; }
  .learning-lesson-heading { padding: 0 0 24px; }
  .learning-content { padding: 0; }
  .learning-content .rich-content { font-size: 16px; line-height: 1.75; }
  .learning-exercise, .learning-exercise.is-complete { padding: 22px 18px; }
  .exercise-option { padding: 14px 8px; gap: 12px; }
  .exercise-option.is-correct::before, .exercise-option.is-wrong::before { left: -19px; }
  .is-authoring .player-block { padding: 32px 12px 12px; }
  .inline-editor-actions .btn { flex: 1 1 130px; }
  .learner-dialog p { font-size: 16px; padding: 12px 16px; }
  .learning-lesson-footer { padding: 24px 0; }
}
@media (prefers-reduced-motion: reduce) { .is-revealed { animation: none; } }
