:root {
  --bg: #ffffff; --fg: #1d2330; --muted: #5b6475; --line: #dde1ea;
  --accent: #0b6e8a; --soft: #f3f6fa; --warn-bg: #fff6df; --warn-fg: #6b4e00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d; --fg: #e4e8ef; --muted: #98a2b3; --line: #2a3140;
    --accent: #5cc3df; --soft: #1a202b; --warn-bg: #3a2f10; --warn-fg: #f2d98a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.top { display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.brand { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--fg); }
.top-links { margin-left: auto; }
.menu-btn { display: none; background: none; border: 1px solid var(--line); color: var(--fg);
  border-radius: 6px; padding: 4px 10px; font-size: 1.1rem; }
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); max-width: 1300px; margin: 0 auto; }
.side { padding: 16px; border-right: 1px solid var(--line); font-size: .92rem;
  position: sticky; top: 53px; height: calc(100vh - 53px); overflow-y: auto; }
.side ul { list-style: none; padding-left: 14px; margin: 4px 0; }
.side summary { cursor: pointer; font-weight: 600; margin: 6px 0; }
.side summary a { text-decoration: none; color: var(--fg); }
.side li.current > a { font-weight: 600; }
.content { padding: 24px clamp(16px, 4vw, 48px) 64px; min-width: 0; max-width: 900px; }
h1 { line-height: 1.2; margin-top: 0; }
.lead { font-size: 1.1rem; color: var(--muted); }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.banner { background: var(--warn-bg); color: var(--warn-fg); padding: 8px 12px; border-radius: 6px; }
.prose h2 { margin-top: 2.2rem; padding-top: .6rem; border-top: 1px solid var(--line); }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--soft); }
.prose pre { background: var(--soft); padding: 12px; overflow-x: auto; border-radius: 6px; }
.prose code { font-size: .9em; }
.term { text-decoration: underline dotted; color: inherit; cursor: help; }
.missing-term { background: #ffd6d6; color: #8a0000; padding: 0 3px; border-radius: 3px; }
.toc { margin: 12px 0 20px; font-size: .9rem; }
.toc ul { columns: 2; padding-left: 20px; }
.stage-card { border: 1px solid var(--line); border-radius: 10px; padding: 8px 20px 12px; margin: 16px 0; }
.stage-card h2 { margin: 8px 0; }
.count { color: var(--muted); font-size: .8rem; margin-left: 8px; }
.topic-list { list-style: none; padding: 0; }
.topic-list li { margin: 12px 0; }
.pager { display: flex; justify-content: space-between; margin-top: 40px; gap: 12px; }
.calculator, .plot, .gated { border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 12px 0; background: var(--soft); }
.plot { min-height: 340px; padding: 4px; }
.calc-row { display: grid; grid-template-columns: 1fr 110px 1fr; gap: 10px; align-items: center; margin: 6px 0; }
.calc-row input[type=number] { width: 100%; padding: 4px 6px; }
.calc-out { margin-top: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.gloss-tools { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.gloss-tools input { flex: 1; min-width: 200px; padding: 6px 10px; }
.glossary dt { font-weight: 600; margin-top: 18px; }
.glossary dd { margin: 4px 0 0; }
.glossary .kind { font-size: .72rem; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 0 6px; margin-left: 6px; }
.meta { color: var(--muted); font-size: .88rem; margin: 2px 0; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .menu-btn { display: inline-block; }
  .side { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  body.nav-open .side { display: block; }
  .calc-row { grid-template-columns: 1fr 1fr; }
  .calc-row span { grid-column: 1 / -1; }
  .toc ul { columns: 1; }
}
@media print { .top, .side, .pager, .menu-btn { display: none; } .layout { display: block; } }
.foot { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; max-width: 1300px;
  margin: 0 auto; padding: 18px 20px 28px; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.legal h2 { margin-top: 1.8rem; }
.legal .updated { color: var(--muted); }
.top-links { display: flex; align-items: center; gap: 14px; }
.top-links .btn { padding: 4px 12px; border: 1px solid var(--accent); border-radius: 6px; text-decoration: none; }
form.inline { display: inline; margin: 0; }
button.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.authbox { max-width: 520px; }
.authbox label.field { display: block; margin: 12px 0 4px; font-weight: 600; }
.authbox input[type=text], .authbox input[type=email], .authbox input[type=password] { width: 100%; padding: 8px 10px; font: inherit; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.authbox .check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; font-weight: 400; }
.authbox .check input { margin-top: 5px; }
.authbox fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 18px 0; padding: 6px 14px 10px; }
.authbox legend { font-weight: 600; padding: 0 6px; }
.authbox button.primary { padding: 9px 18px; font: inherit; font-weight: 600; border: 0; border-radius: 6px; background: var(--accent); color: var(--bg); cursor: pointer; }
.errors { border: 1px solid #c0392b; background: rgba(192,57,43,.1); border-radius: 6px; padding: 8px 14px; }
.errors ul { margin: 4px 0; padding-left: 18px; }
.notice { border: 1px solid var(--accent); border-radius: 6px; padding: 8px 14px; }
.small { color: var(--muted); font-size: .88rem; }
table.consents { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.consents th, table.consents td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }

/* Sign-in (Firebase): Google button, "or" divider, busy state */
.authbox button.secondary { padding: 9px 18px; font: inherit; font-weight: 600; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); cursor: pointer; width: 100%; }
.authbox .divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 18px 0; }
.authbox .divider::before, .authbox .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.authbox button[disabled] { opacity: .6; cursor: progress; }
.authbox .actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
