:root {
  color-scheme: light;
  --bg: #f4f5fa;
  --bg-2: #e9edf6;
  --surface: rgb(255 255 255 / 72%);
  --surface-strong: rgb(255 255 255 / 90%);
  --surface-soft: rgb(89 72 180 / 7%);
  --border: rgb(28 32 49 / 12%);
  --border-strong: rgb(28 32 49 / 22%);
  --text: #181b27;
  --muted: #5d6578;
  --muted-2: #7d8494;
  --accent: #6755d4;
  --accent-2: #087f73;
  --system-bg: #0b0f1a;
  --system-text: #d9f4ec;
  --shadow: 0 28px 90px rgb(37 42 66 / 14%);
  --radius: 24px;
  --reader-scale: 1;
  --reader-width: 49rem;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-reader-size="0"] { --reader-scale: 0.92; }
html[data-reader-size="2"] { --reader-scale: 1.1; }
html[data-reader-width="wide"] { --reader-width: 57rem; }

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070a12;
  --bg-2: #0c1220;
  --surface: rgb(255 255 255 / 6.5%);
  --surface-strong: rgb(255 255 255 / 9.5%);
  --surface-soft: rgb(255 255 255 / 4.5%);
  --border: rgb(255 255 255 / 12%);
  --border-strong: rgb(255 255 255 / 22%);
  --text: #f6f7fb;
  --muted: #aab2c3;
  --muted-2: #7f899d;
  --accent: #9b8cff;
  --accent-2: #42d7bb;
  --system-bg: #05070d;
  --system-text: #cef5e9;
  --shadow: 0 28px 90px rgb(0 0 0 / 42%);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;
    --bg: #070a12;
    --bg-2: #0c1220;
    --surface: rgb(255 255 255 / 6.5%);
    --surface-strong: rgb(255 255 255 / 9.5%);
    --surface-soft: rgb(255 255 255 / 4.5%);
    --border: rgb(255 255 255 / 12%);
    --border-strong: rgb(255 255 255 / 22%);
    --text: #f6f7fb;
    --muted: #aab2c3;
    --muted-2: #7f899d;
    --accent: #9b8cff;
    --accent-2: #42d7bb;
    --system-bg: #05070d;
    --system-text: #cef5e9;
    --shadow: 0 28px 90px rgb(0 0 0 / 42%);
  }
}

* {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(900px 520px at 8% -8%, rgb(155 140 255 / 25%), transparent 62%),
    radial-gradient(760px 460px at 94% 8%, rgb(66 215 187 / 15%), transparent 58%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 52%, var(--bg) 100%);
  color: var(--text);
  font-family: var(--serif);
  font-size: clamp(1.06rem, 0.99rem + 0.25vw, 1.18rem);
  line-height: 1.72;
  text-rendering: optimizeLegibility;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgb(127 137 157 / 7%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(127 137 157 / 7%) 1px, transparent 1px);
  background-size: 48px 48px;
  content: "";
  mask-image: linear-gradient(to bottom, #000, transparent 88%);
  pointer-events: none;
}

a {
  color: inherit;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 0.18rem solid var(--accent-2);
  outline-offset: 0.2rem;
}

.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: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.7rem 0.95rem;
  transform: translateY(-200%);
  border-radius: 0.7rem;
  background: var(--text);
  color: var(--bg);
  font: 800 0.8rem/1 var(--sans);
  text-decoration: none;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 1rem 0;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 94%, transparent), color-mix(in srgb, var(--bg) 60%, transparent), transparent);
  pointer-events: none;
}

.header-inner,
.wide-shell {
  width: min(100% - 2rem, 72.5rem);
  margin-inline: auto;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.25rem;
  gap: 1rem;
  padding: 0.6rem 0.72rem 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 1.15rem;
  background: color-mix(in srgb, var(--bg) 76%, transparent);
  box-shadow: 0 14px 48px rgb(0 0 0 / 14%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--text);
  font: 850 0.86rem/1.15 var(--sans);
  letter-spacing: -0.02em;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  place-items: center;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, #f4f0ff, #a99cff 54%, #61e4ce);
  box-shadow: 0 8px 26px rgb(155 140 255 / 32%);
  color: #080b13;
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 850;
}

.header-actions,
.site-nav {
  display: flex;
  align-items: center;
}

.header-actions {
  justify-content: flex-end;
  gap: 0.45rem;
}

.site-nav {
  gap: 0.15rem;
  font: 760 0.78rem/1 var(--sans);
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border-radius: 0.7rem;
  color: var(--muted);
  text-decoration: none;
  transition: 160ms ease;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  background: var(--surface-strong);
  color: var(--text);
}

.theme-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.reader-tools {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: var(--surface-soft);
}

.reader-tools button {
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.35rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: 800 0.76rem/1 var(--sans);
}

.reader-tools button:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.theme-picker::before {
  position: absolute;
  left: 0.72rem;
  color: var(--accent-2);
  content: "◐";
  font: 850 0.82rem/1 var(--sans);
  pointer-events: none;
}

