/* Novel Reader — quiet, component-led reading UI */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans SC", "Source Han Sans SC", "Source Han Sans CN", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 180ms ease, color 180ms ease;
}
button, input { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; }
button:disabled { cursor: not-allowed; }
button:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
input:focus-visible { outline: 0; }
.hidden, [hidden] { display: none !important; }
.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;
}

/* Home */
.home {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(64px, 9vh, 104px) 32px 64px;
}
.home-brand, .url-panel, .home-error, .recent { width: min(1120px, 100%); }
.home-brand { margin-bottom: 30px; }
.home-brand h1 {
  margin: 0;
  font-size: clamp(32px, 3vw, 38px);
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.035em;
}
.url-panel {
  display: grid;
  gap: 14px;
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}
.url-row { display: flex; gap: 10px; }
.url-row input {
  flex: 1;
  min-width: 0;
  height: 60px;
  padding: 0 19px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--field-bg);
  outline: 0;
  font-size: 17px;
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}
.url-row input:hover { border-color: var(--border-hover); }
.url-row input:focus {
  border-color: var(--accent);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.url-row input::placeholder { color: var(--text-muted); }
.btn-primary, .btn-secondary {
  min-height: 44px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  transition: transform 150ms ease, background-color 150ms ease, opacity 150ms ease, box-shadow 150ms ease;
}
.btn-primary {
  min-width: 116px;
  height: 60px;
  padding: 0 26px;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 5px 14px var(--accent-shadow);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 9px 22px var(--accent-shadow);
  transform: translateY(-2px);
}
.btn-primary:active, .btn-secondary:active, .recent-item:active, .icon-btn:active,
.chapter-nav button:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.btn-primary:disabled { opacity: 0.5; }
.btn-secondary { justify-self: end; padding: 0 14px; background: transparent; color: var(--accent); }
.btn-secondary:hover { background: var(--accent-soft); transform: translateY(-1px); }
.home-error {
  margin-top: 14px;
  padding: 13px 15px;
  border: 1px solid var(--danger-border);
  border-radius: 14px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
  line-height: 1.55;
}
.recent { margin-top: 42px; }
.recent h2 {
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 1.4;
  font-weight: 620;
  letter-spacing: -0.015em;
}
.recent-list { display: grid; gap: 8px; }
.recent-item {
  width: 100%;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elevated);
  text-align: left;
  transition: transform 120ms ease, border-color 140ms ease, background-color 140ms ease;
}
.recent-item:hover {
  border-color: var(--border-hover);
  background: var(--surface-hover);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.recent-item:active { transform: scale(0.99); }
.recent-meta { min-width: 0; }
.recent-book {
  margin-bottom: 4px;
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-chapter {
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-progress {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.recent-empty {
  padding: 26px 18px;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}

/* Reader chrome */
.reader { min-height: 100vh; display: flex; flex-direction: column; }
.reader-header, .reader-footer {
  position: sticky;
  z-index: 20;
  background: var(--bg-chrome);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  transition: opacity 220ms ease, transform 220ms ease;
}
.reader-header { top: 0; border-bottom: 1px solid var(--border); }
.reader-footer { bottom: 0; border-top: 1px solid var(--border); }
.reader.immersive .reader-header { opacity: 0; transform: translateY(-8px); pointer-events: none; }
.reader.immersive .reader-footer { opacity: 0; transform: translateY(8px); pointer-events: none; }
.header-inner, .footer-inner {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 9px;
  text-align: center;
}
.header-book, .header-chapter { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-book { max-width: 38%; font-size: 15px; font-weight: 620; }
.header-chapter { max-width: 48%; color: var(--text-secondary); font-size: 14px; }
.header-chapter:not(:empty)::before { content: "·"; margin-right: 9px; color: var(--text-muted); }
.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border-radius: 13px;
  background: transparent;
  color: var(--text-secondary);
  transition: transform 120ms ease, background-color 140ms ease, color 140ms ease;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:hover svg { transform: scale(1.08); }
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 150ms ease;
}
.footer-inner { min-height: 44px; justify-content: center; color: var(--text-secondary); font-size: 13px; }
#footer-chapter { display: none; }
.footer-progress { font-weight: 600; font-variant-numeric: tabular-nums; }
.loading-bar {
  position: fixed;
  inset: 0 0 auto;
  height: 3px;
  z-index: 100;
  overflow: hidden;
  opacity: 0;
  transition: opacity 160ms ease;
}
.loading-bar.active { opacity: 1; }
.loading-bar::after {
  content: "";
  display: block;
  width: 36%;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  animation: loading-slide 900ms ease-in-out infinite;
}
@keyframes loading-slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* Reading content */
.reader-main { flex: 1; padding: 56px 24px 88px; }
.article {
  width: min(var(--content-width, 760px), 100%);
  margin: 0 auto;
  color: var(--text);
  font-size: var(--font-size, 19px);
  font-weight: var(--font-weight, 400);
  line-height: var(--line-height, 1.9);
  transition: width 180ms ease;
}
.article-title {
  margin: 0 0 38px;
  font-size: calc(var(--font-size, 19px) * 1.48);
  font-weight: 650;
  line-height: 1.35;
  text-align: center;
  letter-spacing: -0.025em;
}
.article p {
  margin: 0 0 var(--paragraph-spacing, 0.85em);
  text-align: justify;
  text-indent: var(--indent-size, 2em);
  text-justify: inter-ideograph;
  word-break: break-word;
}
.article p.no-indent { text-indent: 0; }
.chapter-block { position: relative; padding-bottom: 8px; }
.chapter-block + .chapter-block { margin-top: 2.4em; padding-top: 1.6em; border-top: 1px solid var(--border); }
.chapter-block-title {
  margin: 0 0 1.5em;
  color: var(--text);
  font-size: calc(var(--font-size, 19px) * 1.36);
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
  letter-spacing: -0.02em;
}
.chapter-block-body p:last-child { margin-bottom: 0; }
.chapter-nav {
  width: min(var(--content-width, 760px), 100%);
  margin: 60px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.chapter-nav button {
  min-width: 124px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  font-weight: 560;
  transition: transform 120ms ease, border-color 140ms ease, background-color 140ms ease;
}
.chapter-nav button:hover:not(:disabled) {
  border-color: var(--border-hover);
  background: var(--surface-hover);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}
.chapter-nav button:disabled { opacity: 0.38; }
.reader-status {
  width: min(var(--content-width, 760px), 100%);
  margin: 28px auto 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
}
.reader-status.error { color: var(--danger); }

/* Drawers */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 15, 18, 0.36);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 50;
  width: min(400px, 92vw);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.catalog { left: 0; border-radius: 0 22px 22px 0; transform: translateX(-104%); }
.drawer.settings { right: 0; border-radius: 22px 0 0 22px; transform: translateX(104%); }
.drawer.open { transform: translate(0); }
.drawer-header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 10px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -0.02em; }
.drawer-body { flex: 1; overflow: auto; padding: 18px 18px 28px; }
.drawer-search {
  width: 100%;
  height: 48px;
  margin-bottom: 12px;
  padding: 0 15px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--field-bg);
  outline: 0;
  font-size: 15px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.drawer-search:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.catalog-list { display: grid; gap: 10px; }
.catalog-section {
  overflow: clip;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
}
.catalog-section summary {
  min-height: 48px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 620;
  list-style: none;
  transition: background-color 140ms ease;
}
.catalog-section summary::-webkit-details-marker { display: none; }
.catalog-section summary::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 160ms ease;
}
.catalog-section summary > span:first-child { margin-right: auto; }
.catalog-section summary:hover { background: var(--surface-hover); }
.catalog-section[open] summary { border-bottom: 1px solid var(--border); }
.catalog-section[open] summary::before { transform: rotate(45deg) translate(-1px, -1px); }
.catalog-section-count { color: var(--text-secondary); font-size: 13px; font-weight: 500; }
.catalog-section-list { padding: 6px; }
.catalog-section[open] .catalog-section-list { animation: catalog-reveal 180ms ease-out; }
@keyframes catalog-reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.catalog-item {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}
.catalog-item:hover { background: var(--surface-hover); color: var(--text); transform: translateX(3px); }
.catalog-item:active { transform: translateX(1px) scale(0.99); }
.catalog-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 620; }
.catalog-note { padding: 24px 8px; color: var(--text-secondary); font-size: 14px; line-height: 1.6; text-align: center; }

/* Settings */
.setting-group { margin-bottom: 24px; }
.setting-label {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--text);
  font-size: 15px;
  font-weight: 560;
}
.setting-value { color: var(--text-secondary); font-size: 14px; font-weight: 500; font-variant-numeric: tabular-nums; }
.setting-divider { height: 1px; margin: 4px 0 24px; background: var(--border); }
input[type="range"] {
  width: 100%;
  height: 32px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type="range"]:focus { outline: 0; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) 0, var(--accent) var(--fill, 50%), var(--border-strong) var(--fill, 50%), var(--border-strong) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -7.5px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--bg-elevated);
  box-shadow: 0 2px 7px rgba(15, 15, 18, 0.2);
  transition: transform 100ms ease;
}
input[type="range"]:hover::-webkit-slider-thumb, input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 999px; background: var(--border-strong); }
input[type="range"]::-moz-range-progress { height: 5px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 2px solid var(--accent); border-radius: 50%; background: var(--bg-elevated); }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] { flex: 1; }
.range-end { flex: 0 0 auto; color: var(--text-secondary); font-size: 13px; }
.setting-hint { margin: 8px 0 0; color: var(--text-secondary); font-size: 13px; line-height: 1.5; }
.auto-toggle {
  width: 100%;
  min-height: 46px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg-elevated);
  font-size: 14px;
  font-weight: 620;
  transition: transform 120ms ease, opacity 140ms ease, background-color 140ms ease;
}
.auto-toggle:hover { opacity: 0.92; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.auto-toggle:active { transform: scale(0.99); }
.auto-toggle.running { background: var(--accent); color: var(--accent-contrast); }
.auto-toggle svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.theme-option {
  min-height: 52px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  font-size: 14px;
  font-weight: 560;
  transition: transform 120ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.theme-option:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.theme-option.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.theme-option[data-theme-value="light"] { background: #fafafa; color: #202024; }
.theme-option[data-theme-value="sepia"] { background: #f5edda; color: #3e352a; }
.theme-option[data-theme-value="green"] { background: #eaf1e8; color: #303b32; }
.theme-option[data-theme-value="dark"] { background: #1c1c20; color: #ececef; }

/* Auto-read floating control */
.auto-bar {
  position: fixed;
  left: 50%;
  bottom: 62px;
  z-index: 30;
  max-width: calc(100vw - 24px);
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-chrome);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px) saturate(130%);
  -webkit-backdrop-filter: blur(14px) saturate(130%);
  transform: translateX(-50%);
  transition: opacity 180ms ease, transform 180ms ease;
}
.reader.immersive .auto-bar { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(8px); }
.auto-bar-play, .auto-bar-close {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border-radius: 11px;
}
.auto-bar-play { background: var(--accent); color: var(--accent-contrast); }
.auto-bar-play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.auto-bar-close { background: transparent; color: var(--text-secondary); }
.auto-bar-close:hover { background: var(--surface-hover); color: var(--text); }
.auto-bar-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.auto-bar-tag, .auto-bar-speed-val { color: var(--text-secondary); font-size: 13px; }
.auto-bar-speed-val { min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.auto-bar-range { width: 150px; flex: 1 1 auto; }

@media (max-width: 768px) and (hover: none), (max-width: 520px) {
  .home { padding: 48px 18px 40px; }
  .home-brand { margin-bottom: 22px; }
  .url-panel { padding: 16px; border-radius: 18px; }
  .url-row { flex-direction: column; }
  .url-row input { flex: none; width: 100%; height: 54px; font-size: 16px; }
  .btn-primary { width: 100%; height: 54px; }
  .recent { margin-top: 36px; }
  .header-inner { padding: 8px 10px; }
  .header-book { display: none; }
  .header-chapter { max-width: 100%; }
  .header-chapter:not(:empty)::before { content: none; }
  .reader-main { padding: 34px 18px 76px; }
  .article-title { margin-bottom: 30px; font-size: 24px !important; }
  .chapter-nav { flex-direction: column; }
  .chapter-nav button { width: 100%; }
  .drawer.catalog { width: min(380px, 94vw); }
  .drawer.settings {
    top: auto;
    left: 0;
    right: 0;
    width: 100%;
    height: min(78vh, 640px);
    border-radius: 22px 22px 0 0;
    transform: translateY(104%);
  }
  .drawer.settings.open { transform: translateY(0); }
  .auto-bar { bottom: 58px; gap: 6px; }
  .auto-bar-range { width: 102px; }
  .auto-bar-tag { display: none; }
}

@media (max-width: 420px) {
  .home-brand h1 { font-size: 25px; }
  .icon-btn { width: 42px; height: 42px; }
}

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

@media (prefers-contrast: more) {
  .url-panel, .recent-item, .drawer, .chapter-nav button { border-color: var(--text-secondary); }
}
