/* Erklärbär – shared styles */
:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f2eee7;
  --text: #1f1d1a;
  --muted: #6b655c;
  --line: #e2ddd3;
  --accent: #c2571a;
  --accent-soft: #f6e3d6;
  --ok: #2f7d4f;
  --warn: #b23a3a;
  --alice: #d1495b;
  --bob: #2e6fd1;
  --eve: #7a5bb5;
  --series-1: #c2571a;
  --series-2: #2e6fd1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --surface: #1f1e1b;
    --surface-2: #2a2824;
    --text: #ece8e1;
    --muted: #a39d93;
    --line: #36332e;
    --accent: #f08a4b;
    --accent-soft: #3a2a20;
    --ok: #5cc28a;
    --warn: #ef7a7a;
    --alice: #f07583;
    --bob: #6ea2f2;
    --eve: #a98ae0;
    --series-1: #cf6a2c;
    --series-2: #5a8fe0;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --surface: #1f1e1b; --surface-2: #2a2824; --text: #ece8e1;
  --muted: #a39d93; --line: #36332e; --accent: #f08a4b; --accent-soft: #3a2a20;
  --ok: #5cc28a; --warn: #ef7a7a; --alice: #f07583; --bob: #6ea2f2; --eve: #a98ae0;
  --series-1: #cf6a2c; --series-2: #5a8fe0;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 var(--font);
}
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .92em; }

.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; height: 56px;
}
.brand {
  font-weight: 700; text-decoration: none; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.brand svg { width: 26px; height: 26px; }
.theme-toggle {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 14px; cursor: pointer;
}

/* Typography */
h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.15; margin: 40px 0 8px; letter-spacing: -.01em; }
h2 { font-size: 24px; margin: 48px 0 8px; }
h3 { font-size: 18px; margin: 24px 0 4px; }
.lead { font-size: 19px; color: var(--muted); margin: 0 0 24px; max-width: 46em; }
p { max-width: 46em; }
.crumbs { font-size: 14px; color: var(--muted); margin-top: 24px; }
.crumbs a { color: var(--muted); }

/* Topic grid */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 20px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  margin-bottom: 64px;
}
.card {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: var(--text); overflow: hidden;
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .thumb { aspect-ratio: 16/9; background: var(--surface-2); display: grid; place-items: center; }
.card .thumb svg { width: 70%; height: 70%; }
.card .body { padding: 14px 16px 16px; }
.card h3 { margin: 0 0 4px; }
.card p { margin: 0; color: var(--muted); font-size: 15px; }
.card .tag { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 600; }
.card.placeholder { border-style: dashed; color: var(--muted); align-items: center; justify-content: center; min-height: 200px; padding: 16px; text-align: center; }
.card.placeholder:hover { transform: none; border-color: var(--line); }

/* Explanation building blocks */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin: 20px 0;
}
.panel svg { display: block; width: 100%; height: auto; }
.caption { font-size: 14px; color: var(--muted); margin: 8px 0 0; }
.controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin-top: 16px; }
.controls label { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.controls input[type="range"] { width: 160px; accent-color: var(--accent); }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 8px 16px; font: inherit; font-size: 15px; cursor: pointer;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: .4; cursor: default; }
.callout {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  padding: 12px 16px; border-radius: 0 10px 10px 0; margin: 20px 0; max-width: 46em;
}
.callout p { margin: 0; }
.steps-indicator { display: flex; gap: 6px; margin-bottom: 12px; }
.steps-indicator span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.steps-indicator span.on { background: var(--accent); }
.step-text { min-height: 4.8em; margin: 12px 0 0; }
input[type="text"], input[type="search"], textarea {
  width: 100%; font: inherit; font-family: var(--mono); font-size: 15px;
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; padding: 24px 0 40px; margin-top: 64px; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; }
.pager .pg { display: flex; flex-direction: column; gap: 2px; max-width: 48%; min-width: 0; overflow-wrap: anywhere; hyphens: auto; text-decoration: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--surface); color: var(--text); }
.pager .pg:hover { border-color: var(--accent); }
.pager .pg.next { margin-left: auto; text-align: right; }
.pager .pg-dir { font-size: 13px; color: var(--muted); }
.pager .pg-title { font-weight: 600; color: var(--accent); }

