:root {
  color-scheme: light;
  --paper: #f6f5f0;
  --card: #fffdf8;
  --ink: #28332e;
  --muted: #55645b;
  --rule: #d9ddd3;
  --brand: #273d36;
  --accent: #dfebd6;
  --focus: #375e9a;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  font: 16px/1.5 system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.topbar { min-height: 72px; padding: 10px max(18px, calc((100vw - 1160px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--rule); }
.wordmark { display: inline-flex; align-items: center; gap: 10px; padding: 0; background: transparent; color: inherit; border: 0; font-weight: 700; letter-spacing: -.035em; min-height: 44px; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: 7px; min-height: 44px; padding: 8px 14px; border: 1px solid transparent; border-radius: 10px; font-weight: 650; }
.primary { background: var(--brand); color: #fff; }
.primary:not(:disabled):hover { background: #3a5449; }
.quiet { background: var(--card); border-color: var(--rule); color: var(--brand); }
.quiet:not(:disabled):hover { background: var(--accent); }
.library { max-width: 1080px; margin: auto; padding: clamp(34px, 8vw, 100px) 20px 48px; }
.library-heading { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 25px; }
.library h1 { font: 500 clamp(2.4rem, 7vw, 4rem)/1.06 var(--serif); letter-spacing: -.05em; }
.library-heading p, .empty p, .muted { color: var(--muted); }
.library-heading p { margin-top: 8px; }
.empty { display: grid; justify-items: center; align-content: center; text-align: center; min-height: 300px; border: 1px dashed #bdc9bd; border-radius: 20px; padding: 24px; background: var(--card); }
.empty h2 { margin: 15px 0 5px; font: 600 1.55rem/1.15 var(--serif); }
.empty-icon { background: var(--accent); padding: 13px; border-radius: 22px; display: flex; }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.book { background: var(--card); border: 1px solid var(--rule); border-radius: 16px; min-width: 0; }
.book-open { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 14px; align-items: center; width: 100%; border: 0; border-radius: inherit; padding: 17px; background: transparent; text-align: start; color: inherit; }
.book-open:hover { background: var(--accent); }
.book-mark { display: grid; place-items: center; height: 64px; border-radius: 5px 12px 12px 5px; background: var(--accent); color: var(--brand); font: 600 1.35rem var(--serif); }
.book-title { display: block; overflow-wrap: anywhere; font: 600 1.28rem/1.2 var(--serif); }
.book-meta { display: block; color: var(--muted); margin-top: 5px; font-size: .88rem; }
.reader { max-width: 1160px; margin: auto; }
.reading-pane { min-width: 0; padding: 0 20px 124px; }
.reading-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 21px 0; border-bottom: 1px solid var(--rule); margin-bottom: 26px; }
.reading-title { font-weight: 680; overflow-wrap: anywhere; }
.reading-location { color: var(--muted); font-size: .85rem; }
.sidebar { display: none; }
.toc-list { list-style: none; padding: 0; margin: 10px 0; }
.toc-list button { display: block; width: 100%; min-height: 44px; padding: 8px 10px; border: none; border-radius: 8px; text-align: start; background: transparent; overflow-wrap: anywhere; color: var(--ink); }
.toc-list button:hover, .toc-list button[aria-current] { background: var(--accent); }
.chapter { max-width: 68ch; margin: 0 auto; font: clamp(1.17rem, 2vw, 1.37rem)/1.7 var(--serif); overflow-wrap: anywhere; }
.chapter :is(h1, h2, h3, h4, h5, h6) { margin: 1.1em 0 .55em; line-height: 1.2; text-wrap: pretty; }
.chapter :first-child { margin-block-start: 0; }
.chapter p { margin: 0 0 .85em; }
.chapter img { max-width: 100%; height: auto; }
.chapter figure, .chapter blockquote { margin-inline: 0; }
.chapter blockquote { border-inline-start: 3px solid var(--rule); padding-inline-start: 1em; }
.chapter a { color: #315641; }
.chapter table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.chapter td, .chapter th { padding: .2em .45em; border: 1px solid var(--rule); }
.chapter pre { white-space: pre-wrap; }
.chapter .reading-fragment { color: inherit; border-radius: .2em; background: #dae9a8; box-shadow: 0 0 0 2px #dae9a8; }
.chapter [data-fragment] { scroll-margin-top: 18px; }
.chapter.can-narrate [data-fragment] { cursor: pointer; }
@media (hover: hover) {
  .chapter.can-narrate [data-fragment]:hover { text-decoration: underline; text-decoration-color: var(--muted); text-decoration-thickness: 1px; }
}
.chapter-nav { display: flex; justify-content: space-between; gap: 10px; max-width: 68ch; margin: 30px auto 0; }
.player { position: fixed; z-index: 2; inset: auto 0 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--rule); }
.player-content, .player progress { max-width: 1080px; margin: auto; }
.player-content { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.player p { color: var(--muted); font-size: .84rem; }
#player-speed { min-width: 68px; padding-inline: 8px; }
.player progress { display: block; width: 100%; margin-top: 4px; height: 7px; accent-color: var(--brand); }
.buffer-panel { position: relative; margin-inline-start: auto; font-size: .77rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.buffer-panel summary { cursor: pointer; min-height: 44px; align-content: center; padding-inline: 8px; white-space: nowrap; }
.buffer-details { position: absolute; inset: auto 0 calc(100% + 8px) auto; width: min(265px, calc(100vw - 32px)); padding: 10px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--card); box-shadow: 0 4px 16px rgb(39 61 54 / 12%); }
.buffer-details ol { list-style: none; margin: 7px 0 0; padding: 0; max-height: min(26dvh, 10rem); overflow: auto; }
.buffer-details li { padding: 4px 0; border-top: 1px solid var(--rule); }
.notice { margin: 0 0 15px; border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; background: var(--card); }
dialog { width: min(100% - 28px, 470px); max-height: calc(100dvh - 28px); padding: 0; border: 1px solid var(--rule); border-radius: 16px; color: var(--ink); background: var(--card); }
dialog::backdrop { background: rgb(25 43 36 / 44%); }
.dialog-heading { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--rule); }
.dialog-heading h2, .sidebar h2 { font: 600 1.55rem var(--serif); }
.settings-body, #toc { padding: 16px 20px 20px; }
.setting { display: grid; gap: 5px; margin-bottom: 15px; }
.setting label { font-weight: 650; }
.muted { font-size: .84rem; }
.setting select { width: 100%; min-height: 44px; border: 1px solid var(--rule); border-radius: 8px; padding: 6px 8px; color: var(--ink); background: var(--paper); }
.offline { display: grid; justify-items: start; gap: 10px; padding-top: 14px; border-top: 1px solid var(--rule); color: var(--muted); }
@media (min-width: 850px) {
  .reader { display: grid; grid-template-columns: minmax(190px, 240px) minmax(0, 1fr); }
  .sidebar { display: block; position: sticky; top: 15px; max-height: calc(100dvh - 100px); overflow: auto; align-self: start; padding: 31px 15px 20px; }
  .reading-pane { padding-inline: 35px; border-inline-start: 1px solid var(--rule); }
  .mobile-toc { display: none; }
}
@media (max-width: 480px) {
  #player-status { order: 1; flex-basis: 100%; }
  .buffer-panel summary { min-height: 38px; }
}
