/* Lernbibliothek – keine externen Fonts/Assets, damit alles offline funktioniert. */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --text: #1c1d22;
  --muted: #646876;
  --border: #e1e3ea;
  --brand: #1f6fd1;
  --accent: var(--brand);
  --ok: #2b8a3e;
  --warn: #b35c00;
  --danger: #c92a2a;
  --mark: #ffe58a;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 2px 8px rgb(16 24 40 / 5%);
  --radius: 10px;
  --topbar-h: 60px;
  --sidebar-w: 270px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1c1f26;
    --surface-2: #252932;
    --text: #e8e9ee;
    --muted: #9a9fad;
    --border: #2f343f;
    --mark: #8a6d00;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--topbar-h) + 12px); }

body {
  margin: 0;
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Kopfzeile ---------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; text-decoration: none; white-space: nowrap; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #1f6fd1, #7b3fe4); color: #fff; font-weight: 800;
}
.search { flex: 1; max-width: 560px; }
.search input {
  width: 100%; height: 40px; padding: 0 14px;
  font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid transparent; border-radius: 20px;
  outline: none; transition: border-color .15s, background .15s;
}
.search input:focus { border-color: var(--brand); background: var(--surface); }
.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a { text-decoration: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a.active { color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, transparent); }
.icon-btn { border: 0; background: none; font-size: 1.3rem; color: var(--text); cursor: pointer; padding: 6px; border-radius: 6px; }
.menu-btn { display: none; }

/* ---------- Grundlayout ---------- */

.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.main { padding: 24px 32px 64px; max-width: 1400px; width: 100%; outline: none; }

.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 18px 12px 24px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar-title { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 8px 8px; }
.sidebar-foot { padding: 16px 8px 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.nav-area { margin-bottom: 2px; }
.nav-area > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; list-style: none; font-weight: 600;
}
.nav-area > summary::-webkit-details-marker { display: none; }
.nav-area > summary::after { content: "▸"; color: var(--muted); font-size: .8rem; transition: transform .15s; }
.nav-area[open] > summary::after { transform: rotate(90deg); }
.nav-area > summary:hover { background: var(--surface-2); }
.nav-area > summary a { flex: 1; text-decoration: none; }
.nav-area > summary a.active { color: var(--accent); }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.nav-item {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 5px 8px; border-radius: 6px; text-decoration: none; font-size: .92rem; color: var(--muted);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 600; }
.nav-pct { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-pct.complete { color: var(--ok); font-weight: 700; }

/* ---------- Bausteine ---------- */

.breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; font-size: .88rem; color: var(--muted); margin-bottom: 14px; }
.breadcrumb a { text-decoration: none; }
.breadcrumb a:hover { color: var(--text); text-decoration: underline; }
.breadcrumb [aria-current] { color: var(--text); }
.breadcrumb .sep { opacity: .6; }

