/* Paper & ink: a warm editorial audiobook player. System serif on purpose — works offline. */
:root {
  --bg: #f4efe6;
  --surface: #fbf8f2;
  --ink: #1d1a16;
  --muted: #7a7166;
  --line: #e2d9cb;
  --accent: #b4441f;
  --accent-ink: #fff8f0;
  --track: #e6dccd;
  --shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 24px 48px -20px rgba(64,38,18,.45), 0 4px 10px -4px rgba(64,38,18,.25);
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --r-cover: 14px;
  --dur: 180ms;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] {
  --bg: #15130f; --surface: #1d1a15; --ink: #efe7da; --muted: #9a8f80; --line: #2d2922;
  --accent: #e2774f; --accent-ink: #1a0f08; --track: #332e26;
  --shadow: 0 24px 48px -18px rgba(0,0,0,.8), 0 4px 12px -4px rgba(0,0,0,.6);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f; --surface: #1d1a15; --ink: #efe7da; --muted: #9a8f80; --line: #2d2922;
    --accent: #e2774f; --accent-ink: #1a0f08; --track: #332e26;
    --shadow: 0 24px 48px -18px rgba(0,0,0,.8), 0 4px 12px -4px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 var(--sans);
  background-image: var(--grain);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 24px; height: 24px; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

#app { max-width: 560px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
.view { animation: rise 420ms var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.eyebrow { margin: 0; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); font-weight: 600; }

/* ---------- library ---------- */
.lib-head { padding: 20px 4px 18px; border-bottom: 1px solid var(--line); }
.lib-head h1 { font: 600 clamp(34px, 9vw, 46px)/1 var(--serif); margin: 8px 0 6px; letter-spacing: -.01em; }
.lib-sub { margin: 0; color: var(--muted); font-size: 14px; }
.shelf { list-style: none; margin: 0; padding: 0; }
.book {
  display: grid; grid-template-columns: 72px 1fr; gap: 16px; align-items: center;
  width: 100%; text-align: left; padding: 18px 4px; border-bottom: 1px solid var(--line);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.book:hover { background: var(--surface); }
.book:active { transform: scale(.985); }
.book .thumb { width: 72px; aspect-ratio: 1; border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.book h2 { font: 600 19px/1.2 var(--serif); margin: 0 0 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.book .bar { height: 3px; background: var(--track); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.book .bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; }
.badge { color: var(--accent); font-weight: 600; }
.empty, .gate p { color: var(--muted); padding: 32px 4px; }
.gate h1 { font: 600 30px/1.1 var(--serif); margin-top: 40px; }

/* generated cover when a torrent has no image */
.gen-cover {
  width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: space-between;
  padding: 12%; color: #fff8ef; background: var(--hue, #6d3b22);
  background-image: var(--grain), linear-gradient(160deg, rgba(255,255,255,.14), rgba(0,0,0,.28));
}
.gen-cover b { font: 600 clamp(12px, 7cqw, 44px)/1.05 var(--serif); display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.gen-cover span { font-size: clamp(7px, 3.2cqw, 13px); letter-spacing: .16em; text-transform: uppercase; opacity: .75; }
.thumb, .cover { container-type: inline-size; }

/* ---------- player ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; min-height: 40px; }
.sync { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--sync-dot, var(--muted)); }
.sync[data-s="ok"] { --sync-dot: #5a9a5f; }
.sync[data-s="local"] { --sync-dot: #d19a2e; }
.sync[data-s="off"] { --sync-dot: var(--accent); }

.stage { display: grid; justify-items: center; gap: 22px; margin: 8px 0 22px; }
.cover {
  margin: 0; width: min(74vw, 320px); aspect-ratio: 1; border-radius: var(--r-cover); overflow: hidden;
  box-shadow: var(--shadow); transition: transform 500ms var(--ease);
}
.cover img, .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
#player:not(.playing) .cover { transform: scale(.94); }
.titles { text-align: center; max-width: 100%; }
.chapter-no { margin: 0; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.chapter-title { font: 600 clamp(22px, 6vw, 28px)/1.15 var(--serif); margin: 6px 0 4px; overflow-wrap: anywhere; }
.book-title { font-size: 14px; font-weight: 400; color: var(--muted); margin: 0; }

.scrub { margin-bottom: 14px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0;
  --p: 0%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px; background: linear-gradient(to right, var(--ink) var(--p), var(--track) var(--p));
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5.5px; border-radius: 50%;
  background: var(--ink); box-shadow: 0 0 0 4px var(--bg); transition: transform var(--dur) var(--ease);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.35); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--ink); }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.book-line { height: 2px; background: var(--track); margin-top: 14px; border-radius: 1px; overflow: hidden; }
.book-line i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 600ms linear; }
.book-left { margin: 6px 0 0; font-size: 12px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }

.transport { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px 18px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; transition: background var(--dur), transform var(--dur) var(--ease); }
.icon-btn:hover { background: var(--surface); }
.icon-btn:active { transform: scale(.9); }
.icon-btn.big svg { width: 32px; height: 32px; }
.icon-btn:disabled { opacity: .3; }
.play {
  width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 14px 28px -12px color-mix(in srgb, var(--accent) 80%, transparent);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur);
}
.play svg { width: 34px; height: 34px; }
.play:hover { transform: translateY(-1px); }
.play:active { transform: scale(.93); }
.play.loading { animation: breathe 1.2s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .65; } }

.chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 18px; border: 1px solid var(--line); background: var(--surface); font-size: 14px;
  font-variant-numeric: tabular-nums; transition: border-color var(--dur), background var(--dur), transform var(--dur) var(--ease);
}
.chip svg { width: 18px; height: 18px; }
.chip:active { transform: scale(.95); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.dl-bar { height: 3px; background: var(--track); border-radius: 2px; margin: 12px 20px 0; overflow: hidden; }
.dl-bar i { display: block; height: 100%; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform 300ms linear; }

.list-head { font: 600 13px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 34px 4px 4px; }
.chapters { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.chapters button {
  width: 100%; display: grid; grid-template-columns: 38px 1fr auto 22px; gap: 10px; align-items: center;
  padding: 13px 4px; border-bottom: 1px solid var(--line); text-align: left; transition: background var(--dur);
}
.chapters button:hover { background: var(--surface); }
.chapters .n { font: 500 20px/1 var(--serif); color: var(--muted); font-variant-numeric: oldstyle-nums; }
.chapters .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapters .d { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chapters .o svg { width: 18px; height: 18px; color: var(--muted); }
.chapters .o.saved svg { color: #5a9a5f; }
.chapters li.done .t { color: var(--muted); }
.chapters li.current .n, .chapters li.current .t { color: var(--accent); font-weight: 600; }
.storage { font-size: 12px; color: var(--muted); text-align: center; margin: 18px 0 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: var(--ink); color: var(--bg);
  font-size: 14px; box-shadow: var(--shadow); animation: rise 260ms var(--ease) both; z-index: 10;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.thumb .gen-cover { padding: 10%; justify-content: flex-end; }
.thumb .gen-cover span { display: none; }
.thumb .gen-cover b { font-size: 11px; -webkit-line-clamp: 4; }