.theme-picker select {
  min-height: 2.75rem;
  padding: 0 2rem 0 1.85rem;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  appearance: none;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  font: 760 0.75rem/1 var(--sans);
}

.theme-picker::after {
  position: absolute;
  right: 0.7rem;
  color: var(--muted-2);
  content: "▾";
  font: 700 0.7rem/1 var(--sans);
  pointer-events: none;
}

.home-main {
  padding: clamp(2.75rem, 7vw, 5.75rem) 0 5rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(17rem, 0.65fr);
  align-items: stretch;
  gap: 1.25rem;
}

.hero > div:first-child,
.hero-note,
.synopsis,
#chapters,
.reader-main {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
}

.hero > div:first-child {
  position: relative;
  overflow: hidden;
  padding: clamp(2rem, 5vw, 4rem);
  border-radius: var(--radius);
}

.hero > div:first-child::after {
  position: absolute;
  right: -10rem;
  bottom: -13rem;
  width: 24rem;
  height: 24rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(155 140 255 / 34%), transparent 68%);
  content: "";
  pointer-events: none;
}

.eyebrow,
.chapter-label,
.section-label {
  position: relative;
  z-index: 1;
  margin: 0 0 0.9rem;
  color: var(--accent);
  font: 850 0.72rem/1.3 var(--sans);
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.eyebrow::before {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.65rem;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 0.3rem color-mix(in srgb, var(--accent-2) 14%, transparent), 0 0 1.5rem color-mix(in srgb, var(--accent-2) 55%, transparent);
  content: "";
}

.hero h1,
.chapter-header h1 {
  position: relative;
  z-index: 1;
  margin: 0;
  font-family: var(--serif);
  font-weight: 650;
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.hero h1 {
  max-width: 10ch;
  font-size: clamp(3.4rem, 10vw, 7.25rem);
}

.tagline {
  position: relative;
  z-index: 1;
  max-width: 34rem;
  margin: 1.55rem 0 0;
  color: var(--muted);
  font-size: clamp(1.15rem, 1rem + 0.6vw, 1.55rem);
  line-height: 1.55;
}

.hero-note {
  align-self: stretch;
  padding: 1.6rem;
  border-radius: var(--radius);
}

.hero-note p {
  margin: 0;
}

.hero-note p + p {
  margin-top: 0.8rem;
}

.hero-note .small {
  color: var(--muted);
  font: 0.8rem/1.55 var(--sans);
}

.start-reading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  margin-top: 1.25rem;
  padding: 0 1.05rem;
  border-radius: 0.85rem;
  background: linear-gradient(135deg, #f4f0ff, #aa9fff 55%, #67e6d1);
  box-shadow: 0 12px 32px rgb(155 140 255 / 28%);
  color: #090b14;
  font: 820 0.82rem/1 var(--sans);
  text-decoration: none;
  transition: transform 160ms ease;
}

.start-reading:hover {
  transform: translateY(-2px);
}

.story-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr);
  align-items: start;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.synopsis,
#chapters {
  padding: clamp(1.6rem, 4vw, 2.5rem);
  border-radius: var(--radius);
}

.synopsis p {
  max-width: 35rem;
  margin: 0;
}

.synopsis p + p {
  margin-top: 1em;
}

.contents-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--border);
}

