:root {
  --paper: #f8f8f6;
  --ink: #1b1d22;
  --muted: #676b73;
  --rule: #d9dad5;
  --accent: #3a4fa6;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", "Noto Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --measure: 42rem;
}
html[data-theme="sepia"] {
  --paper: #f4ecd9;
  --ink: #3a2e22;
  --muted: #7d6b55;
  --rule: #dfd2b6;
  --accent: #8b4a2b;
}
html[data-theme="dark"] {
  --paper: #15171b;
  --ink: #d9dad6;
  --muted: #8d919a;
  --rule: #2d3138;
  --accent: #93a4ea;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--paper); color: var(--ink); }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
img { max-width: 100%; height: auto; }

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 0.5em;
}

/* Site frame ---------------------------------------------------------- */
.site-header, .site-main, .site-footer {
  max-width: 64rem;
  margin: 0 auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-top: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
}
.site-name {
  font-family: var(--serif);
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}
.site-main { padding-top: 2rem; padding-bottom: 4rem; }
.site-footer {
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.875rem;
}
.page-title { font-size: 2rem; margin-bottom: 1.5rem; }
.empty { color: var(--muted); }

/* Buttons ------------------------------------------------------------- */
.reader-button, .theme-button {
  font: inherit;
  font-size: 0.9375rem;
  padding: 0.35rem 0.75rem;
  background: transparent;
  color: inherit;
  border: 1px solid var(--rule);
  border-radius: 2px;
  cursor: pointer;
  text-decoration: none;
}
.reader-button:hover, .theme-button:hover { border-color: var(--ink); }
.reader-button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.reader-button:disabled { opacity: 0.4; cursor: default; }
.reader-link {
  font: inherit;
  font-size: 0.875rem;
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  justify-self: start;
}

/* Library ------------------------------------------------------------- */
.novel-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 2rem 1.5rem;
}
.novel-grid a { color: inherit; text-decoration: none; display: block; }
.novel-grid a:hover .novel-title { text-decoration: underline; }
.novel-cover {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--rule);
  margin-bottom: 0.625rem;
}
.novel-title { font-family: var(--serif); font-weight: 600; line-height: 1.25; display: block; }
.novel-author, .novel-langs { display: block; color: var(--muted); font-size: 0.875rem; }

/* Novel page ---------------------------------------------------------- */
.novel-header { display: grid; grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 2.5rem; }
@media (min-width: 40rem) {
  .novel-header { grid-template-columns: 12rem 1fr; align-items: start; }
}
.novel-cover--large { width: 12rem; max-width: 50%; margin: 0; }
.novel-heading { font-size: clamp(1.75rem, 4vw, 2.75rem); }
.novel-byline { font-size: 1.125rem; margin: 0 0 0.5rem; }
.novel-meta { color: var(--muted); margin: 0 0 1rem; }
.languages { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin-bottom: 1.25rem; }
.languages .current { font-weight: 600; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.2em; }
.button {
  display: inline-block;
  padding: 0.625rem 1.125rem;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
  border-radius: 2px;
  font-weight: 600;
}
.button:hover { background: var(--accent); }
.novel-description {
  max-width: var(--measure);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.65;
  margin-bottom: 2.5rem;
}
.chapters h2 { font-size: 1.375rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.chapter-list { list-style: none; margin: 0; padding: 0; column-gap: 3rem; }
@media (min-width: 48rem) { .chapter-list { columns: 2; } }
.chapter-list li { break-inside: avoid; padding: 0.4rem 0; border-bottom: 1px solid var(--rule); }
.chapter-list a { color: inherit; text-decoration: none; display: flex; gap: 0.75rem; }
.chapter-list a:hover { color: var(--accent); }
.chapter-number { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.5rem; flex-shrink: 0; }

/* Reader -------------------------------------------------------------- */
.reading .site-main { max-width: none; padding: 0; }
.reader {
  --reader-size: 18px;
  --reader-font: var(--serif);
  --reader-leading: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.reader[data-font="sans"] { --reader-font: var(--sans); }
.reader[data-font="wide"] { --reader-font: Verdana, "DejaVu Sans", Geneva, sans-serif; }
.reader[data-spacing="tight"] { --reader-leading: 1.5; }
.reader[data-spacing="loose"] { --reader-leading: 2; }

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  font-size: 0.9375rem;
}
.reader-back {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40%;
}
.reader-chapter {
  flex: 1;
  text-align: center;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 40rem) { .reader-chapter { display: none; } .reader-back { flex: 1; max-width: none; } }
.reader-actions { display: flex; gap: 0.5rem; align-items: center; }
.reader-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.reader-progress-bar { height: 100%; width: 0; background: var(--accent); }

.reader-settings {
  position: fixed;
  top: 3.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  width: min(calc(100% - 2rem), 40rem);
  padding: 1rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  display: grid;
  gap: 0.75rem;
}
.reader-settings[hidden] { display: none; }
.setting { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.setting-label { width: 5rem; color: var(--muted); }
.setting-value { min-width: 2rem; text-align: center; font-variant-numeric: tabular-nums; }

.reader-content { flex: 1; }
.reader-inner { max-width: var(--measure); margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.reader .chapter-heading { font-size: calc(var(--reader-size) * 1.5); margin: 0.5rem 0 1.5rem; }
.chapter-body {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-leading);
}
.chapter-body p { margin: 0 0 1em; }
.chapter-body img { display: block; margin: 1.5rem auto; }
.chapter-body h1, .chapter-body h2, .chapter-body h3 { break-after: avoid; }
.chapter-end {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.9375rem;
}

.reader-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
}
.reader-indicator { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Paged layout: the viewport is the page, columns are the pages ---------- */
html.paged, html.paged body { height: 100%; overflow: hidden; }
.reader[data-layout="pages"] { height: 100vh; height: 100dvh; min-height: 0; }
.reader[data-layout="pages"] .reader-bar,
.reader[data-layout="pages"] .reader-foot { position: static; }
.reader[data-layout="pages"] .reader-progress { display: none; }
.reader[data-layout="pages"] .reader-content {
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.reader[data-layout="pages"] .reader-inner {
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 1.25rem;
  column-width: var(--page-width, 30rem);
  column-gap: var(--page-gap, 48px);
  column-fill: auto;
}
.reader[data-layout="pages"] .chapter-body img { max-height: 60vh; break-inside: avoid; }

/* Step 7: search box, continue button, error pages ---------------------- */
.site-header { align-items: center; }
.search { display: flex; gap: 0.5rem; flex: 1; max-width: 22rem; }
.search input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 0.35rem 0.6rem;
  background: var(--paper);
  color: inherit;
  border: 1px solid var(--rule);
  border-radius: 2px;
}
@media (max-width: 40rem) {
  .site-header { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
}
.novel-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.button--secondary { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
.button--secondary:hover { background: var(--ink); color: var(--paper); }
.error-page { max-width: var(--measure); }