:root {
  color-scheme: dark;
  --bg: #0b100d;
  --bg-deep: #070a08;
  --surface: #121a15;
  --surface-raised: #18231c;
  --surface-soft: rgba(232, 225, 203, 0.055);
  --border: rgba(232, 225, 203, 0.14);
  --border-strong: rgba(232, 225, 203, 0.28);
  --text: #eee9dc;
  --text-soft: #d7d1c2;
  --muted: #a7ac9f;
  --muted-2: #7d867b;
  --gold: #d3a954;
  --gold-bright: #f0cb7a;
  --moss: #85ad87;
  --danger: #bd765f;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
  --radius: 22px;
  --reader: 720px;
  --reader-font: 1.12rem;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eee8dc;
  --bg-deep: #e2dacb;
  --surface: #f8f4eb;
  --surface-raised: #fffaf0;
  --surface-soft: rgba(62, 55, 39, 0.055);
  --border: rgba(61, 55, 42, 0.16);
  --border-strong: rgba(61, 55, 42, 0.29);
  --text: #28291f;
  --text-soft: #414236;
  --muted: #696c61;
  --muted-2: #87897d;
  --gold: #986d1e;
  --gold-bright: #7e5815;
  --moss: #506f50;
  --danger: #914b39;
  --shadow: 0 25px 70px rgba(71, 59, 37, 0.13);
}

@media (prefers-color-scheme: light) {
  html:not([data-theme]) {
    color-scheme: light;
    --bg: #eee8dc;
    --bg-deep: #e2dacb;
    --surface: #f8f4eb;
    --surface-raised: #fffaf0;
    --surface-soft: rgba(62, 55, 39, 0.055);
    --border: rgba(61, 55, 42, 0.16);
    --border-strong: rgba(61, 55, 42, 0.29);
    --text: #28291f;
    --text-soft: #414236;
    --muted: #696c61;
    --muted-2: #87897d;
    --gold: #986d1e;
    --gold-bright: #7e5815;
    --moss: #506f50;
    --danger: #914b39;
    --shadow: 0 25px 70px rgba(71, 59, 37, 0.13);
  }
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--bg-deep);
}

html[data-reader-size="0"] { --reader-font: 1rem; }
html[data-reader-size="1"] { --reader-font: 1.12rem; }
html[data-reader-size="2"] { --reader-font: 1.26rem; }
html[data-reader-width="wide"] { --reader: 860px; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 10% -10%, color-mix(in srgb, var(--moss) 18%, transparent), transparent 65%),
    radial-gradient(800px 540px at 94% 2%, color-mix(in srgb, var(--gold) 14%, transparent), transparent 68%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.16;
  background-image:
    linear-gradient(115deg, transparent 0 48%, var(--border) 49%, transparent 50%),
    linear-gradient(25deg, transparent 0 48%, var(--border) 49%, transparent 50%);
  background-size: 140px 140px;
  mask-image: linear-gradient(to bottom, #000, transparent 85%);
}

a { color: inherit; }
a:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--bg);
  background: var(--text);
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-180%);
}

.skip-link:focus { transform: translateY(0); }

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 80;
  height: 3px;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--moss), var(--gold-bright));
  box-shadow: 0 0 18px color-mix(in srgb, var(--gold) 45%, transparent);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.header-inner {
  width: min(1180px, calc(100% - 32px));
  min-height: 70px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-weight: 850;
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid color-mix(in srgb, var(--gold) 55%, var(--border));
  border-radius: 50%;
  color: var(--gold-bright);
  background: var(--surface-raised);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  box-shadow: inset 0 0 0 4px var(--surface-soft);
}

.header-actions, .site-nav, .reader-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.site-nav a, .reader-tools button {
  min-height: 38px;
  padding: 9px 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 0.83rem;
  font-weight: 760;
  text-decoration: none;
  cursor: pointer;
}

.site-nav a:hover, .reader-tools button:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-soft);
}

.reader-tools {
  margin-left: 6px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.reader-tools button { min-width: 38px; }

.theme-picker select {
  min-height: 38px;
  margin-left: 6px;
  padding: 8px 30px 8px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-soft);
  background: var(--surface);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
}

.index-main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(54px, 8vw, 96px) 0 80px;
}

.book-hero {
  position: relative;
  overflow: hidden;
  padding: clamp(34px, 7vw, 76px);
  border: 1px solid var(--border);
  border-radius: 30px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--moss) 14%, transparent), transparent 48%),
    var(--surface);
  box-shadow: var(--shadow);
}

