/* ============================================================
   墨屿 — immersive reader, themes, typography & paywall
   ============================================================ */

body.reading-mode {
  background: var(--reader-bg, #e9e1d2);
  overflow: hidden;
}

body.reading-mode .site-header,
body.reading-mode .announcement,
body.reading-mode .site-footer,
body.reading-mode .site-grain {
  display: none !important;
}

body.reading-mode #main {
  height: 100vh;
}

.reader-shell {
  --reader-bg: #e9e1d2;
  --reader-paper: #f7f1e5;
  --reader-text: #393229;
  --reader-muted: #8b7f6b;
  --reader-line: rgba(72, 58, 39, 0.13);
  --reader-accent: #9f4837;
  --reader-soft: rgba(159, 72, 55, 0.08);
  --reader-shadow: 0 35px 80px -55px rgba(61, 45, 26, 0.5);
  position: relative;
  height: 100vh;
  overflow: hidden;
  background: var(--reader-bg);
  color: var(--reader-text);
  transition: background 0.35s, color 0.35s;
}

.reader-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.25;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='170' height='170'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='170' height='170' filter='url(%23n)' opacity='.18'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  z-index: 1;
}

.reader-shell[data-reader-theme="night"],
.reader-shell[data-reader-theme="gilded"],
.reader-shell[data-reader-theme="crimson"],
.reader-shell[data-reader-theme="starlight"] {
  --reader-shadow: 0 40px 90px -50px rgba(0, 0, 0, 0.7);
}

.reader-shell[data-reader-theme="night"]::before,
.reader-shell[data-reader-theme="gilded"]::before,
.reader-shell[data-reader-theme="crimson"]::before,
.reader-shell[data-reader-theme="starlight"]::before {
  opacity: 0.12;
  mix-blend-mode: screen;
}

/* Theme definitions */
.reader-shell[data-reader-theme="paper"] {
  --reader-bg: #e7ded0;
  --reader-paper: #f8f2e6;
  --reader-text: #393229;
  --reader-muted: #8b7f6b;
  --reader-line: rgba(72, 58, 39, 0.13);
  --reader-accent: #9f4837;
  --reader-soft: rgba(159, 72, 55, 0.075);
}

.reader-shell[data-reader-theme="moon"] {
  --reader-bg: #e5e8e8;
  --reader-paper: #f5f7f5;
  --reader-text: #343b3d;
  --reader-muted: #7d888a;
  --reader-line: rgba(52, 67, 72, 0.12);
  --reader-accent: #5c7882;
  --reader-soft: rgba(92, 120, 130, 0.08);
}

.reader-shell[data-reader-theme="celadon"] {
  --reader-bg: #dbe3da;
  --reader-paper: #f1f5ed;
  --reader-text: #344039;
  --reader-muted: #7a887a;
  --reader-line: rgba(53, 71, 58, 0.12);
  --reader-accent: #687f69;
  --reader-soft: rgba(104, 127, 105, 0.08);
}

.reader-shell[data-reader-theme="sepia"] {
  --reader-bg: #dccbb2;
  --reader-paper: #f0e3cd;
  --reader-text: #433728;
  --reader-muted: #8d7a60;
  --reader-line: rgba(84, 65, 40, 0.14);
  --reader-accent: #986245;
  --reader-soft: rgba(152, 98, 69, 0.08);
}

.reader-shell[data-reader-theme="night"] {
  --reader-bg: #121519;
  --reader-paper: #1a1e23;
  --reader-text: #b9bec1;
  --reader-muted: #6f787e;
  --reader-line: rgba(185, 190, 193, 0.09);
  --reader-accent: #bd8b65;
  --reader-soft: rgba(189, 139, 101, 0.08);
}

.reader-shell[data-reader-theme="gilded"] {
  --reader-bg: #0f1511;
  --reader-paper: #18201a;
  --reader-text: #d8cdb5;
  --reader-muted: #8b816b;
  --reader-line: rgba(205, 180, 137, 0.12);
  --reader-accent: #c8a265;
  --reader-soft: rgba(200, 162, 101, 0.08);
}

