/* ===== Design-Tokens: Theme A „Klarer Himmel“ (Standard) ===== */
:root {
  --font: "Manrope", system-ui, -apple-system, sans-serif;
  --font-display: var(--font);
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --bg: #F3F6FB;
  --surface: #FFFFFF;
  --surface-2: #F8FAFD;
  --ink: #122033;
  --muted: #5B6B82;
  --faint: #7A8899;
  --border: #DCE4EF;
  --border-strong: #BFD4F5;
  --accent: #1D6FE0;
  --accent-ink: #124FA8;
  --accent-soft: #E4EEFC;
  --on-accent: #FFFFFF;
  --ok: #1B9A6B; --ok-ink: #146B4A; --ok-soft: #DFF5EA;
  --warn: #D98500; --warn-ink: #8A5300; --warn-soft: #FFF1D6;
  --danger: #D9534F; --danger-ink: #B3261E; --danger-soft: #FDECEC;
  --merke-bg: #FFF7DD; --merke-border: #F3DE8F;
  --term-bg: #E4EEFC; --term-ink: #124FA8;
  --radius: 16px; --radius-sm: 12px; --radius-xs: 8px;
  --shadow: 0 1px 2px rgba(18,32,51,.05);
  --nav-w: 232px;
  --img-bg: #FFFFFF;
}
:root[data-theme="cockpit"] {
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --bg: #0F141B; --surface: #171E27; --surface-2: #1F2833;
  --ink: #EAF0F6; --muted: #8FA0B3; --faint: #6F8094;
  --border: #27313D; --border-strong: #3A4756;
  --accent: #F4B33D; --accent-ink: #F4B33D; --accent-soft: #3B2A0C; --on-accent: #1A1300;
  --ok: #5BE3A6; --ok-ink: #5BE3A6; --ok-soft: #153A2E;
  --warn: #F4B33D; --warn-ink: #F4B33D; --warn-soft: #3B2A0C;
  --danger: #FF6B6B; --danger-ink: #FF8A80; --danger-soft: #3B1A1A;
  --merke-bg: #3B2A0C; --merke-border: #6B4A10;
  --term-bg: transparent; --term-ink: #35D1C0;
  --radius: 10px; --radius-sm: 8px; --radius-xs: 6px;
  --shadow: none;
  color-scheme: dark;
}
:root[data-theme="handbuch"] {
  --font: "Source Sans 3", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --bg: #F5EFE3; --surface: #FFFDF8; --surface-2: #F1EADC;
  --ink: #2B2520; --muted: #6F655A; --faint: #8C7F6E;
  --border: #D9CDB8; --border-strong: #B8A98D;
  --accent: #9A3B2E; --accent-ink: #9A3B2E; --accent-soft: #FBECE8; --on-accent: #FFF8EE;
  --ok: #4F6B3A; --ok-ink: #34491F; --ok-soft: #E7EADB;
  --warn: #B86A1E; --warn-ink: #8A3B1E; --warn-soft: #F9E4D6;
  --danger: #9A3B2E; --danger-ink: #7A2A20; --danger-soft: #FBECE8;
  --merke-bg: #FBF3D9; --merke-border: #E3CF8A;
  --term-bg: transparent; --term-ink: #9A3B2E;
  --radius: 6px; --radius-sm: 6px; --radius-xs: 4px;
  --shadow: none;
}

/* ===== Basis ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; margin: 0; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 20px; font-weight: 800; }
h3 { font-size: 17px; font-weight: 800; }
:root[data-theme="handbuch"] h1, :root[data-theme="handbuch"] h2, :root[data-theme="handbuch"] h3 { font-weight: 600; }
.boot { padding: 40px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.gap-s { gap: 6px; } .gap-l { gap: 20px; }
.mt { margin-top: 12px; } .mt-l { margin-top: 24px; } .mb { margin-bottom: 12px; }
.center { text-align: center; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ===== Layout ===== */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; }
.sidenav { display: none; flex: 0 0 var(--nav-w); flex-direction: column; gap: 4px; padding: 24px 14px; background: var(--surface); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh; height: 100dvh; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 20px; }
.brand .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); display: flex; align-items: center; justify-content: center; color: var(--on-accent); flex: none; }
.brand b { font-size: 16px; font-weight: 800; display: block; }
.brand span { font-size: 12px; color: var(--muted); }
.navlink { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 14px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 700; font-size: 15px; }
.navlink:hover { text-decoration: none; background: var(--surface-2); }
.navlink.active { background: var(--accent-soft); color: var(--accent-ink); }
.navlink svg { flex: none; }
.navsep { height: 1px; background: var(--border); margin: 8px 6px; }
.main { flex: 1; min-width: 0; padding: 20px 16px 96px; max-width: 1180px; margin: 0 auto; width: 100%; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--surface); border-top: 1px solid var(--border); padding: 0 6px env(safe-area-inset-bottom); z-index: 30; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 6px; color: var(--faint); font-size: 11px; font-weight: 700; min-height: 54px; }
.tab:hover { text-decoration: none; }
.tab.active { color: var(--accent-ink); }
@media (min-width: 900px) {
  .sidenav { display: flex; }
  .tabbar { display: none; }
  .main { padding: 32px 36px 48px; }
}

