:root {
  color-scheme: light;
  --page: #f5f4f0;
  --surface: #ffffff;
  --surface-muted: #eceae4;
  --ink: #24221f;
  --ink-soft: #69655f;
  --line: #d5d2ca;
  --accent: #9e3c34;
  --accent-hover: #7f2f29;
  --secondary: #356451;
  --danger: #a13232;
  --focus: #156f99;
  --shadow: 0 12px 32px rgb(36 34 31 / 8%);
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --reading-font: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", STSong, serif;
  --article-size: 18px;
  --article-leading: 1.9;
  --article-width: 58rem;
  --header-height: 64px;
  font-family: var(--ui-font);
  font-synthesis: none;
  letter-spacing: 0;
  background: var(--page);
  color: var(--ink);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #1c1b19;
  --surface: #262421;
  --surface-muted: #312e2a;
  --ink: #ece7de;
  --ink-soft: #b3ada3;
  --line: #48443e;
  --accent: #d27a70;
  --accent-hover: #e69389;
  --secondary: #77ab91;
  --danger: #e18484;
  --focus: #6eb5d5;
  --shadow: 0 14px 36px rgb(0 0 0 / 22%);
}

:root[data-theme="eye"] {
  color-scheme: light;
  --page: #edf0e7;
  --surface: #f8faf4;
  --surface-muted: #e2e8dc;
  --ink: #293129;
  --ink-soft: #626b61;
  --line: #cbd3c6;
  --accent: #98453d;
  --accent-hover: #79362f;
  --secondary: #38624e;
  --danger: #9c3434;
  --focus: #23698b;
}

:root[data-font="small"] { --article-size: 16px; }
:root[data-font="medium"] { --article-size: 18px; }
:root[data-font="large"] { --article-size: 21px; }
:root[data-leading="compact"] { --article-leading: 1.68; }
:root[data-leading="normal"] { --article-leading: 1.9; }
:root[data-leading="relaxed"] { --article-leading: 2.14; }
:root[data-width="narrow"] { --article-width: 44rem; }
:root[data-width="normal"] { --article-width: 58rem; }
:root[data-width="wide"] { --article-width: 68rem; }

* { box-sizing: border-box; }

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--ui-font);
  letter-spacing: 0;
}

body.panel-open { overflow: hidden; }
button, input { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
button { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

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

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  transform: translateY(-150%);
  border-radius: 4px;
  background: var(--ink);
  color: var(--page);
}
.skip-link:focus { transform: translateY(0); }

.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
}
.icon-button:hover { border-color: var(--line); background: var(--surface-muted); color: var(--ink); }