.book-hero::after {
  content: "";
  position: absolute;
  width: 420px;
  height: 420px;
  right: -210px;
  bottom: -250px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  box-shadow: 0 0 0 34px var(--surface-soft), 0 0 0 68px color-mix(in srgb, var(--gold) 6%, transparent);
}

.hero-kicker {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero-kicker span {
  width: 36px;
  height: 1px;
  background: var(--gold);
}

.eyebrow {
  position: relative;
  z-index: 1;
  margin: 0 0 12px;
  color: var(--moss);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.book-hero h1 {
  position: relative;
  z-index: 1;
  max-width: 850px;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.1rem, 8.5vw, 7.4rem);
  font-weight: 500;
  line-height: 0.9;
  letter-spacing: -0.055em;
}

.book-title {
  position: relative;
  z-index: 1;
  margin: 18px 0 0;
  color: var(--gold-bright);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 3vw, 2.15rem);
  font-style: italic;
}

.tagline {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 42px 0 12px;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  line-height: 1.25;
}

.book-description {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.75;
}

.book-stats {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-width: 760px;
  margin: 34px 0 0;
}

.book-stats div {
  padding: 15px 17px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.book-stats dt {
  color: var(--muted-2);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.book-stats dd {
  margin: 5px 0 0;
  font-weight: 760;
}

.reading-actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.start-reading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 19px;
  border: 1px solid var(--gold);
  border-radius: 13px;
  color: #17130a;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  font-size: 0.9rem;
  font-weight: 850;
  text-decoration: none;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.start-reading:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px color-mix(in srgb, var(--gold) 20%, transparent);
}

.start-reading.secondary {
  color: var(--text-soft);
  border-color: var(--border);
  background: var(--surface-soft);
}

.contents-panel {
  margin-top: 34px;
  padding: clamp(24px, 5vw, 46px);
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.contents-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.contents-heading p {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
}

.contents-heading span { color: var(--muted); font-size: 0.82rem; }

.part-section { padding: 30px 0 6px; }

.part-header {
  display: grid;
  grid-template-columns: 90px minmax(160px, 0.55fr) 1fr;
  gap: 20px;
  align-items: baseline;
  margin-bottom: 14px;
}

.part-header p {
  margin: 0;
  color: var(--gold);
  font-size: 0.69rem;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.part-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  font-weight: 500;
}

.part-header span { color: var(--muted); line-height: 1.55; }

.contents-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.contents-list li + li { border-top: 1px solid var(--border); }

.contents-list a {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 66px;
  padding: 10px 12px;
  border-radius: 12px;
  text-decoration: none;
  transition: background 0.16s ease, transform 0.16s ease;
}

.contents-list a:hover, .contents-list a.last-read {
  background: var(--surface-soft);
  transform: translateX(3px);
}

.contents-list a.last-read { box-shadow: inset 3px 0 0 var(--gold); }
.chapter-number { color: var(--muted-2); font-size: 0.76rem; font-weight: 760; }
.chapter-title { font-family: Georgia, "Times New Roman", serif; font-size: 1.08rem; }
.reading-time { color: var(--muted-2); font-size: 0.76rem; }

.reader-main {
  width: min(var(--reader), calc(100% - 36px));
  margin: 0 auto;
  padding: clamp(52px, 8vw, 92px) 0 70px;
}

.chapter-header {
  margin-bottom: clamp(48px, 8vw, 78px);
  padding-bottom: 34px;
  border-bottom: 1px solid var(--border);
}

.chapter-label {
  margin: 0 0 13px;
  color: var(--gold);
  font-size: 0.71rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.chapter-header h1, .collected-chapter-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.45rem, 7vw, 4.8rem);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -0.045em;
}

.chapter-meta {
  margin: 18px 0 0;
  color: var(--muted-2);
  font-size: 0.8rem;
  font-weight: 720;
}

.chapter-description {
  margin: 17px 0 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.06rem;
  font-style: italic;
  line-height: 1.55;
}

.prose {
  color: var(--text-soft);
  font-family: Georgia, "Times New Roman", Charter, serif;
  font-size: var(--reader-font);
  line-height: 1.84;
}

.prose p { margin: 0 0 1.48em; }

.prose > p:first-child::first-letter {
  float: left;
  margin: 0.08em 0.11em 0 0;
  color: var(--gold-bright);
  font-size: 3.7em;
  font-weight: 500;
  line-height: 0.76;
}

.counter-record-page .prose,
.collected-counter-record .prose {
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--surface-raised) 76%, transparent);
  padding: clamp(24px, 5vw, 48px);
  font-family: Georgia, "Times New Roman", serif;
  font-size: calc(var(--reader-font) * 0.92);
}

