@font-face { font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("/static/fonts/literata-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("/static/fonts/literata-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url("/static/fonts/literata-latin-ext-wght-italic.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+A720-A7FF; }
@font-face { font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url("/static/fonts/literata-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+20AC; }

:root {
  --ink: #0B1220;
  --gold: #E3B63C;
  --gold-text: #7E5B0C;
  --paper: #FFFEF9;
  --stone: #5B6270;
  --rule: #E2DCCB;
  --serif: "Literata", "Iowan Old Style", Palatino, Georgia, serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--serif); font-size: 1.0625rem; line-height: 1.6;
  color: var(--ink); background: var(--paper); font-variant-numeric: oldstyle-nums proportional-nums; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 2px; }

/* ---------- Bibliothek ---------- */
.shelf { max-width: 42rem; margin: 0 auto; padding: 3.5rem 1.5rem 5rem; }
.masthead { margin-bottom: 3.5rem; }
.masthead .publisher { font-size: 0.95rem; color: var(--stone); margin: 0; }
.masthead .publisher a { text-decoration: none; }
.masthead h1 { font-size: clamp(3rem, 12vw, 5.25rem); font-weight: 800; line-height: 0.95;
  letter-spacing: -0.02em; margin: 0.2rem 0 1rem; }
.masthead h1::after { content: ""; display: block; width: 3.5rem; height: 5px; background: var(--gold);
  margin-top: 1.1rem; }
.masthead .intro { max-width: 32rem; color: var(--stone); margin: 0; }

.book { margin-bottom: 3.25rem; }
.book h2 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin: 0 0 0.9rem; }
.book h2 a { text-decoration: none; }
.book h2 a:hover { text-decoration: underline; text-decoration-color: var(--gold); text-decoration-thickness: 2px; }

.toc { list-style: none; margin: 0; padding: 0; }
.toc li { border-top: 1px solid var(--rule); }
.toc li:last-child { border-bottom: 1px solid var(--rule); }
.toc a { display: flex; align-items: baseline; gap: 0.6rem; padding: 0.7rem 0; text-decoration: none; }
.toc .num { flex: 0 0 2.2rem; font-variant-numeric: lining-nums tabular-nums; color: var(--gold-text); font-weight: 600; }
.toc .name { flex: 0 1 auto; }
.toc .leader { flex: 1 1 1rem; border-bottom: 2px dotted var(--rule); transform: translateY(-0.3em); min-width: 1rem; }
.toc .pages { flex: 0 0 auto; color: var(--stone); font-size: 0.9rem; font-variant-numeric: lining-nums tabular-nums; }
.toc a:hover .name { text-decoration: underline; text-decoration-color: var(--gold); text-decoration-thickness: 2px; }
.toc a:hover .leader { border-bottom-color: var(--gold); }

.empty { color: var(--stone); font-style: italic; }
.back { display: inline-block; margin-bottom: 2rem; color: var(--stone); text-decoration: none; }
.back:hover { color: var(--ink); }
footer.site { margin-top: 4rem; font-size: 0.9rem; color: var(--stone); }

/* ---------- Hintergrund: Bibliothek mit Holztisch ---------- */
html:has(body.dunkel), html:has(body.reading) { background: #120C07; }
body.dunkel, body.reading { background: transparent; position: relative; isolation: isolate; }
body.dunkel::before, body.reading::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: url("/static/img/hintergrund.webp") center 65% / cover no-repeat;
}
@media (max-width: 900px) {
  body.dunkel::before, body.reading::before { background-image: url("/static/img/hintergrund-960.webp"); }
}
body.dunkel::after, body.reading::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
}
/* Bibliothek: dunkler abgetönt, damit die Schrift gut lesbar bleibt */
body.dunkel::after { background: linear-gradient(90deg, rgba(14,9,5,.80) 0%, rgba(14,9,5,.68) 55%, rgba(14,9,5,.40) 100%); }
/* Reader: heller, das Buch liegt auf dem Tisch */
body.reading::after { background: radial-gradient(ellipse at 50% 55%, rgba(14,9,5,.15) 0%, rgba(14,9,5,.55) 75%); }

body.dunkel { color: #F1EADC; }
body.dunkel .masthead .publisher, body.dunkel .masthead .intro, body.dunkel footer.site,
body.dunkel .back, body.dunkel .empty, body.dunkel .toc .pages { color: #C9BFAE; }
body.dunkel .back:hover { color: #fff; }
body.dunkel .toc li { border-color: rgba(241, 234, 220, .16); }
body.dunkel .toc .leader { border-bottom-color: rgba(241, 234, 220, .22); }
body.dunkel .toc .num { color: var(--gold); }
body.dunkel .masthead h1, body.dunkel .book h2 { text-shadow: 0 2px 18px rgba(0,0,0,.6); }

/* ---------- Reader ---------- */
body.reading { color: #F1EADC; min-height: 100vh; display: flex; flex-direction: column; }
.reader-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 1rem 1.25rem 0.5rem; max-width: 76rem; width: 100%; margin: 0 auto; }
.reader-head a { color: var(--gold); text-decoration: none; }
.reader-head a:hover { text-decoration: underline; }
.reader-head h1 { font-size: 1.05rem; font-weight: 600; margin: 0; text-align: right; }
.reader-head h1 span { color: #C9BFAE; font-weight: 400; }
.reader-head { text-shadow: 0 1px 10px rgba(0,0,0,.7); }
.stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0.5rem; min-width: 0; overflow: hidden; }
#flipbook { position: relative; flex: none; transition: transform .45s ease; filter: drop-shadow(0 18px 28px rgba(0,0,0,.55)) drop-shadow(0 4px 8px rgba(0,0,0,.4)); }
#flipbook .page { background: #fff; overflow: hidden; }
#flipbook .page.leer { background: transparent; }
#flipbook .page img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.5rem 1.25rem;
  padding: 0.75rem 1rem 1.5rem; }
.controls button, .controls a {
  font: inherit; font-size: 0.95rem; color: #F1EADC; background: rgba(18, 12, 7, .55); border: 1px solid rgba(241, 234, 220, .22);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  border-radius: 999px; padding: 0.4rem 1rem; cursor: pointer; text-decoration: none; }
.controls button:hover, .controls a:hover { border-color: var(--gold); color: var(--gold); }
.controls button:disabled { opacity: 0.4; cursor: default; border-color: rgba(241, 234, 220, .22); color: #F1EADC; }
.controls .counter { font-variant-numeric: lining-nums tabular-nums; color: #E4DACA; text-shadow: 0 1px 8px rgba(0,0,0,.8); min-width: 7rem; text-align: center; }
.controls .next-ch { border-color: var(--gold); color: var(--gold); }

/* ---------- Vorlesen ---------- */
.listen { width: 100%; max-width: 34rem; margin: 0 auto; padding: 0 1rem 2rem; display: grid; gap: 0.5rem; justify-items: center; }
.listen-by { margin: 0; font-size: 0.95rem; color: #E4DACA; font-style: italic; text-shadow: 0 1px 8px rgba(0,0,0,.8); }
.listen audio { width: 100%; }
.follow { font-size: 0.9rem; color: #E4DACA; text-shadow: 0 1px 8px rgba(0,0,0,.8); display: flex; gap: 0.5rem; align-items: center; cursor: pointer; }
.follow input { accent-color: var(--gold); }
.listen-note { text-align: center; color: #E4DACA; font-style: italic; margin: 0 1rem 2rem; }

/* ---------- Upload ---------- */
fieldset.choice { border: 0; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
fieldset.choice legend { font-weight: 600; margin-bottom: 0.3rem; padding: 0; }
fieldset.choice label { display: grid; grid-template-columns: auto 1fr; column-gap: 0.6rem; font-weight: 400;
  padding: 0.7rem 0.8rem; border: 1px solid #C9C2AE; border-radius: 6px; background: #fff; cursor: pointer; }
fieldset.choice label[hidden] { display: none; }
fieldset.choice input { margin-top: 0.35rem; accent-color: var(--ink); }
fieldset.choice span { grid-column: 2; font-size: 0.9rem; color: var(--stone); }
fieldset.choice label:has(input:checked) { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--gold); }
.parts { list-style: none; margin: 0; padding: 0; max-height: 22rem; overflow-y: auto; border: 1px solid #C9C2AE;
  border-radius: 6px; background: #fff; }
.parts li { display: grid; grid-template-columns: auto 1fr auto; gap: 0.6rem; align-items: center;
  padding: 0.4rem 0.6rem; border-top: 1px solid var(--rule); }
.parts li:first-child { border-top: 0; }
.parts input[type=text] { border: 0; padding: 0.3rem 0; font: inherit; width: 100%; background: transparent; }
.parts input[type=checkbox] { accent-color: var(--ink); width: 1.1rem; height: 1.1rem; }
.parts span { font-size: 0.85rem; color: var(--stone); font-variant-numeric: lining-nums tabular-nums; }

.drop { display: block; border: 2px dashed var(--rule); border-radius: 10px; padding: 2.5rem 1.5rem; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--gold); background: #FFF8E4; }
.drop strong { display: block; font-size: 1.2rem; margin-bottom: 0.25rem; }
.drop span { color: var(--stone); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }

form.meta { display: grid; gap: 1.1rem; margin-top: 2rem; }
form.meta[hidden] { display: none; }
.field label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.field .hint { font-size: 0.9rem; color: var(--stone); margin: 0.25rem 0 0; }
.field input, .field select { width: 100%; font: inherit; padding: 0.6rem 0.75rem; border: 1px solid #C9C2AE;
  border-radius: 6px; background: #fff; color: var(--ink); }
.row { display: grid; grid-template-columns: 7rem 1fr; gap: 1rem; }
.primary { font: inherit; font-weight: 600; background: var(--ink); color: var(--paper); border: 0; border-radius: 6px;
  padding: 0.8rem 1.4rem; cursor: pointer; justify-self: start; }
.primary:hover { background: #1C2940; }
.primary:disabled { opacity: 0.6; cursor: progress; }
.status { margin-top: 1.25rem; padding: 0.9rem 1rem; border-left: 4px solid var(--gold); background: #FFF8E4; }
.status.error { border-left-color: #B3261E; background: #FCEDEC; }
.status[hidden] { display: none; }
.admin-list { margin-top: 4rem; }
.admin-list h2 { font-size: 1.3rem; margin: 2rem 0 0.5rem; }
.admin-list li { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 1rem; align-items: baseline;
  padding: 0.55rem 0; border-top: 1px solid var(--rule); }
.admin-list .audio-state { font-size: 0.85rem; color: var(--stone); text-align: right; }
.admin-list .audio-state.pending { color: var(--gold-text); }
.admin-list .audio-state.error { color: #B3261E; }
.admin-list .actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.25rem 1.1rem; }
.conflict { padding: 0.8rem 1rem; border-left: 4px solid #B3261E; background: #FCEDEC; }
.conflict[hidden] { display: none; }
.conflict p { margin: 0 0 0.5rem; }
.conflict label { display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.95rem; cursor: pointer; }
form.move { grid-column: 1 / -1; display: grid; grid-template-columns: 5rem 1fr; gap: 0.5rem; padding: 0.6rem 0 0.2rem; }
form.move[hidden] { display: none; }
form.move select, form.move input { font: inherit; font-size: 0.95rem; padding: 0.45rem 0.6rem; border: 1px solid #C9C2AE;
  border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; }
form.move select, form.move input[name=new_book_title] { grid-column: 1 / -1; }
form.move input[name=new_book_title][hidden] { display: none; }
form.move button { grid-column: 1 / -1; justify-self: start; }
.primary.small { padding: 0.5rem 1rem; font-size: 0.95rem; }
.trash span:first-child { color: var(--stone); }
.linkbtn.plain { color: var(--ink); text-decoration: underline; text-decoration-color: var(--rule); cursor: pointer; }
.linkbtn.plain:hover { text-decoration-color: var(--gold); }
.admin-list ul { list-style: none; padding: 0; margin: 0; }
.linkbtn { font: inherit; font-size: 0.9rem; background: none; border: 0; color: #B3261E; cursor: pointer; padding: 0; }
.linkbtn:hover { text-decoration: underline; }

@media (max-width: 520px) {
  .row { grid-template-columns: 1fr; }
  .reader-head { flex-direction: column; gap: 0.2rem; }
  .reader-head h1 { text-align: left; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