.command-button, .text-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
.command-button {
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}
.command-primary { background: var(--accent); color: #fff; }
.command-primary:hover { background: var(--accent-hover); }
.command-secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.command-secondary:hover { border-color: var(--ink-soft); background: var(--surface-muted); }
.command-danger { background: var(--danger); color: #fff; }
.command-button:disabled { cursor: wait; opacity: 0.68; }
.text-link { padding: 8px 6px; color: var(--ink-soft); font-weight: 600; }
.text-link:hover { color: var(--accent); }

.brand-lockup { display: inline-flex; align-items: center; gap: 10px; }
.brand-link { text-decoration: none; }
.brand-mark { display: block; width: 4px; height: 28px; border-radius: 1px; background: var(--accent); }
.brand-name { font: 700 22px/1.2 var(--reading-font); }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 13px; font-weight: 700; }

.site-header {
  position: sticky;
  z-index: 30;
  top: 0;
  display: flex;
  min-height: var(--header-height);
  padding: 8px clamp(16px, 4vw, 48px);
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--page) 94%, transparent);
  backdrop-filter: blur(12px);
}
.header-actions, .reader-header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions form, .reader-header-actions form, .site-header form { margin: 0; }
.page-container { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.shelf-container, .book-container { padding: 64px 0 96px; }
.page-heading h1, .book-identity h1 {
  max-width: 900px;
  margin: 0;
  font: 700 52px/1.2 var(--reading-font);
}

.book-grid { display: grid; margin-top: 36px; gap: 16px; }
.book-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.book-number {
  align-self: stretch;
  display: grid;
  min-height: 104px;
  place-items: center;
  border-right: 1px solid var(--line);
  color: var(--accent);
  font: 700 20px/1 var(--reading-font);
  writing-mode: vertical-rl;
}
.book-card h2 { margin: 0; font: 700 25px/1.35 var(--reading-font); }
.book-card h2 a { text-decoration: none; }
.book-card h2 a:hover { color: var(--accent); }
.book-summary { max-width: 68ch; margin: 12px 0 0; color: var(--ink-soft); }
.book-stats { display: flex; flex-wrap: wrap; gap: 10px 24px; margin: 18px 0 0; }
.book-stats div { display: flex; gap: 7px; align-items: baseline; }
.book-stats dt { color: var(--ink-soft); font-size: 13px; }
.book-stats dd { margin: 0; font-weight: 700; }
.book-stats .recent { min-width: 0; max-width: 100%; }
.book-stats .recent dd { min-width: 0; max-width: 28ch; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-actions { display: flex; align-items: center; gap: 12px; }
.empty-state { padding: 96px 24px; text-align: center; }
.empty-icon { width: 48px; height: 48px; color: var(--ink-soft); }
.empty-state h2 { margin: 20px 0 8px; font-family: var(--reading-font); }
.empty-state p { margin: 0; color: var(--ink-soft); }

.breadcrumb { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 48px; color: var(--ink-soft); font-size: 14px; }
.breadcrumb a:hover { color: var(--accent); }
.book-identity { padding-bottom: 48px; border-bottom: 1px solid var(--line); }
.book-lead { max-width: 70ch; margin: 20px 0 0; color: var(--ink-soft); font-size: 18px; line-height: 1.75; }
.directory-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.content-notice { margin: 24px 0 0; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--surface-muted); }
.volume-list { margin-top: 56px; }
.volume-section + .volume-section { margin-top: 56px; }
.volume-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; padding-bottom: 12px; border-bottom: 2px solid var(--ink); }
.volume-heading h2 { margin: 0; font: 700 24px/1.35 var(--reading-font); }
.volume-heading span { color: var(--ink-soft); font-size: 14px; }
.chapter-list { margin: 0; padding: 0; list-style: none; }
.chapter-row { border-bottom: 1px solid var(--line); }
.chapter-row > a, .chapter-unavailable {
  display: grid;
  min-height: 58px;
  grid-template-columns: 58px minmax(0, 1fr) auto 24px;
  gap: 12px;
  align-items: center;
  padding: 8px 4px;
  text-decoration: none;
}
.chapter-row > a:hover { color: var(--accent); }
.chapter-number { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.chapter-title { min-width: 0; overflow-wrap: anywhere; }
.chapter-status { color: var(--secondary); font-size: 13px; font-weight: 700; }
.chapter-issue { color: var(--danger); font-size: 13px; }
.chapter-error { background: color-mix(in srgb, var(--danger) 5%, transparent); }

.confirm-dialog {
  width: min(460px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgb(0 0 0 / 25%);
}
.confirm-dialog::backdrop { background: rgb(0 0 0 / 50%); }
.confirm-dialog form { padding: 28px; }
.confirm-dialog h2 { margin: 0; font: 700 22px/1.35 var(--reading-font); }
.confirm-dialog p { color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.login-page, .error-page { display: grid; place-items: center; padding: 24px; }
.login-shell { width: min(420px, 100%); }
.login-panel { padding: 34px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow); }
.login-panel h1 { margin: 40px 0 28px; font: 700 30px/1.25 var(--reading-font); }
.field-group label { display: block; margin-bottom: 8px; font-weight: 700; }
.password-field { position: relative; }
.password-field input { width: 100%; min-height: 48px; padding: 10px 54px 10px 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--page); color: var(--ink); }
.password-field input:focus { border-color: var(--focus); }
.password-toggle { position: absolute; top: 2px; right: 2px; }
.field-error { min-height: 24px; margin: 7px 0 12px; color: var(--danger); font-size: 14px; }
.login-form .command-button { width: 100%; }
.status-shell { width: min(560px, 100%); text-align: center; }
.status-shell .brand-lockup { margin-bottom: 48px; }
.status-code { margin: 0; color: var(--accent); font-size: 14px; font-weight: 800; }
.status-shell h1 { margin: 8px 0 12px; font: 700 44px/1.2 var(--reading-font); }
.status-shell > p:last-of-type { margin: 0 0 28px; color: var(--ink-soft); }

.reader-page { padding-top: var(--header-height); }
.reader-header {
  position: fixed;
  z-index: 60;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  height: var(--header-height);
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 8px 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--page) 94%, transparent);
  backdrop-filter: blur(12px);
  transition: transform 200ms ease;
}
.reader-header.is-hidden { transform: translateY(-100%); }
.reader-header.is-hidden:focus-within { transform: translateY(0); }
.reader-location { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); font-size: 14px; }
.reader-location a { text-decoration: none; }
.reader-location a:hover { color: var(--accent); }
.reading-progress-track { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; }
.reading-progress-track span { display: block; width: 0; height: 100%; background: var(--accent); }
.reader-layout { display: grid; min-height: calc(100dvh - var(--header-height)); grid-template-columns: 236px minmax(0, 1fr) 220px; }
.reader-side { min-width: 0; padding: 28px 18px; background: var(--page); }
.reader-contents { border-right: 1px solid var(--line); }
.reader-settings { border-left: 1px solid var(--line); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel-heading h2 { margin: 0; font: 700 18px/1.35 var(--reading-font); overflow-wrap: anywhere; }
.panel-close { display: none; }

.reader-chapter-nav { margin-top: 28px; }
.reader-chapter-nav section + section { margin-top: 28px; }
.reader-chapter-nav h3 { margin: 0 0 8px; color: var(--ink-soft); font-size: 13px; }
.reader-chapter-nav ol { margin: 0; padding: 0; list-style: none; }
.reader-chapter-nav li { margin: 2px 0; }
.reader-chapter-nav a, .disabled-chapter { display: block; min-height: 40px; padding: 9px 8px; border-radius: 4px; color: var(--ink-soft); font-size: 14px; text-decoration: none; overflow-wrap: anywhere; }
.reader-chapter-nav a:hover { background: var(--surface-muted); color: var(--ink); }
.reader-chapter-nav a > span { margin-right: 7px; font-variant-numeric: tabular-nums; }
.reader-chapter-nav .is-active a { border-left: 3px solid var(--accent); background: var(--surface-muted); color: var(--ink); font-weight: 700; }
.reader-chapter-nav .chapter-status { display: block; margin: 2px 0 0 35px; }
.reader-chapter-nav .is-error { color: var(--danger); }

.reader-main { min-width: 0; }
.novel-article { width: min(var(--article-width), calc(100% - 56px)); margin: 0 auto; padding: 72px 0 96px; }
.chapter-context { margin: 0 0 32px; color: var(--accent); font-size: 13px; font-weight: 700; text-align: center; }
.prose { color: var(--ink); font: var(--article-size)/var(--article-leading) var(--reading-font); overflow-wrap: anywhere; }
.prose h1 { margin: 0 0 2.4em; font-size: 1.85em; line-height: 1.35; text-align: center; }
.prose h2, .prose h3 { margin: 2em 0 1em; line-height: 1.4; }
.prose p { margin: 0 0 1.2em; }
.prose blockquote { margin: 1.8em 0; padding: 0.2em 0 0.2em 1.25em; border-left: 3px solid var(--secondary); color: var(--ink-soft); }
.prose a { color: var(--secondary); }
.prose pre { max-width: 100%; padding: 16px; overflow: auto; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-muted); font: 0.85em/1.6 ui-monospace, monospace; }
.prose table { width: 100%; border-collapse: collapse; font: 0.88em/1.5 var(--ui-font); }
.prose th, .prose td { padding: 8px; border: 1px solid var(--line); text-align: left; }

