:root {
  --bg: #f6f0e8;
  --paper: #fffaf3;
  --ink: #2b2622;
  --muted: #786f66;
  --line: rgba(43, 38, 34, 0.14);
  --accent: #9b5746;
  --accent-strong: #783d32;
  --panel: rgba(255, 250, 243, 0.92);
  --shadow: 0 18px 46px rgba(52, 42, 34, 0.16);
  --reader-font-size: 18px;
  --reader-font: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body.dark {
  --bg: #191815;
  --paper: #22201c;
  --ink: #eee4d8;
  --muted: #b8aa9d;
  --line: rgba(238, 228, 216, 0.16);
  --accent: #d08b74;
  --accent-strong: #f0b19a;
  --panel: rgba(34, 32, 28, 0.94);
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.32);
}

button {
  color: inherit;
  font: inherit;
}

.hero {
  position: relative;
  min-height: 86svh;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  isolation: isolate;
}

.hero-cover,
.hero-shade {
  position: absolute;
  inset: 0;
}

.hero-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: -2;
}

.hero-shade {
  background:
    linear-gradient(180deg, rgba(20, 18, 16, 0.14) 0%, rgba(20, 18, 16, 0.16) 38%, rgba(20, 18, 16, 0.78) 100%),
    linear-gradient(90deg, rgba(20, 18, 16, 0.56), rgba(20, 18, 16, 0.08));
  z-index: -1;
}

.hero-content {
  width: min(100%, 960px);
  padding: 0 clamp(22px, 6vw, 72px) max(42px, env(safe-area-inset-bottom));
  color: #fff7ed;
}

.kicker {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 0;
  color: rgba(255, 247, 237, 0.76);
}

h1 {
  margin: 0;
  font-size: clamp(44px, 9vw, 82px);
  line-height: 0.98;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 520px;
  margin: 18px 0 24px;
  font-size: 17px;
  line-height: 1.75;
  color: rgba(255, 247, 237, 0.86);
}

.hero-actions,
.font-controls,
.chapter-nav {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.tool-button,
.nav-button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button,
.ghost-button {
  padding: 0 18px;
}

.primary-button {
  background: #fff7ed;
  color: #2b2622;
  font-weight: 700;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.32);
  color: #fff7ed;
  backdrop-filter: blur(12px);
}

.layout {
  display: grid;
  grid-template-columns: minmax(230px, 290px) minmax(0, 720px);
  gap: 34px;
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  padding: 30px 0 64px;
  align-items: start;
}

.chapter-panel {
  position: sticky;
  top: 18px;
  max-height: calc(100svh - 36px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.close-panel {
  display: none;
  width: 38px;
  background: transparent;
  border-color: var(--line);
}

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

.chapter-link {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  text-align: left;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1.45;
}

.chapter-link.active {
  color: var(--ink);
  background: rgba(155, 87, 70, 0.13);
  font-weight: 700;
}

.reader {
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 5vw, 44px);
}

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.tool-button,
.nav-button {
  padding: 0 12px;
  background: transparent;
  border-color: var(--line);
}

.tool-button:active,
.nav-button:active,
.chapter-link:active {
  transform: translateY(1px);
}

.reader-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.chapter-content {
  padding-top: 22px;
  font-family: var(--reader-font);
  font-size: var(--reader-font-size);
  line-height: 1.95;
  word-break: break-word;
}

.chapter-content h1 {
  color: var(--ink);
  font-size: clamp(30px, 8vw, 46px);
  line-height: 1.2;
  margin: 0 0 24px;
}

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

.chapter-content hr {
  width: 42%;
  margin: 34px auto;
  border: 0;
  border-top: 1px solid var(--line);
}

.chapter-nav {
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 20px;
  margin-top: 26px;
}

.nav-button {
  min-width: 112px;
}

.nav-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

body.sans-reader {
  --reader-font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (max-width: 760px) {
  .hero {
    min-height: 82svh;
  }

  .layout {
    display: block;
    width: 100%;
    padding: 0 0 42px;
  }

  .reader {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .reader-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    margin: -18px -18px 18px;
    padding: 10px 18px;
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
  }

  .chapter-panel {
    position: fixed;
    inset: auto 12px 12px 12px;
    z-index: 20;
    max-height: min(68svh, 560px);
    transform: translateY(calc(100% + 24px));
    transition: transform 180ms ease;
  }

  .chapter-panel.open {
    transform: translateY(0);
  }

  .close-panel {
    display: inline-grid;
    place-items: center;
  }
}

@media (min-width: 761px) {
  #chapterToggle {
    display: none;
  }
}
