:root{
  --bg:#faf7f2; --fg:#1f1d1a; --muted:#7a7468; --line:#e6e0d4; --accent:#8a3b1f; --btn:#efe9dc;
  --serif: "Source Serif 4", "Noto Serif", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Roboto", sans-serif;
}
@media (prefers-color-scheme: dark){
  :root{ --bg:#141413; --fg:#e9e4d9; --muted:#9a9488; --line:#2b2a27; --accent:#e0906b; --btn:#23221f; }
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%;margin:0;background:var(--bg);color:var(--fg)}
body{font-family:var(--sans);display:flex;flex-direction:column;overflow:hidden}

#top{display:flex;align-items:center;justify-content:space-between;
  padding:calc(env(safe-area-inset-top) + 8px) 16px 6px;min-height:44px}
#progress{font-size:12px;color:var(--muted);letter-spacing:.04em}
#lib{background:none;border:0;color:var(--muted);font:inherit;font-size:14px;padding:8px 4px}
#lib b{font-weight:600;color:var(--fg)}

#reader{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch;outline:none;scroll-behavior:auto}
#text{max-width:36rem;margin:0 auto;padding:12px 20px 40px;font-family:var(--serif);font-size:1.2rem;line-height:1.65}
#text h1{font-size:1.7rem;line-height:1.2;margin:.5rem 0 .4rem;font-weight:600}
#text .by{font-family:var(--sans);font-size:.9rem;color:var(--muted);margin:0 0 1.6rem}
#text .by span+span::before{content:" · "}
#text p{margin:0 0 1.05em;hyphens:auto}
#text.poem p{white-space:pre-wrap;margin-bottom:1.6em;line-height:1.55}
#text .end{font-family:var(--sans);font-size:.9rem;color:var(--muted);margin-top:2.4rem;padding-top:1rem;border-top:1px solid var(--line)}
#text .end a{color:var(--accent)}
#text .status{color:var(--muted);font-family:var(--sans)}
#text[dir=rtl]{font-family:"Noto Serif Hebrew","Frank Ruhl Libre","David",var(--serif)}
#text[dir=rtl] .by{font-family:var(--sans)}

#bar{display:flex;gap:10px;padding:10px 16px calc(env(safe-area-inset-bottom) + 12px);
  border-top:1px solid var(--line);background:var(--bg)}
#bar button{flex:1;height:54px;border:0;border-radius:14px;background:var(--btn);color:var(--fg);
  font:600 1rem var(--sans)}
#bar button.primary{background:var(--accent);color:#fff}
#bar button[aria-pressed=true]{outline:2px solid var(--accent);outline-offset:-2px}
#bar button:active{transform:scale(.98)}

#library{position:fixed;inset:0;background:var(--bg);display:flex;flex-direction:column;z-index:5}
#library[hidden]{display:none}
#library header{display:flex;align-items:center;gap:12px;padding:calc(env(safe-area-inset-top) + 8px) 12px 8px;border-bottom:1px solid var(--line)}
#library h2{margin:0;font-size:1.1rem}
#back{background:none;border:0;color:var(--accent);font:inherit;padding:10px 8px}
#savedlist{list-style:none;margin:0;padding:0;overflow-y:auto;flex:1}
#savedlist li{display:flex;align-items:center;border-bottom:1px solid var(--line)}
#savedlist .open{flex:1;text-align:start;background:none;border:0;color:var(--fg);padding:14px 16px;font:inherit;min-width:0}
#savedlist .t{display:block;font-family:var(--serif);font-size:1.05rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#savedlist .m{display:block;font-size:.82rem;color:var(--muted);margin-top:2px}
#savedlist .del{background:none;border:0;color:var(--muted);font-size:1.2rem;padding:14px 18px}
#empty{padding:24px 16px;color:var(--muted)}
