:root {
  --ink: #251c16;
  --muted: #7d6d61;
  --paper: #f7f0e6;
  --paper-deep: #ede1d0;
  --sidebar: #191512;
  --sidebar-muted: #b6a18e;
  --accent: #b75f2a;
  --accent-soft: #e8c5a8;
  --line: rgba(37, 28, 22, 0.12);
  --shadow: 0 24px 80px rgba(40, 23, 11, 0.16);
  --reader-font-size: 18px;
  --reader-line-height: 1.9;
  --reader-font-weight: 400;
}

body[data-font-size="compact"] {
  --reader-font-size: 16px;
}

body[data-font-size="large"] {
  --reader-font-size: 20px;
}

body[data-line-height="compact"] {
  --reader-line-height: 1.72;
}

body[data-line-height="loose"] {
  --reader-line-height: 2.08;
}

body[data-font-weight="strong"] {
  --reader-font-weight: 500;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper-deep);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 82% 8%, rgba(183, 95, 42, 0.14), transparent 28rem),
    linear-gradient(135deg, #fbf5ec 0%, #ead8c1 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  padding: 28px 22px 0;
  color: #f7efe6;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 34%),
    var(--sidebar);
  box-shadow: 14px 0 60px rgba(25, 21, 18, 0.18);
}

.sidebar-top {
  min-width: 0;
}

.brand {
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand h1 {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 30px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 650;
}

.subtitle {
  margin: 14px 0 0;
  color: var(--sidebar-muted);
  line-height: 1.7;
  font-size: 14px;
}

.search {
  display: grid;
  gap: 10px;
  margin: 22px 0 16px;
  color: var(--sidebar-muted);
  font-size: 14px;
}

.search input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  outline: none;
  padding: 12px 16px;
  color: #fff8ef;
  background: rgba(255, 255, 255, 0.07);
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.search input:focus {
  border-color: rgba(232, 197, 168, 0.72);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 0 4px rgba(183, 95, 42, 0.22);
}

.search-results {
  display: grid;
  gap: 10px;
  max-height: 34vh;
  margin: 0 0 18px;
  overflow: auto;
  padding-right: 3px;
}

.search-result {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 12px;
  color: #f8eee2;
  text-align: left;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.search-result:focus,
.search-result:hover {
  outline: none;
  border-color: rgba(232, 197, 168, 0.56);
  background: rgba(255, 255, 255, 0.1);
}

.search-result strong {
  display: block;
  margin-bottom: 6px;
}

.search-result small {
  color: var(--sidebar-muted);
}

.search-result p {
  margin: 8px 0 0;
  color: #d8c7b7;
  font-size: 13px;
  line-height: 1.55;
}

.toc {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 14px 4px 28px 0;
  scrollbar-color: rgba(232, 197, 168, 0.36) transparent;
}

.toc-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin: 4px 0 0;
  padding: 14px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.toc-label {
  margin: 0;
  color: #f8eee2;
  font-size: 14px;
  font-weight: 700;
}

.toc-count {
  margin: 4px 0 0;
  color: var(--sidebar-muted);
  font-size: 12px;
}

.order-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  padding: 3px;
  background: rgba(255, 255, 255, 0.06);
}

.order-toggle button {
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--sidebar-muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  transition: color 160ms ease, background 160ms ease;
}

.order-toggle button:hover,
.order-toggle button:focus {
  outline: none;
  color: #fff8ef;
}

.order-toggle button.active {
  color: var(--sidebar);
  background: var(--accent-soft);
}

.volume {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 10px;
}

.volume-header {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-radius: 16px;
  padding: 10px 12px;
  color: #f8eee2;
  text-align: left;
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
  transition: background 160ms ease;
}

.volume-header:hover,
.volume-header:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
}

.volume-header strong,
.volume-header small {
  display: block;
}

.volume-header strong {
  font-size: 14px;
}

.volume-header small {
  margin-top: 4px;
  color: var(--sidebar-muted);
  font-size: 11px;
}

.volume-action {
  flex: 0 0 auto;
  border: 1px solid rgba(232, 197, 168, 0.28);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--accent-soft);
  font-size: 12px;
  line-height: 1;
  background: rgba(232, 197, 168, 0.08);
}

