/* Shared tokens let new interface components inherit either palette. */
:root {
  --surface: #fff;
  --surface-raised: #fff;
  --surface-soft: #f4f1f8;
  --paper: #f8f9f5;
  --accent: #75608e;
  --accent-soft: #f0edf7;
  --accent-ink: #fff;
  --button-bg: #30372f;
  --button-ink: #fff;
  --danger: #a54f37;
}

.header-controls { display: flex; align-items: center; justify-content: flex-end; gap: 18px; min-width: 0; }
.site-header .theme-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  gap: 6px;
  min-height: 36px;
  padding: 8px 11px;
  margin: 0;
  border: 1px solid #ddd5e7;
  border-radius: 10px;
  background: #f3eff8;
  color: #6d5887;
  font: inherit;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle svg { width: 17px; height: 17px; flex: 0 0 auto; }
.site-header .theme-toggle:hover { background: #eae3f3; border-color: #bbaeCA; color: #57406f; }
.site-header .theme-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

html[data-theme="galactic"] {
  color-scheme: dark;
  --canvas: #090f20;
  --ink: #eef0ff;
  --muted: #aeb8d4;
  --line: #303a57;
  --focus: #88d9ed;
  --surface: #121a31;
  --surface-raised: #19223c;
  --surface-soft: #202944;
  --paper: #121a31;
  --accent: #c7b7ff;
  --accent-soft: #2a2546;
  --accent-ink: #18162c;
  --button-bg: #c7b7ff;
  --button-ink: #18162c;
  --danger: #ffb3a9;
  background: radial-gradient(ellipse at 4% 8%, #45337835, transparent 52%), radial-gradient(ellipse at 98% 50%, #14557326, transparent 48%), var(--canvas);
  background-attachment: fixed;
}
html[data-theme="galactic"] body { isolation: isolate; }
html[data-theme="galactic"] body::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: .32;
  background-image: radial-gradient(circle at 20px 30px, #d8e4ff 0 .7px, transparent 1px), radial-gradient(circle at 130px 70px, #c3b7f9 0 .7px, transparent 1.2px), radial-gradient(circle at 90px 160px, #a8dceb 0 .6px, transparent 1px);
  background-size: 251px 233px, 367px 307px, 307px 379px;
}
html[data-theme="galactic"] ::selection { color: #f6f2ff; background: #62519a; }
html[data-theme="galactic"] .brand { color: #eeeaff; }
html[data-theme="galactic"] .brand-mark { color: #a998dc; }
html[data-theme="galactic"] .brand-dot { color: #8dd9ee; }
html[data-theme="galactic"] .site-header .theme-toggle { color: #e4daff; background: #30274a; border-color: #74649e; box-shadow: inset 0 0 0 1px #b9a4ff0a; }
html[data-theme="galactic"] .site-header .theme-toggle:hover { color: #fff; background: #3b305b; border-color: #a38bd4; }

/* Paper surfaces, including the teacher workspace and conversation history. */
html[data-theme="galactic"] :is(.subject-card, .lesson-card, .material-card, .problem-card, .workspace-problem, .composer, .api-panel, .allowance-panel, .conversation-card, .student-card, .content-record, .transcript-problem, .student-stat, .student-settings, .skip-link) {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 8px 30px #01040c16;
}
html[data-theme="galactic"] :is(.subject-card, .lesson-card, .material-card, .problem-link, .conversation-card, .student-card):hover { background: var(--surface-raised); border-color: #716293; box-shadow: 0 8px 28px #03061030; }
html[data-theme="galactic"] .subject-card.is-selected { border-color: #9f8acb; box-shadow: 0 0 0 1px #9f8acb; }
html[data-theme="galactic"] .card-action { border-color: var(--line); }
html[data-theme="galactic"] :is(.arrow-circle, .conversation-open) { border-color: #46516e; color: var(--accent); }
html[data-theme="galactic"] .subject-card:hover .arrow-circle { background: var(--accent-soft); border-color: #79669a; }
html[data-theme="galactic"] :is(.empty-state, .library-empty) { border-color: #46516e; background: #121a3166; }
html[data-theme="galactic"] :is(.subject-symbol, .account-symbol, .assessment-label) { background: var(--accent-soft); color: #d4c7ff; border-color: #4b3e68; }
html[data-theme="galactic"] .number-theory .subject-symbol { background: #153345; color: #98dcea; }
html[data-theme="galactic"] :is(.material-icon, .count-badge, .thinking-mark, .conversation-avatar) { background: #202c46; color: #c5d4ee; }
html[data-theme="galactic"] :is(.material-arrow, .breadcrumbs span[aria-hidden], .workspace-nav > span > span, .conversation-card-copy p > span, .conversation-card-date > span, .transcript-meta > span) { color: #8796b8; }
html[data-theme="galactic"] :is(.eyebrow-line, .note-line, .transcript-end > span) { background: #74678f; }

/* Secondary copy remains legible on the darker canvas and raised surfaces. */
html[data-theme="galactic"] :is(.intro-description, .subject-topics, .site-footer, .account-footer, .teacher-footer, .header-label, .account-nav, .teacher-header-nav a, .teacher-header-nav a span, .account-eyebrow, .account-note, .account-setup-link, .field-help, .workspace-section-heading p, .usage-label, .usage-label > span, .usage-currency, .usage-count, .usage-scope, .usage-scope strong, .api-settings-footer p, .library-heading > span, .conversation-card-copy > p, .conversation-card-date, .library-note, .student-card p span, .content-record-meta, .content-count, .content-removed > summary, .content-removed > summary span, .content-form-footer > p, .teacher-back, .transcript-meta, .transcript-submeta, .transcript-speaker, .transcript-action, .transcript-message-meta time, .transcript-note, .message-details, .transcript-end p, .message-label, .message-tutor .message-label, .preview-notice) { color: var(--muted); }
html[data-theme="galactic"] :is(.eyebrow, .lecture-intro .eyebrow, .teacher-intro .eyebrow, .transcript-header .eyebrow, .lesson-kicker, .problem-open, .student-open) { color: #c5b3e5; }
html[data-theme="galactic"] :is(.account-field label, .workspace-field label, .content-field > label, .api-toggle, .api-counter-date time, .student-card h3, .usage-amount, .transcript-problem h2, .transcript-text) { color: var(--ink); }
html[data-theme="galactic"] :is(.text-link, .workspace-text-link, .content-record-actions > a, .content-record h3 a:hover, .account-setup-link a, .privacy-copy a, .usage-explanation summary, .student-card-copy .student-balance) { color: var(--accent); }
html[data-theme="galactic"] :is(.text-link, .workspace-text-link, .content-record-actions > a, .account-setup-link a, .privacy-copy a):hover { color: #e6ddff; }
html[data-theme="galactic"] :is(.account-nav a, .teacher-header-nav a, .teacher-back):hover { color: var(--ink); }
html[data-theme="galactic"] :is(.lecture-edit-link, .account-nav button, .account-nav .account-button, .teacher-header-nav button) { border-color: var(--line); color: var(--muted); }
html[data-theme="galactic"] :is(.lecture-edit-link, .account-nav button, .account-nav .account-button, .teacher-header-nav button):hover { background: var(--surface-raised); border-color: #716293; color: var(--ink); }

/* Form controls, including native menus, file pickers, and autofill. */
html[data-theme="galactic"] :is(.account-field input, .workspace-field select, .allowance-entry input, .content-field input:not([type="checkbox"]), .content-field select, .content-field textarea) { color: var(--ink); background-color: var(--surface); border-color: #46516e; }
html[data-theme="galactic"] :is(input, textarea)::placeholder { color: #9aa7c6; opacity: 1; }
html[data-theme="galactic"] :is(.account-field input, .workspace-field select, .allowance-entry input, .content-field input:not([type="checkbox"]), .content-field select, .content-field textarea):focus { border-color: #b4a1e5; box-shadow: 0 0 0 3px #b4a1e520; }
html[data-theme="galactic"] :is(.account-field input, .workspace-field select, .content-field input, .content-field select, .content-field textarea)[aria-invalid="true"] { border-color: #e6968f; }
html[data-theme="galactic"] :is(.content-field input, .content-field select, .allowance-entry input):disabled { color: #95a1bd; background-color: #1d263c; }
html[data-theme="galactic"] input:-webkit-autofill { -webkit-text-fill-color: var(--ink); box-shadow: 0 0 0 1000px var(--surface) inset; caret-color: var(--ink); }
html[data-theme="galactic"] input[type="checkbox"] { accent-color: var(--accent); }
html[data-theme="galactic"] .content-field input[type="file"]::file-selector-button { color: #e1d6ff; border-color: #65557f; background: var(--accent-soft); }
html[data-theme="galactic"] :is(.content-quiet-button, .api-reset-button, .conversation-history-controls button) { color: #d6c8f4; border-color: #514568; background: var(--accent-soft); }
html[data-theme="galactic"] :is(.content-quiet-button, .api-reset-button, .conversation-history-controls button):hover { background: #3a3153; border-color: #7d6a9b; }
html[data-theme="galactic"] :is(.account-submit, .workspace-button, .composer .check-button) { color: var(--button-ink); border-color: var(--button-bg); background: var(--button-bg); }
html[data-theme="galactic"] :is(.account-submit, .workspace-button, .composer .check-button):hover:enabled,
html[data-theme="galactic"] a.workspace-button:hover { background: #daceff; border-color: #daceff; }
html[data-theme="galactic"] .api-toggle input { background: #2c3651; border-color: #5a6685; }
html[data-theme="galactic"] .api-toggle input:checked { background: #a18bd6; border-color: #a18bd6; }
html[data-theme="galactic"] .api-toggle input::before { background: #f0eaff; }

/* Conversations and maths keep the same hierarchy as the light palette. */
html[data-theme="galactic"] :is(.message-tutor .message-bubble, .from-tutor .transcript-bubble) { color: var(--ink); background: var(--surface); border-color: var(--line); }
html[data-theme="galactic"] :is(.message-student .message-bubble, .from-student .transcript-bubble) { color: #eee5ff; background: #302742; border-color: #4b3d63; }
html[data-theme="galactic"] .composer:focus-within { border-color: #9e88cc; box-shadow: 0 0 0 3px #9e88cc12; }
html[data-theme="galactic"] .composer textarea { color: var(--ink); background: transparent; scrollbar-color: #52607e transparent; }
html[data-theme="galactic"] .composer .hint-button { color: #dfd2ff; background: var(--accent-soft); border-color: #514568; }
html[data-theme="galactic"] .composer .hint-button:hover:enabled { background: #3a3153; }
html[data-theme="galactic"] .workspace-scroll { scrollbar-color: #46516e transparent; }
html[data-theme="galactic"] .katex { color: inherit; }

/* Feedback colors distinguish success, caution, and errors without bright cards. */
html[data-theme="galactic"] :is(.api-status, .student-status, .settings-saved) { color: #a8e4d0; background: #183333; border-color: #345958; }
html[data-theme="galactic"] .api-status > span { background: #8fd5bd; }
html[data-theme="galactic"] :is(.api-status.is-paused, .student-status.is-inactive, .solution-label, .content-archive-notice) { color: #f0d2a5; background: #352c29; border-color: #64513d; }
html[data-theme="galactic"] .api-status.is-paused > span { background: #e4be83; }
html[data-theme="galactic"] :is(.usage-unconfirmed, .content-archive-notice p) { color: #e4c897; }
html[data-theme="galactic"] :is(.form-errors, .field-errors, .composer-error, .student-delete-link, .content-record-actions > .content-remove, .content-remove) { color: var(--danger); }
html[data-theme="galactic"] .form-errors { background: #38232d; border-color: #69404b; }
html[data-theme="galactic"] .content-removed .content-record { background: #10172a; }
html[data-theme="galactic"] .content-remove-button { color: #ffe3dc; background: #693e4a; border-color: #9a626f; }
html[data-theme="galactic"] .content-remove-button:hover:enabled { color: #fff0ed; background: #80505e; border-color: #b67b88; }
html[data-theme="galactic"] .api-usage { border-color: var(--line); }
html[data-theme="galactic"] :is(dialog, [role="dialog"]) { color: var(--ink); background-color: var(--surface); border-color: var(--line); }
html[data-theme="galactic"] dialog::backdrop { background: #020611b3; }
html[data-theme="galactic"] :is(table, th, td) { border-color: var(--line); }

@media (max-width: 900px) {
  .site-header { gap: 16px; }
  .header-controls { gap: 12px; }
  .account-nav, .teacher-header-nav { column-gap: 13px; }
}
@media (max-width: 560px) {
  .header-controls { width: 100%; justify-content: flex-start; }
  .site-header:has(.header-controls > .header-label) { align-items: center; flex-wrap: nowrap; }
  .site-header:has(.header-controls > .header-label) .header-controls { width: auto; margin-left: auto; }
  .site-header .theme-toggle { min-height: 32px; padding: 6px 8px; font-size: 10px; gap: 4px; }
  .site-header .theme-toggle svg { width: 15px; height: 15px; }
  .account-nav, .teacher-header-nav { gap: 5px 12px; }
  .workspace-page .site-header { flex-basis: auto; min-height: 100px; }
}
@media (max-width: 380px) {
  .account-nav, .teacher-header-nav { column-gap: 9px; }
  .site-header .theme-toggle { padding-inline: 7px; }
}
