/* AI Math Explorer: Editorial Base Light & Dark Stylesheet */
:root {
  --bg: #f9f7f2;
  --surface: #ffffff;
  --surface-alt: #f2eee5;
  --text: #191815;
  --text-secondary: #3f3c36;
  --muted: #58534b;
  --line: #e2ddd2;
  --line-strong: #cbc3b4;
  --accent: #8c3810;
  --accent-hover: #6c290a;
  --accent-soft: #f5eae1;
  --accent-ink: #ffffff;
  --ink-btn: #1d1b18;
  --ink-btn-text: #faf8f4;
  --math-blue: #1e4d7b;
  --math-blue-soft: #eaf1f8;
  --code-bg: #f1ede4;
  --shadow-sm: 0 1px 2px rgba(25, 24, 21, 0.05);
  --shadow-md: 0 6px 20px rgba(25, 24, 21, 0.07);
  --b-proved-bg: #e4f1ea;
  --b-proved-fg: #185136;
  --b-counter-bg: #f6e7df;
  --b-counter-fg: #86330c;
  --b-bound-bg: #ede9f7;
  --b-bound-fg: #44317a;
  --b-conj-bg: #e7eff7;
  --b-conj-fg: #1c4a76;
  --b-lean-bg: #e8efe9;
  --b-lean-fg: #1f5438;
  --b-cited-bg: #f6eed7;
  --b-cited-fg: #6b4608;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  --radius-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131210;
    --surface: #1c1a17;
    --surface-alt: #24211d;
    --text: #ede9e0;
    --text-secondary: #cdc7bb;
    --muted: #aba599;
    --line: #322e28;
    --line-strong: #484239;
    --accent: #e89b6c;
    --accent-hover: #f2b48d;
    --accent-soft: #2b211a;
    --accent-ink: #161310;
    --ink-btn: #ede9e0;
    --ink-btn-text: #151412;
    --math-blue: #83b8eb;
    --math-blue-soft: #182430;
    --code-bg: #23201c;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.32);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.42);
    --b-proved-bg: #172b21;
    --b-proved-fg: #7fd4a6;
    --b-counter-bg: #2f1f16;
    --b-counter-fg: #f0a476;
    --b-bound-bg: #241f33;
    --b-bound-fg: #c2b3f2;
    --b-conj-bg: #182635;
    --b-conj-fg: #87bcf0;
    --b-lean-bg: #172c22;
    --b-lean-fg: #82d6a9;
    --b-cited-bg: #2e2514;
    --b-cited-fg: #ecc872;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #131210;
  --surface: #1c1a17;
  --surface-alt: #24211d;
  --text: #ede9e0;
  --text-secondary: #cdc7bb;
  --muted: #aba599;
  --line: #322e28;
  --line-strong: #484239;
  --accent: #e89b6c;
  --accent-hover: #f2b48d;
  --accent-soft: #2b211a;
  --accent-ink: #161310;
  --ink-btn: #ede9e0;
  --ink-btn-text: #151412;
  --math-blue: #83b8eb;
  --math-blue-soft: #182430;
  --code-bg: #23201c;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.32);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.42);
  --b-proved-bg: #172b21;
  --b-proved-fg: #7fd4a6;
  --b-counter-bg: #2f1f16;
  --b-counter-fg: #f0a476;
  --b-bound-bg: #241f33;
  --b-bound-fg: #c2b3f2;
  --b-conj-bg: #182635;
  --b-conj-fg: #87bcf0;
  --b-lean-bg: #172c22;
  --b-lean-fg: #82d6a9;
  --b-cited-bg: #2e2514;
  --b-cited-fg: #ecc872;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.62;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; top: -120px; left: 16px; z-index: 200;
  padding: 10px 16px; background: var(--ink-btn); color: var(--ink-btn-text);
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  text-decoration: none; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 12px; }

.wrap { max-width: 1220px; margin: 0 auto; padding: 0 24px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 60;
  background: color-mix(in srgb, var(--bg) 93%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans); font-size: 14.5px;
}
.header-row {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px 20px; min-height: 58px; padding-top: 6px; padding-bottom: 6px;
}
.brand {
  display: inline-flex; align-items: center; gap: 9px; min-height: 44px;
  color: var(--text); font-weight: 700; font-size: 15.5px;
  text-decoration: none; letter-spacing: -0.01em;
}
.brand:hover { color: var(--accent); }
.brand-mark { flex-shrink: 0; }

.site-nav {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin-left: auto;
}
.site-nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px;
  color: var(--muted); text-decoration: none; font-weight: 500;
  border-radius: var(--radius-sm); position: relative; white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--surface-alt); }
