/* Two views: the library (a shelf of covers) and the reader (one column of text, a sticky top bar, a fixed player bar).
   Themes by data-theme on <html>: auto (follows the system), light, sepia, dark. Text size: --fs. */
:root { --paper:#eef1ec; --raised:#f8faf6; --ink:#1f2a2e; --muted:#5e6b6e; --line:#d5dbd4; --accent:#0f766e; --on-accent:#fff; --mark:#dce8a4; --bad:#b4432b;
  --serif:"Literata",Georgia,serif; --sans:"Golos Text",system-ui,sans-serif; --fs:19px; --col:36rem; }
:root[data-theme="sepia"] { --paper:#efe5cf; --raised:#f7efdc; --ink:#3a2e20; --muted:#7a6a55; --line:#d9ccb0; --accent:#8a4b12; --mark:#ecd28a; }
:root[data-theme="dark"] { --paper:#141a1a; --raised:#1b2323; --ink:#dfe7e4; --muted:#93a19f; --line:#2c3736; --accent:#3cc4b4; --on-accent:#08201d; --mark:#234e48; --bad:#f07a62; color-scheme:dark; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] { --paper:#141a1a; --raised:#1b2323; --ink:#dfe7e4; --muted:#93a19f; --line:#2c3736; --accent:#3cc4b4; --on-accent:#08201d; --mark:#234e48; --bad:#f07a62; color-scheme:dark; } }

* { box-sizing:border-box; } [hidden] { display:none !important; }
html { -webkit-text-size-adjust:100%; }
body { margin:0; background:var(--paper); color:var(--ink); font:16px/1.5 var(--sans); }
button, select, input { font:inherit; color:inherit; }
button { cursor:pointer; }
:focus-visible { outline:2px solid var(--accent); outline-offset:2px; border-radius:6px; }
.btn { font-weight:500; padding:10px 20px; border-radius:10px; background:var(--raised); border:1px solid var(--line); }
.btn:hover { border-color:var(--accent); }
.btn.pri { background:var(--accent); color:var(--on-accent); border-color:transparent; }
.icon { width:44px; height:44px; display:inline-grid; place-items:center; background:none; border:0; border-radius:10px; color:var(--ink); font-size:1.5rem; line-height:1; }
.icon:hover { background:color-mix(in srgb, var(--ink) 8%, transparent); }
.icon svg { width:24px; height:24px; }
select { background:var(--raised); border:1px solid var(--line); border-radius:8px; padding:6px 10px; }

/* library */
#library { max-width:68rem; margin:0 auto; padding:clamp(28px, 7vw, 72px) max(20px, env(safe-area-inset-left)) 80px; }
.lib-head h1 { font:600 clamp(2.6rem, 8vw, 4.2rem)/1 var(--serif); letter-spacing:-.02em; margin:0 0 .35em; }
.lede { font:400 1.15rem/1.55 var(--serif); max-width:34rem; margin:0 0 1.4em; color:var(--ink); }
.lib-actions { display:flex; flex-wrap:wrap; align-items:center; gap:10px 18px; }
.formats { color:var(--muted); font-size:.9rem; }
.notes { margin-top:18px; display:grid; gap:8px; }
.note { display:flex; gap:12px; align-items:baseline; justify-content:space-between; background:var(--raised); border:1px solid var(--line); border-left:3px solid var(--accent); border-radius:8px; padding:9px 12px; font-size:.93rem; }
.note.err { border-left-color:var(--bad); }
.note button { background:none; border:0; color:var(--muted); padding:0 4px; }
.shelf { margin-top:clamp(28px, 5vw, 48px); display:grid; grid-template-columns:repeat(auto-fill, minmax(132px, 1fr)); gap:30px 22px; }
.book { position:relative; min-width:0; }
.cover { display:block; width:100%; aspect-ratio:2/3; padding:0; border:0; border-radius:3px 6px 6px 3px; overflow:hidden; background:var(--line);
  box-shadow:inset 4px 0 0 rgb(0 0 0 / .18), 0 1px 1px rgb(0 0 0 / .2), 0 10px 22px -12px rgb(0 0 0 / .55); transition:transform .15s; }
.cover:hover { transform:translateY(-3px); }
.cover img { width:100%; height:100%; object-fit:cover; display:block; }
/* a book without a cover gets a cloth binding: one colour picked from the title, a thin ivory frame, the title set in the text face */
.gen { display:flex; flex-direction:column; justify-content:space-between; height:100%; padding:16% 13% 12% 15%; text-align:left; background:var(--c); color:#f3ead2; position:relative; }
.gen::after { content:""; position:absolute; inset:7px 7px 7px 11px; border:1px solid rgb(243 234 210 / .45); border-radius:1px; pointer-events:none; }
.gen b { font:600 clamp(.95rem, 1.1vw + .6rem, 1.15rem)/1.2 var(--serif); overflow-wrap:anywhere; display:-webkit-box; -webkit-line-clamp:6; -webkit-box-orient:vertical; overflow:hidden; }
.gen i { font:400 .74rem/1.25 var(--sans); font-style:normal; opacity:.85; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
.book .meta { margin-top:10px; font-size:.88rem; line-height:1.3; }
.book .meta b { display:block; font-weight:500; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.book .meta span { display:block; color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.book .bar { height:3px; background:var(--line); border-radius:2px; margin-top:7px; overflow:hidden; } .book .bar i { display:block; height:100%; background:var(--accent); }
.book .del { position:absolute; top:6px; right:6px; width:30px; height:30px; border-radius:50%; border:0; background:rgb(20 26 26 / .72); color:#fff; font-size:1.1rem; line-height:1; opacity:0; transition:opacity .15s; }
.book:hover .del, .book .del:focus-visible { opacity:1; }
@media (hover:none) { .book .del { opacity:1; } }
.book .ask { position:absolute; inset:0 0 auto 0; aspect-ratio:2/3; display:grid; place-content:center; gap:8px; padding:10px; text-align:center; background:rgb(20 26 26 / .88); color:#fff; border-radius:3px 6px 6px 3px; font-size:.88rem; }
.book .ask button { border:0; border-radius:8px; padding:7px 10px; background:#fff; color:#1f2a2e; font-weight:500; } .book .ask button.no { background:transparent; color:#fff; border:1px solid rgb(255 255 255 / .5); }
.book.busy .cover { opacity:.55; }
.empty { margin-top:40px; max-width:34rem; color:var(--muted); }
.drop { position:fixed; inset:0; z-index:50; display:grid; place-items:center; background:color-mix(in srgb, var(--paper) 88%, transparent); }
.drop div { font:500 1.6rem var(--serif); padding:40px 56px; border:2px dashed var(--accent); border-radius:16px; }

/* reader */
.topbar { position:sticky; top:0; z-index:5; display:grid; grid-template-columns:44px 1fr 44px; align-items:center; gap:6px; padding:6px max(8px, env(safe-area-inset-left)); padding-top:max(6px, env(safe-area-inset-top));
  background:color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter:blur(8px); border-bottom:1px solid var(--line); }
.where { min-width:0; background:none; border:0; border-radius:8px; padding:3px 10px; text-align:center; line-height:1.25; }
.where:hover { background:color-mix(in srgb, var(--ink) 8%, transparent); }
.where span, .where b { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.where span { font-size:.78rem; color:var(--muted); } .where b { font-weight:500; font-size:.95rem; }
.aa { font:600 1.05rem var(--serif); }
.txt { max-width:calc(var(--col) + 40px); margin:0 auto; padding:clamp(24px, 6vw, 56px) 20px calc(190px + env(safe-area-inset-bottom));
  font:400 var(--fs)/1.72 var(--serif); hyphens:auto; overflow-wrap:break-word; font-variant-numeric:oldstyle-nums; }
.txt p { margin:0; text-indent:1.5em; }
.txt h2 + p, .txt h3 + p, .txt h4 + p, .txt hr + p, .txt figure + p, .txt p:first-child, .txt p.v { text-indent:0; }
.txt p.v { padding-left:1.5em; } .txt p.v + p:not(.v), .txt p:not(.v) + p.v { margin-top:.9em; }
.txt h2, .txt h3, .txt h4 { font-family:var(--serif); font-weight:600; line-height:1.25; text-wrap:balance; hyphens:manual; margin:1.8em 0 .8em; }
.txt h2 { font-size:1.55em; letter-spacing:-.01em; } .txt h3 { font-size:1.22em; } .txt h4 { font-size:1.05em; }
.txt > :first-child { margin-top:0; }
.txt hr { border:0; margin:1.4em auto; width:4em; border-top:1px solid var(--muted); opacity:.6; }
.txt figure { margin:1.4em 0; text-align:center; } .txt figure img { max-width:100%; max-height:80vh; border-radius:3px; }
.txt .quiet { color:var(--muted); font-size:.9em; }
.s { border-radius:3px; padding:.12em 0; -webkit-box-decoration-break:clone; box-decoration-break:clone; cursor:pointer; transition:background-color .18s; }
@media (hover:hover) { .s:hover { background:color-mix(in srgb, var(--mark) 45%, transparent); } }
.s.on { background:var(--mark); box-shadow:-.18em 0 0 var(--mark), .18em 0 0 var(--mark); }
.endnav { max-width:var(--col); margin:2.5em auto 0; display:flex; justify-content:space-between; gap:12px; font-family:var(--sans); font-size:.95rem; }
.follow { position:fixed; left:50%; transform:translateX(-50%); bottom:calc(96px + env(safe-area-inset-bottom)); z-index:6; padding:8px 16px; border-radius:999px; border:0;
  background:var(--ink); color:var(--paper); font-weight:500; font-size:.9rem; box-shadow:0 6px 18px -6px rgb(0 0 0 / .5); }

.player { position:fixed; left:0; right:0; bottom:0; z-index:6; background:var(--raised); border-top:1px solid var(--line); padding-bottom:env(safe-area-inset-bottom); }
.prog { height:3px; background:var(--line); } .prog i { display:block; height:100%; width:0; background:var(--accent); transition:width .3s; }
.pl-row { max-width:60rem; margin:0 auto; display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:10px; padding:8px max(12px, env(safe-area-inset-left)); }
.pl-info { min-width:0; font-size:.85rem; color:var(--muted); line-height:1.3; font-variant-numeric:tabular-nums; }
.pl-info > span { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } #pct { color:var(--ink); font-weight:500; }
.pl-main { display:flex; align-items:center; gap:6px; }
.play { position:relative; width:58px; height:58px; border-radius:50%; border:0; background:var(--accent); color:var(--on-accent); display:grid; place-items:center; }
.play svg { width:28px; height:28px; grid-area:1/1; } .play .i-pause, .play .spin { display:none; }
.play[data-state="playing"] .i-play, .play[data-state="loading"] .i-play { display:none; } .play[data-state="playing"] .i-pause { display:block; }
.play[data-state="loading"] .spin { display:block; grid-area:1/1; width:24px; height:24px; border-radius:50%; border:3px solid color-mix(in srgb, var(--on-accent) 35%, transparent); border-top-color:var(--on-accent); animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }
.pl-side { display:flex; justify-content:flex-end; align-items:center; gap:10px; min-width:0; }
.speed { display:inline-flex; align-items:center; border:1px solid var(--line); border-radius:8px; background:var(--paper); }
.speed button { width:34px; height:34px; border:0; background:none; font-size:1.15rem; } .speed output { min-width:3.4em; text-align:center; font-size:.88rem; font-variant-numeric:tabular-nums; }
#voice2 { max-width:9.5rem; }
@media (max-width:640px) { #voice2, #left { display:none; } .pl-row { gap:4px; } .speed button { width:30px; } }
@media (max-width:420px) { #status { display:none; } }

/* sheets: contents and settings */
.sheet { border:0; padding:0; color:var(--ink); background:var(--raised); width:min(30rem, 100vw); max-width:100vw; height:100dvh; max-height:100dvh; margin:0 0 0 auto; box-shadow:-12px 0 40px -18px rgb(0 0 0 / .5); }
.sheet::backdrop { background:rgb(10 16 16 / .35); }
.sheet-head { position:sticky; top:0; display:flex; align-items:center; justify-content:space-between; padding:10px 10px 10px 22px; background:var(--raised); border-bottom:1px solid var(--line); }
.sheet-head h2 { font:600 1.15rem var(--serif); margin:0; }
#toclist { list-style:none; margin:0; padding:8px 10px 30px; }
#toclist button { width:100%; text-align:left; background:none; border:0; border-radius:8px; padding:9px 12px; display:flex; gap:12px; justify-content:space-between; align-items:baseline; font-family:var(--serif); }
#toclist button:hover { background:color-mix(in srgb, var(--ink) 7%, transparent); }
#toclist button[aria-current="true"] { background:var(--mark); }
#toclist small { color:var(--muted); font:400 .78rem var(--sans); white-space:nowrap; }
.set-body { padding:6px 22px 40px; }
.set-body h3 { font:600 1rem var(--serif); margin:26px 0 10px; }
.f { display:grid; grid-template-columns:6.2rem 1fr 3.2rem; align-items:center; gap:10px; margin:10px 0; font-size:.93rem; color:var(--muted); }
.f select, .f .seg { grid-column:2 / 4; } .f output { color:var(--ink); text-align:right; font-variant-numeric:tabular-nums; }
.f[role="group"]:has(#sleep) { grid-template-columns:1fr; } .f[role="group"]:has(#sleep) .seg { grid-column:1; }
.f input[type="range"] { width:100%; accent-color:var(--accent); }
.c { display:flex; gap:10px; align-items:flex-start; font-size:.93rem; margin:14px 0; } .c input { margin-top:.25em; accent-color:var(--accent); }
.seg { display:flex; flex-wrap:wrap; gap:6px; }
.seg button { border:1px solid var(--line); background:var(--paper); border-radius:8px; padding:6px 11px; font-size:.88rem; color:var(--ink); }
.seg button[aria-pressed="true"] { background:var(--ink); color:var(--paper); border-color:var(--ink); }
.hint { font-size:.85rem; color:var(--muted); margin:8px 0; }
@media (prefers-reduced-motion: reduce) { * { transition:none !important; scroll-behavior:auto !important; } .play[data-state="loading"] .spin { animation-duration:2s; } }
