:root {
  --bg: #14171d;
  --surface: #1e222b;
  --surface-2: #272c37;
  --line: #313744;
  --text: #f1f2f4;
  --muted: #9aa1ad;
  --accent: #f2a93b;
  --accent-ink: #1a1306;
  --danger: #ff6b6b;
  --ok: #5fd08a;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
svg { width: 24px; height: 24px; fill: currentColor; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 19px; margin: 0; }

/* ---------- Anmeldung ---------- */
.login-box { max-width: 380px; margin: 0 auto; padding: calc(48px + var(--safe-top)) 24px 32px; text-align: center; }
.login-logo { width: 88px; height: 88px; border-radius: 22px; margin-bottom: 12px; }
.login-box h1 { margin-bottom: 28px; }
.login-box form { display: grid; gap: 14px; text-align: left; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; font-size: 17px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.primary {
  background: var(--accent); color: var(--accent-ink); font-weight: 650;
  border-radius: 12px; min-height: 52px; font-size: 17px; margin-top: 6px;
}
.primary:disabled { opacity: .6; }
.link { color: var(--accent); min-height: 44px; }
.error { color: var(--danger); margin: 0; font-size: 15px; }

/* ---------- Liste ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 12px 10px 18px;
  background: rgba(20, 23, 29, .94);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.icon-btn { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn-spacer { width: 48px; }

.banner { margin: 4px 16px 8px; padding: 10px 14px; border-radius: 12px; background: #3a2a14; color: #ffd9a0; font-size: 14px; }
.banner.info { background: #16303a; color: #a8e2f5; }

.book-list { list-style: none; margin: 0; padding: 0 0 calc(110px + var(--safe-bottom)); }
.book {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 8px 10px 16px; min-height: 92px;
  border-bottom: 1px solid var(--line);
}
.book.unavailable { opacity: .45; }
.book-open { flex: 1; display: flex; align-items: center; gap: 14px; text-align: left; min-width: 0; }
.cover {
  width: 68px; height: 68px; flex: none; border-radius: 10px; object-fit: cover;
  background: var(--surface-2) center/40% no-repeat;
}
.book-text { min-width: 0; flex: 1; }
.book-title {
  font-weight: 600; font-size: 16px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.book.current .book-title { color: var(--accent); }

.dl { width: 52px; height: 52px; flex: none; display: grid; place-items: center; position: relative; color: var(--muted); border-radius: 50%; }
.dl:active { background: var(--surface-2); }
.dl.done { color: var(--ok); }
.dl.busy { color: var(--accent); }
.dl .ring { position: absolute; inset: 6px; width: 40px; height: 40px; transform: rotate(-90deg); }
.dl .ring circle { fill: none; stroke-width: 3; }
.dl .ring .track { stroke: var(--surface-2); }
.dl .ring .fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .3s; }
.dl .pct { font-size: 11px; font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 40px 24px; }

/* Mini-Player */
.mini {
  position: fixed; left: 8px; right: 8px; bottom: calc(8px + var(--safe-bottom)); z-index: 6;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 8px; border-radius: 16px;
  background: var(--surface-2); box-shadow: 0 8px 28px rgba(0,0,0,.45);
}
.mini img { width: 52px; height: 52px; border-radius: 9px; object-fit: cover; background: var(--surface); }
.mini-text { flex: 1; min-width: 0; }
.mini-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-play { width: 56px; height: 56px; background: var(--accent); color: var(--accent-ink); }
.mini-play svg { width: 28px; height: 28px; }

/* ---------- Player ---------- */
.player {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto;
  background: linear-gradient(180deg, #232733 0%, var(--bg) 55%);
  display: flex; flex-direction: column;
  padding: var(--safe-top) 20px calc(12px + var(--safe-bottom));
  animation: slide-up .22s ease-out;
}
@keyframes slide-up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.player-top { display: flex; align-items: center; justify-content: space-between; margin: 4px -8px 0; }
.player-top svg { width: 30px; height: 30px; }
.p-source { font-size: 13px; color: var(--muted); }

.p-cover-wrap { display: flex; justify-content: center; padding: 8px 0 14px; flex: 1 1 auto; min-height: 0; align-items: center; }
.p-cover {
  width: min(78vw, 42vh, 380px); aspect-ratio: 1; object-fit: cover; border-radius: 16px;
  background: var(--surface-2); box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.p-meta { text-align: center; }
.p-title { font-size: 20px; font-weight: 700; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.p-author { color: var(--muted); font-size: 15px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-chapter { color: var(--accent); font-size: 15px; margin-top: 6px; min-height: 36px; padding: 0 10px; }

.p-progress { margin-top: 6px; }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 36px; padding: 0;
  background: transparent; border: 0; outline: none;
}
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--surface-2) var(--fill, 0%)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface-2); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--text); margin-top: -8px; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--text); border: 0; }
.p-times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -4px; }
.p-total { text-align: center; font-size: 13px; color: var(--muted); margin-top: 2px; }

