/* TMG Editorial Design System (Offline-First, Low-Glare) */
:root, [data-theme="dark"] {
  --bg: #141619;
  --surface: #1c1f24;
  --border: #2d323b;
  --text: #e2e0d8;
  --muted: #9aa0a6;
  --accent: #6cb6ff;
  --warn: #e59866;
}
[data-theme="light"] {
  --bg: #f6f3ec;
  --surface: #ede9df;
  --border: #d6d0c4;
  --text: #23211d;
  --muted: #635e54;
  --accent: #1d5fa7;
  --warn: #b45309;
}
*, *::before, *::after { box-sizing: border-box; }
html { font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem); scroll-behavior: smooth; overflow-x: hidden; }
body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Georgia, serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
code, pre, .math-inline, .math-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: 48px; padding: 0 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar-title {
  font-size: 0.95rem; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; color: var(--text); text-decoration: none;
}
.icon-btn {
  min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); font-size: 1rem; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { border-color: var(--border); background: var(--bg); }
.drawer {
  position: fixed; top: 48px; left: 0; bottom: 0; width: 290px; max-width: 85vw;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px; overflow-y: auto; z-index: 60;
  transform: translateX(-100%); transition: transform 0.2s ease;
}
.drawer.open { transform: translateX(0); }
.drawer h3 { margin: 0 0 10px 0; font-size: 0.85rem; text-transform: uppercase; color: var(--muted); }
.drawer a { display: block; padding: 6px 0; color: var(--text); text-decoration: none; font-size: 0.9rem; }
.drawer a.lvl-3 { padding-left: 14px; color: var(--muted); font-size: 0.85rem; }
.drawer a:hover { color: var(--accent); }
.page-shell { display: flex; justify-content: center; gap: 32px; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.container { max-width: 65ch; width: 100%; margin: 0 auto; padding: 24px 6px 64px; min-width: 0; }
.right-toc {
  display: none; position: sticky; top: 68px; align-self: flex-start;
  width: 240px; max-height: calc(100vh - 88px); overflow-y: auto;
  padding-left: 14px; border-left: 1px solid var(--border); font-size: 0.82rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.right-toc::-webkit-scrollbar { width: 4px; }
.right-toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.right-toc h3 { margin: 0 0 8px 0; font-size: 0.75rem; text-transform: uppercase; color: var(--muted); }
.right-toc a { display: block; padding: 4px 0; color: var(--muted); text-decoration: none; line-height: 1.35; }
.right-toc a.lvl-3 { padding-left: 12px; font-size: 0.78rem; }
.right-toc a:hover, .right-toc a.active, .drawer a.active { color: var(--accent); font-weight: 600; }
@media (min-width: 1100px) { .right-toc { display: block; } }
h1, h2, h3, h4 { line-height: 1.25; margin-top: 2em; margin-bottom: 0.6em; }
h1 { margin-top: 0.5em; font-size: 1.8rem; }
a { color: var(--accent); }
pre { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 14px; overflow-x: auto; font-size: 0.85rem; }
code { background: var(--surface); padding: 2px 5px; border-radius: 4px; font-size: 0.88em; }
pre code { background: none; padding: 0; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 1.2em 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
th { background: var(--surface); }
figure { margin: 1.6em 0; text-align: center; }
figure img { max-width: 100%; height: auto; border-radius: 6px; cursor: zoom-in; border: 1px solid var(--border); }
figcaption { margin-top: 8px; font-size: 0.85rem; color: var(--muted); }
.callout { border-left: 3px solid var(--accent); background: var(--surface); padding: 10px 14px; margin: 1.2em 0; border-radius: 0 6px 6px 0; }
.callout-warning, .callout-caution { border-left-color: var(--warn); }
.callout-faq summary { cursor: pointer; font-weight: 600; list-style: none; padding: 4px 0; }
.callout-faq summary::before { content: "▸ "; color: var(--accent); }
.callout-faq[open] summary::before { content: "▾ "; }
.callout-body { margin-top: 8px; font-size: 0.95rem; }
.math-display { background: var(--surface); border: 1px solid var(--border); padding: 10px 14px; border-radius: 6px; overflow-x: auto; margin: 1em 0; text-align: center; }
.mermaid-block { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 10px; margin: 1em 0; overflow-x: auto; }
.mermaid-block svg { cursor: zoom-in; max-width: 100%; height: auto; }
.mermaid-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; }
.missing-asset { border: 1px dashed var(--warn); padding: 14px; border-radius: 6px; color: var(--warn); text-align: center; margin: 1em 0; }
.page-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--border); }
.page-nav a { color: var(--accent); text-decoration: none; font-weight: 600; }
.status-pill { display: inline-block; font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.glossary-card {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(92vw, 540px); max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; z-index: 90; display: none;
}
.glossary-card.open { display: block; }
.glossary-card-hdr { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.glossary-card-title { font-weight: 700; font-size: 1rem; color: var(--accent); }
.glossary-card-body { font-size: 0.92rem; line-height: 1.55; margin-bottom: 10px; }
.tok-kw { color: #ff7b72; font-weight: 600; }
.tok-str { color: #a5d6ff; }
.tok-num { color: #79c0ff; }
.tok-cmt { color: var(--muted); font-style: italic; }
.tok-type { color: #ffa657; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 100; display: none; flex-direction: column; }
.lightbox.open { display: flex; }
.lightbox-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 10px; }
.lightbox-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 16px; }
.lightbox-stage img { max-width: 95vw; max-height: 85vh; transition: transform 0.15s ease; transform-origin: center center; }
