/* =========================================================
   LeseWelt – Design
   ========================================================= */

:root {
  --ui-font: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --book-font: 'Literata', Georgia, serif;
  --radius: 14px;
  --nav-w: 88px;
  --nav-h: 64px;
  --danger: #c0392b;
  --ok: #2e8b57;
  --star: #f2b600;

  /* Hell (Standard) */
  --paper: #fbfaf7;
  --ink: #1f1f22;
  --muted: #6d6a66;
  --line: #e7e3db;
  --surface: #ffffff;
  --surface-2: #f3f0ea;
  --accent: #c2562f;
  --accent-ink: #ffffff;
  --accent-soft: rgb(194 86 47 / 0.14);
  --hl-lookup: rgb(230 140 60 / 0.32);
  --hl-tts: rgb(255 204 64 / 0.45);
  --shadow: 0 1px 2px rgb(40 30 20 / 0.06), 0 4px 14px rgb(40 30 20 / 0.07);
  --shadow-lg: 0 10px 40px rgb(30 20 10 / 0.18), 0 2px 8px rgb(30 20 10 / 0.08);
  color-scheme: light;
}

[data-theme='sepia'] {
  --paper: #f4ecd8;
  --ink: #3b2f22;
  --muted: #7d6c57;
  --line: #e1d4b6;
  --surface: #fbf5e6;
  --surface-2: #efe4c9;
  --accent: #a24b24;
  --accent-soft: rgb(162 75 36 / 0.14);
  --hl-lookup: rgb(210 120 40 / 0.3);
  --hl-tts: rgb(230 180 40 / 0.42);
  color-scheme: light;
}

[data-theme='dark'] {
  --paper: #1b1c1f;
  --ink: #dcd8d0;
  --muted: #908b83;
  --line: #313338;
  --surface: #24262a;
  --surface-2: #2d3035;
  --accent: #e98a5f;
  --accent-ink: #1b1c1f;
  --accent-soft: rgb(233 138 95 / 0.18);
  --hl-lookup: rgb(233 138 95 / 0.32);
  --hl-tts: rgb(230 190 70 / 0.3);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 14px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 12px 40px rgb(0 0 0 / 0.55);
  --danger: #ff7b6b;
  --ok: #6ccf98;
  color-scheme: dark;
}

