/* Shared design tokens and unified light/dark theme system for SEPlanet. */
:root {
  color-scheme: light;
  --paper: #ffffff;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --control-bg: #f6f8fa;
  --control-hover: #eef1f5;
  --overlay: #ffffff;
  --wash: #f6f8fa;
  --soft: #f6eef9;
  --ink: #1f2328;
  --ink-fill: #1f2328;
  --on-ink: #ffffff;
  --body-ink: #2c3542;
  --muted: #59636e;
  --faint: #858b96;
  --line: #e3e7ee;
  --line-soft: #edf0f4;
  --line-strong: #c6ccd7;
  --accent: #681674;
  --accent-hover: #52105c;
  --accent-on: #ffffff;
  --accent-surface: #f7eef9;
  --accent-line: #dac1e3;
  --accent-ring: rgb(104 22 116 / .18);
  --blue: var(--accent);
  --cyan: var(--accent);
  --green: var(--accent);
  --shadow-sm: 0 1px 2px rgb(15 23 42 / .04), 0 4px 12px rgb(15 23 42 / .03);
  --shadow-md: 0 8px 28px rgb(15 23 42 / .08), 0 2px 6px rgb(15 23 42 / .04);
  --shadow-lg: 0 20px 56px rgb(15 21 32 / .18), 0 4px 14px rgb(15 21 32 / .08);
  --float-shadow: 0 12px 40px rgb(23 37 54 / .14), 0 0 0 1px rgb(15 23 42 / .06);
  --track-inset: inset 0 1px 2px rgb(15 23 42 / .045);
  --pill-active-bg: linear-gradient(180deg, #2c323c 0%, #161a21 56%, #101318 100%);
  --pill-active-hover-bg: linear-gradient(180deg, #353c48 0%, #1d222c 56%, #151920 100%);
  --pill-active-fg: #ffffff;
  --pill-active-shadow: inset 0 1px .5px rgb(255 255 255 / .30), inset 0 -1px 1px rgb(0 0 0 / .45), inset 0 0 0 1px rgb(255 255 255 / .08), 0 6px 16px rgb(15 23 42 / .22), 0 2px 4px rgb(15 23 42 / .14);
  --pill-sheen: linear-gradient(180deg, rgb(255 255 255 / .22) 0%, rgb(255 255 255 / 0) 100%);
  --frosted-bg: linear-gradient(180deg, rgb(255 255 255 / .96) 0%, rgb(248 250 253 / .88) 100%);
  --frosted-shadow: inset 0 1px 0 #ffffff, inset 0 0 0 1px rgb(15 23 42 / .06), 0 3px 10px rgb(15 23 42 / .09), 0 1px 2px rgb(15 23 42 / .05);
  --header-bg: rgb(246 248 250 / .84);
  --radius-sm: 10px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-pill: 999px;
}

.brand-symbol { display: block; width: 36px; height: 36px; flex-shrink: 0; }
.brand-symbol img { display: block; width: 36px; height: 36px; }
.theme-logo-dark { display: none !important; }
.about-section > img { border-radius: 50%; }

/* Header icon tools: clean, unified visual rhythm with non-sticky tooltips. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  flex-shrink: 0; width: 40px; height: 40px; padding: 8px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--muted); font: inherit; font-size: 12px;
  line-height: 1; cursor: pointer; touch-action: manipulation;
  transition: color .15s, background-color .15s, border-color .15s;
}
.site-header .theme-toggle[hidden] {
  display: inline-flex !important; visibility: hidden; pointer-events: none;
}
.theme-toggle:hover { color: var(--accent); background: var(--wash); border-color: var(--line); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .theme-moon { display: none; }
.theme-toggle [data-theme-label] { display: none; }
[data-theme="dark"] .theme-toggle .theme-sun { display: none; }
[data-theme="dark"] .theme-toggle .theme-moon { display: block; }

.header-inner > .brand, .masthead > .brand { flex-shrink: 0; }
.header-inner #site-nav, .masthead nav { margin-left: auto; }

/* Subtle desktop-only hover tooltip; never lingers after click focus. */
.site-header .theme-toggle { position: relative; }
.site-header .theme-toggle::after {
  content: attr(aria-label);
  position: absolute; top: calc(100% + 10px); right: 0;
  padding: 6px 10px; border-radius: 7px;
  background: var(--surface-elevated); color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow-md);
  font-size: 12px; line-height: 1.4; white-space: nowrap; pointer-events: none;
  opacity: 0; visibility: hidden; transform: translateY(-2px);
  transition: opacity .14s, transform .14s, visibility .14s; z-index: 30;
}
@media (min-width: 761px) and (hover: hover) and (pointer: fine) {
  .site-header .theme-toggle:not([data-suppress-tip]):hover::after {
    opacity: 1; visibility: visible; transform: translateY(0);
  }
}
@media (max-width: 760px) {
  .nav-ready .header-inner { flex-wrap: nowrap; }
}
@media (max-width: 600px) {
  .masthead { gap: 12px; }
  .masthead nav { gap: 14px; }
}
@media (max-width: 360px) {
  .masthead nav a:first-child { display: none; }
}

/* Unified light & dark semantic palette */
@media screen {
  :root[data-theme="dark"] {
    color-scheme: dark;
    --paper: #0e1319;
    --surface: #151b23;
    --surface-elevated: #1c232d;
    --control-bg: #151b23;
    --control-hover: #1c232d;
    --overlay: #202936;
    --wash: #151b23;
    --soft: #261e34;
    --ink: #e8edf3;
    --ink-fill: #e8edf3;
    --on-ink: #0e1319;
    --body-ink: #c8d2df;
    --muted: #93a0b2;
    --faint: #738195;
    --line: #232b36;
    --line-soft: #1b222c;
    --line-strong: #3a4555;
    --accent: #dfaef0;
    --accent-hover: #f0cdfb;
    --accent-on: #240d2c;
    --accent-surface: #281e36;
    --accent-line: #684b78;
    --accent-ring: rgb(223 174 240 / .24);
    --blue: var(--accent);
    --cyan: var(--accent);
    --green: var(--accent);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .24), 0 4px 12px rgb(0 0 0 / .20);
    --shadow-md: 0 10px 30px rgb(0 0 0 / .42), 0 2px 6px rgb(0 0 0 / .26);
    --shadow-lg: 0 24px 64px rgb(0 0 0 / .58), 0 6px 18px rgb(0 0 0 / .36);
    --float-shadow: 0 14px 42px rgb(0 0 0 / .60), 0 0 0 1px rgb(255 255 255 / .08);
    --track-inset: inset 0 1px 2px rgb(0 0 0 / .32);
    --pill-active-bg: linear-gradient(180deg, #eef3fa 0%, #d0dae8 100%);
    --pill-active-hover-bg: linear-gradient(180deg, #ffffff 0%, #dde6f2 100%);
    --pill-active-fg: #0e1319;
    --pill-active-shadow: inset 0 1px 0 #ffffff, inset 0 -1px 1px rgb(15 23 42 / .18), 0 6px 20px rgb(0 0 0 / .45), 0 0 0 1px rgb(255 255 255 / .20);
    --pill-sheen: linear-gradient(180deg, rgb(255 255 255 / .72) 0%, rgb(255 255 255 / 0) 100%);
    --frosted-bg: linear-gradient(180deg, rgb(255 255 255 / .14) 0%, rgb(255 255 255 / .06) 100%);
    --frosted-shadow: inset 0 1px 0 rgb(255 255 255 / .26), inset 0 0 0 1px rgb(255 255 255 / .09), 0 4px 14px rgb(0 0 0 / .38);
    --header-bg: rgb(21 27 35 / .84);
    background: var(--paper);
    color: var(--ink);
  }

  body { background: var(--paper); color: var(--ink); }
  [data-theme="dark"] body { background: var(--paper); color: var(--ink); }
  [data-theme="dark"] .theme-logo-light { display: none !important; }
  [data-theme="dark"] .theme-logo-dark { display: block !important; }

  /* Shared interactive button & tactile glass pill semantics across both themes */
  :root[data-theme] :is(.primary, .primary-link,
    .filter-group button[aria-pressed="true"], .filter-controls button[aria-pressed="true"]) {
    background: var(--pill-active-bg);
    border-color: transparent;
    color: var(--pill-active-fg);
    box-shadow: var(--pill-active-shadow);
  }
  :root[data-theme] :is(.primary:hover, .primary-link:hover) {
    background: var(--pill-active-hover-bg);
    border-color: transparent;
    color: var(--pill-active-fg);
  }
  :root[data-theme] :is(.button:not(.primary, .primary-link), .reading-tools button,
    .study-note .button, .answer-actions button) {
    color: var(--ink);
    background-color: var(--control-bg);
    border-color: transparent;
  }
  :root[data-theme] :is(.button:not(.primary, .primary-link), .reading-tools button,
    .study-note .button, .answer-actions button):hover {
    color: var(--ink);
    border-color: transparent;
    background-color: var(--control-hover);
  }
  :root[data-theme] :is(.filter-group button[aria-pressed="false"], .filter-controls button[aria-pressed="false"]) {
    color: var(--muted);
    background-color: transparent;
    border-color: transparent;
  }
  :root[data-theme] :is(.filter-group button[aria-pressed="false"], .filter-controls button[aria-pressed="false"]):hover {
    color: var(--ink);
    border-color: transparent;
    background-color: var(--control-hover);
  }
  :root[data-theme] :is(a, button, input, select, textarea, summary):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
  }
  :root[data-theme] #site-nav a:is(:hover, [aria-current="page"]),
  :root[data-theme] .site-header :is(.theme-toggle, .portal-search-toggle, .menu-toggle):is(:hover, :focus-visible) {
    color: var(--accent);
  }
  :root[data-theme] :is(.footer-links a, .course-actions a, .breadcrumb a,
    .article-end a, .case-reading a, .public-entry-links a,
    .reader-body a:not(.button, .primary-link),
    .prose a:not(.button, .primary-link), .study-prose a:not(.button, .primary-link)) {
    color: var(--accent);
    text-decoration-color: var(--accent-line);
  }
  :root[data-theme] :is(.text-link, .home-topics a, .footer-links a, .course-actions a,
    .public-entry-links a, .prose a:not(.button, .primary-link), .reader-body a:not(.button, .primary-link)):hover {
    color: var(--accent-hover);
    text-decoration-color: currentColor;
  }
  :root[data-theme] :is(.article-card, .next-prev > a):hover { border-color: var(--accent); }

  /* Dark mode surfaces, typography & legacy course components */
  [data-theme="dark"] :is(.skip-link, .skip, .article-card, .project-feature, .article-content, .next-prev > a) {
    background: var(--surface); border-color: var(--line);
  }
  [data-theme="dark"] :is(.menu-toggle,
    .study-disclosure, .hint-disclosure, .study-search input, .search-label input,
    .course-card, .lesson-answer textarea) {
    background: var(--surface); color: var(--ink); border-color: var(--line);
  }
  [data-theme="dark"] :is(.search-row input, .select-group select, .reading-filters input, .reading-filters select) {
    background: var(--control-bg); color: var(--ink); border-color: transparent;
  }
  [data-theme="dark"] input::placeholder,
  [data-theme="dark"] textarea::placeholder { color: var(--muted); opacity: 1; }
  [data-theme="dark"] :is(.prose, .prose p, .prose li, .prose dd, .prose blockquote,
    .article-section p, .evidence-table td) { color: var(--body-ink); }
  [data-theme="dark"] :is(.prose code, .study-prose code, .lesson09-reader code) {
    background: var(--accent-surface); color: var(--accent);
  }
  [data-theme="dark"] :is(.prose pre, .study-prose pre, .lesson09-reader pre) {
    background: #0b1019; border-color: var(--line);
  }
  [data-theme="dark"] :is(.prose pre code, .study-prose pre code, .lesson09-reader pre code) {
    background: none; color: var(--ink);
  }
  [data-theme="dark"] :is(.prose section.lesson-answer, .course-card.cs,
    .reading-course-feature, .public-note-entry) {
    background: var(--accent-surface);
  }
  [data-theme="dark"] .study-note {
    background: var(--accent-surface); color: var(--ink);
    border-color: var(--accent-line); border-left-color: var(--accent);
  }
  [data-theme="dark"] .study-note textarea {
    background: var(--paper); color: var(--ink); border-color: var(--line-strong);
  }
  [data-theme="dark"] .study-note .button {
    background: var(--surface); color: var(--accent); border-color: var(--accent-line);
  }
  [data-theme="dark"] .note-conflict { background: #30281c; border-color: #997b49; }
  [data-theme="dark"] :is(.course-picker article, .public-start) { border-color: var(--line); }
  [data-theme="dark"] .badge { background: var(--accent-surface); color: var(--accent); }
  [data-theme="dark"] .badge.preview { background: #352d1d; color: #e8cf8e; }
  [data-theme="dark"] .emblem-core { background: var(--wash); color: var(--accent); border-color: var(--line); }
  [data-theme="dark"] :is(.breadcrumb, .sidebar summary, .sidebar summary span, .series-menu nav a,
    .series-menu nav a > span:first-child, .toc-menu nav a, .sidebar-note, .byline, .byline small,
    .reading-time, .next-prev small, .related > span:first-child, .footer, .series-subtitle,
    .series-description, .series-meta, .source-link, .orbit-label, .reading-path,
    .reading-path > span, .reading-path b, .course-search > span, .search-status,
    .lesson-number, .row-kicker, .row-summary, .row-arrow, .series-about p) { color: var(--muted); }
  [data-theme="dark"] .footer > a { color: var(--ink); }
  [data-theme="dark"] .series-menu nav a[aria-current] { background: var(--accent-surface); color: var(--accent); }
  [data-theme="dark"] .sidebar nav a:hover { color: var(--accent); background: var(--wash); }
  [data-theme="dark"] .lesson-row:hover { background: var(--surface); }
  [data-theme="dark"] .series-about { border-left-color: var(--accent-line); }
  [data-theme="dark"] .reader-body { color: var(--ink); }
  [data-theme="dark"] .lesson09-reader th { background: var(--wash); color: var(--ink); }
  [data-theme="dark"] .lesson09-reader .course-note { background: var(--accent-surface); border-color: var(--accent-line); border-left-color: var(--accent); }
  [data-theme="dark"] .lesson09-reader .course-note > strong { color: var(--accent); }
  [data-theme="dark"] :is(.lesson09-reader .self-check summary, .source-details summary,
    .enhanced-course-reader .lab-notes > summary) { color: var(--ink); }
  [data-theme="dark"] :is(.lesson09-reader .self-check[open], .enhanced-course-reader .lab-notes[open] > summary,
    .lesson09-reader .sources-panel) { background: var(--accent-surface); border-color: var(--accent-line); }
  [data-theme="dark"] .lesson09-reader .self-check[open] summary { color: var(--accent); }
  [data-theme="dark"] .source-grid a { border-color: var(--line); }
  [data-theme="dark"] .reading-course-map nav a { background: var(--surface); border: 1px solid var(--line); }
  [data-theme="dark"] .reading-course-map nav span,
  [data-theme="dark"] .reading-course-map nav small { color: var(--muted); }
  [data-theme="dark"] .reading-course-map summary { color: var(--accent); }
  [data-theme="dark"] .reading-lens:hover { background: var(--accent-surface); }
  [data-theme="dark"] ::selection { background: rgb(223 174 240 / .28); color: #fff; }

  /* Soften light-background illustrations/SVGs in dark mode while preserving source colour semantics. */
  [data-theme="dark"] .entry-cover {
    filter: brightness(.90) contrast(1.04);
  }
  [data-theme="dark"] .lesson09-reader .course-figure > a {
    background: #eef1f6;
    border-color: var(--line-strong);
  }
  [data-theme="dark"] .lesson09-reader .course-figure img,
  [data-theme="dark"] .reader-body svg {
    filter: brightness(.91) contrast(1.03);
    border-radius: 10px;
  }
  [data-theme="dark"] .masthead { background: var(--header-bg); }
  [data-theme="dark"] .site-header { background: transparent; }
}

@media print {
  :root { color-scheme: light; }
  .theme-toggle, .reading-progress, .back-to-top, .cmd-search-dialog { display: none !important; }
}
