:root {
  --bg: #f5f1ea;
  --surface: #fffdf9;
  --surface-2: #f0ebe2;
  --ink: #1f1b16;
  --ink-2: #463f36;
  --muted: #6b6358;
  --line: #e3dccf;
  --accent: #6b2d2d;
  --accent-ink: #fffdf9;
  --accent-soft: #f3e7e4;
  --ok: #2f6b3f;
  --ok-soft: #e4f0e6;
  --warn: #855600;
  --warn-soft: #fbefd5;
  --bad: #9b2c2c;
  --bad-soft: #f8e3e3;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(40 30 20 / 0.06), 0 2px 10px rgb(40 30 20 / 0.04);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161412;
    --surface: #1f1c19;
    --surface-2: #2a2622;
    --ink: #efe9df;
    --ink-2: #d4ccbf;
    --muted: #a59c8e;
    --line: #3a342d;
    --accent: #d99a8f;
    --accent-ink: #1f1210;
    --accent-soft: #3a2422;
    --ok: #8fcf9c;
    --ok-soft: #1d3022;
    --warn: #e9c36b;
    --warn-soft: #3a2f14;
    --bad: #f0a0a0;
    --bad-soft: #3d1e1e;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161412;
  --surface: #1f1c19;
  --surface-2: #2a2622;
  --ink: #efe9df;
  --ink-2: #d4ccbf;
  --muted: #a59c8e;
  --line: #3a342d;
  --accent: #d99a8f;
  --accent-ink: #1f1210;
  --accent-soft: #3a2422;
  --ok: #8fcf9c;
  --ok-soft: #1d3022;
  --warn: #e9c36b;
  --warn-soft: #3a2f14;
  --bad: #f0a0a0;
  --bad-soft: #3d1e1e;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.6rem, 4.5vw, 2.3rem); letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.12rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 0.8em; }
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* Kopfzeile und Navigation */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--serif); font-size: 1.2rem; font-weight: 600; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-family: var(--serif); font-size: 1.15rem; }
.logo.big { width: 56px; height: 56px; font-size: 2rem; border-radius: 14px; }
.topnav { display: none; gap: 4px; margin-left: 12px; }
.topnav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--ink-2); }
.topnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.pill { font-size: 0.75rem; padding: 3px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; text-decoration: none; color: var(--muted); font-size: 0.72rem; }
.tabbar svg { width: 22px; height: 22px; fill: currentColor; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

main {
  max-width: 820px; margin: 0 auto;
  padding: 20px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  outline: none;
}
@media (min-width: 860px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  main { padding-bottom: 48px; }
}

/* Bausteine */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; font-weight: 500; min-height: 42px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.btn.tiny { padding: 2px 8px; min-height: 28px; font-size: 0.8rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.linkish.block { display: flex; flex-direction: column; gap: 2px; text-decoration: none; width: 100%; padding: 10px 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row > .field { flex: 1 1 140px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.error-card { border-color: var(--bad); }
.hero { margin: 8px 0 22px; }
.hero.small { margin-bottom: 16px; }
.lead { font-family: var(--serif); font-size: 1.12rem; color: var(--ink-2); }
.kicker { display: block; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-size: 0.92rem; }
.more { display: inline-block; margin-top: 8px; font-size: 0.92rem; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px 0; color: var(--muted); }
.spin { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: 0.25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Formulare */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field .label { font-weight: 600; font-size: 0.92rem; }
.field .hint { font-size: 0.85rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="url"], input[type="number"], textarea, select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; }
.form-error { color: var(--bad); margin: 0; min-height: 0; }
.form-error:empty { display: none; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand h1 { margin: 0; }

/* Listen */
.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li + li { border-top: 1px solid var(--line); }
.link-list a { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; text-decoration: none; color: var(--ink); }
.link-list .title { font-family: var(--serif); font-size: 1.05rem; }
.link-list .meta, .meta { font-size: 0.85rem; color: var(--muted); }
.plain-list { margin: 0; padding-left: 1.2em; }
.plain-list li { margin: 4px 0; }

.home-grid { display: grid; gap: 16px; }
.home-grid .card { margin: 0; }
@media (min-width: 860px) { .home-grid { grid-template-columns: 1fr 1fr; } .home-grid .tools { grid-column: 1 / -1; } }
.tool-row, .tool-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.tool { display: flex; flex-direction: column; gap: 4px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--ink); background: var(--bg); }
.tool strong { font-family: var(--serif); font-size: 1.05rem; color: var(--accent); }
.tool span { font-size: 0.9rem; color: var(--ink-2); }
.tool.big { padding: 18px; background: var(--surface); }
.tool-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* Module */
.track { margin-bottom: 30px; }
.track-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 10px; }
.track-head h2 { margin-bottom: 2px; }
.track-letter { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; font-family: var(--serif); font-size: 1.3rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.track-rule { font-size: 0.92rem; color: var(--ink-2); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.module-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.module-card { display: flex; flex-direction: column; gap: 6px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.module-card:hover { border-color: var(--accent); }
.module-card strong { font-family: var(--serif); font-size: 1.08rem; }
.module-card .summary { font-size: 0.88rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.module-card .kicker { display: flex; justify-content: space-between; }
.status-hint { font-size: 0.8rem; color: var(--muted); font-style: italic; }
.stage { flex: none; align-self: flex-start; white-space: nowrap; font-size: 0.72rem; padding: 1px 8px; border-radius: 99px; text-transform: none; letter-spacing: 0; background: var(--surface-2); color: var(--ink-2); font-weight: 500; }
.stage.stage-deepened { background: var(--warn-soft); color: var(--warn); }
.stage.stage-done { background: var(--ok-soft); color: var(--ok); }

.module-head { margin-bottom: 12px; }
.module-meta { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; font-size: 0.88rem; }
.stage-select select { width: auto; padding: 4px 8px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 14px -16px 18px; padding: 0 16px; scrollbar-width: none; position: sticky; top: 57px; background: var(--bg); z-index: 5; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 10px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.regen { margin-top: 24px; font-size: 0.88rem; }

.generating { text-align: center; }
.generating .loading { padding: 10px 0; }
.tool-log { text-align: left; font-size: 0.85rem; color: var(--muted); max-height: 220px; overflow: auto; }
.step { font-size: 0.9rem; }

/* Lesetext */
.prose { font-family: var(--serif); font-size: 1.06rem; line-height: 1.62; }
.prose h2, .prose h3, .prose h4, .prose h5 { margin-top: 1.3em; }
.prose h5 { font-size: 1rem; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin: 0.25em 0; }
.prose blockquote { margin: 1em 0; padding: 0.2em 1em; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.prose a { text-decoration-thickness: 1px; text-underline-offset: 2px; overflow-wrap: anywhere; }
.prose code { font-size: 0.9em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.table-wrap { overflow-x: auto; margin: 1em 0; }
.prose table { border-collapse: collapse; font-family: var(--sans); font-size: 0.9rem; min-width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }

.mark { display: inline-block; font-family: var(--sans); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; padding: 1px 7px; border-radius: 99px; vertical-align: 0.12em; margin-right: 3px; cursor: help; }
.mark-gesichert { background: var(--ok-soft); color: var(--ok); }
.mark-umstritten { background: var(--warn-soft); color: var(--warn); }
.mark-widerlegt { background: var(--bad-soft); color: var(--bad); }

.timeline ol { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 4px 0 10px 16px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .date { display: block; font-weight: 700; font-size: 0.9rem; color: var(--accent); }

.source-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.source-card header h3 { margin: 2px 0 4px; }
.source-card .excerpt { font-family: var(--serif); font-size: 1.05rem; line-height: 1.6; margin: 12px 0; padding: 10px 16px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.source-card .excerpt p:last-child { margin-bottom: 0; }
.source-card .context { font-size: 0.98rem; color: var(--ink-2); }
.reference { font-size: 0.85rem; color: var(--muted); }
.source-questions ul { margin: 4px 0 12px; padding-left: 1.2em; }

.question-list { padding-left: 1.2em; }
.question-list li { margin: 10px 0; font-family: var(--serif); font-size: 1.05rem; }
.questions-tab section { margin-bottom: 18px; }

.controversy { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.positions { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.position { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--bg); display: flex; flex-direction: column; gap: 6px; }
.position .prose { font-size: 1rem; }
.position .btn { margin-top: auto; align-self: flex-start; }
.evidence { font-size: 0.88rem; color: var(--ink-2); }
.label { font-weight: 600; }
.note { margin-top: 12px; font-size: 0.98rem; }

.literature { list-style: none; padding: 0; }
.literature li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.lit-title { font-family: var(--serif); }
.lit-link { margin-left: 8px; font-size: 0.85rem; }
.literature p { margin: 4px 0 0; font-size: 0.9rem; }

/* Gespräch */
.conv-head { margin-bottom: 12px; }
.conv-head h1 { font-size: clamp(1.3rem, 4vw, 1.8rem); }
.conv-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.setup-card { border-left: 3px solid var(--accent); background: var(--surface); padding: 12px 16px; border-radius: 0 10px 10px 0; margin-bottom: 18px; }
.setup-card .claim { font-family: var(--serif); font-size: 1.1rem; margin: 4px 0; }
.messages { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.msg.user { align-self: flex-end; max-width: 88%; }
.msg.user .bubble { background: var(--accent-soft); border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.ai .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 14px 16px; overflow-wrap: anywhere; }
.msg.ai .bubble > :last-child { margin-bottom: 0; }
.msg.ai.streaming .bubble:empty { display: none; }
.tool-line { font-size: 0.85rem; color: var(--muted); margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }
.dots { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.searched { font-size: 0.78rem; color: var(--muted); margin: 6px 4px 0; }
.sources { margin: 6px 4px 0; font-size: 0.88rem; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources ol { padding-left: 1.4em; margin: 6px 0; }
.sources li { margin: 6px 0; overflow-wrap: anywhere; }
.sources .host { color: var(--muted); }
.sources q { display: block; color: var(--ink-2); font-style: italic; font-size: 0.85rem; margin-top: 2px; }
.empty { text-align: center; padding: 20px; }
.composer { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); }
@media (min-width: 860px) { .composer { bottom: 16px; } }
.composer textarea { border: 0; background: transparent; padding: 6px; min-height: 70px; }
.composer textarea:focus { outline: none; }
.composer-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.status { margin: 0; font-size: 0.85rem; color: var(--muted); }
.status.error { color: var(--bad); }

.evaluation h3 { font-size: 1.25rem; }
.eval-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin: 12px 0; }
.eval-side { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.eval-side ul { padding-left: 1.2em; margin: 4px 0 10px; }
.verdict { border-top: 1px solid var(--line); padding-top: 12px; }

/* Lernstand */
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; border-radius: 99px; background: var(--surface-2); font-size: 0.9rem; }
.chip.origin-self { background: var(--accent-soft); }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1.1rem; width: 26px; height: 26px; border-radius: 50%; }
.chip-x:hover { background: var(--line); }
.question-items { list-style: none; padding: 0; margin: 0; }
.question-items li { display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.question-items li.resolved .q { color: var(--muted); text-decoration: line-through; }
.question-items .q { font-family: var(--serif); }
.q-actions { display: flex; gap: 4px; flex: none; }
.tag { margin-left: 6px; font-size: 0.75rem; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); text-decoration: none; font-family: var(--sans); }
.progress-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.progress-list { list-style: none; padding: 0; margin: 0; }
.progress-list li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; font-size: 0.92rem; }
.progress-list a { text-decoration: none; color: var(--ink); }
details summary { cursor: pointer; }
