/* The Shelf reader: calm, large type, one chapter at a time, comfortable for an hour */
:root { --bg: #fbf8f1; --fg: #1d1a15; --mut: #7a7366; --line: #e6dfcf; --acc: #9a6a12; --bar: #f0b84e; --fs: 20px; --lh: 1.75; --safe-b: env(safe-area-inset-bottom, 0px); }
[data-theme='sepia'] { --bg: #f1e4c8; --fg: #3a2c16; --mut: #8a7650; --line: #dccaa3; --acc: #7a4f0c; }
[data-theme='night'] { --bg: #0e0b08; --fg: #e4d8bc; --mut: #9a8e74; --line: #2a2318; --acc: #f0b84e; }
[data-space='tight'] { --lh: 1.55; }
[data-space='airy'] { --lh: 1.95; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--fg); transition: background 0.25s, color 0.25s; }
body { font-family: 'Inter', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 8px; }

/* progress across the whole book */
.prog { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 60; background: transparent; }
.prog i { display: block; height: 100%; width: 0; background: var(--bar); transition: width 0.15s; }

/* top bar and bottom dock slide away while reading down, and come back when you scroll up */
.bar { position: fixed; top: 0; left: 0; right: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 4px; padding: 0 max(8px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); transition: transform 0.28s ease; }
.bar .t { flex: 1; min-width: 0; text-align: center; font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; color: var(--mut); }
.ib { min-width: 46px; height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: none; border: 0; border-radius: 999px; cursor: pointer; text-decoration: none; padding: 0 10px; }
.ib:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); }
.ib.wide span { font-size: 14px; font-weight: 600; display: none; }
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 4px; padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + var(--safe-b)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); transition: transform 0.28s ease; }
.hide-bars .bar { transform: translateY(-101%); }
.hide-bars .dock { transform: translateY(101%); }
.step { height: 48px; border: 0; background: none; border-radius: 14px; cursor: pointer; display: grid; place-items: center; }
.step:hover:not(:disabled) { background: color-mix(in srgb, var(--fg) 8%, transparent); }
.step:disabled { opacity: 0.25; cursor: default; }
.where { background: none; border: 0; cursor: pointer; text-align: center; padding: 4px 8px; border-radius: 12px; min-width: 0; }
.where span { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where small { display: block; font-size: 12px; color: var(--mut); margin-top: 1px; }

/* the page itself */
main { max-width: 41rem; margin: 0 auto; padding: 96px max(24px, env(safe-area-inset-left)) 28px; }
.ch-no { font-size: 12px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--acc); }
article h1 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: clamp(30px, 6.4vw, 44px); line-height: 1.1; margin: 12px 0 10px; letter-spacing: -0.015em; text-wrap: balance; overflow-wrap: break-word; }
.ch-meta { color: var(--mut); font-size: 14px; margin: 0 0 34px; padding-bottom: 26px; border-bottom: 1px solid var(--line); }
article { font-family: 'Newsreader', Georgia, serif; font-size: var(--fs); line-height: var(--lh); overflow-wrap: break-word; hyphens: manual; }
[data-font='sans'] article { font-family: 'Inter', system-ui, sans-serif; font-size: calc(var(--fs) - 2.5px); }
article.in { animation: rise 0.35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
article p { margin: 0 0 1.2em; }
article h2 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 1.34em; line-height: 1.2; margin: 2.1em 0 0.65em; text-wrap: balance; }
article h3 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 1.1em; margin: 1.7em 0 0.45em; }
article blockquote { margin: 1.5em 0; padding: 0.15em 0 0.15em 1.1em; border-left: 3px solid var(--bar); font-style: italic; }
article blockquote p { margin: 0.5em 0; }
article ul, article ol { padding-left: 1.25em; margin: 0 0 1.2em; }
article li { margin: 0.45em 0; }
article hr { border: 0; text-align: center; margin: 2.2em 0; }
article hr::before { content: '· · ·'; letter-spacing: 0.6em; color: var(--mut); }
article strong { font-weight: 600; }
article ::selection { background: color-mix(in srgb, var(--bar) 45%, transparent); }