.reader-shell[data-reader-theme="crimson"] {
  --reader-bg: #150f12;
  --reader-paper: #21171b;
  --reader-text: #d5c2bb;
  --reader-muted: #8a716f;
  --reader-line: rgba(208, 171, 160, 0.1);
  --reader-accent: #c37668;
  --reader-soft: rgba(195, 118, 104, 0.08);
}

.reader-shell[data-reader-theme="starlight"] {
  --reader-bg: #0b0e18;
  --reader-paper: #141827;
  --reader-text: #cbd0df;
  --reader-muted: #777e99;
  --reader-line: rgba(168, 175, 210, 0.1);
  --reader-accent: #9d9fcd;
  --reader-soft: rgba(157, 159, 205, 0.08);
}

/* Top bar */
.reader-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 62px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 27px;
  background: color-mix(in srgb, var(--reader-bg) 86%, transparent);
  border-bottom: 1px solid var(--reader-line);
  backdrop-filter: saturate(130%) blur(16px);
  -webkit-backdrop-filter: saturate(130%) blur(16px);
  color: var(--reader-text);
}

.reader-bar-left {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  flex: 1;
}

.reader-back {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--reader-muted);
  flex: none;
  transition: background 0.2s, color 0.2s;
}

.reader-back:hover {
  background: var(--reader-soft);
  color: var(--reader-text);
}

.reader-book-name {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.reader-book-name strong {
  font-family: var(--font-serif);
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-book-name span {
  font-size: 9.5px;
  color: var(--reader-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-bar-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 36%;
  font-family: var(--font-serif);
  font-size: 11px;
  color: var(--reader-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.reader-bar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.reader-tool {
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 50px;
  color: var(--reader-muted);
  font-size: 9.5px;
  transition: background 0.2s, color 0.2s;
}

.reader-tool:hover,
.reader-tool.is-active {
  background: var(--reader-soft);
  color: var(--reader-text);
}

.reader-tool.is-saved {
  color: var(--reader-accent);
}

.reader-tool .icon {
  color: currentColor;
}

.reader-tool-divider {
  width: 1px;
  height: 17px;
  background: var(--reader-line);
  margin: 0 5px;
}

.reader-top-progress {
  position: fixed;
  top: 61px;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 31;
  background: transparent;
}

.reader-top-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--reader-accent);
  opacity: 0.65;
  transition: width 0.1s linear;
}

/* Scroll surface */
.reader-scroll {
  position: absolute;
  inset: 62px 0 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  z-index: 2;
}

.reader-scroll::-webkit-scrollbar {
  width: 6px;
}

.reader-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.reader-scroll::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--reader-muted) 30%, transparent);
  border-radius: 99px;
}

.reader-paper {
  width: min(100% - 64px, var(--reader-width, 820px));
  margin: 0 auto;
  padding: 72px clamp(34px, 7vw, 82px) 54px;
  background: var(--reader-paper);
  color: var(--reader-text);
  min-height: calc(100vh - 62px);
  box-shadow: var(--reader-shadow);
  position: relative;
  transition: width 0.3s var(--ease), background 0.3s, color 0.3s;
}

.reader-paper::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: color-mix(in srgb, var(--reader-accent) 18%, transparent);
  opacity: 0.5;
}

.reader-paper::after {
  content: "墨屿";
  position: absolute;
  right: 25px;
  top: 28px;
  writing-mode: vertical-rl;
  font-family: var(--font-kai);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--reader-muted);
  opacity: 0.34;
}

.reader-chapter-head {
  margin-bottom: 53px;
  position: relative;
}

.reader-chapter-index {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-serif);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  color: var(--reader-accent);
  text-transform: uppercase;
}

.reader-chapter-index::after {
  content: "";
  width: 39px;
  height: 1px;
  background: currentColor;
  opacity: 0.4;
}

.reader-chapter-head h1 {
  margin-top: 17px;
  font-family: var(--font-serif);
  font-size: clamp(1.8rem, 3vw, 2.35rem);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.45;
  color: var(--reader-text);
}

.reader-chapter-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 17px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--reader-line);
  font-size: 9px;
  color: var(--reader-muted);
}

.reader-chapter-meta span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.reader-content {
  font-family: var(--font-serif);
  font-size: var(--reader-font-size, 19px);
  line-height: var(--reader-line-height, 1.95);
  letter-spacing: 0.02em;
  color: var(--reader-font-color, var(--reader-text));
  transition: font-size 0.2s, line-height 0.2s, color 0.2s;
}