.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 20px;
  background: var(--surface-2); color: var(--muted);
}
.t-grundwissen { --tc: #1f6fd1; }
.t-aufgaben { --tc: #2b8a3e; }
.t-versuch { --tc: #d9480f; }
.t-arbeitsblatt { --tc: #7b3fe4; }
.badge[class*="t-"]:not(.t-none) { background: color-mix(in srgb, var(--tc, var(--muted)) 14%, transparent); color: var(--tc, var(--muted)); }
.badge-warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.tag {
  position: relative; z-index: 1;
  font-size: .8rem; text-decoration: none; color: var(--muted);
  padding: 2px 9px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface);
}
.tag:hover { color: var(--brand); border-color: var(--brand); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-cloud .tag { font-size: calc(.8rem * var(--w, 1)); }

.progress { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bar { flex: 1; height: 6px; min-width: 40px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .25s; }
.bar-label { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: .9rem; font-weight: 600; text-decoration: none; cursor: pointer;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .85rem; text-decoration: none; padding: 5px 12px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.chip span { font-size: .75rem; opacity: .75; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--tc, var(--text)); border-color: var(--tc, var(--text)); color: var(--surface); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.chip-toggle { margin-left: auto; }

.block {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state .tag-cloud { justify-content: center; margin-top: 12px; }
.notice {
  margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: .9rem;
  background: color-mix(in srgb, var(--warn) 10%, transparent); border-left: 4px solid var(--warn);
}

.link-list { list-style: none; margin: 0; padding: 0; }
.link-list li { display: flex; flex-direction: column; padding: 8px 0 8px 12px; border-left: 3px solid var(--accent); margin-bottom: 8px; }
.link-list a { font-weight: 600; text-decoration: none; }
.link-list a:hover { text-decoration: underline; }

/* ---------- Startseite ---------- */

.hero { margin: 8px 0 24px; }
.hero h1 { font-size: 2.1rem; }
.hero p { color: var(--muted); max-width: 70ch; margin: 0 0 12px; }
.hero-progress { display: flex; align-items: center; gap: 16px; max-width: 520px; }
.hero-progress .progress { flex: 1; }

.area-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; margin-bottom: 24px; }
.area-tile {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--accent);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.area-tile p { margin: 0; color: var(--muted); font-size: .9rem; }
.area-head { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.area-head h2 { margin: 0; color: var(--accent); }
.area-head:hover h2 { text-decoration: underline; }
.area-icon {
  display: grid; place-items: center; width: 42px; height: 42px; flex: none; font-size: 1.4rem;
  border-radius: 10px; background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.topic-list { list-style: none; margin: 0; padding: 0; flex: 1; }
.topic-list li { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding: 5px 0; }
.topic-list a { text-decoration: none; }
.topic-list a:hover { color: var(--accent); text-decoration: underline; }

.home-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }

/* ---------- Kategorie ---------- */

.cat-header {
  background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--accent);
  border-radius: var(--radius); padding: 20px 24px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.cat-title { display: flex; align-items: center; gap: 14px; }
.cat-title h1 { margin: 0; color: var(--accent); }
.cat-header > p { color: var(--muted); margin: 10px 0 0; max-width: 75ch; }
.cat-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-top: 14px; font-size: .88rem; color: var(--muted); }
.cat-stats .progress { flex: 1; min-width: 200px; max-width: 360px; }

.topic { margin-bottom: 28px; }
.topic .topic { margin: 18px 0 0; padding-left: 16px; border-left: 2px solid var(--border); }
.topic-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-bottom: 4px; }
.topic-head h2, .topic-head h3, .topic-head h4 { margin: 0; }
.topic-head a { text-decoration: none; }
.topic-head a:hover { color: var(--accent); text-decoration: underline; }
.topic-head .progress { width: 200px; }
.topic > p.muted { margin: 0 0 10px; font-size: .9rem; }

/* ---------- Dokumentkarten ---------- */

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.doc-card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 12px; box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.doc-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.doc-card:focus-within { border-color: var(--accent); }
.doc-card.is-done { background: color-mix(in srgb, var(--ok) 5%, var(--surface)); }
.doc-card-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.file-ext { margin-left: auto; font-size: .72rem; color: var(--muted); font-weight: 600; }
.doc-path { font-size: .78rem; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.doc-card h3 { margin: 0 0 4px; }
.doc-card h3 a { text-decoration: none; }
.stretched::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.stretched:focus { outline: none; }
.stretched:focus-visible::after { outline: 2px solid var(--accent); outline-offset: 2px; }
.doc-summary { margin: 0 0 4px; font-size: .88rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.chapter-hits { list-style: none; margin: 6px 0; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; font-size: .85rem; }
.chapter-hits a { position: relative; z-index: 1; text-decoration: none; display: block; padding: 2px 0; }
.chapter-hits a:hover { color: var(--accent); text-decoration: underline; }
.doc-card-foot { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 8px; }
.doc-card-foot .progress { flex: 1; }
.check-btn {
  position: relative; z-index: 1;
  width: 30px; height: 30px; flex: none; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--border); background: var(--surface); color: transparent; font-weight: 800;
}
.check-btn:hover { border-color: var(--ok); color: var(--ok); }
.check-btn[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ---------- Dokumentansicht ---------- */

.doc-head { margin-bottom: 18px; }
.doc-head h1 { margin: 6px 0 6px; }
.doc-head .lead { font-size: 1.05rem; max-width: 80ch; margin: 0 0 6px; }
.doc-body { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }
.toc {
  position: sticky; top: calc(var(--topbar-h) + 16px);
  background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  max-height: calc(100vh - var(--topbar-h) - 32px); overflow-y: auto;
}
.toc-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.toc-head h2 { margin: 0; }
.chapter-list { list-style: none; margin: 0; padding: 0; }
.chapter { display: flex; gap: 8px; align-items: flex-start; border-radius: 8px; padding: 2px; }
.chapter.active { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.chapter-link {
  flex: 1; display: grid; grid-template-columns: 1fr auto; gap: 0 8px; text-align: left;
  font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 6px 6px; border-radius: 6px;
}
.chapter-link:hover .ch-title { color: var(--accent); text-decoration: underline; }
.ch-title { font-weight: 600; font-size: .92rem; }
.ch-page { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.ch-kw { grid-column: 1 / -1; font-size: .76rem; color: var(--muted); }
.chapter.done .ch-title { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ok) 60%, transparent); }
.chk { position: relative; flex: none; margin-top: 7px; cursor: pointer; }
.chk input { position: absolute; opacity: 0; width: 20px; height: 20px; margin: 0; cursor: pointer; }
.chk span { display: grid; place-items: center; width: 20px; height: 20px; border: 2px solid var(--border); border-radius: 6px; background: var(--surface); }
.chk input:checked + span { background: var(--ok); border-color: var(--ok); }
.chk input:checked + span::after { content: "✓"; color: #fff; font-size: .75rem; font-weight: 800; }
.chk input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.toc-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

.viewer {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
  height: calc(100vh - var(--topbar-h) - 40px); min-height: 480px;
}
.viewer iframe, .viewer video { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.viewer img { max-width: 100%; max-height: 100%; display: block; margin: auto; }
.viewer audio { margin: 40px auto; display: block; }

/* ---------- Fortschritt ---------- */

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 1.8rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .88rem; }
.progress-areas { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 20px; }
.area-progress { border-top: 5px solid var(--accent); }
.area-progress h2 a { text-decoration: none; color: var(--accent); }
.progress-tree { list-style: none; margin: 12px 0 0; padding: 0; }
.progress-tree li { display: grid; grid-template-columns: minmax(0, 1fr) 160px; gap: 10px; align-items: center; padding: 4px 0; font-size: .9rem; }
.progress-tree li.depth-2 { padding-left: 16px; }
.progress-tree li.depth-3 { padding-left: 32px; }
.progress-tree a { text-decoration: none; }
.progress-tree a:hover { text-decoration: underline; }

/* ---------- Responsiv ---------- */

@media (max-width: 1100px) {
  .doc-body { grid-template-columns: 1fr; }
  .toc { position: static; max-height: none; }
  .viewer { height: 80vh; }
}

@media (max-width: 900px) {
  :root { --topbar-h: 56px; }
  .menu-btn { display: block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); z-index: 25; width: min(320px, 85vw);
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  .main { padding: 18px 16px 48px; }
  .topnav a[data-nav="home"] { display: none; }
}

@media (max-width: 600px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand span:last-child { display: none; }
  .topnav a { padding: 8px 6px; font-size: .85rem; }
  .chip-toggle { margin-left: 0; }
  h1, .hero h1 { font-size: 1.5rem; }
}
