:root {
  color-scheme: dark;
  --bg: #202a3b;
  --surface: #29354a;
  --border: #46536a;
  --ink: #f8f0e5;
  --muted: #c1c9d6;
  --gold: #f1cb8e;
  --paper: #f0e4d3;
  --paper-ink: #2e251d;
  --serif: "Baskervville", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: "Inter", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: radial-gradient(ellipse at 70% 0%, #2d3950, transparent 40rem), var(--bg); color: var(--ink); font: 1rem/1.55 var(--sans); }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, select, input { font: inherit; }
button, select, .primary, .back {
  min-height: 44px;
  padding: .58rem 1rem;
  border: 1px solid var(--border);
  border-radius: .6rem;
  background: var(--surface);
  color: var(--ink);
}
button, select, a { touch-action: manipulation; }
button, select { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.primary { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; background: var(--gold); border-color: transparent; color: #2d2217; font-weight: 700; text-decoration: none; }
.primary:hover { background: #ffdcaa; }
.wrap { width: min(100% - 2rem, 71rem); margin-inline: auto; }
.header { border-bottom: 1px solid var(--border); background: #1e2839; }
.header-inner { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.header-actions, .account { display: flex; align-items: center; gap: .7rem; }
.account { color: var(--muted); font-size: .78rem; }
.account > span:nth-child(2) { display: grid; line-height: 1.25; }
.account strong { color: var(--ink); }
.account small { max-width: 13rem; overflow: hidden; text-overflow: ellipsis; }
.account-avatar { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 50%; background: #52617a; color: var(--ink); font-weight: 750; }
.account #logout { min-height: 36px; padding: .35rem .7rem; }
.brand { display: inline-flex; align-items: center; gap: .7rem; min-height: 44px; text-decoration: none; font-size: .89rem; font-weight: 750; letter-spacing: .11em; white-space: nowrap; }
.brand em { color: var(--gold); font: italic 1.25rem var(--serif); letter-spacing: 0; }
.brand-mark { position: relative; width: 38px; height: 38px; border: 1px solid #806c54; border-radius: 9px; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; top: 10px; width: 9px; height: 14px; border: 1px solid var(--gold); }
.brand-mark::before { left: 7px; transform: skewY(14deg); border-radius: 2px 0 0 2px; }
.brand-mark::after { right: 7px; transform: skewY(-14deg); border-radius: 0 2px 2px 0; }
.skip { position: absolute; top: -100px; left: 1rem; padding: .6rem; background: var(--surface); z-index: 2; }
.skip:focus { top: 0; }
main { padding-block: clamp(2rem, 5vw, 4.6rem) 5rem; }
main:focus { outline: none; }
.auth-gate { min-height: min(42rem, calc(100vh - 10rem)); display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(18rem, .95fr); align-items: center; gap: clamp(2rem, 8vw, 7rem); }
.auth-gate > div:first-child { display: grid; justify-items: start; gap: 1.2rem; }
.auth-gate h1 { max-width: 12ch; }
.auth-gate p:not(.eyebrow) { max-width: 39rem; color: var(--muted); }
.auth-gate .primary { margin-top: .5rem; }
.auth-gate .eyebrow { color: var(--gold); font-size: .75rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.auth-error:not(:empty) { padding: .7rem .9rem; border: 1px solid #b97878; border-radius: .5rem; color: #ffd5d5 !important; }
.auth-art { position: relative; min-height: 28rem; }
.auth-art span { position: absolute; inset: 8% 17%; border: 1px solid #8b7559; border-radius: .45rem 1rem 1rem .45rem; background: linear-gradient(145deg, #52637d, #344156); box-shadow: -1.2rem 1.5rem 2.5rem #10172270; transform: rotate(8deg); }
.auth-art span:nth-child(2) { inset: 15% 25% 2% 9%; background: linear-gradient(145deg, #8a5f56, #503a3c); transform: rotate(-10deg); }
.auth-art span:nth-child(3) { inset: 3% 8% 20% 29%; background: linear-gradient(145deg, #6b7565, #3b493e); transform: rotate(16deg); }
#notice:empty { display: none; }
#notice { margin-bottom: 1rem; color: var(--gold); }
.intro { margin-bottom: clamp(1.25rem, 3vw, 2rem); }
h1 { font: 400 clamp(2.45rem, 6.5vw, 5.4rem)/1.02 var(--serif); letter-spacing: -.055em; overflow-wrap: anywhere; }
.intro p, #reader-author { margin-top: .7rem; color: var(--muted); }
.hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); overflow: hidden; border-radius: 1rem; background: var(--paper); color: var(--paper-ink); }
.hero-info { z-index: 1; display: grid; align-content: center; justify-items: start; gap: .65rem; padding: clamp(1.35rem, 5vw, 4.3rem); }
.hero .eyebrow { color: #79502f; font-size: .73rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.hero h2 { font: 400 clamp(2rem, 4.75vw, 4.35rem)/.99 var(--serif); letter-spacing: -.05em; overflow-wrap: anywhere; }
.hero-info > p:nth-of-type(2) { color: #604c3d; }
.hero .primary { margin-top: .55rem; background: #382b22; color: var(--ink); }
.hero .primary:hover { background: #544033; }
.hero :focus-visible, article :focus-visible { outline-color: #69401e; }
.hero-art { position: relative; isolation: isolate; display: grid; place-items: center; min-height: 19rem; padding: 2rem; overflow: hidden; background: radial-gradient(ellipse at 65% 18%, #c79264, transparent 64%), linear-gradient(150deg, #a66a4e, #6b4137); }
.hero-art::before { content: ""; position: absolute; z-index: -1; width: min(88%, 25rem); aspect-ratio: 1; border: 1px solid #fff3d971; border-radius: 50%; box-shadow: 0 0 0 1.3rem #fbe3bc18, 0 0 0 2.6rem #fbe3bc18; }
.hero .cover { width: min(69%, 12rem); transform: rotate(-8deg); box-shadow: 1.25rem 1.6rem 2.5rem #3d241daa; }
.hero-progress { display: flex; gap: .65rem; align-items: center; max-width: 100%; color: #684d37; font-size: .8rem; }
progress { width: clamp(5rem, 14vw, 10rem); height: .5rem; accent-color: #805433; }
.section-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin: clamp(2rem, 5vw, 3.6rem) 0 1.15rem; }
.collection-title { display: flex; gap: .8rem; align-items: baseline; }
.section-heading h2 { font: 400 clamp(1.7rem, 4vw, 2.4rem)/1.1 var(--serif); letter-spacing: -.035em; }
.section-heading span, .card-details p, .card-meta, #no-results { color: var(--muted); }
#count { font-size: .82rem; white-space: nowrap; }
.search { display: flex; min-width: min(100%, 15rem); align-items: center; gap: .65rem; padding-inline: .85rem; border: 1px solid var(--border); border-radius: .6rem; background: var(--surface); }
.search:focus-within { outline: 2px solid var(--gold); outline-offset: 2px; }
.search input { min-height: 44px; width: 100%; border: 0; padding: 0; outline: none; background: transparent; color: var(--ink); font-size: .9rem; }
.search input::placeholder { color: var(--muted); }
.search-mark { position: relative; flex: 0 0 13px; height: 13px; border: 1.5px solid currentColor; border-radius: 50%; }
.search-mark::after { content: ""; position: absolute; top: 10px; left: 9px; width: 5px; border-top: 1.5px solid currentColor; transform: rotate(45deg); }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11.5rem), 1fr)); gap: 1.15rem; }
.book-card { min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: .8rem; background: var(--surface); text-decoration: none; overflow-wrap: anywhere; }
.book-card:hover { border-color: #b08a65; }
.card-art { display: grid; place-items: center; min-height: 10.5rem; padding: 1rem; background: radial-gradient(ellipse at 65% 20%, #485674, transparent 80%), #303d53; }
.card-art .cover { width: min(70%, 6.5rem); padding: .45rem; }
.card-details { display: grid; gap: .3rem; padding: .85rem; }
.card-details h3 { font: 400 1.15rem/1.2 var(--serif); }
.card-details p, .card-meta { font-size: .82rem; }
.card-meta { display: flex; justify-content: space-between; align-items: center; gap: .3rem; }
.card-meta small { font-size: inherit; }
.card-arrow { color: var(--gold); }
.cover { aspect-ratio: 4 / 5.55; display: flex; flex-direction: column; justify-content: space-between; gap: .35rem; padding: .7rem; border: 1px solid #fff3d971; border-left: .38rem solid #33272058; border-radius: .15rem .45rem .45rem .15rem; background: linear-gradient(152deg, #794b3e, #4e2c28); color: #fff0d9; box-shadow: .35rem .55rem 1rem #180e0aaa; overflow: hidden; }
.cover.palette-1 { background: linear-gradient(150deg, #496561, #293e3b); }
.cover.palette-2 { background: linear-gradient(150deg, #675573, #403148); }
@media (max-width: 700px) {
  .auth-gate { grid-template-columns: 1fr; min-height: auto; }
  .auth-art { min-height: 17rem; order: -1; }
  .account > span:nth-child(2), .account-avatar { display: none; }
  .header-actions { gap: .35rem; }
  .account #logout { padding-inline: .55rem; }
}
.cover span, .cover small { font-size: clamp(.53rem, 1vw, .65rem); letter-spacing: .09em; }
.cover strong { font: 400 clamp(.85rem, 2.1vw, 1.8rem)/1.06 var(--serif); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.card-art .cover strong { font-size: .85rem; }
.back { display: inline-flex; align-items: center; text-decoration: none; margin-bottom: 1.4rem; }
.narration {
  position: sticky;
  top: .5rem;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(7.25rem, max-content) minmax(0, 1fr) max-content max-content;
  align-items: center;
  gap: .8rem;
  margin-top: 1.5rem;
  padding: .7rem;
  border: 1px solid var(--border);
  border-radius: .8rem;
  background: var(--surface);
  box-shadow: 0 .5rem 1.25rem #10172450;
}
.narration-position { display: grid; gap: .1rem; font-size: .9rem; }
.narration-position span, .narration-rate label { color: var(--muted); font-size: .8rem; }
.narration-rate { display: flex; align-items: center; gap: .5rem; }
.narration-rate select { width: auto; padding-inline: .6rem; }
.ask-button { border-color: #72819b; background: #35445d; white-space: nowrap; }
.ask-button:hover { background: #40516d; }
.reader-layout { display: grid; gap: 1rem; margin-top: 1.6rem; }
.reader-layout aside { display: grid; gap: .65rem; align-content: start; min-width: 0; padding: 1rem; border: 1px solid var(--border); border-radius: .8rem; background: var(--surface); }
.reader-layout label { font-weight: 650; font-size: .85rem; }
select { width: 100%; }
#reader-format, .reader-hint { color: var(--muted); font-size: .85rem; }
.reader-notes { display: grid; gap: .55rem; margin-top: .5rem; padding-top: .85rem; border-top: 1px solid var(--border); }
.notes-heading { display: flex; align-items: center; justify-content: space-between; gap: .45rem; }
.notes-heading h2 { font: 400 1.1rem/1.2 var(--serif); }
.notes-heading button { min-height: 36px; padding: .35rem .55rem; font-size: .76rem; }
#notes-list { display: grid; gap: .45rem; max-height: 21rem; overflow-y: auto; }
.notes-empty { color: var(--muted); font-size: .78rem; }
.note-card { display: grid; gap: .15rem; width: 100%; height: auto; padding: .6rem; text-align: left; background: #303d53; }
.note-card strong { font-size: .82rem; }
.note-card span { display: -webkit-box; overflow: hidden; color: var(--muted); font-size: .75rem; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.note-card small { color: var(--gold); font-size: .68rem; }
article { min-width: 0; padding: clamp(1rem, 5vw, 3.5rem); border: 1px solid #d7c5ae; border-radius: .9rem; background: var(--paper); color: var(--paper-ink); }
.locator { color: #79502f; font-size: .8rem; font-weight: 700; }
#chapter-title { font: 400 clamp(1.7rem, 4vw, 2.8rem)/1.1 var(--serif); margin-top: .5rem; overflow-wrap: anywhere; }
#passage { display: grid; gap: .4rem; margin-block: 1rem; }
.paragraph { display: block; scroll-margin-top: 8rem; padding: .65rem .8rem; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; border-color: transparent; background: transparent; color: inherit; font: 400 clamp(1.05rem, 2.5vw, 1.22rem)/1.75 var(--serif); }
.paragraph:hover { background: #e7d5be; }
.paragraph[aria-current] { background: #e8d2b6; border-color: #ad845d; }
article .reader-hint { color: #695747; }
.chapter-actions, .dialog-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.4rem; }
.chapter-actions button { background: #382b22; border-color: transparent; }
.danger { color: #ffb6a7; }
dialog { width: min(100% - 2rem, 30rem); border: 1px solid var(--border); border-radius: 1rem; background: var(--surface); color: var(--ink); padding: clamp(1rem, 4vw, 1.7rem); }
dialog::backdrop { background: #101724b8; }
dialog h2 { margin-bottom: 1rem; font: 400 2.2rem/1.1 var(--serif); }
.ask-dialog { width: min(100% - 1rem, 42rem); max-height: min(90vh, 52rem); padding: 0; overflow: hidden; }
.ask-shell { display: grid; grid-template-rows: auto auto minmax(5rem, 1fr) auto auto; max-height: min(90vh, 52rem); }
.ask-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; padding: 1.2rem 1.2rem .8rem; border-bottom: 1px solid var(--border); }
.ask-header h2 { margin: 0; }
.ask-header-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: .45rem; }
#ask-clear { color: var(--muted); font-size: .78rem; }
.ask-eyebrow { color: var(--gold); font-size: .72rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
#ask-close { width: 44px; padding: 0; font-size: 1.6rem; line-height: 1; }
.ask-context { margin: .8rem 1.2rem 0; color: var(--muted); font-size: .84rem; }
.ask-messages { display: grid; align-content: start; gap: .75rem; overflow-y: auto; padding: 1rem 1.2rem; }
.ask-empty { align-self: center; max-width: 28rem; margin: 1rem auto; color: var(--muted); text-align: center; }
.ask-message { display: grid; gap: .35rem; max-width: 91%; padding: .85rem; border-radius: .75rem; }
.ask-message-user { justify-self: end; background: #3c4c67; }
.ask-message-answer { justify-self: start; background: #243044; border: 1px solid var(--border); }
.ask-author, .source-title { color: var(--gold); font-size: .73rem; font-weight: 750; }
.answer-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.answer-type { padding: .15rem .45rem; border: 1px solid #76849a; border-radius: 999px; color: var(--muted); font-size: .68rem; }
.answer-sources { display: grid; gap: .45rem; margin-top: .5rem; }
.source-card { display: grid; gap: .18rem; width: 100%; height: auto; padding: .65rem; text-align: left; background: #303d53; }
.source-card small { color: var(--gold); }
.source-card span { color: var(--muted); font-size: .84rem; }
#ask-form { display: grid; gap: .45rem; padding: 1rem 1.2rem; border-top: 1px solid var(--border); }
#ask-form label { font-size: .8rem; font-weight: 700; }
#ask-question { width: 100%; resize: vertical; min-height: 5rem; max-height: 11rem; padding: .7rem; border: 1px solid var(--border); border-radius: .55rem; background: #1d2738; color: var(--ink); font: inherit; }
.ask-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; }
#ask-status { color: var(--gold); font-size: .8rem; }
.resume-book { margin: 0 1.2rem 1rem; border-color: #9e805e; color: var(--gold); }
.note-dialog { width: min(100% - 1rem, 32rem); }
.note-dialog form { display: grid; gap: .8rem; }
.note-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.note-header h2 { margin: 0; }
#note-close { width: 44px; padding: 0; font-size: 1.6rem; line-height: 1; }
.note-context { color: var(--gold); font-size: .82rem; }
.note-dialog label { font-size: .84rem; font-weight: 700; }
.note-dialog label span { color: var(--muted); font-weight: 400; }
#note-text { width: 100%; resize: vertical; min-height: 7rem; max-height: 16rem; padding: .7rem; border: 1px solid var(--border); border-radius: .55rem; background: #1d2738; color: var(--ink); font: inherit; }
#note-status { min-height: 1.2rem; color: var(--gold); font-size: .8rem; }
.note-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
#note-source { margin-right: auto; }
.file-field { display: grid; gap: .6rem; padding: 1rem; border: 1px dashed #77859c; border-radius: .65rem; }
.file-field input { max-width: 100%; }
.file-field input::file-selector-button { margin-right: .65rem; border: 0; border-radius: .4rem; padding: .6rem; background: #3b4a63; color: var(--ink); cursor: pointer; }
.file-field small { color: var(--muted); }
.checkbox { display: flex; gap: .65rem; align-items: baseline; margin-top: 1rem; }
.checkbox input { accent-color: var(--gold); }
#upload-status { margin-top: .6rem; color: var(--gold); }
.dialog-actions { justify-content: flex-end; }
@media (min-width: 720px) {
  .wrap { width: min(100% - 4rem, 71rem); }
  .reader-layout { grid-template-columns: minmax(11rem, .29fr) minmax(0, 1fr); align-items: start; gap: 1.45rem; }
  .reader-layout aside { position: sticky; top: 7rem; max-height: calc(100vh - 8rem); overflow-y: auto; }
}
@media (max-width: 560px) {
  .narration { grid-template-columns: minmax(0, 1fr) max-content; gap: .5rem; }
  .narration-toggle { justify-self: start; }
  .narration-position { grid-column: 1 / -1; grid-row: 2; }
  .ask-button { grid-column: 1 / -1; width: 100%; }
  .ask-dialog { width: calc(100% - .5rem); max-height: 96vh; }
  .ask-shell { max-height: 96vh; }
  .note-dialog { width: calc(100% - .5rem); }
  .hero { grid-template-columns: 1fr; }
  .hero-art { min-height: 12rem; padding: 1rem; }
  .hero .cover { width: 6.5rem; }
  .hero-art::before { width: 10rem; }
  .books { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .card-art { min-height: 8rem; }
  .card-details { padding: .65rem; }
  .search { width: 100%; }
}