.chapter-footer-nav {
  display: grid;
  width: min(var(--article-width), calc(100% - 56px));
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  margin: 0 auto 96px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.chapter-nav-link, .directory-link { display: flex; min-width: 0; min-height: 68px; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 4px; text-decoration: none; }
.chapter-nav-link:hover, .directory-link:hover { background: var(--surface-muted); }
.chapter-nav-link.next { justify-content: flex-end; text-align: right; }
.chapter-nav-link span { min-width: 0; }
.chapter-nav-link small { display: block; color: var(--ink-soft); }
.chapter-nav-link strong { display: block; overflow: hidden; font-family: var(--reading-font); text-overflow: ellipsis; white-space: nowrap; }
.chapter-nav-link.is-disabled { color: var(--ink-soft); opacity: 0.62; }
.directory-link { flex-direction: column; justify-content: center; color: var(--ink-soft); font-size: 13px; }

.setting-group { margin: 0 0 24px; padding: 0; border: 0; }
.setting-group:first-of-type { margin-top: 32px; }
.setting-group legend { margin-bottom: 8px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.segmented-control { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.segmented-control button { min-height: 40px; padding: 6px; border: 0; border-right: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer; }
.segmented-control button:last-child { border-right: 0; }
.segmented-control button:hover { color: var(--ink); }
.segmented-control button[aria-pressed="true"] { background: var(--secondary); color: #fff; }
.progress-readout { display: flex; justify-content: space-between; gap: 12px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 14px; }
.progress-readout strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.mobile-panel-button, .panel-scrim { display: none; }

@media (max-width: 1100px) {
  .reader-layout { grid-template-columns: minmax(0, 1fr); }
  .reader-side {
    position: fixed;
    z-index: 90;
    right: 0;
    bottom: 0;
    left: 0;
    max-height: min(82dvh, 760px);
    padding: 24px max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    overflow: auto;
    transform: translateY(105%);
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
    background: var(--surface);
    box-shadow: 0 -16px 48px rgb(0 0 0 / 24%);
    transition: transform 220ms ease;
  }
  .reader-side.is-open { transform: translateY(0); }
  .panel-close, .mobile-panel-button { display: inline-grid; }
  .panel-scrim { position: fixed; z-index: 80; inset: 0; background: rgb(0 0 0 / 48%); }
  .panel-scrim.is-open { display: block; }
  .reader-settings .setting-group, .reader-settings .panel-heading, .reader-settings .progress-readout { max-width: 560px; margin-right: auto; margin-left: auto; }
}

@media (max-width: 760px) {
  :root { --header-height: 58px; }
  .site-header { padding-right: 12px; padding-left: 16px; }
  .page-container { width: min(100% - 24px, 1180px); }
  .shelf-container, .book-container { padding: 40px 0 72px; }
  .page-heading h1, .book-identity h1 { font-size: 34px; }
  .status-shell h1 { font-size: 34px; }
  .book-card { grid-template-columns: 44px minmax(0, 1fr); gap: 16px; padding: 20px 16px; }
  .book-number { min-height: 96px; font-size: 16px; }
  .book-card h2 { font-size: 21px; }
  .book-actions { grid-column: 1 / -1; justify-content: flex-end; padding-top: 12px; border-top: 1px solid var(--line); }
  .book-stats .recent { flex-basis: 100%; }
  .book-stats .recent dd { max-width: 22ch; }
  .breadcrumb { margin-bottom: 32px; }
  .book-identity { padding-bottom: 36px; }
  .volume-list { margin-top: 40px; }
  .chapter-row > a, .chapter-unavailable { min-height: 56px; grid-template-columns: 44px minmax(0, 1fr) auto; }
  .chapter-row .icon { display: none; }
  .chapter-status { grid-column: 2; }
  .chapter-issue { grid-column: 2 / -1; }
  .reader-header { gap: 10px; padding: 6px 8px 6px 12px; }
  .reader-header .brand-name { display: none; }
  .reader-location { font-size: 13px; }
  .reader-header-actions { gap: 0; }
  .reader-header-actions form { display: none; }
  .novel-article { width: min(var(--article-width), calc(100% - 32px)); padding: 48px 0 72px; }
  .prose { font-size: max(16px, var(--article-size)); }
  .prose h1 { margin-bottom: 2em; font-size: 1.55em; }
  .chapter-footer-nav { width: calc(100% - 24px); grid-template-columns: 1fr 64px 1fr; gap: 4px; margin-bottom: 72px; }
  .chapter-nav-link { padding: 8px; }
  .chapter-nav-link strong { max-width: 16ch; font-size: 14px; }
  .directory-link { padding-right: 6px; padding-left: 6px; }
  .login-panel { padding: 28px 22px; }
}

@media (max-width: 430px) {
  .book-actions { display: grid; grid-template-columns: auto 1fr; }
  .book-actions .command-button { width: 100%; }
  .chapter-nav-link strong { max-width: 10ch; }
  .chapter-nav-link .icon { display: none; }
}

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