:root {
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --size: 19px;
  --measure: 36rem;
}
:root[data-theme='hell'] {
  --bg: #ffffff; --fg: #1d1d1f; --muted: #6b6b70; --line: #e4e4e7; --card: #f6f6f7; --accent: #2f5d8a; --accent-fg: #fff; --bar: #2f5d8a;
}
:root[data-theme='sepia'] {
  --bg: #f6f1e7; --fg: #2b2420; --muted: #7a6c5e; --line: #e2d8c6; --card: #efe7d8; --accent: #8a3b2a; --accent-fg: #fff; --bar: #8a3b2a;
}
:root[data-theme='dunkel'] {
  --bg: #15161a; --fg: #d9d6cf; --muted: #8c8a85; --line: #2c2e34; --card: #1f2127; --accent: #d9a35b; --accent-fg: #15161a; --bar: #d9a35b;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font-family: var(--sans); -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.loading { text-align: center; color: var(--muted); padding: 4rem 1rem; }

/* ---------- Anmeldung & Bibliothek ---------- */
.wrap { max-width: 44rem; margin: 0 auto; padding: max(1.5rem, env(safe-area-inset-top)) 1rem 3rem; }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.brand h1 { font-family: var(--serif); font-size: 1.6rem; margin: 0; }
.brand .who { font-size: .9rem; color: var(--muted); display: flex; gap: .5rem; align-items: center; }
.link { background: none; border: 0; color: var(--accent); padding: .25rem; text-decoration: underline; }

.login { max-width: 22rem; margin: 3rem auto; text-align: center; }
.login h1 { font-family: var(--serif); font-size: 2rem; margin: 0 0 .25rem; }
.login p { color: var(--muted); margin: 0 0 1.5rem; }
.people { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-bottom: 1rem; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .55rem 1.1rem; }
.chip[aria-pressed='true'] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.pin { width: 100%; font-size: 1.4rem; letter-spacing: .4em; text-align: center; padding: .7rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--card); }
.primary { width: 100%; margin-top: .8rem; padding: .8rem 1rem; border: 0; border-radius: .7rem; background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.primary:disabled { opacity: .5; }
.error { color: #c0392b; min-height: 1.4em; margin-top: .6rem; font-size: .95rem; }
:root[data-theme='dunkel'] .error { color: #ff8a7a; }

.book { display: grid; grid-template-columns: 7.5rem 1fr; gap: 1.2rem; padding: 1.2rem; border: 1px solid var(--line); background: var(--card); border-radius: 1rem; }
.cover { aspect-ratio: 2 / 3; border-radius: .4rem .7rem .7rem .4rem; background: linear-gradient(160deg, #24384d, #0d1620 70%); color: #eef3f7; display: flex; flex-direction: column; justify-content: space-between; padding: .8rem .6rem; box-shadow: inset 6px 0 0 rgba(255,255,255,.08), 0 6px 18px rgba(0,0,0,.25); font-family: var(--serif); text-align: center; position: relative; overflow: hidden; }
.cover::after { content: ''; position: absolute; inset: auto -20% -10% -20%; height: 45%; background: radial-gradient(ellipse at 50% 100%, rgba(255,255,255,.35), transparent 70%); }
.cover b { font-size: .85rem; letter-spacing: .05em; text-transform: uppercase; margin-top: .6rem; white-space: nowrap; position: relative; z-index: 1; }
.cover small { font-size: .62rem; opacity: .8; }
.book h2 { font-family: var(--serif); margin: .1rem 0 .2rem; font-size: 1.5rem; }
.book .sub { color: var(--muted); margin: 0 0 .8rem; }
.meter { height: .4rem; background: var(--line); border-radius: 999px; overflow: hidden; margin: .4rem 0 .3rem; }
.meter i { display: block; height: 100%; background: var(--bar); }
.status { font-size: .9rem; color: var(--muted); margin: 0 0 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.actions .primary { width: auto; margin: 0; }
.secondary { padding: .8rem 1rem; border-radius: .7rem; border: 1px solid var(--line); background: transparent; }
.sharehint { font-size: .85rem; color: var(--muted); margin-top: 1rem; word-break: break-all; }

/* ---------- Leser ---------- */
.bar { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); transition: transform .25s; }
.bar.hide { transform: translateY(-100%); }
.bar .row { max-width: 52rem; margin: 0 auto; display: flex; align-items: center; gap: .25rem; padding: .35rem .5rem; }
.bar .title { flex: 1; min-width: 0; text-align: center; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { background: none; border: 0; padding: .45rem .6rem; border-radius: .5rem; font-size: 1rem; line-height: 1; min-width: 2.5rem; min-height: 2.5rem; }
.icon:hover { background: var(--card); }
.saved { font-size: .75rem; color: var(--muted); min-width: 4.6rem; text-align: right; }
.progress { height: 3px; background: var(--line); }
.progress i { display: block; height: 100%; width: 0; background: var(--bar); transition: width .3s; }

.reader { max-width: var(--measure); margin: 0 auto; padding: 2.5rem 1.25rem 4rem; font-family: var(--serif); font-size: var(--size); line-height: 1.6; }
:root[data-font='sans'] .reader { font-family: var(--sans); }
.reader .part { text-align: center; font-size: .7em; letter-spacing: .2em; color: var(--muted); text-transform: uppercase; margin: 0 0 1.5rem; }
.reader h2 { text-align: center; font-size: 1em; letter-spacing: .2em; text-transform: uppercase; margin: 0 0 .3rem; font-weight: 600; }
.reader h3 { text-align: center; font-weight: normal; font-style: italic; font-size: 1.35em; margin: 0 0 2.2rem; }
.reader p { margin: 0 0 .9em; hyphens: auto; -webkit-hyphens: auto; text-align: justify; }
.reader p.dateline { text-align: left; color: var(--muted); font-size: .9em; margin-bottom: 1.6em; }
.reader hr.scene { border: 0; text-align: center; margin: 1.8em 0; }
.reader hr.scene::before { content: '◆'; color: var(--muted); font-size: .8em; }
.next { display: block; width: 100%; margin: 3rem 0 0; padding: 1rem; border-radius: .8rem; border: 1px solid var(--line); background: var(--card); font-family: var(--sans); font-size: 1rem; }
.next small { display: block; color: var(--muted); font-size: .85rem; }
.end { text-align: center; color: var(--muted); font-family: var(--sans); margin-top: 3rem; }
.resume { position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: .6rem 1rem; border-radius: 999px; font-size: .9rem; box-shadow: 0 6px 18px rgba(0,0,0,.25); z-index: 30; opacity: 0; transition: opacity .3s; pointer-events: none; max-width: calc(100% - 2rem); text-align: center; }
.resume.on { opacity: 1; }

/* Seitenleiste & Einstellungen */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet { position: fixed; z-index: 41; background: var(--bg); color: var(--fg); overflow: auto; font-family: var(--sans); }
.sheet.toc { top: 0; bottom: 0; left: 0; width: min(24rem, 90vw); padding: max(1rem, env(safe-area-inset-top)) 0 1rem; border-right: 1px solid var(--line); }
.sheet.toc h4 { margin: 1.2rem 1.2rem .4rem; font-size: .75rem; letter-spacing: .15em; color: var(--muted); text-transform: uppercase; }
.sheet.toc button { display: flex; gap: .6rem; width: 100%; text-align: left; background: none; border: 0; padding: .55rem 1.2rem; align-items: baseline; }
.sheet.toc button:hover { background: var(--card); }
.sheet.toc button.cur { background: var(--card); font-weight: 600; }
.sheet.toc .lbl { color: var(--muted); min-width: 5.2rem; font-size: .85rem; }
.sheet.toc .done { margin-left: auto; color: var(--muted); font-size: .8rem; }
.sheet.settings { right: .5rem; top: calc(3.2rem + env(safe-area-inset-top)); width: min(20rem, calc(100vw - 1rem)); border: 1px solid var(--line); border-radius: 1rem; padding: 1rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.settings .grp { margin-bottom: 1rem; }
.settings .grp:last-child { margin-bottom: 0; }
.settings label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .4rem; }
.seg { display: flex; gap: .4rem; }
.seg button { flex: 1; padding: .55rem; border-radius: .6rem; border: 1px solid var(--line); background: var(--card); }
.seg button[aria-pressed='true'] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.swatch-hell { background: #fff !important; color: #1d1d1f !important; }
.swatch-sepia { background: #f6f1e7 !important; color: #2b2420 !important; }
.swatch-dunkel { background: #15161a !important; color: #d9d6cf !important; }

@media (max-width: 30rem) {
  .book { grid-template-columns: 5.5rem 1fr; padding: 1rem; gap: 1rem; }
  .cover { padding: .7rem .3rem; }
  .cover b { font-size: .6rem; letter-spacing: 0; }
  .reader { padding: 1.8rem 1rem 4rem; }
  .saved { display: none; }
}