.p-controls { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 10px; }
.ctl { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; position: relative; }
.ctl:active { background: var(--surface-2); }
.ctl svg { width: 34px; height: 34px; }
.ctl span { position: absolute; font-size: 10px; font-weight: 700; top: 50%; left: 50%; transform: translate(-50%, -18%); }
.ctl.small { width: 52px; height: 52px; color: var(--muted); }
.ctl.small svg { width: 26px; height: 26px; }
.ctl.play { width: 84px; height: 84px; background: var(--accent); color: var(--accent-ink); }
.ctl.play:active { background: #d8922a; }
.ctl.play svg { width: 40px; height: 40px; }
.spinner { width: 34px; height: 34px; border: 4px solid rgba(26,19,6,.25); border-top-color: var(--accent-ink); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.p-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 4px; }
.p-actions button {
  display: grid; justify-items: center; gap: 4px; padding: 10px 2px; min-height: 64px;
  border-radius: 12px; color: var(--muted); font-size: 12px;
}
.p-actions button:active { background: var(--surface-2); }
.p-actions b { color: var(--text); font-size: 16px; height: 24px; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.p-actions button.active b, .p-actions button.active { color: var(--accent); }

/* ---------- Auswahlfenster ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 82vh; max-height: 82dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 0 calc(10px + var(--safe-bottom));
  animation: sheet-in .2s ease-out;
}
@keyframes sheet-in { from { transform: translateY(100%); } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { padding: 0 20px 10px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 8px; }
.opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  min-height: 54px; padding: 10px 12px; border-radius: 12px; text-align: left; font-size: 17px;
}
.opt:active { background: var(--surface-2); }
.opt.selected { color: var(--accent); font-weight: 600; }
.opt small { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.opt.danger { color: var(--danger); }
.grid-opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 4px 12px 8px; }
.grid-opts .opt { justify-content: center; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.grid-opts .opt.selected { background: var(--accent); color: var(--accent-ink); }
.sheet .primary { width: calc(100% - 24px); margin: 4px 12px 10px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.sheet .primary svg { width: 20px; height: 20px; }
.sheet-note { color: var(--muted); font-size: 14px; padding: 4px 14px 12px; margin: 0; }

.bm { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.bm:last-child { border-bottom: 0; }
.bm-jump { flex: 1; text-align: left; padding: 12px; min-height: 60px; min-width: 0; border-radius: 12px; }
.bm-jump:active { background: var(--surface-2); }
.bm-time { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.bm-note { color: var(--text); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-note.placeholder { color: var(--muted); }
.bm .icon-btn { color: var(--muted); flex: none; }
.bm input { margin: 6px 0; }

/* ---------- Hinweis ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(90px + var(--safe-bottom)); z-index: 30;
  background: #2f3542; color: var(--text); border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); font-size: 15px; animation: fade .2s;
}
.toast button { color: var(--accent); font-weight: 650; min-height: 40px; padding: 0 6px; white-space: nowrap; }

@media (min-width: 700px) {
  .book-list, .topbar, .banner { max-width: 680px; margin-left: auto; margin-right: auto; }
  .mini { max-width: 664px; margin: 0 auto; }
  .player { padding-left: max(20px, calc(50vw - 260px)); padding-right: max(20px, calc(50vw - 260px)); }
  .sheet { max-width: 560px; margin: 0 auto; }
}

/* ---------- Infos zum Hörbuch ---------- */
.info { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; padding: 4px 14px 12px; font-size: 15px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.info-text { margin: 0; padding: 0 14px 12px; font-size: 16px; line-height: 1.5; }
.p-title { cursor: pointer; }
.steps { margin: 0; padding: 0 14px 12px 36px; font-size: 16px; line-height: 1.5; }
.steps li { margin-bottom: 8px; }