/* ===== Komponenten ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.card.accent { border-color: var(--border-strong); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px 10px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); color: inherit; }
a.list-row:hover { background: var(--surface-2); text-decoration: none; }
.list-row.group { background: var(--surface-2); font-weight: 800; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 16px; }
.list-row.current { background: var(--surface-2); }
.unit-num { width: 44px; flex: none; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-weight: 700; font-size: 15px; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; filter: brightness(0.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent-ink); }
.btn.danger { color: var(--danger-ink); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.icon { padding: 0; width: 44px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: var(--ok-soft); color: var(--ok-ink); }
.chip.warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip.blue { background: var(--accent-soft); color: var(--accent-ink); }
.chip.danger { background: var(--danger-soft); color: var(--danger-ink); }
:root[data-theme="handbuch"] .chip { border-radius: 4px; text-transform: uppercase; letter-spacing: .03em; font-size: 11px; }
:root[data-theme="cockpit"] .chip { border-radius: 5px; text-transform: uppercase; letter-spacing: .04em; font-size: 11px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.ok > i { background: var(--ok); }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 700px) { .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.metric .label { font-size: 12px; font-weight: 700; color: var(--muted); }
.metric .value { font-size: 28px; font-weight: 800; margin-top: 4px; font-family: var(--font-display); }
.metric .value small { font-size: 14px; color: var(--muted); font-weight: 700; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.cols > .col-main { flex: 1 1 520px; min-width: 0; }
.cols > .col-side { flex: 1 1 260px; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 13px; font-weight: 700; color: var(--muted); }
input[type=text], input[type=number], input[type=search], select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 10px 12px; min-height: 44px; width: 100%; }
textarea { min-height: 90px; line-height: 1.45; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.search { display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); min-height: 46px; }
.search input { border: 0; padding: 0; min-height: 0; background: transparent; }
.search input:focus { outline: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips .chip { cursor: pointer; flex: none; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 700; font-size: 14px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
@media (min-width: 900px) { .toast { bottom: 32px; } }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.kicker { font-size: 12px; font-weight: 800; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.sparkbars { display: flex; align-items: flex-end; gap: 5px; height: 56px; }
.sparkbars i { flex: 1; background: var(--border-strong); border-radius: 3px 3px 0 0; min-height: 2px; }
.sparkbars i.hi { background: var(--accent); }

/* ===== Lese-Ansicht ===== */
.reader { max-width: 760px; margin: 0 auto; }
.reader-head { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 6px 0 10px; display: flex; align-items: center; gap: 10px; }
.reader-title { flex: 1; min-width: 0; }
.reader-title h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-body { font-size: 17px; line-height: 1.6; display: flex; flex-direction: column; gap: 16px; }
.reader-body p { margin: 0; }
.reader-body h3 { font-size: 19px; margin-top: 10px; }
.reader-body h4 { font-size: 17px; margin-top: 6px; color: var(--muted); }
.reader-body ul { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.term { background: var(--term-bg); color: var(--term-ink); border-radius: 5px; padding: 0 3px; font-weight: 700; }
:root[data-theme="cockpit"] .term { border-bottom: 1px dotted var(--term-ink); border-radius: 0; padding: 0; }
.merke { background: var(--merke-bg); border: 1px solid var(--merke-border); border-radius: var(--radius-sm); padding: 12px 16px; }
.merke .kicker { color: var(--warn-ink); margin-bottom: 4px; }
.hint { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 16px; }
:root[data-theme="handbuch"] .hint { border-left: 3px solid var(--ok); border-radius: 0; }
.kurz { font-weight: 700; }
figure.fig { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
figure.fig img { display: block; width: 100%; max-height: 420px; object-fit: contain; background: var(--img-bg); cursor: zoom-in; }
figure.fig figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); }
.reader-foot { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.reader-foot .btn { flex: 1 1 140px; }
.page-marker { font-size: 11px; color: var(--faint); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; border-top: 1px dashed var(--border); padding-top: 6px; margin-top: 4px; }

/* ===== Lightbox ===== */
.lightbox { position: fixed; inset: 0; background: rgba(8,12,20,.94); z-index: 100; display: flex; flex-direction: column; }
.lightbox .lb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; color: #fff; padding-top: max(12px, env(safe-area-inset-top)); }
.lightbox .lb-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; }
.lightbox img.zoomed { max-width: none; max-height: none; width: 200%; }
.lightbox .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); color: #fff; }