/* end of a chapter */
.pager { max-width: 41rem; margin: 8px auto 0; padding: 0 max(24px, env(safe-area-inset-left)); display: grid; gap: 12px; }
.pager a { display: block; border: 1.5px solid var(--line); border-radius: 18px; padding: 18px 20px; text-decoration: none; transition: border-color 0.15s, transform 0.15s; }
.pager a:hover { border-color: var(--fg); transform: translateY(-1px); }
.pager small { display: block; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--mut); font-weight: 600; margin-bottom: 4px; }
.pager b { font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 18px; line-height: 1.25; display: block; }
.pager .next { background: color-mix(in srgb, var(--bar) 18%, transparent); border-color: color-mix(in srgb, var(--bar) 55%, transparent); }
.pager .prev { border-style: dashed; }
.dl { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 30px auto calc(110px + var(--safe-b)); padding: 0 max(24px, env(safe-area-inset-left)); max-width: 41rem; }
.dl a { font-weight: 600; font-size: 14px; border: 1.5px solid var(--line); border-radius: 999px; padding: 11px 20px; text-decoration: none; }
.dl a:hover { border-color: var(--fg); }

/* chapters */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.toc { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(400px, 90vw); background: var(--bg); border-right: 1px solid var(--line); overflow: auto; transform: translateX(-102%); transition: transform 0.25s; padding: 0 0 calc(24px + var(--safe-b)); }
.toc.open { transform: none; }
.toc-h { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 22px; background: var(--bg); border-bottom: 1px solid var(--line); font-family: 'Fraunces', serif; font-size: 17px; }
#toc-list { padding: 8px 10px; }
.toc a { display: flex; gap: 12px; align-items: baseline; padding: 13px 14px; border-radius: 12px; text-decoration: none; line-height: 1.35; font-size: 16px; }
.toc a:hover { background: color-mix(in srgb, var(--fg) 7%, transparent); }
.toc a.read { color: var(--mut); }
.toc a.read::after { content: '✓'; margin-left: auto; font-size: 13px; }
.toc a[aria-current] { background: color-mix(in srgb, var(--bar) 26%, transparent); font-weight: 600; color: var(--fg); }

/* text and look */
.panel { position: fixed; z-index: 50; top: 62px; right: 10px; width: min(340px, calc(100vw - 20px)); background: var(--bg); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 24px 60px -16px rgba(0, 0, 0, 0.45); padding: 18px; display: none; }
.panel.open { display: block; }
.panel h4 { margin: 16px 0 8px; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--mut); font-weight: 600; }
.panel h4:first-child { margin-top: 0; }
.themes, .seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg:has(button:nth-child(2):last-child) { grid-template-columns: 1fr 1fr; }
.themes button, .seg button { height: 46px; border-radius: 12px; border: 1.5px solid var(--line); background: none; cursor: pointer; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.themes i { width: 16px; height: 16px; border-radius: 50%; border: 1px solid #8884; }
.themes button[aria-pressed='true'], .seg button[aria-pressed='true'] { border-color: var(--fg); background: color-mix(in srgb, var(--fg) 8%, transparent); }
.size { display: flex; align-items: center; gap: 12px; }
.size button { width: 36px; height: 36px; border: 0; background: none; cursor: pointer; font-family: 'Newsreader', serif; font-size: 15px; }
.size input { flex: 1; accent-color: var(--acc); height: 32px; }

@media (min-width: 760px) {
  .ib.wide span { display: inline; }
  main { padding-top: 110px; }
  .pager { grid-template-columns: 1fr 1fr; }
  .pager .next { grid-column: 2; text-align: right; }
  .pager .prev + .next { grid-column: 2; }
  .dock { left: 50%; right: auto; bottom: 18px; transform: translateX(-50%); width: 440px; border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 14px 40px -12px rgba(0, 0, 0, 0.35); }
  .hide-bars .dock { transform: translateX(-50%) translateY(140%); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
