:root {
  color-scheme: light;
  --paper: #f3ecdc;
  --paper-deep: #e8ddc5;
  --ink: #2b2925;
  --muted: #756e61;
  --line: rgba(43, 41, 37, 0.13);
  --accent: #9b3f2f;
  --sidebar-width: 300px;
  --font-size: 19px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
}

button {
  color: inherit;
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar-width);
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--paper-deep);
}

.book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px 26px 18px;
}

.book-header h1 {
  margin: 3px 0 0;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 0.15em;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

.catalog-meta {
  display: flex;
  justify-content: space-between;
  padding: 0 26px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 11px;
}

.chapter-list {
  padding: 12px;
}

.chapter-link {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.chapter-link:hover,
.chapter-link.active {
  background: rgba(255, 255, 255, 0.45);
}

.chapter-link.active {
  color: var(--accent);
}

.chapter-number {
  flex: 0 0 32px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.chapter-name {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-badge {
  margin-left: auto;
  padding: 2px 5px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 9px;
}

.reader {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  align-items: center;
  height: 58px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(14px);
}

.toolbar-title {
  overflow: hidden;
  font-size: 13px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  justify-content: flex-end;
}

.icon-button,
.text-button {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.icon-button:hover,
.text-button:hover {
  background: var(--line);
}

.text-button {
  color: var(--muted);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 12px;
}

#openSidebar {
  visibility: hidden;
}

.progress-track {
  position: sticky;
  top: 58px;
  z-index: 11;
  height: 2px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 100ms linear;
}

.chapter {
  width: min(760px, calc(100% - 48px));
  min-height: calc(100vh - 160px);
  margin: 0 auto;
  padding: 74px 0 48px;
  font-size: var(--font-size);
  line-height: 2;
}

.chapter h2 {
  margin: 0 0 54px;
  font-size: 1.65em;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}

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

.chapter-status {
  display: block;
  width: fit-content;
  margin: -38px auto 46px;
  padding: 3px 9px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  font-size: 11px;
}

.welcome {
  padding-top: 14vh;
  text-align: center;
}

.welcome h2 {
  margin: 12px 0 32px;
  font-size: 52px;
  letter-spacing: 0.16em;
}

.welcome p {
  color: var(--muted);
  text-align: center;
}

.loading {
  font-size: 13px;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  width: min(760px, calc(100% - 48px));
  margin: 0 auto;
  padding: 24px 0 64px;
  border-top: 1px solid var(--line);
}

.chapter-nav button {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.chapter-nav button:disabled {
  cursor: default;
  opacity: 0.3;
}

.mobile-only,
.scrim {
  display: none;
}

body.dark {
  color-scheme: dark;
  --paper: #1b1c1b;
  --paper-deep: #151615;
  --ink: #d8d2c5;
  --muted: #928d83;
  --line: rgba(255, 255, 255, 0.1);
  --accent: #d27865;
}

body.dark .chapter-link:hover,
body.dark .chapter-link.active {
  background: rgba(255, 255, 255, 0.06);
}

@media (max-width: 820px) {
  .sidebar {
    width: min(86vw, 340px);
    transform: translateX(-102%);
    transition: transform 220ms ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .reader {
    margin-left: 0;
  }

  #openSidebar,
  .mobile-only {
    display: inline-block;
    visibility: visible;
  }

  .toolbar {
    grid-template-columns: 52px 1fr 126px;
    padding: 0 10px;
  }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    background: rgba(0, 0, 0, 0.35);
  }

  body.sidebar-open .scrim {
    display: block;
  }

  .chapter {
    width: min(100% - 36px, 680px);
    padding-top: 48px;
    font-size: var(--font-size);
    line-height: 1.9;
  }

  .chapter h2 {
    margin-bottom: 40px;
    font-size: 1.45em;
  }

  .chapter-nav {
    width: calc(100% - 36px);
  }
}