.part-title {
  margin: 2.25rem 0 0.65rem;
  color: var(--muted-2);
  font: 800 0.68rem/1.3 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.part-title:first-of-type {
  margin-top: 0;
}

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

.contents-list a {
  display: grid;
  grid-template-columns: 4.8rem 1fr auto;
  align-items: center;
  min-height: 4.85rem;
  gap: 1rem;
  margin: 0 -0.7rem;
  padding: 0 0.7rem;
  border-radius: 0.75rem;
  color: var(--text);
  text-decoration: none;
  transition: 160ms ease;
}

.contents-list a:hover {
  background: var(--surface-strong);
  transform: translateX(0.15rem);
}

.contents-list a.last-read {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
}

.contents-list a.last-read::after {
  position: absolute;
  top: 0.5rem;
  right: 0.65rem;
  color: var(--accent);
  content: "Continue";
  font: 800 0.58rem/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-number,
.reading-time,
.byline,
.story-footer,
.chapter-nav {
  font-family: var(--sans);
}

.chapter-number {
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-title {
  font-size: clamp(1.05rem, 1rem + 0.25vw, 1.23rem);
  font-weight: 650;
}

.reading-time {
  color: var(--muted-2);
  font-size: 0.68rem;
  white-space: nowrap;
}

.reader-main {
  width: min(100% - 2rem, var(--reader-width));
  margin: clamp(2rem, 5vw, 4.5rem) auto 3rem;
  padding: clamp(2rem, 6vw, 4rem);
  border-radius: var(--radius);
}

.chapter-header {
  position: relative;
  overflow: hidden;
  margin-bottom: clamp(3rem, 7vw, 5rem);
  padding-bottom: 2.2rem;
  border-bottom: 1px solid var(--border);
}

.chapter-header::after {
  position: absolute;
  right: -4rem;
  bottom: -6rem;
  width: 12rem;
  height: 12rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(155 140 255 / 23%), transparent 68%);
  content: "";
}

.chapter-header h1 {
  max-width: 13ch;
  font-size: clamp(2.6rem, 8vw, 5.25rem);
}

.byline {
  position: relative;
  z-index: 1;
  margin: 1.35rem 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.025em;
}

.prose {
  font-size: calc(1em * var(--reader-scale));
  hanging-punctuation: first last;
  hyphens: auto;
}

.prose p {
  margin: 0;
  orphans: 3;
  widows: 3;
}

.prose p + p {
  margin-top: 0.85em;
  text-indent: 1.2em;
}

.prose > p:first-of-type::first-letter {
  float: left;
  margin: 0.08em 0.12em 0 0;
  color: var(--accent);
  font-size: 3.7em;
  font-weight: 650;
  line-height: 0.78;
}

.prose hr {
  width: 4rem;
  margin: 3.25rem auto;
  border: 0;
  border-top: 2px solid var(--accent);
  opacity: 0.7;
}

.system {
  overflow-x: auto;
  margin: 2rem 0;
  padding: 1.25rem 1.3rem;
  border: 1px solid rgb(155 140 255 / 35%);
  border-left: 0.25rem solid var(--accent-2);
  border-radius: 0.8rem;
  background: var(--system-bg);
  box-shadow: 0 14px 36px rgb(0 0 0 / 18%);
  color: var(--system-text);
  font: 0.82rem/1.62 ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.message {
  margin: 1.4rem 0;
  padding: 0.95rem 1.05rem;
  border: 1px solid var(--border);
  border-left: 0.22rem solid var(--accent);
  border-radius: 0.75rem;
  background: var(--surface-soft);
  font-family: var(--sans);
  font-size: 0.9rem;
  line-height: 1.55;
}

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: clamp(3.5rem, 9vw, 6rem);
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.chapter-nav a {
  display: flex;
  min-height: 4.7rem;
  flex-direction: column;
  justify-content: center;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--surface-soft);
  color: var(--text);
  text-decoration: none;
  transition: 160ms ease;
}

.chapter-nav a:hover {
  border-color: var(--border-strong);
  background: var(--surface-strong);
  transform: translateY(-2px);
}

.chapter-nav a:last-child {
  align-items: flex-end;
  text-align: right;
}

.chapter-nav .direction {
  margin-bottom: 0.25rem;
  color: var(--accent);
  font-size: 0.63rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-nav .nav-title {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 650;
}

.story-footer {
  padding: 1.5rem 1rem 3rem;
  color: var(--muted-2);
  font-size: 0.7rem;
  text-align: center;
}

@media (max-width: 48rem) {
  .hero,
  .story-grid {
    grid-template-columns: 1fr;
  }

  .header-inner {
    flex-wrap: wrap;
  }

  .header-actions {
    flex: 1 1 auto;
  }
}

@media (max-width: 38rem) {
  .site-header {
    padding: 0.65rem 0;
  }

  .header-inner,
  .wide-shell,
  .reader-main {
    width: min(100% - 1.25rem, 49rem);
  }

  .header-inner {
    gap: 0.35rem;
    padding: 0.45rem 0.5rem;
    border-radius: 1rem;
  }

  .brand span:last-child {
    display: none;
  }

  .header-actions {
    min-width: 0;
    gap: 0.25rem;
  }

  .site-nav {
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  .site-nav a {
    min-height: 2.65rem;
    padding-inline: 0.52rem;
    font-size: 0.7rem;
  }

  .theme-picker select {
    width: 3rem;
    min-height: 2.65rem;
    padding-inline: 0;
    color: transparent;
  }

  .theme-picker::before {
    left: 1rem;
  }

  .theme-picker::after {
    display: none;
  }

  .reader-tools {
    order: 3;
  }

  .home-main {
    padding-top: 1.5rem;
  }

  .hero > div:first-child,
  .hero-note,
  .synopsis,
  #chapters,
  .reader-main {
    border-radius: 1.1rem;
  }

  .reader-main {
    margin-top: 1.25rem;
    padding: 1.5rem 1.1rem 2rem;
  }

  .contents-list a {
    grid-template-columns: 4.1rem 1fr;
    gap: 0.6rem;
  }

  .reading-time {
    display: none;
  }

  .chapter-nav {
    grid-template-columns: 1fr;
  }

  .chapter-nav a:last-child {
    align-items: flex-start;
    text-align: left;
  }

  .prose p + p {
    text-indent: 0.85em;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

@media print {
  body {
    background: #fff;
    color: #000;
    font-size: 11.5pt;
  }

  body::before,
  .site-header,
  .chapter-nav,
  .story-footer,
  .skip-link {
    display: none;
  }

  .reader-main {
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: #fff;
    box-shadow: none;
  }

  .system {
    border: 1px solid #777;
    background: #fff;
    color: #000;
  }
}