/* Navigation: header search, table of contents, related topics */
.header-actions { display: flex; align-items: center; gap: 8px; }
.search-btn { display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 4px 10px 4px 10px; font: inherit; font-size: 14px; cursor: pointer; }
.search-btn svg { width: 15px; height: 15px; }
.search-btn kbd { font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--muted); }
.search-btn:hover, .theme-toggle:hover { border-color: var(--accent); color: var(--text); }
@media (max-width: 480px) { .search-btn span, .search-btn kbd { display: none; } }
.search-dlg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; }
.search-dlg[hidden] { display: none; }
.search-panel { width: 100%; max-width: 620px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0,0,0,.25); overflow: hidden; }
.search-panel .search-input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; font-family: var(--font); font-size: 17px; padding: 14px 16px; background: var(--surface); outline: none; }
.search-list { list-style: none; margin: 0; padding: 6px; max-height: 60vh; overflow-y: auto; }
.search-list li a { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
.search-list li[aria-selected="true"] a, .search-list li a:hover { background: var(--accent-soft); }
.search-list .sr-cat { grid-row: span 2; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); font-weight: 600; padding-top: 3px; min-width: 7.5em; }
.search-list .sr-kurz { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-list .search-hint { padding: 12px 10px; color: var(--muted); font-size: 14px; }
.search-foot { border-top: 1px solid var(--line); padding: 8px 14px; font-size: 12px; color: var(--muted); }
@media (max-width: 560px) { .search-list .sr-cat { grid-row: auto; min-width: 0; } .search-list li a { grid-template-columns: 1fr; } }
body.noscroll { overflow: hidden; }

.toc { max-width: 46em; margin: 0 0 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 10px 16px; }
.toc summary { cursor: pointer; font-weight: 600; font-size: 15px; color: var(--muted); }
.toc ol { margin: 8px 0 4px; padding-left: 1.4em; columns: 2 18em; column-gap: 28px; font-size: 15px; }
.toc li { margin: 3px 0; break-inside: avoid; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }
h2[id] { scroll-margin-top: 16px; }

.related { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); }
.related-head { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.related-list { display: flex; flex-wrap: wrap; gap: 8px; }
.related .rel { overflow-wrap: anywhere; min-width: 0; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 14px; text-decoration: none; color: var(--text); background: var(--surface); }
.related a.rel:hover { border-color: var(--accent); }
.related .rel.cur { background: var(--accent); border-color: var(--accent); color: #fff; }

.to-top { position: fixed; right: 16px; bottom: 16px; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
.to-top.show { opacity: .9; pointer-events: auto; }

/* Overview: search and sticky category bar */
.ov-search { margin: 8px 0 12px; }
.ov-search input { font-family: var(--font); font-size: 17px; }
.filters.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0; margin: 0 0 8px; border-bottom: 1px solid var(--line); }
.cat-desc { color: var(--muted); font-size: 15px; margin: -8px 0 14px; }
.cat { scroll-margin-top: 64px; }
.ov-count { color: var(--muted); font-size: 15px; margin: 0 0 12px; }

/* Sources */
.sources { margin-top: 56px; padding-top: 8px; border-top: 1px solid var(--line); }
.sources h2 { margin-top: 24px; }
.sources ol, .sources ul { padding-left: 1.4em; max-width: 46em; }
.sources li { margin: 0 0 10px; font-size: 15px; }
.sources li .note { color: var(--muted); }

/* Generic tooltip for charts */
.tip {
  position: fixed; pointer-events: none; z-index: 10; display: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; box-shadow: var(--shadow);
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .panel { padding: 14px; }
  .controls input[type="range"] { width: 120px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (max-width: 560px) {
  .filters.sticky { position: static; }
}