.reader-content p {
  text-indent: 2em;
  margin: 0 0 var(--reader-paragraph-gap, 1.15em);
  text-align: justify;
  word-break: break-word;
}

.reader-content p:first-child {
  text-indent: 0;
}

.reader-content p:first-child::first-letter {
  font-family: var(--font-kai);
  font-size: 2.35em;
  float: left;
  line-height: 0.86;
  margin: 5px 9px 0 0;
  color: var(--reader-accent);
}

.reader-content.font-song { font-family: var(--font-serif); }
.reader-content.font-hei { font-family: var(--font-sans); font-weight: 350; letter-spacing: 0.04em; }
.reader-content.font-kai { font-family: var(--font-kai); font-size: calc(var(--reader-font-size, 19px) + 1px); letter-spacing: 0.04em; }
.reader-content.font-fang { font-family: var(--font-fang); letter-spacing: 0.05em; }
.reader-content.font-deng { font-family: "DengXian", "Noto Sans SC", "Microsoft YaHei", sans-serif; font-weight: 300; letter-spacing: 0.06em; }
.reader-content.font-noto { font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif; font-weight: 300; letter-spacing: 0.03em; }

.reader-content.is-preview {
  position: relative;
  max-height: 330px;
  overflow: hidden;
}

.reader-content.no-dropcap p:first-child::first-letter {
  font-family: inherit;
  float: none;
  font-size: inherit;
  line-height: inherit;
  margin: 0;
  color: inherit;
}

.reader-chapter-end {
  margin-top: 70px;
  padding-top: 30px;
  border-top: 1px solid var(--reader-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.reader-end-mark {
  width: 35px;
  height: 35px;
  border: 1px solid color-mix(in srgb, var(--reader-accent) 50%, transparent);
  display: grid;
  place-items: center;
  color: var(--reader-accent);
  font-family: var(--font-kai);
  font-size: 15px;
  transform: rotate(-4deg);
  opacity: 0.8;
}

.reader-chapter-end p {
  font-family: var(--font-kai);
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--reader-muted);
}

.reader-chapter-end small {
  font-size: 7.5px;
  letter-spacing: 0.2em;
  color: var(--reader-muted);
  opacity: 0.55;
}

.reader-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin-top: 35px;
}

.reader-pager a,
.reader-pager span {
  min-height: 74px;
  padding: 13px 17px;
  border: 1px solid var(--reader-line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  transition: border-color 0.2s, background 0.2s;
  color: var(--reader-text);
}

.reader-pager a:hover {
  border-color: color-mix(in srgb, var(--reader-accent) 48%, transparent);
  background: var(--reader-soft);
}

.reader-pager small {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 8.5px;
  color: var(--reader-muted);
  letter-spacing: 0.08em;
}

.reader-pager strong {
  font-family: var(--font-serif);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-pager .next {
  text-align: right;
  align-items: flex-end;
}

.reader-pager .is-disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.reader-copyright {
  margin-top: 34px;
  text-align: center;
  font-size: 8px;
  line-height: 1.8;
  color: var(--reader-muted);
  opacity: 0.55;
  letter-spacing: 0.01em;
}

.reader-copyright strong {
  font-weight: 500;
  color: var(--reader-muted);
}

/* Settings drawer */
.reader-settings {
  position: fixed;
  z-index: 60;
  right: 0;
  top: 0;
  bottom: 0;
  width: 392px;
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: -30px 0 80px rgba(20, 15, 10, 0.18);
  transform: translateX(100%);
  transition: transform 0.45s var(--ease);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reader-settings.is-open {
  transform: none;
}

.reader-settings-head {
  padding: 22px 24px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.reader-settings-head h2 {
  font-family: var(--font-serif);
  font-size: 17px;
  letter-spacing: 0.02em;
}

.reader-settings-head span {
  display: block;
  margin-top: 3px;
  font-size: 8px;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-transform: uppercase;
}

.reader-settings-body {
  padding: 22px 24px 35px;
  overflow-y: auto;
  flex: 1;
}

.reader-setting-block {
  margin-bottom: 27px;
}

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

.reader-setting-label h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.reader-setting-label h3 .icon {
  color: var(--accent);
}

.reader-setting-label span {
  font-size: 8.5px;
  color: var(--muted);
}

.theme-option-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.theme-option {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px;
  text-align: left;
  transition: border-color 0.2s, transform 0.2s;
  overflow: hidden;
}

.theme-option:hover {
  transform: translateY(-2px);
}

.theme-option.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 11%, transparent);
}

.theme-option.is-locked .theme-swatch {
  filter: saturate(0.75);
}

.theme-option.is-locked::after {
  content: "会员";
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 2;
  padding: 1px 5px;
  border-radius: 999px;
  background: rgba(18, 15, 11, 0.58);
  border: 1px solid rgba(220, 183, 124, 0.34);
  color: #dfbc83;
  font-size: 6.5px;
  line-height: 1.5;
  letter-spacing: 0.04em;
  backdrop-filter: blur(5px);
}

.theme-swatch {
  height: 48px;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 0 9px;
}

.theme-swatch::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(90deg, transparent 0 9px, rgba(240, 230, 210, 0.12) 9px 10px, transparent 10px);
  pointer-events: none;
}

.theme-swatch i {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.4;
}

.theme-swatch i:nth-child(1) { width: 70%; opacity: 0.7; }
.theme-swatch i:nth-child(2) { width: 88%; }
.theme-swatch i:nth-child(3) { width: 55%; }

.theme-option-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  margin-top: 6px;
  padding: 0 2px 2px;
  font-size: 8.5px;
  color: var(--ink-soft);
}