/* ===== Quiz ===== */
.quiz { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.qtext { font-size: 18px; font-weight: 700; line-height: 1.45; }
.opt { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 14px; border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); font-size: 16px; line-height: 1.4; cursor: pointer; }
.opt:hover { border-color: var(--border-strong); }
.opt.selected { border-color: var(--accent); }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--danger); background: var(--danger-soft); }
.opt:disabled { cursor: default; }
.letter { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; color: var(--muted); }
.opt.correct .letter { background: var(--ok); color: #fff; }
.opt.wrong .letter { background: var(--danger); color: #fff; }
.feedback { border-radius: var(--radius-sm); padding: 14px 16px; border: 1px solid var(--border); }
.feedback.ok { background: var(--ok-soft); border-color: var(--ok); }
.feedback.bad { background: var(--danger-soft); border-color: var(--danger); }
.flashcard { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 22px; min-height: 220px; display: flex; flex-direction: column; gap: 10px; }
.flashcard .front { font-size: 24px; font-weight: 800; font-family: var(--font-display); }
.flashcard .back { font-size: 16px; line-height: 1.55; border-top: 1px solid var(--border); padding-top: 12px; }
.rate { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.rate .btn { flex-direction: column; gap: 2px; min-height: 58px; padding: 0 6px; }
.rate .btn small { font-weight: 500; font-size: 11px; opacity: .8; }
.timer { font-family: var(--font-mono); font-weight: 700; background: var(--warn-soft); color: var(--warn-ink); padding: 6px 10px; border-radius: var(--radius-xs); }
.timer.low { background: var(--danger-soft); color: var(--danger-ink); }
.dots { display: flex; flex-wrap: wrap; gap: 6px; }
.dot { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); }
.dot.answered { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent-soft); }
.dot.flag { border-color: var(--warn); }
.dot.current { outline: 2px solid var(--accent); }
.dot.ok { background: var(--ok-soft); color: var(--ok-ink); }
.dot.bad { background: var(--danger-soft); color: var(--danger-ink); }

/* ===== Galerie ===== */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.figcard { display: block; overflow: hidden; color: inherit; cursor: pointer; }
.figcard img { display: block; width: 100%; height: 120px; object-fit: contain; background: var(--img-bg); }
.figcard .cap { padding: 10px 12px; border-top: 1px solid var(--border); }
.figcard .cap b { display: block; font-size: 11px; color: var(--accent-ink); }
.figcard .cap span { display: block; font-size: 13px; font-weight: 700; line-height: 1.35; margin-top: 2px; }
.figcard:hover { text-decoration: none; border-color: var(--border-strong); }

/* ===== Seitenverwaltung ===== */
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 20px; background: var(--surface); display: flex; flex-direction: column; gap: 10px; }
.dropzone.over { background: var(--accent-soft); }
.thumb { width: 44px; height: 58px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); flex: none; }
.thumb.ph { display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 11px; }
.page-editor { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.page-editor .img-col { flex: 1 1 380px; min-width: 0; }
.page-editor .blocks-col { flex: 1 1 380px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.cropper { position: relative; user-select: none; -webkit-user-select: none; touch-action: none; border: 1px solid var(--border); border-radius: var(--radius-xs); overflow: hidden; background: #fff; }
.cropper img { display: block; width: 100%; }
.cropper .box { position: absolute; border: 2px solid var(--accent); background: rgba(29,111,224,.12); pointer-events: none; }
.cropper .box.other { border-color: var(--warn); background: rgba(217,133,0,.08); border-style: dashed; }
.cropper .box label { position: absolute; left: 0; top: -22px; background: var(--accent); color: var(--on-accent); font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 4px; }
.cropper .box.other label { background: var(--warn); }
.block { border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 10px 12px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.block .block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.block select { width: auto; min-height: 32px; padding: 4px 8px; font-size: 13px; }
.block textarea { min-height: 60px; font-size: 14px; }
.block.figure { border-color: var(--border-strong); }
.block.active { outline: 2px solid var(--accent); }
.qrow { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-top: 1px solid var(--border); }
.qrow .opts { display: grid; grid-template-columns: 1fr; gap: 4px; font-size: 14px; }
.qrow .opts span.correct { color: var(--ok-ink); font-weight: 700; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--border); }
.table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-top: 0; }
.theme-pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.theme-pick button { padding: 12px; border-radius: var(--radius-sm); border: 2px solid var(--border); background: var(--surface); cursor: pointer; text-align: left; font-weight: 700; }
.theme-pick button.active { border-color: var(--accent); }
.theme-pick .sw { display: flex; gap: 4px; margin-bottom: 8px; }
.theme-pick .sw i { width: 18px; height: 18px; border-radius: 4px; display: block; border: 1px solid rgba(0,0,0,.1); }
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.badge-dot.busy { background: var(--warn); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .4; } to { opacity: 1; } }

/* ===== Vorlesen ===== */
.blk { border-radius: var(--radius-xs); transition: background .2s; margin: -4px -8px; padding: 4px 8px; }
.blk.reading { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); }
.ttsbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 25; display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: calc(100% - 24px); }
@media (min-width: 900px) { .ttsbar { bottom: 24px; } }
.ttsbar .btn { min-height: 40px; }
.ttsbar .btn.icon { width: 40px; }
.ttsbar select { min-height: 36px; padding: 4px 8px; width: auto; font-size: 13px; }
.ttsbar .pos { font-size: 12px; color: var(--muted); font-weight: 700; white-space: nowrap; padding: 0 4px; }