[data-theme='black'] {
  --paper: #000000;
  --ink: #c9c5bd;
  --muted: #85817a;
  --line: #222326;
  --surface: #121314;
  --surface-2: #1c1d1f;
  --accent: #e98a5f;
  --accent-ink: #000000;
  --accent-soft: rgb(233 138 95 / 0.18);
  --hl-lookup: rgb(233 138 95 / 0.3);
  --hl-tts: rgb(230 190 70 / 0.28);
  --shadow: none;
  --shadow-lg: 0 12px 40px rgb(0 0 0 / 0.8), 0 0 0 1px #2a2b2e;
  --danger: #ff7b6b;
  --ok: #6ccf98;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.25s, color 0.25s;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg { display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Navigation ---------- */

.app-nav {
  position: fixed;
  z-index: 40;
  display: flex;
  background: var(--surface);
  border-color: var(--line);
}
.app-nav a {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 14px;
  transition: color 0.15s, background-color 0.15s;
}
.app-nav a svg { width: 24px; height: 24px; }
.app-nav a:hover { color: var(--ink); }
.app-nav a[aria-current='page'] { color: var(--accent); }
.app-nav a[aria-current='page'] .nav-ico { background: var(--accent-soft); }
.nav-ico { display: grid; place-items: center; width: 52px; height: 30px; border-radius: 999px; transition: background-color 0.15s; }
.app-nav b {
  position: absolute;
  top: 2px;
  left: calc(50% + 8px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.68rem;
  line-height: 18px;
  text-align: center;
}
.app-nav .nav-brand { display: none; }

@media (min-width: 761px) {
  .app-nav {
    top: 0; bottom: 0; left: 0;
    width: var(--nav-w);
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 18px 8px;
    border-right: 1px solid var(--line);
  }
  .app-nav a { width: 72px; height: 64px; }
  .app-nav .nav-brand { display: flex; height: auto; margin-bottom: 14px; }
  .nav-brand img { width: 40px; height: 40px; border-radius: 10px; }
  #view { margin-left: var(--nav-w); }
}
@media (max-width: 760px) {
  .app-nav {
    left: 0; right: 0; bottom: 0;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    justify-content: space-around;
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
  .app-nav a { flex: 1; }
  #view { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
}
body[data-route='read'] .app-nav, body[data-route='train'] .app-nav { display: none; }
body[data-route='read'] #view, body[data-route='train'] #view { margin-left: 0; padding-bottom: 0; }

/* ---------- Seiten ---------- */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 36px 64px;
}
@media (max-width: 760px) {
  .page { padding: calc(14px + env(safe-area-inset-top)) 16px 32px; }
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}
.page-head h1 { margin: 0; font-family: var(--book-font); font-size: 1.9rem; font-weight: 600; letter-spacing: -0.01em; }
.page-head p { margin: 2px 0 0; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { border-radius: 9px; box-shadow: var(--shadow); }
.brand p { color: var(--muted); font-size: 0.9rem; }
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (max-width: 760px) {
  .page-head h1 { font-size: 1.55rem; }
  .lib-actions { width: 100%; }
  .lib-actions .search { flex: 1 1 100%; }
  .lib-actions .btn { flex: 1; justify-content: center; }
}

h2 { font-size: 1.15rem; margin: 0 0 12px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }

/* ---------- Bedienelemente ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 0.88rem; }
.btn.big { min-height: 54px; padding: 0 28px; font-size: 1.05rem; border-radius: 16px; }
.btn:disabled { opacity: 0.6; cursor: default; }
kbd { font: 600 0.72rem var(--ui-font); padding: 1px 6px; border-radius: 5px; border: 1px solid currentColor; opacity: 0.6; }
@media (pointer: coarse) { kbd { display: none; } }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  transition: background-color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.icon-btn.big { width: 52px; height: 52px; background: var(--accent); color: var(--accent-ink); border-radius: 50%; }

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.87rem;
  white-space: nowrap;
}
.chip-btn:hover { border-color: var(--muted); }
.chip-btn svg { width: 18px; height: 18px; }
.chip-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip-btn.on svg { fill: var(--star); color: var(--star); }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  min-width: 240px;
}
.search svg { width: 18px; height: 18px; flex: none; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; color: var(--ink); }

.input, .select {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
}
.select { width: auto; max-width: 100%; }
textarea.input { resize: vertical; line-height: 1.5; font-family: var(--book-font); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.9rem;
}
.seg-btn[aria-checked='true'] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.seg.fonts .seg-btn { font-weight: 400; font-size: 1rem; }
.sw { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgb(0 0 0 / 0.2); }
.sw-light { background: #fbfaf7; }
.sw-sepia { background: #f4ecd8; }
.sw-dark { background: #1b1c1f; }
.sw-black { background: #000; }

.field { margin: 0 0 18px; }
.field-label { font-weight: 700; font-size: 0.86rem; margin-bottom: 8px; color: var(--ink); }
.hint { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 6px; line-height: 1.4; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row .select { flex: 1; }
.stepper { display: flex; align-items: center; gap: 12px; }
.fs-val { min-width: 56px; text-align: center; font-weight: 700; }

.row-toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; cursor: pointer; }
.row-text { display: flex; flex-direction: column; }
.row-text small { color: var(--muted); font-size: 0.8rem; }
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background-color 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.range { width: 100%; accent-color: var(--accent); }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.progress { height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; flex: 1; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { min-height: 34px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 0.85rem; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.lang-chip { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- Bibliothek ---------- */

.continue-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px;
  margin-bottom: 34px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.continue-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.continue-info { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.continue-info strong { font-family: var(--book-font); font-size: 1.25rem; font-weight: 600; }
.continue-info .progress { max-width: 360px; margin: 6px 0 2px; flex: none; }
.eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent); }
@media (max-width: 560px) { .continue-btn { display: none; } }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 30px 24px;
}
@media (max-width: 560px) {
  .book-grid { grid-template-columns: repeat(2, 1fr); gap: 22px 16px; }
}
.book-card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.book-link { display: block; border-radius: 6px; color: inherit; text-decoration: none; }
.cover {
  aspect-ratio: 2 / 3;
  width: 100%;
  border-radius: 4px 10px 10px 4px;
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12), 0 8px 22px rgb(0 0 0 / 0.14), inset 3px 0 0 rgb(255 255 255 / 0.08);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.book-link:hover .cover { transform: translateY(-3px) rotate(-0.4deg); box-shadow: 0 2px 4px rgb(0 0 0 / 0.12), 0 16px 32px rgb(0 0 0 / 0.2); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.small { width: 70px; flex: none; border-radius: 3px 7px 7px 3px; }
.cover.gen {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16% 12% 12% 16%;
  background: linear-gradient(155deg, var(--c1), var(--c2));
  color: #f6efe2;
}
.cover.gen::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 7%;
  background: linear-gradient(90deg, rgb(0 0 0 / 0.25), rgb(255 255 255 / 0.06));
}
.gen-title { font-family: var(--book-font); font-weight: 600; font-size: clamp(0.8rem, 1.1vw + 0.5rem, 1.15rem); line-height: 1.2; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.gen-author { font-size: 0.75rem; opacity: 0.8; letter-spacing: 0.03em; }
.cover.small.gen { padding: 10px 8px; }
.cover.small .gen-title { font-size: 0.56rem; -webkit-line-clamp: 5; overflow-wrap: break-word; }
.cover.small .gen-author { display: none; }
.book-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.book-title { color: var(--ink); text-decoration: none; font-weight: 700; font-size: 0.95rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-author { color: var(--muted); font-size: 0.84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-foot { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.book-foot .pct { font-size: 0.75rem; color: var(--muted); min-width: 30px; }

.empty { text-align: center; max-width: 520px; margin: 30px auto; padding: 36px 24px; border: 1.5px dashed var(--line); border-radius: 24px; }
.empty-art { font-size: 3.2rem; line-height: 1; margin-bottom: 12px; }
.empty h3 { margin: 0 0 8px; font-family: var(--book-font); font-size: 1.3rem; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.empty-search { padding: 20px 0; }

.sources { margin-top: 56px; }
.source-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 14px; }
.source-list a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s;
}
.source-list a:hover { border-color: var(--accent); }
.source-list span { color: var(--muted); font-size: 0.86rem; }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.drop-overlay div { padding: 40px 60px; border: 3px dashed var(--accent); border-radius: 24px; font-size: 1.4rem; font-weight: 700; color: var(--accent); background: var(--surface); }

.menu-list { display: flex; flex-direction: column; gap: 4px; }
.book-info { display: flex; flex-direction: column; gap: 4px; padding: 0 4px 12px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.book-info strong { font-family: var(--book-font); font-size: 1.1rem; }
.menu-item { display: block; text-align: left; padding: 12px; border-radius: 10px; border: 0; background: none; color: var(--ink); text-decoration: none; font-weight: 600; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }
.paste-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Dialoge ---------- */

.sheet-dialog {
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  border-radius: 22px;
  width: min(560px, calc(100vw - 32px));
  max-height: min(88dvh, 920px);
  box-shadow: var(--shadow-lg);
}
.sheet-dialog[open] { display: flex; flex-direction: column; animation: pop 0.2s ease-out; }
.sheet-dialog.small { width: min(420px, calc(100vw - 32px)); }
.sheet-dialog::backdrop { background: rgb(10 8 5 / 0.38); backdrop-filter: blur(2px); }
.sheet-grip { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 4px 22px; }
.sheet-head h2 { margin: 0; font-size: 1.12rem; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 6px 22px 26px; }
@media (min-width: 761px) {
  .sheet-dialog.side-right, .sheet-dialog.side-left {
    height: 100dvh;
    max-height: 100dvh;
    width: min(420px, 92vw);
    margin: 0;
    border-radius: 0;
    animation: none;
  }
  .sheet-dialog.side-right { margin-left: auto; border-radius: 22px 0 0 22px; }
  .sheet-dialog.side-left { margin-right: auto; border-radius: 0 22px 22px 0; }
  .sheet-dialog.side-right[open] { animation: slide-l 0.22s ease-out; }
  .sheet-dialog.side-left[open] { animation: slide-r 0.22s ease-out; }
}
@media (max-width: 760px) {
  .sheet-dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    max-height: 90dvh;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sheet-dialog[open] { animation: slide-up 0.24s ease-out; }
  .sheet-grip { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
}
@keyframes pop { from { opacity: 0; transform: scale(0.97); } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0.4; } }
@keyframes slide-l { from { transform: translateX(40px); opacity: 0.4; } }
@keyframes slide-r { from { transform: translateX(-40px); opacity: 0.4; } }
.confirm p { font-size: 1.05rem; margin: 4px 0 20px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Toasts ---------- */

#toasts {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 24px);
  pointer-events: none;
}
@media (max-width: 760px) { body:not([data-route='read']) #toasts { bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); } }
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: 14px;
  background: #26272b;
  color: #f4f1ea;
  font-size: 0.93rem;
  font-weight: 500;
  box-shadow: 0 8px 26px rgb(0 0 0 / 0.25);
  pointer-events: auto;
  animation: toast-in 0.22s ease-out;
  transition: opacity 0.35s, transform 0.35s;
}
.toast.out { opacity: 0; transform: translateY(8px); }
.toast-error { background: #7d2419; }
.toast-success { background: #1f5b3d; }
.toast-btn { border: 0; background: rgb(255 255 255 / 0.16); color: inherit; font-weight: 700; padding: 5px 10px; border-radius: 8px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* =========================================================
   Leser
   ========================================================= */

.reader {
  --gap: 48px;
  --page-w: 720px;
  --cols: 1;
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}

.r-slim {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 32px;
  padding: 0 16px;
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.r-slim-top { height: calc(32px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); text-overflow: ellipsis; display: block; text-align: center; line-height: calc(32px); }
.r-slim-bottom {
  justify-content: space-between;
  height: calc(32px + env(safe-area-inset-bottom));
  padding: 0 calc(var(--gap) / 2) env(safe-area-inset-bottom);
  width: min(100%, var(--page-w));
  margin: 0 auto;
}
.r-slim-bottom span:nth-child(2) { font-variant-numeric: tabular-nums; }

.r-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  outline: none;
  touch-action: pan-y pinch-zoom;
}
.reader[data-mode='scroll'] .r-viewport { overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }

.r-clip { width: var(--page-w); max-width: 100%; height: 100%; margin: 0 auto; position: relative; overflow: hidden; }
.reader[data-mode='scroll'] .r-clip { height: auto; overflow: visible; padding-bottom: 12vh; }

.book-text {
  font-family: var(--book-font);
  font-size: var(--fs, 20px);
  line-height: var(--lh, 1.6);
  text-align: var(--align, justify);
  hyphens: auto;
  -webkit-hyphens: auto;
  hyphenate-limit-chars: 7 3 3;
  overflow-wrap: break-word;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  padding: 16px calc(var(--gap) / 2) 12px;
  color: var(--ink);
  cursor: text;
}
.reader[data-justify='false'] .book-text { hyphens: manual; -webkit-hyphens: manual; }
.reader[data-mode='paged'] .book-text {
  height: 100%;
  width: var(--page-w);
  column-count: var(--cols);
  column-gap: var(--gap);
  column-fill: auto;
  padding-block: 10px 6px;
  transition: transform 0.32s cubic-bezier(0.22, 0.8, 0.3, 1);
  will-change: transform;
}
@media (prefers-reduced-motion: reduce) {
  .reader[data-mode='paged'] .book-text { transition-duration: 0.01s; }
}

.book-text p { margin: 0 0 0.2em; text-indent: 1.4em; orphans: 2; widows: 2; }
.book-text :is(h1, h2, h3, h4, h5, h6) + p,
.book-text p:first-child,
.book-text :is(.c, .r, br + p),
.book-text blockquote p,
.book-text li p,
.book-text .poem p,
.book-text figure + p,
.book-text img + p,
.book-text hr + p { text-indent: 0; }
.book-text :is(h1, h2, h3, h4, h5, h6) {
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-indent: 0;
  hyphens: manual;
  text-wrap: balance;
  break-after: avoid;
  break-inside: avoid;
  letter-spacing: -0.005em;
}
.book-text h1 { font-size: 1.6em; margin: 1.2em 0 1em; }
.book-text h2 { font-size: 1.4em; margin: 1.1em 0 0.9em; }
.book-text h3 { font-size: 1.18em; margin: 1em 0 0.7em; }
.book-text :is(h4, h5, h6) { font-size: 1.02em; margin: 1em 0 0.5em; }
.book-text > :first-child:is(h1, h2, h3) { margin-top: 0.4em; }
.book-text img {
  display: block;
  max-width: 100%;
  max-height: calc(var(--page-h, 80vh) - 40px);
  height: auto;
  margin: 0.8em auto;
  break-inside: avoid;
  border-radius: 3px;
}
[data-theme='dark'] .book-text img, [data-theme='black'] .book-text img { filter: brightness(0.9); }
.book-text figure { margin: 1em 0; break-inside: avoid; }
.book-text figcaption { font-size: 0.85em; color: var(--muted); text-align: center; }
.book-text blockquote { margin: 0.8em 0 0.8em 1.4em; }
.book-text .epigraph { margin: 0.6em 0 1.4em auto; max-width: 78%; font-size: 0.92em; font-style: italic; text-align: start; }
.book-text .poem { margin: 1em 0 1em 1.6em; text-align: start; }
.book-text .poem p { margin: 0; }
.book-text .stanza { margin-bottom: 0.9em; }
.book-text .c { text-align: center; }
.book-text .r { text-align: end; }
.book-text ul, .book-text ol { padding-inline-start: 1.5em; margin: 0.6em 0; }
.book-text li { margin: 0.2em 0; }
.book-text a[data-href] { color: var(--accent); text-decoration: none; }
.book-text a.note { font-size: 0.72em; vertical-align: super; line-height: 0; padding: 0 0.15em; font-weight: 700; }
.book-text hr { border: 0; height: auto; margin: 1.2em 0; text-align: center; }
.book-text hr::after { content: '⁂'; color: var(--muted); }
.book-text table { border-collapse: collapse; font-size: 0.88em; margin: 1em 0; break-inside: avoid; }
.book-text :is(td, th) { border: 1px solid var(--line); padding: 0.3em 0.5em; }
.book-text pre { white-space: pre-wrap; font-size: 0.85em; }
.book-text dt { font-weight: 700; }
.book-text dd { margin: 0 0 0.5em 1.4em; }
.book-text ::selection { background: var(--accent-soft); }
.end-mark { display: inline-block; width: 0; height: 0; }

::highlight(lookup) { background-color: var(--hl-lookup); }
::highlight(tts) { background-color: var(--hl-tts); }
::highlight(saved) {
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.r-chap-end { text-align: center; padding: 36px 16px 20px; color: var(--muted); }
.r-chap-end:empty { display: none; }
.r-chap-end p { margin: 0 0 14px; }
.reader[data-mode='paged'] .r-chap-end { display: none; }

/* seitliche Blätter-Pfeile (nur Maus) */
.r-side {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 44px;
  height: 88px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s, background-color 0.2s;
}
.r-side svg { width: 28px; height: 28px; }
.r-side.prev { left: 8px; }
.r-side.next { right: 8px; }
.r-viewport:hover .r-side { opacity: 0.55; }
.r-side:hover { opacity: 1 !important; background: var(--surface-2); }
.reader[data-mode='scroll'] .r-side { display: none; }
@media (pointer: coarse) { .r-side { display: none; } }

/* Leisten (einblendbar) */
.r-top, .r-bottom {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.2s ease;
}
.r-top {
  top: 0;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  border-bottom: 1px solid var(--line);
  transform: translateY(-100%);
}
.r-bottom {
  bottom: 0;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  transform: translateY(100%);
}
.reader.ui-visible :is(.r-top, .r-bottom) { opacity: 1; transform: none; pointer-events: auto; }
.r-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 6px; }
.r-title strong, .r-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-title strong { font-size: 0.98rem; }
.r-title span { font-size: 0.8rem; color: var(--muted); }
.r-range-wrap { flex: 1; position: relative; display: flex; align-items: center; padding: 0 6px; }
.r-range-wrap input { width: 100%; accent-color: var(--accent); height: 30px; }
.r-range-label {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.82rem;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.r-range-label.show { opacity: 1; }

/* Auswahl-Leiste */
.sel-bar {
  position: fixed;
  z-index: 65;
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: var(--shadow-lg);
  animation: pop 0.15s ease-out;
}
.sel-bar button {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font-weight: 600;
  font-size: 0.9rem;
}
.sel-bar button:hover { background: rgb(128 128 128 / 0.25); }
.sel-bar svg { width: 19px; height: 19px; }

/* Vorlese-Leiste */
.tts-bar {
  position: absolute;
  z-index: 35;
  left: 50%;
  bottom: calc(44px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}
.reader.ui-visible .tts-bar { bottom: calc(76px + env(safe-area-inset-bottom)); }

/* Inhaltsverzeichnis */
.toc-book { display: flex; flex-direction: column; gap: 2px; padding: 0 4px 14px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.toc-book strong { font-family: var(--book-font); font-size: 1.15rem; }
.toc-list { display: flex; flex-direction: column; gap: 2px; }
.toc-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px 10px calc(12px + var(--depth, 0) * 18px);
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font-size: calc(0.98rem - var(--depth, 0) * 0.04rem);
}
.toc-item:hover { background: var(--surface-2); }
.toc-item small { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.toc-item.current { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* =========================================================
   Wörterbuch-Popup
   ========================================================= */

.lookup {
  position: fixed;
  z-index: 70;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  font-family: var(--ui-font);
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  transition: opacity 0.16s ease, transform 0.2s ease;
}
.lookup.show { opacity: 1; transform: none !important; }
.lookup.card { border-radius: 18px; padding: 14px 16px 12px; transform: translateY(6px); }
.lookup.sheet { left: 8px; right: 8px; border-radius: 22px; padding: 6px 16px 14px; max-height: 56dvh; }
.lookup.sheet-bottom { bottom: calc(8px + env(safe-area-inset-bottom)); transform: translateY(18px); }
.lookup.sheet-top { top: calc(8px + env(safe-area-inset-top)); transform: translateY(-18px); }
.lk-grip { display: none; }
.lookup.sheet .lk-grip { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 8px; }
.lk-head { display: flex; align-items: flex-start; gap: 8px; }
.lk-word-wrap { flex: 1; min-width: 0; }
.lk-word { margin: 0; font-family: var(--book-font); font-size: 1.65rem; font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.lk-ipa { color: var(--muted); font-size: 0.98rem; margin-top: 2px; font-family: 'Source Sans 3', 'Segoe UI', 'Lucida Sans Unicode', 'Arial Unicode MS', sans-serif; }
.lk-ipa:empty { display: none; }
.lk-head-actions { display: flex; gap: 2px; margin: -4px -6px 0 0; }
.lk-star svg { fill: none; }
.lk-star.on { color: var(--star); }
.lk-star.on svg { fill: var(--star); }
.lk-speak { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 10px 0 2px; }
.lk-speak > span:empty { display: none; }
.lk-speak > span { display: contents; }
.lk-lang { margin-left: auto; }
.lk-lang select {
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  max-width: 120px;
}
.lk-sec { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 12px; }
.lk-label { font-size: 0.7rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.lk-main { margin: 0 0 8px; font-size: 1.3rem; font-weight: 600; line-height: 1.3; }
.lk-main-long { font-size: 1.06rem; font-weight: 500; line-height: 1.55; }
.lk-alts { display: grid; gap: 6px; }
.lk-alt { display: flex; gap: 8px; align-items: baseline; }
.lk-pos { flex: none; min-width: 5.5em; font-size: 0.78rem; font-style: italic; color: var(--muted); }
.lk-terms { display: flex; flex-wrap: wrap; gap: 4px; }
.term { border: 0; border-radius: 8px; padding: 3px 9px; background: var(--surface-2); color: var(--ink); font-size: 0.95rem; }
.term:hover { background: var(--accent-soft); }
.lk-ctx { margin: 0 0 10px; font-family: var(--book-font); font-size: 1rem; line-height: 1.55; }
.lk-ctx mark, .vr-ctx mark, .fc-ctx mark { background: var(--hl-lookup); color: inherit; border-radius: 3px; padding: 0 2px; }
.lk-row { display: flex; flex-wrap: wrap; gap: 6px; }
.lk-sent-tr { margin: 10px 0 0; padding: 8px 12px; line-height: 1.55; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 10px 10px 0; }
.lk-defs summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; margin: 0; }
.lk-defs summary::-webkit-details-marker { display: none; }
.lk-defs summary::after { content: '▸'; transition: transform 0.15s; }
.lk-defs[open] summary::after { transform: rotate(90deg); }
.lk-def ol { margin: 4px 0 10px; padding-left: 1.3em; }
.lk-def li { margin-bottom: 5px; font-size: 0.92rem; line-height: 1.45; }
.lk-ex { color: var(--muted); font-style: italic; margin-top: 2px; }
.lk-foot { margin-top: 12px; font-size: 0.72rem; color: var(--muted); }
.lk-foot:empty { display: none; }
.lk-err { color: var(--danger); margin: 0 0 8px; }
.lk-phrase { flex: 1; margin: 2px 0 0; padding-left: 12px; border-left: 3px solid var(--line); font-family: var(--book-font); font-size: 1.04rem; line-height: 1.5; max-height: 7.6em; overflow-y: auto; }
.lk-note { font-size: 1rem; line-height: 1.55; margin-bottom: 12px; padding: 0; text-align: start; hyphens: manual; cursor: auto; }
.lk-note p { text-indent: 0; margin: 0 0 0.4em; }
.skel {
  height: 18px;
  margin: 8px 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skel.short { width: 55%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Darstellungs-Panel */
.display-panel .seg.themes .seg-btn { flex: 1 1 calc(50% - 6px); justify-content: center; }
.display-panel .seg.fonts .seg-btn { flex: 1 1 calc(50% - 6px); justify-content: center; }
.display-panel .select { width: 100%; }

/* =========================================================
   Vokabelheft & Training
   ========================================================= */

.vocab-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.vocab-tools .search { flex: 1; }
.vocab-list { display: flex; flex-direction: column; gap: 10px; }
.vocab-row {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.vr-main { flex: 1; min-width: 0; }
.vr-word { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.vr-word strong { font-family: var(--book-font); font-size: 1.22rem; font-weight: 600; }
.ipa { color: var(--muted); font-size: 0.9rem; }
.vr-tr { margin-top: 2px; font-size: 1.02rem; font-weight: 600; }
.vr-tr .muted { font-weight: 400; }
.vr-ctx { margin: 6px 0 4px; font-family: var(--book-font); font-size: 0.94rem; line-height: 1.5; color: var(--muted); }
.vr-src { font-size: 0.78rem; }
.vr-actions { display: flex; flex-direction: column; gap: 2px; }
.box-dots { display: inline-flex; gap: 3px; margin-left: 2px; }
.box-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.box-dots i.on { background: var(--ok); }

.train { max-width: 720px; min-height: 100dvh; display: flex; flex-direction: column; }
.train-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.train-progress { flex: 1; min-width: 80px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.train-progress span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.flashcard {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 340px;
  padding: 36px 24px;
  border-radius: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
}
.fc-lang { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.fc-front { font-family: var(--book-font); font-size: clamp(2rem, 6vw, 3rem); font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.fc-ctx { max-width: 540px; font-family: var(--book-font); color: var(--muted); line-height: 1.55; margin: 6px 0 0; }
.fc-back { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 16px; margin-top: 4px; border-top: 1px solid var(--line); width: 100%; animation: pop 0.2s; }
.fc-answer { font-size: clamp(1.4rem, 4.5vw, 2rem); font-weight: 700; color: var(--accent); }
.train-actions { display: flex; gap: 10px; justify-content: center; padding: 20px 0 calc(10px + env(safe-area-inset-bottom)); }
.train-actions .btn.grade { flex: 1; justify-content: center; min-height: 56px; font-size: 1rem; max-width: 200px; }
.grade.g0 { color: var(--danger); }
.grade.g2 { background: var(--ok); color: #fff; border-color: transparent; }
.train-done { margin: auto; text-align: center; padding: 40px 20px; }
.train-done h2 { font-family: var(--book-font); font-size: 1.8rem; }

/* =========================================================
   Einstellungen
   ========================================================= */

.settings { max-width: 760px; }
.card-sec { padding: 22px 22px 8px; margin-bottom: 18px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); }
.card-sec h2 { font-size: 1.1rem; margin-bottom: 16px; }
.card-sec > p { margin-top: 0; }
.device-box { padding: 6px 0 14px; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.device-row .ok { color: var(--ok); font-weight: 600; }
.voice-box { margin-top: 6px; }
.howto { padding-left: 1.2em; line-height: 1.6; }
.howto li { margin-bottom: 6px; }
@media (max-width: 760px) {
  .card-sec { padding: 18px 16px 6px; }
}

.version { margin: 4px 0 2px; font-size: 0.9rem; }
.version strong { font-variant-numeric: tabular-nums; }