.theme-option.is-active .theme-option-name {
  color: var(--accent);
}

.theme-lock {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--gold-soft);
  font-size: 7px;
  color: var(--gold);
  white-space: nowrap;
  flex: none;
}

.font-option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.font-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  text-align: left;
  transition: border-color 0.2s, background 0.2s;
}

.font-option:hover {
  border-color: var(--line-strong);
}

.font-option.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.font-sample {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 12px;
  color: var(--ink);
  flex: none;
}

.font-option-body {
  min-width: 0;
  flex: 1;
}

.font-option-body strong {
  display: block;
  font-size: 9px;
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.font-option-body small {
  display: block;
  font-size: 6.5px;
  color: var(--muted);
  margin-top: 1px;
}

.font-option .theme-lock {
  flex: none;
}

.font-option.is-locked {
  opacity: 0.7;
}

.size-control {
  display: flex;
  align-items: center;
  gap: 13px;
}

.size-control button {
  width: 35px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  color: var(--ink-soft);
  flex: none;
  transition: border-color 0.2s, color 0.2s;
}

.size-control button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.size-control input[type="range"] {
  flex: 1;
  height: 3px;
  accent-color: var(--accent);
  cursor: pointer;
}

.size-value {
  min-width: 40px;
  text-align: right;
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--ink-soft);
}

.color-grid {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.color-dot {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 2px solid transparent;
  position: relative;
  transition: transform 0.2s, border-color 0.2s;
}

.color-dot:hover {
  transform: scale(1.1);
}

.color-dot.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--surface);
}

.color-dot.is-active::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
}

