/* 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; }
[hidden] { display: none !important; }
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 { padding-top: 24px; }
.gate .eyebrow { padding: 0; color: var(--accent); }
.gate h1 { font: 600 34px/1.1 var(--serif); margin: 10px 0 0; }

/* 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; }

/* ---------- tabs ---------- */
.tabs {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin: 0 -16px; padding: 8px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.tabs button {
  height: 38px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--muted);
  transition: background var(--dur), color var(--dur);
}
.tabs button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 0 var(--line), 0 2px 8px -4px rgba(0,0,0,.25); }

/* ---------- active downloads ---------- */
.downloads { margin-top: 8px; }
.downloads ol { list-style: none; margin: 0; padding: 0; }
.dl-item { padding: 12px 4px; border-bottom: 1px solid var(--line); }
.dl-item .t { margin: 0; font: 600 16px/1.25 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-item .s { margin: 4px 0 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dl-item .bar { height: 3px; background: var(--track); border-radius: 2px; overflow: hidden; }
.dl-item .bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; transition: transform 1s linear; }

/* ---------- catalog ---------- */
.searchbar {
  display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; padding: 0 14px; height: 48px;
  border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.searchbar svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.searchbar input { flex: 1; min-width: 0; border: 0; background: none; color: var(--ink); font: 17px var(--sans); outline: none; }
.searchbar input::placeholder { color: var(--muted); font-family: var(--serif); font-style: italic; }
.chips-row {
  display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 10px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.chips-row::-webkit-scrollbar { display: none; }
.chips-row .chip { flex: none; scroll-snap-align: start; height: 32px; font-size: 13px; }
.chips-row .chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.sort { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--track); margin: 2px 0 6px; }
.sort button { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.sort button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; }
.result .people { margin: -2px 0 6px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result h2 { font-size: 17px; }
.seeds { font-weight: 600; }
.seeds[data-lvl="3"] { color: #5a9a5f; }
.seeds[data-lvl="2"] { color: #b88a2a; }
.seeds[data-lvl="1"], .seeds[data-lvl="0"] { color: var(--accent); }
.more {
  display: block; width: 100%; margin: 16px 0; height: 46px; border-radius: 12px;
  border: 1px dashed var(--line); color: var(--muted); font-weight: 600;
}
.more:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- release sheet ---------- */
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 22px 22px 0 0; background: var(--bg); color: var(--ink);
  box-shadow: 0 -20px 60px -20px rgba(0,0,0,.5);
}
.sheet[open] { animation: sheet-up 380ms var(--ease) both; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.sheet::backdrop { background: rgba(20, 14, 8, .45); backdrop-filter: blur(3px); }
.sheet-body { position: relative; padding: 20px 20px calc(28px + env(safe-area-inset-bottom)); background-image: var(--grain); }
.sheet-close { position: absolute; top: 12px; left: 10px; transform: rotate(-90deg); }
.sheet-hero { display: grid; place-items: center; margin: 18px 0 18px; }
.sheet-cover { width: min(56vw, 230px); aspect-ratio: 1; border-radius: var(--r-cover); overflow: hidden; box-shadow: var(--shadow); }
.sheet-cover img { width: 100%; height: 100%; object-fit: cover; }
.sheet-title { font: 600 clamp(21px, 5.6vw, 26px)/1.18 var(--serif); margin: 0 0 14px; text-align: center; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 18px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.cta {
  width: 100%; height: 54px; border-radius: 16px; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px;
  box-shadow: 0 14px 28px -14px color-mix(in srgb, var(--accent) 80%, transparent);
  transition: transform var(--dur) var(--ease), opacity var(--dur);
}
.cta svg { width: 20px; height: 20px; }
.cta:active { transform: scale(.97); }
.cta:disabled { opacity: .85; }
.cta.done { background: #5a9a5f; box-shadow: none; }
.desc { font: 16px/1.55 var(--serif); margin: 20px 0 0; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; text-align: center; }
.sheet-loading { text-align: center; color: var(--muted); padding: 40px 0; }
.book > div:last-child { min-width: 0; }
.chips-row .chip { max-width: 72vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 30px; }

/* ---------- offline install flow ---------- */
.offline-cta {
  margin-top: 14px; display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: 19px; border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent); font-weight: 600; font-size: 14px; background: color-mix(in srgb, var(--accent) 8%, transparent);
  transition: background var(--dur), transform var(--dur) var(--ease);
}
.offline-cta svg { width: 18px; height: 18px; }
.offline-cta:active { transform: scale(.96); }
.pwa-note { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.pwa-note p { margin: 0 0 8px; }
.pwa-note button { color: var(--accent); font-weight: 600; }
.guide-lead { font: 16px/1.5 var(--serif); margin: 0 0 14px; }
.steps { margin: 0 0 18px; padding-left: 22px; display: grid; gap: 10px; font-size: 15px; }
.steps li::marker { color: var(--accent); font-weight: 700; }
.link-box {
  width: 100%; height: 44px; margin-bottom: 10px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font: 13px ui-monospace, Menlo, monospace;
}
.ghost {
  width: 100%; height: 48px; margin-top: 10px; border-radius: 14px; border: 1px solid var(--line);
  font-weight: 600; color: var(--ink); transition: border-color var(--dur);
}
.ghost:hover { border-color: var(--accent); }
.login-form { display: grid; gap: 10px; margin-top: 18px; }
.login-form input {
  height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: 15px var(--sans);
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.login-form .ghost { margin-top: 0; }

/* ---------- login & downloads ---------- */
.tabs { grid-template-columns: repeat(3, 1fr); }
.segmented.two { grid-template-columns: repeat(2, 1fr); margin-top: 22px; }
.gate .gate-hint { margin: 0; padding: 0 2px 2px; font-size: 14px; line-height: 1.45; }
.gate-hint b { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.login-form input.code-input { font: 500 26px/1 var(--serif); letter-spacing: .28em; text-align: center; font-variant-numeric: tabular-nums; }
.login-form input.code-input::placeholder { font-family: var(--sans, inherit); font-size: 16px; letter-spacing: 0; }
.linkish { justify-self: center; padding: 8px 10px; font-size: 14px; color: var(--muted); border-radius: 8px; transition: color var(--dur); }
.linkish:hover:not(:disabled) { color: var(--accent); }
.linkish:disabled { opacity: .6; font-variant-numeric: tabular-nums; }
.move-banner { display: flex; align-items: center; gap: 12px; margin: 10px 0 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 14px; line-height: 1.35; }
.move-banner span { flex: 1; color: var(--muted); }
.move-banner b { display: block; color: var(--ink); font: 600 16px/1.25 var(--serif); margin-bottom: 2px; }
.move-banner button { flex: none; padding: 8px 12px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 600; }
.alt-login { margin-top: 22px; color: var(--muted); font-size: 14px; }
.alt-login summary { cursor: pointer; }
.add-form { display: grid; gap: 10px; margin: 16px 0 6px; }
.add-form input#add-magnet {
  height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: 14px ui-monospace, Menlo, monospace;
}
.add-form input#add-magnet:focus { outline: none; border-color: var(--accent); }
.add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.add-row .cta, .add-row .ghost { margin: 0; height: 48px; }
.file-btn { display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden; padding: 0 10px; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-btn:focus-within { border-color: var(--accent); }
.jobs-list { list-style: none; margin: 12px 0 0; padding: 0; }
.job { padding: 14px 4px; border-bottom: 1px solid var(--line); }
.job .t { margin: 0; font: 600 16px/1.3 var(--serif); overflow-wrap: anywhere; }
.job .s { margin: 4px 0 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.job .s .bad { color: var(--accent); }
.job .bar { height: 3px; background: var(--track); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
.job .bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; transition: transform 1s linear; }
.acts { display: flex; gap: 8px; flex-wrap: wrap; }
.act {
  display: inline-flex; align-items: center; height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  font-size: 14px; font-weight: 600; color: var(--ink); text-decoration: none; background: var(--surface);
  transition: border-color var(--dur), transform var(--dur) var(--ease);
}
.act:active { transform: scale(.95); }
.act.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.act.danger { color: var(--accent); }
.act[aria-pressed="true"] { border-color: var(--accent); }
.logout { margin-top: 28px; color: var(--muted); }

/* ---------- book text & bookmarks ---------- */
.text-panel {
  width: 100%; height: min(52vh, 460px); overflow-y: auto; padding: 18px 16px; border-radius: var(--r-cover);
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--line);
  font: 18px/1.65 var(--serif); scroll-behavior: smooth;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; /* notes use word picking, not native selection */
}
.text-panel p { margin: 0 0 14px; }
.seg { border-radius: 4px; transition: background var(--dur), color var(--dur); cursor: pointer; }
/* orange background = playing now, blue = words being picked for a note, green underline = saved note */
:root { --sel: rgba(64, 132, 255, .42); --note: #2f8f6f; }
:root[data-theme="dark"] { --note: #5cc79f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --note: #5cc79f; } }
.seg.now { background: color-mix(in srgb, var(--accent) 24%, transparent); color: var(--ink); -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.w { border-radius: 3px; }
.w.note { text-decoration: underline 3px var(--note); text-underline-offset: 5px; text-decoration-skip-ink: none; }
.w.pick { background: var(--sel); box-shadow: 0 0 0 2px var(--sel); }
.text-panel.picking .w { cursor: pointer; }
.text-panel.picking { box-shadow: inset 0 0 0 2px var(--sel); }
.note-bar {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  width: min(528px, calc(100% - 24px)); padding: 12px; border-radius: 16px; background: var(--surface);
  box-shadow: var(--shadow), 0 0 0 1px var(--line); animation: rise 200ms var(--ease) both;
}
.note-bar p { margin: 0 0 10px; font-size: 14px; color: var(--muted); text-align: center; }
.note-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.note-actions .ghost, .note-actions .cta { margin: 0; height: 46px; }
.cta:disabled { opacity: .45; }
.text-gap, .text-wait { font: 14px/1.5 var(--sans); color: var(--muted); padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }
.text-gap { cursor: pointer; }
.bm-list { list-style: none; margin: 0; padding: 0; }
.bm-list li { display: grid; grid-template-columns: 1fr 40px; align-items: start; border-bottom: 1px solid var(--line); }
.bm-go { text-align: left; padding: 14px 4px; display: grid; gap: 6px; }
.bm-go q { font: italic 16px/1.5 var(--serif); quotes: "«" "»"; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.bm-noquote { color: var(--muted); font-style: italic; }
.bm-meta { font-size: 13px; color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.bm-del { margin-top: 10px; color: var(--muted); }
.files-link { display: flex; align-items: center; justify-content: center; text-decoration: none; margin-top: 16px; }
.text-status { width: 100%; margin: 0 0 -10px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.bm-tools { display: flex; flex-direction: column; align-items: center; }
.bm-edit {
  width: 100%; margin: 6px 0 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: italic 16px/1.5 var(--serif); resize: vertical;
}
.bm-edit:focus { outline: none; border-color: var(--accent); }
.bm-list li { grid-template-columns: 1fr 44px; }
a.chip { text-decoration: none; color: inherit; }
.dl-row { display: grid; grid-template-columns: 1fr 36px; align-items: center; gap: 6px; }
.dl-cancel { width: 36px; height: 36px; color: var(--muted); }

/* =================== app shell: tab bar + mini player =================== */
:root { --tabbar-h: 60px; --mini-h: 64px; }
#app { padding-bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }
body.with-mini #app { padding-bottom: calc(var(--tabbar-h) + var(--mini-h) + 36px + env(safe-area-inset-bottom)); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 6px 8px env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button { display: grid; justify-items: center; align-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; transition: color var(--dur); }
.tabbar svg { width: 24px; height: 24px; }
.tabbar button[aria-pressed="true"] { color: var(--accent); }
.mini {
  position: fixed; z-index: 24; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 8px + env(safe-area-inset-bottom)); width: min(544px, calc(100% - 16px));
  height: var(--mini-h); display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 12px;
  padding: 8px 8px 8px 8px; border-radius: 16px; background: var(--surface); text-align: left;
  box-shadow: 0 12px 30px -14px rgba(0,0,0,.5), 0 0 0 1px var(--line); animation: rise 260ms var(--ease) both;
}
.mini-thumb { width: 48px; height: 48px; border-radius: 9px; overflow: hidden; container-type: inline-size; }
.mini-thumb img { width: 100%; height: 100%; object-fit: cover; }
.mini-thumb .gen-cover span { display: none; }
.mini-thumb .gen-cover b { font-size: 8px; -webkit-line-clamp: 3; }
.mini-text { min-width: 0; display: grid; gap: 2px; }
.mini-text b { font: 600 15px/1.2 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-text span { font-size: 12px; color: var(--muted); }
.mini-play { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.mini-play svg { width: 22px; height: 22px; }

/* =================== library =================== */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; margin: 16px 0 6px; border-radius: 12px; background: var(--track); }
.segmented button { height: 36px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; transition: background var(--dur), color var(--dur); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 6px; }
.stats div { padding: 14px 10px; border-radius: 14px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); text-align: center; }
.stats b { display: block; font: 600 28px/1 var(--serif); color: var(--accent); }
.stats span { font-size: 12px; color: var(--muted); }
.book .people { margin: -2px 0 6px; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rl-item { border-bottom: 1px solid var(--line); }
.rl-item .book { border-bottom: 0; padding-bottom: 8px; }
.rl-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; padding: 0 4px 12px 92px; }
.rl-actions .icon-btn { width: 36px; height: 36px; color: var(--muted); }
.rl-actions .icon-btn svg { width: 18px; height: 18px; }
.bad { color: var(--accent); }
.dl-cancel svg { width: 18px; height: 18px; }

/* =================== notes tab =================== */
.nb { margin-top: 18px; }
.nb-head { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; padding: 0 4px 10px; border-bottom: 1px solid var(--line); }
.nb-head:has(.nb-restore) { grid-template-columns: 52px 1fr auto; }
.nb-restore { padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; transition: border-color var(--dur); }
.nb-restore:hover { border-color: var(--accent); }
.nb-restore:disabled { opacity: .6; }
.nb-head .thumb { width: 52px; aspect-ratio: 1; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); }
.nb-head h2 { font: 600 18px/1.2 var(--serif); margin: 0 0 2px; }
.nb-head .people { margin: 0; font-size: 13px; color: var(--muted); }
.nb-list { list-style: none; margin: 0; padding: 0; }
.nb-note { width: 100%; text-align: left; display: grid; gap: 6px; padding: 14px 4px; border-bottom: 1px solid var(--line); transition: background var(--dur); }
.nb-note:hover { background: var(--surface); }
.nb-note q { font: italic 17px/1.5 var(--serif); quotes: "«" "»"; }

/* =================== profile =================== */
.row-btn {
  width: 100%; display: grid; grid-template-columns: 28px 1fr; gap: 14px; align-items: center; text-align: left;
  padding: 16px 6px; border-bottom: 1px solid var(--line); font-size: 16px; font-weight: 600; transition: background var(--dur);
}
.row-btn:hover { background: var(--surface); }
.row-btn svg { width: 26px; height: 26px; color: var(--accent); }
.row-btn small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.profile-storage { text-align: left; padding: 0 6px; }
#profile .pwa-note { margin: 12px 0; }

/* =================== player =================== */
.pl-top { display: grid; grid-template-columns: 44px 1fr 92px; align-items: center; min-height: 48px; }
.pl-top-right { display: flex; justify-content: flex-end; }
.pl-top .icon-btn svg { width: 24px; height: 24px; }
#text-btn[aria-pressed="true"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.pl-chapter { justify-self: center; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 700; padding: 8px 10px; border-radius: 10px; }
.pl-chapter:hover { background: var(--surface); }
.sync { justify-content: center; margin: 0 0 4px; }
.stage { margin-top: 4px; gap: 18px; }
.chapter-title { display: block; margin: 0 auto 4px; text-align: center; font: 600 clamp(21px, 5.6vw, 26px)/1.18 var(--serif); overflow-wrap: anywhere; }
.book-title { margin: 0; font-size: 14px; color: var(--muted); text-align: center; }
.book-author { color: var(--muted); }
.text-panel { height: min(48vh, 440px); }
.transport { padding: 2px 4px 14px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px 0 4px; border-top: 1px solid var(--line); }
.action { display: grid; justify-items: center; gap: 4px; padding: 8px 0; border-radius: 14px; color: var(--ink); transition: background var(--dur), transform var(--dur) var(--ease); }
.action:hover { background: var(--surface); }
.action:active { transform: scale(.94); }
.action-ico { position: relative; height: 26px; display: grid; place-items: center; }
.action-ico svg { width: 26px; height: 26px; }
.rate-ico { font: 700 17px/26px var(--sans); font-variant-numeric: tabular-nums; }
.action-label { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.action[aria-pressed="true"] .action-ico, .action[aria-pressed="true"] .action-label { color: var(--accent); }
.badge-n {
  position: absolute; top: -6px; right: -12px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink); font: 700 11px/18px var(--sans); text-align: center;
}
.note-bar { bottom: calc(16px + env(safe-area-inset-bottom)); }

/* =================== sheets =================== */
.sheet-close { transform: none; }
.sheet-body .sheet-title { margin-top: 2px; }
.big-value { margin: 0 0 16px; text-align: center; font: 600 44px/1 var(--serif); color: var(--accent); font-variant-numeric: tabular-nums; }
.option-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.opt { height: 52px; border-radius: 14px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.opt[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.option-list { list-style: none; margin: 0; padding: 0; }
.opt-row { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 16px 6px; border-bottom: 1px solid var(--line); font-size: 17px; text-align: left; }
.opt-row span { font-size: 13px; color: var(--muted); }
.opt-row[aria-pressed="true"] { color: var(--accent); font-weight: 700; }
.opt-row[aria-pressed="true"]::after { content: "✓"; }
.opt-row[aria-pressed="true"] span { margin-left: auto; margin-right: 10px; }
#chapters-sheet .chapters { max-height: 62vh; overflow-y: auto; }
.more-head { display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center; margin: 22px 0 10px; }
.more-head .thumb { width: 64px; aspect-ratio: 1; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.more-head h2 { font: 600 19px/1.2 var(--serif); margin: 0 0 4px; }
.more-head .people { margin: 0; font-size: 13px; color: var(--muted); }
.add-here { margin: 4px 0 6px; }
.rl-toggle { margin-top: 10px; }
.rl-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
/* the whole player fits one phone screen: controls stay at the bottom,
   cover / text take whatever height is left and shrink on small phones */
body[data-view="player"] #app { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
#player:not([hidden]) {
  display: flex; flex-direction: column;
  height: calc(100dvh - max(6px, env(safe-area-inset-top)) - 10px - env(safe-area-inset-bottom));
}
#player > * { flex: none; }
#player .stage {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; margin: 4px 0 8px;
}
#player .cover { flex: 0 1 min(70vw, 300px); width: auto; height: auto; min-height: 72px; max-width: 100%; aspect-ratio: 1; }
#player .text-panel { flex: 1 1 0; width: 100%; height: auto; min-height: 96px; }
#player .titles, #player .text-status { flex: none; }
#player .chapter-title { font-size: clamp(18px, 5vw, 24px); }
#player .scrub { margin-bottom: 4px; }
#player .book-line { margin-top: 8px; }
#player .book-left { margin-top: 4px; }
#player .play { width: 64px; height: 64px; }
#player .transport { padding: 0 4px 6px; }
#player .actions { padding-top: 4px; }
/* toasts never cover the controls */
body:not([data-view="player"]) .toast { bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); }
body.with-mini:not([data-view="player"]) .toast { bottom: calc(var(--tabbar-h) + var(--mini-h) + 28px + env(safe-area-inset-bottom)); }
body[data-view="player"] .toast { bottom: auto; top: calc(64px + env(safe-area-inset-top)); }

/* =================== polish: focus rings, shadows, spacing =================== */
/* iPhone focuses the first button of an opened sheet — no ring for that (keyboard focus is still visible) */
dialog.sheet:focus, dialog.sheet:focus-visible, .sheet-close:focus, .sheet-close:focus-visible { outline: none; }
.sheet-body { padding-top: 30px; }
.sheet-body::before {
  content: ""; position: absolute; top: 9px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 5px; border-radius: 3px; background: var(--line);
}
.sheet-close { top: 10px; left: auto; right: 10px; color: var(--muted); }
.sheet-hero { margin-top: 8px; }
.more-head { margin-top: 10px; padding-right: 44px; }
.cta { box-shadow: 0 6px 14px -10px color-mix(in srgb, var(--accent) 75%, transparent); }
.cta + .ghost, .cta + .rl-toggle, .rl-toggle + .ghost { margin-top: 14px; }
.cta ~ .hint { margin-top: 12px; }
.play { box-shadow: 0 6px 16px -10px color-mix(in srgb, var(--accent) 80%, transparent); }
#player .transport { padding-bottom: 12px; }
#player .actions { margin-top: 2px; padding-top: 8px; }

/* catalog: categories row with real side padding, aligned chips */
.chips-row { margin: 2px -16px 4px; padding: 4px 16px 10px; gap: 8px; scroll-padding-inline: 16px; align-items: center; }
.chips-row .chip { height: 34px; line-height: 32px; padding: 0 14px; display: inline-flex; align-items: center; }
.sort { margin: 4px 0 8px; }

/* mini player: dismiss button */
.mini { grid-template-columns: 48px 1fr 44px 32px; gap: 10px; }
.mini-close { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.mini-close svg { width: 18px; height: 18px; }

/* book text: wrapper holds the "back to reading place" button */
#player .text-wrap { flex: 1 1 0; min-height: 96px; width: 100%; position: relative; display: flex; }
#player .text-wrap .text-panel { flex: 1; height: auto; min-height: 0; }
.text-follow {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 2;
  height: 36px; padding: 0 16px; border-radius: 18px; background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 700; box-shadow: 0 8px 20px -8px rgba(0,0,0,.55); animation: rise 200ms var(--ease) both;
}

.quota { margin: 18px 0 4px; }
.quota p { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.quota-track { height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.quota-track i { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform var(--dur) var(--ease); }
