/* Selbststudium – Übersicht und Themenseite */
:root {
  --bg: #f6f2ea;
  --bg-elev: #fffdf9;
  --fg: #26211b;
  --fg-muted: #6e665b;
  --line: #e3dbcd;
  --accent: #8a5a2b;
  --accent-soft: #f1e5d4;
  --accent-ink: #5c3a17;
  --quote: #a08760;
  --hl: #fff2b8;
  --shadow: 0 10px 30px rgba(60, 40, 10, .10);
  --radius: 12px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-text: "Noto Serif", "Source Serif 4", Georgia, "Times New Roman", serif;
  --head-h: 56px;
  --sidebar-w: 440px;
  --toc-w: 240px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191714; --bg-elev: #221f1b; --fg: #e8e1d5; --fg-muted: #a59b8d; --line: #37322b;
    --accent: #d9a86c; --accent-soft: #3a2f22; --accent-ink: #f0cfa4; --quote: #b39468; --hl: #4a3f1c;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font-ui); font-size: 16px; line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; background: var(--accent-soft); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--fg-muted); }
.small { font-size: .9rem; }
button, select { font: inherit; color: inherit; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }
.wrap-wide { max-width: none; }

/* ---------- Kopf ---------- */
.site-head {
  position: sticky; top: 0; z-index: 30; height: var(--head-h);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.site-head .wrap { height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.logo { font-family: var(--font-text); font-weight: 700; font-size: 1.15rem; color: var(--fg); letter-spacing: .01em; }
.logo:hover { text-decoration: none; color: var(--accent); }
.head-nav { display: flex; align-items: center; gap: .5rem; }
.head-nav select {
  max-width: 18rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem;
  text-overflow: ellipsis;
}
.btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .8rem; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; font-weight: 500;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn[aria-expanded="true"] { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.iconbtn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: .25rem .55rem;
  cursor: pointer; color: var(--fg-muted); line-height: 1.2;
}
.iconbtn:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

/* ---------- Übersicht ---------- */
.page-index main { padding: 2.5rem 1.25rem 4rem; }
.intro h1 { font-family: var(--font-text); font-size: 2.2rem; margin: 0 0 .3rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.1rem; margin: 1.8rem 0 3rem; }
.card {
  display: flex; flex-direction: column; gap: .5rem; padding: 1.3rem 1.4rem; color: var(--fg);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.card-meta { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .82rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .05em; }
.card h2 { font-family: var(--font-text); font-size: 1.35rem; margin: 0; line-height: 1.3; }
.card p { margin: 0; color: var(--fg-muted); font-size: .95rem; }
.card-link { margin-top: auto; color: var(--accent); font-weight: 500; }
.empty { padding: 2rem; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; color: var(--fg-muted); }
.howto { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.6rem; }
.howto h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.howto ol { margin: 0; padding-left: 1.3rem; }
.howto li { margin: .3rem 0; }
.site-foot { padding: 1rem 1.25rem 2.5rem; font-size: .85rem; }

/* ---------- Themenseite: Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--toc-w) minmax(0, 1fr) 0;
  min-height: calc(100vh - var(--head-h));
  transition: grid-template-columns .2s ease;
}
body.sidebar-open .layout { grid-template-columns: var(--toc-w) minmax(0, 1fr) var(--sidebar-w); }
body.resizing .layout { transition: none; }

.toc { border-right: 1px solid var(--line); }
.toc-inner { position: sticky; top: var(--head-h); max-height: calc(100vh - var(--head-h)); overflow-y: auto; padding: 1.4rem 1rem 2rem 1.25rem; }
.toc-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--fg-muted); font-weight: 600; margin-bottom: .6rem; }
.toc nav a {
  display: block; color: var(--fg-muted); font-size: .88rem; padding: .28rem .6rem; border-left: 2px solid transparent; line-height: 1.35;
}
.toc nav a.lvl3 { padding-left: 1.4rem; font-size: .82rem; }
.toc nav a:hover { color: var(--accent); text-decoration: none; }
.toc nav a.active { color: var(--accent-ink); border-left-color: var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; }

.article-wrap { min-width: 0; }
.article { max-width: 46rem; margin: 0 auto; padding: 2.2rem 2rem 5rem; }
.article-meta { font-size: .85rem; margin-bottom: .6rem; }

/* ---------- Markdown-Inhalt ---------- */
.md-body { font-family: var(--font-text); font-size: 1.08rem; line-height: 1.72; }
.md-body h1 { font-size: 2.15rem; line-height: 1.15; margin: 0 0 1.2rem; letter-spacing: -.015em; font-weight: 700; }
.md-body h2 {
  font-size: 1.55rem; margin: 2.8rem 0 1rem; padding-top: 1.2rem; border-top: 1px solid var(--line);
  line-height: 1.25; font-weight: 700; letter-spacing: -.01em;
}
.md-body h3 { font-size: 1.2rem; margin: 2rem 0 .7rem; font-weight: 700; }
.md-body h4 { font-size: 1.02rem; margin: 1.5rem 0 .5rem; font-family: var(--font-ui); text-transform: uppercase; letter-spacing: .06em; color: var(--fg-muted); }
.md-body h2, .md-body h3, .md-body h4 { scroll-margin-top: calc(var(--head-h) + 1rem); }
.md-body p { margin: 0 0 1.05rem; hyphens: auto; }
.md-body p.refs-only { margin-top: -.7rem; padding-left: 1.2rem; font-size: .95em; }
.md-body hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem auto; width: 40%; }
.md-body blockquote {
  margin: 1.4rem 0; padding: .6rem 1.2rem .6rem 1.3rem; border-left: 3px solid var(--quote);
  background: var(--bg-elev); border-radius: 0 10px 10px 0; color: var(--fg); font-style: italic;
}
.md-body blockquote p:last-child { margin-bottom: 0; }
.md-body blockquote strong { font-style: normal; }
.md-body ul, .md-body ol { padding-left: 1.5rem; margin: 0 0 1.1rem; }
.md-body li { margin: .35rem 0; }
.md-body li > p { margin-bottom: .4rem; }
.md-body strong { font-weight: 700; color: var(--accent-ink); }
.md-body em { font-style: italic; }
.md-body .table-wrap { overflow-x: auto; margin: 1.4rem 0; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-elev); }
.md-body table { border-collapse: collapse; width: 100%; font-size: .95rem; font-family: var(--font-ui); }
.md-body th, .md-body td { padding: .6rem .8rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.md-body th { background: var(--accent-soft); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.md-body tr:last-child td { border-bottom: 0; }
.md-body img { max-width: 100%; border-radius: 8px; }
.md-body pre { overflow-x: auto; background: var(--bg-elev); border: 1px solid var(--line); padding: .9rem 1rem; border-radius: 8px; font-size: .9rem; }
.md-body pre code { background: none; padding: 0; }

.md-body a.ext { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); text-underline-offset: 3px; }
.md-body a.ext::after { content: " ↗"; font-family: var(--font-ui); font-size: .75em; opacity: .7; }

/* Bibelstellen-Links */
.bref {
  color: var(--accent); font-family: var(--font-ui); font-size: .88em; font-weight: 500; white-space: nowrap;
  border-bottom: 1px dotted var(--accent); cursor: pointer; padding: 0 .08em; border-radius: 3px;
}
.bref:hover, .bref.active { background: var(--accent-soft); text-decoration: none; border-bottom-style: solid; }
.bref-unknown { color: #b23b3b; border-bottom-color: #b23b3b; }

/* Tooltip */
.ref-tip {
  position: fixed; z-index: 60; max-width: 26rem; width: max-content; padding: .7rem .9rem;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  font-family: var(--font-text); font-size: .93rem; line-height: 1.55; pointer-events: none;
}
.ref-tip .tip-ref { font-family: var(--font-ui); font-weight: 600; color: var(--accent); font-size: .8rem; margin-bottom: .3rem; display: block; }
.ref-tip .tip-v { display: block; margin-top: .25rem; }
.ref-tip .tip-v b { color: var(--accent); font-family: var(--font-ui); font-size: .7rem; vertical-align: super; margin-right: .2em; }
.ref-tip .tip-more { font-family: var(--font-ui); color: var(--fg-muted); font-size: .8rem; margin-top: .4rem; display: block; }

/* Stellenverzeichnis */
.ref-index { margin-top: 4rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.ref-index h2 { font-family: var(--font-text); font-size: 1.3rem; margin: 0 0 .3rem; }
.ref-book { margin: 1rem 0 .4rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-muted); font-weight: 600; }
.ref-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.ref-chips .bref { font-size: .85rem; border: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 999px; padding: .2rem .65rem; background: var(--bg-elev); }
.ref-chips .bref:hover { border-color: var(--accent); }
.ref-chips .bref small { color: var(--fg-muted); margin-left: .3em; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: var(--head-h); height: calc(100vh - var(--head-h));
  display: flex; flex-direction: column; background: var(--bg-elev); border-left: 1px solid var(--line);
  overflow: hidden; visibility: hidden;
}
body.sidebar-open .sidebar { visibility: visible; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .7rem .5rem .9rem; border-bottom: 1px solid var(--line); min-height: 44px; }
.sidebar-ref { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-actions { display: flex; gap: .3rem; }
.sidebar iframe { flex: 1; width: 100%; border: 0; background: var(--bg); }
.sidebar-resize { position: absolute; left: 0; top: 0; width: 6px; height: 100%; cursor: col-resize; z-index: 2; }
.sidebar-resize:hover, body.resizing .sidebar-resize { background: var(--accent-soft); }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe { pointer-events: none; }

/* ---------- Responsiv ---------- */
@media (max-width: 1180px) {
  :root { --toc-w: 0px; }
  .toc { position: fixed; left: 0; top: var(--head-h); bottom: 0; width: 280px; background: var(--bg-elev); z-index: 25; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.toc-open .toc { transform: none; }
  .layout, body.sidebar-open .layout { grid-template-columns: 0 minmax(0, 1fr) var(--sidebar-w); }
}
@media (min-width: 1181px) { #tocToggle { display: none; } }
@media (max-width: 900px) {
  .layout, body.sidebar-open .layout { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .sidebar { position: fixed; right: 0; top: var(--head-h); width: min(100vw, 520px); box-shadow: var(--shadow); z-index: 28; transform: translateX(100%); transition: transform .2s; visibility: visible; }
  body.sidebar-open .sidebar { transform: none; }
  .sidebar-resize { display: none; }
  .article { padding: 1.6rem 1.1rem 4rem; }
  .md-body h1 { font-size: 1.7rem; }
  .head-nav select { display: none; }
}
@media (hover: none) { .ref-tip { display: none !important; } }

@media print {
  .site-head, .toc, .sidebar, .ref-tip, #tocToggle { display: none !important; }
  .layout { display: block; }
  .article { max-width: none; padding: 0; }
  .bref { color: inherit; border: 0; font-family: inherit; font-size: inherit; }
}