.custom-color {
  position: relative;
  width: 25px;
  height: 25px;
  border: 1px dashed var(--line-strong);
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.custom-color input {
  position: absolute;
  inset: -8px;
  width: 45px;
  height: 45px;
  opacity: 0;
  cursor: pointer;
}

.layout-segment {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px;
  gap: 3px;
}

.layout-segment button {
  flex: 1;
  height: 30px;
  border-radius: 5px;
  font-size: 8.5px;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.layout-segment button.is-active {
  background: var(--surface-subtle);
  color: var(--ink);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.setting-row:first-of-type {
  border-top: 0;
}

.setting-row-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 9.5px;
  color: var(--ink-soft);
}

.setting-row-label .icon {
  color: var(--muted);
}

.switch {
  width: 36px;
  height: 21px;
  border-radius: 99px;
  background: var(--surface-deep);
  padding: 2px;
  transition: background 0.25s;
  flex: none;
}

.switch::after {
  content: "";
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--surface-raised);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: transform 0.25s var(--ease);
}

.switch.is-on {
  background: var(--accent);
}

.switch.is-on::after {
  transform: translateX(15px);
}

.reader-settings-foot {
  margin-top: 6px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.reader-settings-foot .btn {
  width: 100%;
  height: 39px;
  font-size: 10.5px;
}

.member-upsell {
  margin-top: 18px;
  padding: 15px;
  border-radius: 8px;
  background:
    radial-gradient(200px 100px at 100% 0%, rgba(195, 157, 99, 0.18), transparent 70%),
    #1c1a16;
  color: #eee5d5;
}

.member-upsell-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 9px;
  color: #cfa96f;
  letter-spacing: 0.06em;
}

.member-upsell p {
  margin-top: 7px;
  font-size: 9px;
  line-height: 1.7;
  color: rgba(238, 229, 213, 0.55);
}

.member-upsell a {
  margin-top: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: #d8b477;
}

.reader-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(15, 12, 8, 0.38);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.reader-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

/* Table of contents drawer */
.reader-toc {
  position: fixed;
  z-index: 60;
  left: 0;
  top: 0;
  bottom: 0;
  width: 370px;
  background: var(--bg-elevated);
  color: var(--ink);
  transform: translateX(-100%);
  transition: transform 0.45s var(--ease);
  display: flex;
  flex-direction: column;
  box-shadow: 30px 0 80px rgba(20, 15, 10, 0.18);
}

.reader-toc.is-open {
  transform: none;
}

.reader-toc-head {
  padding: 22px 23px 18px;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.reader-toc-head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.reader-toc-head h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.35;
}

.reader-toc-head p {
  margin-top: 4px;
  font-size: 8.5px;
  color: var(--muted);
}

.reader-toc-progress {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 8.5px;
  color: var(--muted);
}

.toc-progress-bar {
  flex: 1;
  height: 2px;
  background: var(--surface-deep);
  border-radius: 99px;
  overflow: hidden;
}

.toc-progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.reader-toc-list {
  overflow-y: auto;
  padding: 8px 12px 20px;
  flex: 1;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 11px;
  border-radius: 7px;
  transition: background 0.2s;
  font-size: 10.5px;
  color: var(--ink-soft);
}

.toc-item:hover {
  background: var(--surface-subtle);
}

.toc-item.is-current {
  background: var(--accent-soft);
  color: var(--accent);
}

.toc-item-index {
  font-family: var(--font-serif);
  font-size: 8.5px;
  color: var(--muted-light);
  width: 21px;
  flex: none;
}

.toc-item.is-current .toc-item-index {
  color: var(--accent);
}

.toc-item-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-item-access {
  display: flex;
  color: var(--muted);
  flex: none;
}

.toc-item.is-current .toc-item-access {
  color: var(--accent);
}

/* Paywall */
.reader-paywall {
  position: relative;
  margin-top: -80px;
  padding: 100px 0 20px;
  background: linear-gradient(180deg, transparent, var(--reader-paper) 29%);
}

.reader-paywall-card {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  padding: 33px 31px 27px;
  text-align: center;
  border: 1px solid var(--reader-line);
  background:
    radial-gradient(300px 160px at 50% 0%, var(--reader-soft), transparent 70%),
    var(--reader-paper);
  box-shadow: 0 25px 55px -45px rgba(30, 23, 14, 0.5);
  border-radius: 2px 18px 18px 18px;
}

.paywall-seal {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--reader-accent) 48%, transparent);
  color: var(--reader-accent);
  transform: rotate(-4deg);
}

.paywall-seal .icon {
  transform: rotate(4deg);
}

.reader-paywall-card h2 {
  font-family: var(--font-serif);
  font-size: 22px;
  letter-spacing: 0.01em;
  color: var(--reader-text);
}

.reader-paywall-card > p {
  max-width: 340px;
  margin: 10px auto 20px;
  font-size: 10.5px;
  line-height: 1.8;
  color: var(--reader-muted);
}

.paywall-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paywall-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--reader-line);
  background: transparent;
  border-radius: 8px;
  text-align: left;
  transition: border-color 0.2s, background 0.2s;
  color: var(--reader-text);
}

.paywall-option:hover {
  border-color: color-mix(in srgb, var(--reader-accent) 46%, transparent);
  background: var(--reader-soft);
}