.counter-record-page .prose > p:first-child::first-letter,
.collected-counter-record .prose > p:first-child::first-letter {
  float: none;
  margin: 0;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.counter-record-page .prose blockquote,
.collected-counter-record .prose blockquote {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--gold) 12%, transparent);
}

.prose h2, .prose h3, .prose h4 {
  margin: 2.2em 0 0.8em;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.2;
}

.prose blockquote {
  margin: 2em 0;
  padding: 0.4em 0 0.4em 1.25em;
  border-left: 3px solid var(--gold);
  color: var(--muted);
  font-style: italic;
}

.prose blockquote p { margin: 0; }
.prose ul, .prose ol { margin: 0 0 1.5em; padding-left: 1.4em; }
.prose li { margin: 0.45em 0; }
.prose hr { width: 80px; margin: 3.5em auto; border: 0; border-top: 1px solid var(--border-strong); }

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 72px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 86px;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-soft);
  text-decoration: none;
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.chapter-nav a:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.chapter-nav a:last-child { text-align: right; }
.direction { color: var(--muted-2); font-size: 0.7rem; font-weight: 820; letter-spacing: 0.08em; text-transform: uppercase; }

.story-footer {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  font-size: 0.75rem;
  text-align: center;
}

.full-book { --reader: 760px; }

.full-book-toc {
  margin: 0 0 74px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-soft);
}

.full-book-toc summary { color: var(--text); font-weight: 800; cursor: pointer; }
.full-book-toc ol { margin: 18px 0 0; padding-left: 1.4em; }
.full-book-toc li { margin: 8px 0; color: var(--muted); }
.full-book-toc a { text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.full-book-toc span { display: inline-block; min-width: 92px; color: var(--muted-2); font-size: 0.76rem; }

.collected-chapter {
  scroll-margin-top: 90px;
  padding: 68px 0 22px;
  border-top: 1px solid var(--border);
}

.collected-chapter:first-of-type { border-top: 0; }
.collected-chapter-header { margin-bottom: 48px; }
.collected-chapter-header h2 { font-size: clamp(2.2rem, 6vw, 4rem); }
.back-to-book-top { display: inline-block; margin: 25px 0 30px; color: var(--muted); font-size: 0.78rem; font-weight: 760; text-decoration: none; }

@media (max-width: 860px) {
  .header-inner { align-items: flex-start; padding: 10px 0; }
  .header-actions { align-items: flex-end; flex-direction: column; }
  .part-header { grid-template-columns: 72px 1fr; }
  .part-header span { grid-column: 2; }
}

@media (max-width: 660px) {
  .header-inner { width: min(100% - 20px, 1180px); flex-direction: column; gap: 8px; }
  .header-actions { width: 100%; align-items: center; flex-direction: row; justify-content: space-between; overflow-x: auto; }
  .site-nav a { padding: 8px; }
  .brand-mark { width: 34px; height: 34px; }
  .reader-tools { margin-left: 0; padding-left: 6px; }
  .reader-tools button { min-width: 34px; padding-inline: 7px; }
  .theme-picker select { max-width: 86px; margin-left: 0; }
  .index-main { width: min(100% - 20px, 1120px); padding-top: 30px; }
  .book-hero, .contents-panel { border-radius: 20px; }
  .book-hero { padding: 28px 22px 34px; }
  .book-stats { grid-template-columns: 1fr; }
  .contents-panel { padding: 22px 14px; }
  .contents-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .part-header { display: block; padding-inline: 8px; }
  .part-header h2 { margin: 5px 0 7px; }
  .contents-list a { grid-template-columns: 92px 1fr; gap: 10px; }
  .reading-time { display: none; }
  .reader-main { width: min(100% - 26px, var(--reader)); padding-top: 46px; }
  .chapter-header { margin-bottom: 46px; }
  .prose { line-height: 1.76; }
  .chapter-nav { grid-template-columns: 1fr; }
  .chapter-nav a:last-child { text-align: left; }
}

@media print {
  .site-header, .chapter-nav, .story-footer, .reading-progress, .full-book-toc, .back-to-book-top { display: none !important; }
  body { color: #111; background: #fff; }
  .reader-main { width: 100%; max-width: 740px; padding: 0; }
  .prose { color: #111; font-size: 11pt; line-height: 1.55; }
  .collected-chapter { break-before: page; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
