:root {
  color-scheme: light;
  --paper: #f7f2e8;
  --page: #fffdf7;
  --ink: #292720;
  --muted: #746f65;
  --line: #d9d0c0;
  --accent: #735a32;
  --accent-strong: #4f3b20;
  --shadow: 0 18px 55px rgba(50, 42, 28, 0.12);
  --reader-size: 20px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
#feedbackDialog { max-height: 85vh; overflow-y: auto; }
.saved-note { padding: 14px 0; border-top: 1px solid var(--line); }
.saved-note blockquote { white-space: pre-wrap; }
#feedbackExport { width: 100%; }
#notePrivacy { font-size: 13px; color: var(--muted); }
.collection-info { text-align: left; margin-top: 30px; line-height: 1.6; }
.collection-info h2 { font: 600 30px/1.2 Georgia, serif; }
.collection-notice { width: min(100%, 760px); margin: 0 auto 24px; padding: 16px 22px; border: 1px solid var(--line); border-radius: 8px; line-height: 1.5; }
.ai-disclosure { font-size: 14px; font-weight: 650; }
.fanfiction-credit { font-size: 13px; color: var(--muted); }
.collection-notice p { margin: 0; }
.collection-notice p + p { margin-top: 8px; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, sans-serif; transition: background .2s, color .2s; }
button, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, select:focus-visible, textarea:focus-visible, .chapter:focus-visible { outline: 3px solid #b88b47; outline-offset: 3px; }

body.night {
  color-scheme: dark;
  --paper: #171816;
  --page: #20211e;
  --ink: #e8e2d6;
  --muted: #aaa397;
  --line: #3a3b36;
  --accent: #d0aa70;
  --accent-strong: #ead2ad;
  --shadow: 0 18px 55px rgba(0, 0, 0, .3);
}

.topbar {
  position: fixed; inset: 0 0 auto; z-index: 20; height: 64px; padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 18px;
  background: color-mix(in srgb, var(--paper) 92%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(16px);
}
.topbar button, .chapter-navigation button, .drawer-heading button, .dialog-actions button, .close-button {
  border: 1px solid var(--line); background: var(--page); border-radius: 999px; padding: 8px 13px; cursor: pointer;
}
.text-button { justify-self: start; border-color: transparent !important; background: transparent !important; font-weight: 650; }
.book-identity { display: flex; flex-direction: column; min-width: 0; text-align: center; overflow: hidden; }
.book-identity strong, .book-identity span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-identity strong { font: 600 14px/1.2 Georgia, serif; }
.book-identity span { color: var(--muted); font-size: 12px; margin-top: 2px; }
.reader-tools { justify-self: end; display: flex; gap: 7px; }
.reader-tools button { min-width: 42px; }
.reader-tools select { max-width: 150px; padding: 7px; border: 1px solid var(--line); border-radius: 999px; background: var(--page); color: var(--ink); }

.library-view { min-height: 100vh; padding: 130px 24px 70px; }
.library-heading { max-width: 760px; margin: 0 auto 44px; text-align: center; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.library-heading h1 { margin: 0; font: 600 clamp(38px, 6vw, 64px)/1.05 Georgia, serif; }
.library-heading > p:last-child { color: var(--muted); }
.library-grid { display: grid; grid-template-columns: repeat(2, minmax(250px, 350px)); justify-content: center; gap: 30px; }
.book-card { position: relative; min-height: 330px; overflow: hidden; padding: 0; border: 0; border-radius: 8px 18px 18px 8px; color: #f7f0df; cursor: pointer; box-shadow: var(--shadow); text-align: left; transition: transform .18s, box-shadow .18s; }
.book-card:hover { transform: translateY(-5px); box-shadow: 0 23px 65px rgba(50,42,28,.2); }
.book-card.canonical { background: linear-gradient(145deg, #243b3a, #172525); }
.book-card.experimental { background: linear-gradient(145deg, #5a4031, #35251f); }
.book-spine { position: absolute; inset: 0 auto 0 0; width: 18px; background: rgba(0,0,0,.2); border-right: 1px solid rgba(255,255,255,.12); }
.book-card-copy { position: absolute; inset: auto 30px 32px 42px; display: flex; flex-direction: column; gap: 10px; }
.book-card-copy small { color: #d5c9b0; letter-spacing: .14em; text-transform: uppercase; }
.book-card-copy strong { font: 600 32px/1.08 Georgia, serif; }
.book-card-copy span { color: #d5c9b0; }

.reader-view { min-height: 100vh; }
.reading-scroller { min-height: 100vh; padding: 112px 24px 90px; }
.chapter { width: min(100%, 760px); min-height: calc(100vh - 180px); margin: 0 auto; padding: clamp(38px,7vw,78px) clamp(28px,8vw,88px); background: var(--page); box-shadow: var(--shadow); font: var(--reader-size)/1.78 Georgia, 'Times New Roman', serif; letter-spacing: .002em; }
.chapter .chapter-number { display: block; margin-bottom: 12px; color: var(--accent); font: 800 11px/1.2 Inter, sans-serif; letter-spacing: .18em; text-transform: uppercase; text-align: center; }
.chapter h1 { margin: 0 0 2.25em; font: 600 2.1em/1.12 Georgia, serif; text-align: center; text-wrap: balance; }
.chapter h2, .chapter h3 { margin: 2em 0 .8em; font-family: Georgia, serif; }
.chapter p { margin: 0 0 1em; }
.chapter p + p { text-indent: 1.25em; }
.chapter h1 + p, .chapter .scene-break + p, .chapter blockquote + p { text-indent: 0; }
.chapter blockquote { margin: 1.5em 1em; color: var(--muted); font-style: italic; }
.chapter ul { margin: 1.2em 0; }
.scene-break { margin: 2.5em 0; color: var(--muted); letter-spacing: .45em; text-align: center; }
.chapter-navigation { width: min(100%, 760px); margin: 28px auto 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; color: var(--muted); font-size: 13px; }
.chapter-navigation button:first-child { justify-self: start; }
.chapter-navigation button:last-child { justify-self: end; }
.chapter-navigation button:disabled { opacity: .35; cursor: default; }
.progress-track { position: fixed; z-index: 25; inset: auto 0 0; height: 3px; background: color-mix(in srgb, var(--line) 70%, transparent); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .1s linear; }

.chapter-drawer { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(88vw, 360px); padding: 28px 20px; background: var(--page); border-right: 1px solid var(--line); transform: translateX(-103%); transition: transform .22s ease; overflow-y: auto; }
.chapter-drawer.open { transform: none; }
.drawer-heading { display: flex; justify-content: space-between; align-items: start; padding: 20px 8px; }
.drawer-heading h2 { margin: 0; font: 600 28px Georgia, serif; }
.drawer-heading button, .close-button { border: 0; background: transparent; font-size: 25px; padding: 3px 9px; }
#chapterList { display: grid; gap: 5px; }
#chapterList button { display: grid; grid-template-columns: 30px 1fr; gap: 10px; width: 100%; padding: 13px 12px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
#chapterList button:hover, #chapterList button.active { background: color-mix(in srgb, var(--accent) 13%, transparent); }
#chapterList button span:first-child { color: var(--muted); font-size: 12px; }
.drawer-backdrop { position: fixed; z-index: 35; inset: 0; width: 100%; border: 0; background: rgba(0,0,0,.28); }

.suggest-button { position: fixed; z-index: 30; left: 50%; bottom: 28px; transform: translateX(-50%); border: 0; border-radius: 999px; padding: 12px 20px; background: var(--accent-strong); color: var(--page); font-weight: 750; box-shadow: 0 10px 30px rgba(0,0,0,.25); cursor: pointer; }
.status { position: fixed; z-index: 60; left: 50%; bottom: 25px; transform: translate(-50%, 20px); max-width: min(90vw, 560px); padding: 10px 16px; border-radius: 999px; background: var(--ink); color: var(--page); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; text-align: center; font-size: 13px; }
.status.show { opacity: 1; transform: translate(-50%, 0); }

dialog { width: min(92vw, 560px); border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--page); color: var(--ink); box-shadow: 0 30px 90px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.46); backdrop-filter: blur(2px); }
#feedbackForm { padding: 25px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; }
.dialog-heading h2 { margin: 0; font: 600 28px Georgia, serif; }
dialog blockquote { max-height: 130px; overflow: auto; margin: 22px 0; padding: 14px 16px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); color: var(--muted); font: italic 16px/1.5 Georgia, serif; }
dialog label { display: grid; gap: 7px; margin: 15px 0; color: var(--muted); font-size: 13px; font-weight: 700; }
dialog select, dialog textarea { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; background: var(--paper); color: var(--ink); }
dialog textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: end; gap: 10px; margin-top: 22px; }
.dialog-actions .primary { background: var(--accent-strong); color: var(--page); border-color: transparent; }

@media (max-width: 720px) {
  .topbar { height: auto; min-height: 58px; grid-template-columns: auto minmax(0,1fr); padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 8px; gap: 8px; }
  .book-identity { min-width: 0; text-align: left; }
  .book-identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .book-identity span { display: none; }
  .reader-tools button { min-width: 38px; padding: 7px 9px; }
  .reader-tools select { max-width: 100px; }
  .reader-tools { grid-column: 1 / -1; justify-self: center; justify-content: center; flex-wrap: wrap; }
  #chaptersButton { font-size: 0; }
  #chaptersButton::after { content: '☰'; font-size: 18px; }
  .library-view { padding-top: 160px; }
  .library-grid { grid-template-columns: minmax(0, 360px); }
  .book-card { min-height: 240px; }
  .reading-scroller { padding: 160px 0 65px; }
  .chapter { min-height: calc(100vh - 120px); padding: 42px clamp(22px, 7vw, 44px); box-shadow: none; }
  .chapter-navigation { padding: 0 14px; }
}

@media (max-width: 450px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  #themeButton { font-size: 0; }
  #themeButton::after { content: '◐'; font-size: 17px; }
  .chapter-navigation span { display: none; }
  .chapter-navigation { grid-template-columns: 1fr 1fr; }
}