.paywall-option-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--reader-soft);
  color: var(--reader-accent);
  flex: none;
}

.paywall-option-body {
  flex: 1;
  min-width: 0;
}

.paywall-option-body strong {
  display: block;
  font-size: 10.5px;
  font-weight: 500;
}

.paywall-option-body small {
  display: block;
  font-size: 8px;
  color: var(--reader-muted);
  margin-top: 2px;
}

.paywall-option-price {
  font-family: var(--font-serif);
  font-size: 11.5px;
  color: var(--reader-accent);
  flex: none;
}

.paywall-option.is-primary {
  border-color: color-mix(in srgb, var(--reader-accent) 55%, transparent);
  background: var(--reader-soft);
}

.paywall-foot {
  margin-top: 17px;
  font-size: 8px;
  color: var(--reader-muted);
  opacity: 0.7;
}

/* Loading state inside reader */
.reader-loading {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
  background: var(--reader-bg);
  color: var(--reader-muted);
  font-size: 10px;
  letter-spacing: 0.1em;
}

.reader-loading .loading-mark {
  border-color: var(--reader-line);
  color: var(--reader-accent);
}

/* Reader responsive */
@media (max-width: 1024px) {
  .reader-paper {
    width: min(100% - 40px, var(--reader-width, 820px));
  }

  .reader-settings {
    width: 360px;
  }
}

@media (max-width: 780px) {
  .reader-bar {
    height: 56px;
    padding: 0 12px;
    gap: 8px;
  }

  .reader-scroll {
    inset: 56px 0 0;
  }

  .reader-top-progress {
    top: 55px;
  }

  .reader-book-name span,
  .reader-bar-center {
    display: none;
  }

  .reader-book-name strong {
    font-size: 12.5px;
  }

  .reader-bar-actions {
    gap: 0;
  }

  .reader-tool {
    height: 32px;
    min-width: 32px;
    padding: 0 7px;
  }

  .reader-tool span {
    display: none;
  }

  .reader-tool-divider {
    margin: 0 2px;
  }

  .reader-paper {
    width: 100%;
    padding: 38px 22px 38px;
    min-height: calc(100vh - 56px);
    box-shadow: none;
  }

  .reader-paper::before {
    display: none;
  }

  .reader-paper::after {
    right: 13px;
    top: 17px;
    font-size: 8px;
  }

  .reader-chapter-head {
    margin-bottom: 34px;
  }

  .reader-chapter-head h1 {
    margin-top: 12px;
    font-size: 1.65rem;
  }

  .reader-chapter-index {
    font-size: 8px;
  }

  .reader-chapter-meta {
    margin-top: 13px;
    padding-bottom: 17px;
    font-size: 8px;
    gap: 12px;
  }

  .reader-content {
    font-size: var(--reader-font-size, 17px);
    line-height: var(--reader-line-height, 1.95);
  }

  .reader-content p {
    margin-bottom: var(--reader-paragraph-gap, 1em);
  }

  .reader-content p:first-child::first-letter {
    font-size: 2.1em;
  }

  .reader-chapter-end {
    margin-top: 50px;
  }

  .reader-pager {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .reader-pager .next {
    text-align: left;
    align-items: flex-start;
  }

  .reader-pager a,
  .reader-pager span {
    min-height: 59px;
  }

  .reader-settings {
    width: 100%;
    height: 83vh;
    top: auto;
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }

  .reader-settings.is-open {
    transform: none;
  }

  .reader-settings-head {
    padding: 14px 19px 13px;
    position: relative;
  }

  .reader-settings-head::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 6px;
    width: 34px;
    height: 3px;
    border-radius: 99px;
    background: var(--line-strong);
    transform: translateX(-50%);
  }

  .reader-settings-body {
    padding: 17px 19px 30px;
  }

  .reader-settings-head h2 {
    font-size: 16px;
  }

  .theme-option-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .theme-swatch {
    height: 40px;
  }

  .reader-toc {
    width: min(340px, 91vw);
  }

  .reader-toc-head {
    padding: 18px 19px 15px;
  }
}

@media (max-width: 380px) {
  .reader-paper {
    padding-left: 18px;
    padding-right: 18px;
  }

  .font-option-grid {
    grid-template-columns: 1fr;
  }

  .theme-option-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