.site-nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.site-nav a[aria-current="page"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 6px;
  height: 2px; background: var(--accent); border-radius: 2px;
}

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); font-family: var(--sans); font-size: 13.5px;
  font-weight: 500; cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-icon { font-size: 15px; line-height: 1; }

main, main.wrap { flex: 1 0 auto; width: 100%; padding-top: 26px; padding-bottom: 56px; }
main:focus { outline: none; }

/* Shared Buttons & Range Sliders */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: var(--radius-sm);
  font-family: var(--sans); font-size: 14.5px; font-weight: 600;
  text-decoration: none; border: 1px solid transparent; cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}
.btn-primary { background: var(--ink-btn); color: var(--ink-btn-text); }
.btn-primary:hover { background: var(--accent); color: var(--accent-ink); }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); border-color: var(--text); }
.btn-subtle { background: var(--surface-alt); color: var(--text); border-color: var(--line); }
.btn-subtle:hover { border-color: var(--accent); color: var(--accent); }

.range-input {
  width: 100%; height: 6px; margin: 4px 0 2px; cursor: pointer;
  accent-color: var(--accent);
}
.range-input-lean { accent-color: var(--b-lean-fg); }
.range-input-compared { accent-color: var(--math-blue); }

details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; flex-shrink: 0; width: 0.42em; height: 0.42em; margin-right: 0.6em;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s ease;
}
details[open] > summary::before { transform: rotate(45deg); }

/* Editorial Prose & About Page */
.prose { max-width: 780px; margin: 0 auto; min-width: 0; }
.prose h1 {
  font-size: clamp(1.75rem, 2.8vw, 2.25rem);
  line-height: 1.18; letter-spacing: -0.015em;
  margin: 0 0 0.45em; text-wrap: balance;
}
.prose h2 {
  font-size: 1.35rem; line-height: 1.25; margin: 1.8em 0 0.6em;
  padding-top: 0.75em; border-top: 1px solid var(--line); scroll-margin-top: 76px;
}
.prose h3 { font-size: 1.08rem; line-height: 1.3; margin: 1.3em 0 0.4em; }
.prose p, .prose li { color: var(--text-secondary); overflow-wrap: break-word; }
.prose code {
  font-family: var(--mono); font-size: 0.86em; background: var(--code-bg);
  padding: 0.12em 0.35em; border-radius: 4px; overflow-wrap: anywhere;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--line); font-family: var(--sans);
  font-size: 14px; color: var(--muted); padding: 24px 0 36px;
}
.footer-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.site-footer p { margin: 3px 0; }
.footer-sub { font-size: 13px; }
.footer-contact { color: var(--accent); text-decoration: none; }
.footer-contact:hover { text-decoration: underline; }
.back-top { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; text-decoration: none; }
.back-top:hover { text-decoration: underline; }

/* Responsive Breakpoints */
@media (max-width: 900px) {
  .site-header { position: static; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .header-row { min-height: 46px; gap: 2px 12px; padding-top: 4px; padding-bottom: 4px; }
  .theme-toggle { order: 2; margin-left: auto; padding: 0 10px; }
  .theme-label { display: none; }
  .site-nav {
    order: 3; width: 100%; margin-left: 0; gap: 2px 6px;
    border-top: 1px solid var(--line); justify-content: center; padding: 4px 0;
  }
  .site-nav a { white-space: nowrap; padding: 0 9px; font-size: 13.5px; min-height: 36px; }
  .site-nav a[aria-current="page"]::after { left: 9px; right: 9px; bottom: 3px; }
}

@media (max-width: 700px) {
  .wrap { padding: 0 16px; }
  body { font-size: 17px; }
  main, main.wrap { padding-top: 14px; padding-bottom: 44px; }
}

@media (max-width: 560px) {
  .header-row { min-height: 40px; padding-top: 2px; padding-bottom: 0; }
  .brand, .theme-toggle { min-height: 38px; }
  .site-nav { gap: 2px 4px; padding: 4px 0 6px; }
  .site-nav a { font-size: 12.5px; min-height: 32px; padding: 0 7px; }
  .site-nav a[aria-current="page"]::after { left: 7px; right: 7px; bottom: 2px; }
}

@media print {
  :root, :root[data-theme="dark"] {
    --bg: #ffffff; --surface: #ffffff; --surface-alt: #f7f7f7;
    --text: #000000; --text-secondary: #111111; --muted: #333333;
    --line: #cccccc; --accent: #000000; --accent-soft: #f5f5f5;
  }
  .site-header, .back-top, .skip-link { display: none !important; }
  body { font-size: 11.5pt; line-height: 1.5; background: #fff; color: #000; }
  .wrap, .prose { max-width: 100%; padding: 0; }
  a { color: #000; text-decoration: underline; }
}