.chapter-list {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.chapter-list[hidden] {
  display: none;
}

.chapter-link {
  width: 100%;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0 14px 14px 0;
  padding: 10px 12px;
  color: #f8eee2;
  text-align: left;
  background: transparent;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.chapter-link:hover,
.chapter-link:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(2px);
}

.chapter-link.active {
  border-color: var(--accent);
  background: rgba(183, 95, 42, 0.18);
}

.chapter-link.active::after {
  content: "正在阅读";
  float: right;
  margin-top: 1px;
  color: var(--accent-soft);
  font-size: 11px;
}

.chapter-link span {
  display: block;
  color: var(--sidebar-muted);
  font-size: 12px;
  margin-top: 5px;
}

.reader {
  position: relative;
  width: 100%;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 36px) clamp(14px, 2.2vw, 28px) clamp(36px, 5vw, 64px);
}

.reader-tools {
  position: sticky;
  top: 22px;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}

.settings-button {
  border: 1px solid rgba(37, 28, 22, 0.14);
  border-radius: 999px;
  padding: 9px 14px;
  color: var(--ink);
  background: rgba(247, 240, 230, 0.82);
  box-shadow: 0 12px 38px rgba(40, 23, 11, 0.12);
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(10px);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.settings-button:hover,
.settings-button:focus {
  outline: none;
  border-color: rgba(183, 95, 42, 0.42);
  background: rgba(255, 248, 239, 0.94);
  transform: translateY(-1px);
}

.reader-header {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  align-items: flex-start;
  margin-bottom: 22px;
  animation: liftIn 420ms ease both;
}

.reader-header h2 {
  margin: 0;
  font-size: clamp(28px, 3.8vw, 46px);
  font-weight: 520;
  line-height: 1.18;
  letter-spacing: -0.035em;
}

.chapter-meta {
  flex: 0 0 auto;
  max-width: 220px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
  text-align: right;
}

.chapter-content {
  position: relative;
  border-top: 1px solid var(--line);
  padding-top: 24px;
  font-size: var(--reader-font-size);
  font-weight: var(--reader-font-weight);
  line-height: var(--reader-line-height);
  letter-spacing: 0.02em;
  animation: fadeIn 520ms ease both;
}

.chapter-content p {
  margin: 0 0 1.25em;
}

.chapter-illustration {
  margin: 34px 0;
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.28);
  box-shadow: var(--shadow);
}

.chapter-illustration img,
.illustration-placeholder {
  display: block;
  width: 100%;
  min-height: 260px;
  object-fit: cover;
}

.illustration-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
  background:
    linear-gradient(135deg, rgba(183, 95, 42, 0.16), rgba(37, 28, 22, 0.06)),
    var(--paper);
}

.chapter-illustration figcaption {
  display: grid;
  gap: 4px;
  padding: 14px 18px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.chapter-illustration figcaption strong {
  color: var(--ink);
  font-size: 14px;
}

.hide-illustrations .chapter-illustration {
  display: none;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(25, 21, 18, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  width: min(380px, 92vw);
  height: 100vh;
  padding: 28px;
  color: var(--ink);
  background: rgba(247, 240, 230, 0.96);
  box-shadow: -24px 0 80px rgba(25, 21, 18, 0.2);
  transform: translateX(100%);
  transition: transform 220ms ease;
  backdrop-filter: blur(18px);
}

.settings-open .settings-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.settings-open .settings-drawer {
  transform: translateX(0);
}

.settings-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 22px;
  margin-bottom: 22px;
}

.settings-drawer-header h2 {
  margin: 0;
  font-size: 26px;
}

.settings-close {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
  cursor: pointer;
}

.settings-close:hover,
.settings-close:focus {
  outline: none;
  color: var(--ink);
  border-color: rgba(183, 95, 42, 0.42);
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.32);
  cursor: pointer;
}

.setting-group {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.setting-group-title {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.setting-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.28);
}

.setting-field span {
  color: var(--ink);
  font-size: 14px;
}

.setting-field select {
  min-width: 96px;
  border: 1px solid rgba(37, 28, 22, 0.14);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
}

.setting-row strong,
.setting-row small {
  display: block;
}

.setting-row strong {
  font-size: 15px;
}

.setting-row small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.setting-row input {
  flex: 0 0 auto;
  width: 44px;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes liftIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .reader-header {
    display: block;
  }

  .chapter-meta {
    margin-top: 16px;
    text-align: left;
  }
}
