:root {
  color-scheme: dark;
  --bg:#111111;
  --panel:#1b1b1b;
  --panel-soft:rgba(26,26,26,0.94);
  --panel-border:rgba(255,255,255,0.09);
  --text:#ffffff;
  --muted:#c8c8c8;
  --brand:#ff6268;
  --reader-bg:#151515;
  --paper:#1f1f1f;
  --paper-ink:#ffffff;
  --paper-muted:#b8b8b8;
  --paper-line:rgba(255,255,255,0.13);
  --shadow:0 18px 40px rgba(0,0,0,0.28);
  --book-font-size:18px;
  --book-line-height:1.72;
}

:root[data-theme="light"] {
  color-scheme: light;
  --paper:#fffaf1;
  --paper-ink:#000000;
  --paper-muted:#686055;
  --paper-line:#ddd2c1;
}

* { box-sizing:border-box; }

html {
  scroll-behavior:smooth;
  overflow-y:scroll;
  scrollbar-gutter:stable;
}

body {
  margin:0;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.055), transparent 35%),
    linear-gradient(180deg, var(--bg) 0%, var(--reader-bg) 100%);
  color:var(--text);
  font-family:Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x:hidden;
}

button,
select {
  font:inherit;
}

button {
  border:1px solid var(--panel-border);
  background:rgba(255,255,255,0.04);
  color:var(--text);
  min-height:34px;
  padding:7px 12px;
  border-radius:8px;
  cursor:pointer;
  transition:background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover:not(:disabled),
button:focus-visible:not(:disabled) {
  background:rgba(255,255,255,0.09);
  border-color:rgba(255,255,255,0.18);
  outline:none;
}

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

#toolbar {
  position:fixed;
  top:0;
  left:0;
  right:0;
  min-height:52px;
  z-index:30;
  display:flex;
  align-items:center;
  gap:12px;
  padding:8px 14px;
  border-bottom:1px solid var(--panel-border);
  background:var(--panel-soft);
  box-shadow:var(--shadow);
  backdrop-filter:blur(14px);
}

.toolbarGroup {
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  flex:1 1 0;
  min-width:0;
}

.toolbarBrand {
  flex:0 0 auto;
  flex-wrap:nowrap;
}

.toolbarGroupCenter {
  justify-content:center;
  position:absolute;
  left:50%;
  transform:translateX(-50%);
  flex:0 1 auto;
}

.toolbarMeta {
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
  flex:1 1 0;
  min-width:0;
}

.brandLink {
  transform:translateY(3px);
  color:var(--brand);
  text-decoration:none;
  font-family:"Cinzel", Georgia, "Times New Roman", serif;
  font-size:21px;
  line-height:1;
  font-weight:700;
  white-space:nowrap;
  letter-spacing:0;
}

.brandLink:hover,
.brandLink:focus-visible {
  color:var(--brand);
  outline:none;
}

.menuButton {
  display:inline-flex;
  flex-direction:column;
  justify-content:center;
  gap:4px;
  width:38px;
  min-width:38px;
  height:32px;
  padding:0 9px;
  box-sizing:border-box;
}

.menuButton span {
  display:block;
  width:100%;
  height:2px;
  border-radius:999px;
  background:var(--text);
}

.panelButton {
  position:relative;
  width:38px;
  min-width:38px;
  height:32px;
  padding:0;
  box-sizing:border-box;
}

.panelButtonIcon {
  position:absolute;
  left:9px;
  top:7px;
  width:20px;
  height:16px;
  border:2px solid var(--text);
  border-radius:3px;
  box-sizing:border-box;
}

.panelButtonIcon::after {
  content:"";
  position:absolute;
  top:-2px;
  bottom:-2px;
  right:4px;
  width:2px;
  border-radius:999px;
  background:var(--text);
}

.tocToggleButton {
  position:relative;
  width:40px;
  min-width:40px;
  height:34px;
  padding:0;
  border:1px solid var(--panel-border);
  border-radius:8px;
  background:rgba(255,255,255,0.04);
  color:var(--text);
  box-sizing:border-box;
}

.tocToggleButton:hover,
.tocToggleButton:focus-visible {
  background:rgba(255,255,255,0.09);
  border-color:rgba(255,255,255,0.18);
  outline:none;
}

.tocToggleButton:disabled {
  cursor:default;
  opacity:1;
}

.tocToggleIcon {
  position:absolute;
  left:50%;
  top:50%;
  width:18px;
  height:18px;
  transform:translate(-50%, -50%);
  box-sizing:border-box;
}

.tocToggleIcon::before,
.tocToggleIcon::after {
  content:"";
  position:absolute;
  height:3px;
  border-radius:999px;
  background:currentColor;
}

.tocToggleIcon::before {
  top:4px;
  left:7px;
  width:11px;
  box-shadow:0 7px 0 currentColor;
}

.tocToggleIcon::after {
  top:2px;
  left:1px;
  width:3px;
  height:14px;
  border-radius:999px;
}

.appBackLink {
  color:var(--text);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-size:14px;
  font-weight:500;
  line-height:1;
  width:40px;
  min-width:40px;
  height:34px;
  padding:0;
  border:1px solid var(--panel-border);
  border-radius:8px;
  background:rgba(255,255,255,0.04);
  text-decoration:none;
  box-sizing:border-box;
}

.appBackLink:hover,
.appBackLink:focus-visible {
  background:rgba(255,255,255,0.09);
  border-color:rgba(255,255,255,0.18);
  color:var(--text);
  outline:none;
}

#status {
  color:var(--muted);
  font-size:14px;
  min-height:1.2em;
}

.modeToggle {
  position:relative;
  display:inline-flex;
  align-items:center;
  min-height:36px;
  padding:4px;
  border:1px solid var(--panel-border);
  border-radius:999px;
  background:rgba(255,255,255,0.04);
  cursor:pointer;
}

.controlHomeLink {
  position:relative;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:40px;
  min-width:40px;
  height:34px;
  border:1px solid var(--panel-border);
  border-radius:8px;
  background:rgba(255,255,255,0.04);
  color:var(--text);
  text-decoration:none;
  transition:background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.controlHomeLink:hover,
.controlHomeLink:focus-visible {
  background:rgba(255,255,255,0.09);
  border-color:rgba(255,255,255,0.18);
  outline:none;
}

.homeIcon {
  content:"";
  display:block;
  width:18px;
  height:18px;
  background:currentColor;
  -webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.75 11.25 12 3.5l9.25 7.75'/%3E%3Cpath d='M5.5 10.5V20h13v-9.5'/%3E%3Cpath d='M10 20v-5.5h4V20'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
  mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.75 11.25 12 3.5l9.25 7.75'/%3E%3Cpath d='M5.5 10.5V20h13v-9.5'/%3E%3Cpath d='M10 20v-5.5h4V20'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
}

.modeToggleOption {
  position:relative;
  z-index:1;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:34px;
  height:26px;
  border-radius:999px;
  color:var(--muted);
  font-size:15px;
  line-height:1;
  pointer-events:none;
}

.modeToggleThumb {
  position:absolute;
  top:4px;
  left:4px;
  width:34px;
  height:26px;
  border-radius:999px;
  background:rgba(255,255,255,0.14);
  transition:transform 180ms ease;
}

.modeToggle.active .modeToggleThumb {
  transform:translateX(34px);
}

.modeToggle.active .modeToggleOptionDark,
.modeToggle:not(.active) .modeToggleOptionLight {
  color:var(--text);
}

#fontSizeValue {
  display:none;
}

#reader {
  min-height:100vh;
  padding:88px 18px 48px;
}

#bookSurface {
  width:min(100%, 940px);
  margin:0 auto;
}

.paper {
  min-height:calc(100vh - 142px);
  background:transparent;
  color:var(--paper-ink);
  border:none;
}

.titlePage {
  min-height:58vh;
  display:flex;
  flex-direction:column;
  justify-content:center;
  gap:14px;
  margin:0 0 28px;
  padding:64px min(8vw, 82px);
  background:var(--paper);
  box-shadow:var(--shadow);
  border:1px solid rgba(0,0,0,0.04);
}

.bookTitle {
  margin:0;
  font-family:Georgia, "Times New Roman", serif;
  font-size:clamp(36px, 6vw, 64px);
  line-height:1.05;
  font-weight:400;
}

.bookSubtitle {
  margin:0;
  color:var(--paper-ink);
  font-family:Georgia, "Times New Roman", serif;
  font-size:clamp(24px, 3.3vw, 38px);
  line-height:1.14;
  font-weight:400;
}

.bookAuthor {
  margin:42px 0 0;
  color:var(--paper-ink);
  font-size:17px;
  font-weight:700;
  line-height:1.4;
}

.bookMeta {
  margin:58px 0 0;
  display:flex;
  flex-direction:column;
  gap:2px;
}

.bookMeta > * + * {
  margin-top:0;
}

.bookSource {
  display:block;
  margin:0 0 4px;
  color:var(--paper-ink);
  font-size:13px;
  line-height:1.45;
  text-decoration:underline;
  text-underline-offset:3px;
  width:max-content;
}

.bookCopyright {
  margin:0;
  color:var(--paper-ink);
  font-size:13px;
  line-height:1.45;
}

.tocBlock {
  margin:0 0 28px;
  padding:56px min(8vw, 82px);
  background:var(--paper);
  box-shadow:var(--shadow);
  border:1px solid rgba(0,0,0,0.04);
}

.tocBlock h2,
.chapterHeading {
  margin:0 0 18px;
  font-family:Georgia, "Times New Roman", serif;
  font-size:26px;
  line-height:1.24;
  font-weight:700;
}

.tocBlock ol,
.tocBlock ul {
  margin:0;
  padding:0;
  columns:2;
  column-gap:34px;
  list-style:none;
}

.tocBlock li {
  break-inside:avoid;
  margin:0 0 12px;
}

.tocBlock a {
  color:var(--paper-ink);
  text-decoration:none;
  border-bottom:1px solid transparent;
}

.toc-subtitle {
  display:block;
  margin-top:3px;
  color:var(--paper-muted);
  font-size:.86em;
  line-height:1.35;
}

.tocBlock a:hover,
.tocBlock a:focus-visible {
  border-bottom-color:var(--paper-ink);
  outline:none;
}

.bookBody {
  font-family:Georgia, "Times New Roman", "Noto Serif TC", "Noto Serif JP", serif;
  font-size:var(--book-font-size);
  line-height:var(--book-line-height);
}

.bookBody .chapter {
  margin:0 0 28px;
  padding:58px min(8vw, 82px) 64px;
  background:var(--paper);
  box-shadow:var(--shadow);
  border:1px solid rgba(0,0,0,0.04);
  scroll-margin-top:10px;
}

.bookBody p {
  margin:0 0 1em;
}

.bookBody .chapterHeading {
  margin:0 0 .28em;
  scroll-margin-top:88px;
}

.bookBody .chapter-subtitle {
  margin:0;
  color:var(--paper-ink);
  font-family:Georgia, "Times New Roman", "Noto Serif TC", "Noto Serif JP", serif;
  font-size:calc(var(--book-font-size) + 1px);
  font-weight:700;
  line-height:1.35;
}

.bookBody .chapter > .chapter-subtitle + p {
  margin-top:2.25em;
}

.bookBody .chapter > .chapterHeading + p:not(.chapter-subtitle) {
  margin-top:2.25em;
}

.readerMessage {
  width:min(100%, 720px);
  margin:0 auto;
  padding:38px 28px;
  border:1px solid var(--panel-border);
  border-radius:12px;
  background:rgba(255,255,255,0.04);
  color:var(--text);
  text-align:center;
  box-shadow:var(--shadow);
}

.readerMessage h1 {
  margin:0 0 10px;
  font-size:24px;
}

.readerMessage p {
  margin:0;
  color:var(--muted);
  line-height:1.55;
}

.resumePrompt {
  position:fixed;
  left:50%;
  bottom:28px;
  z-index:30;
  display:inline-flex;
  align-items:center;
  gap:8px;
  transform:translateX(-50%);
  padding:10px 14px;
  border:1px solid rgba(255,255,255,.18);
  border-radius:999px;
  background:rgba(28,28,28,.92);
  color:#fff;
  box-shadow:0 14px 34px rgba(0,0,0,.42);
  backdrop-filter:blur(14px);
  font-size:14px;
  font-weight:600;
  line-height:1.2;
  cursor:pointer;
}

.resumePrompt:hover,
.resumePrompt:focus-visible {
  background:rgba(42,42,42,.96);
}

:root[data-theme="light"] .resumePrompt {
  border-color:rgba(0,0,0,.22);
  background:rgba(22,22,22,.94);
  color:#fff;
}

:root[data-theme="light"] .resumePrompt:hover,
:root[data-theme="light"] .resumePrompt:focus-visible {
  border-color:rgba(0,0,0,.36);
  background:rgba(0,0,0,.98);
}

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

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

.tocBackdrop {
  position:fixed;
  inset:52px 0 0;
  z-index:22;
  background:rgba(0,0,0,.28);
  opacity:0;
  pointer-events:none;
  transition:opacity 180ms ease;
}

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

.tocOverlay {
  position:fixed;
  top:68px;
  left:50%;
  z-index:35;
  display:none;
  width:min(520px, calc(100vw - 32px));
  max-height:min(680px, calc(100vh - 92px));
  overflow:hidden;
  transform:translate(-50%, -8px);
  border:1px solid var(--panel-border);
  border-radius:8px;
  background:rgba(22,22,22,.98);
  box-shadow:0 22px 44px rgba(0,0,0,.45);
  backdrop-filter:blur(14px);
}

.tocCloseButton {
  position:absolute;
  top:8px;
  right:22px;
  z-index:2;
  width:34px;
  min-width:34px;
  height:34px;
  padding:0;
  border:1px solid transparent;
  border-radius:8px;
  background:transparent;
}

.tocCloseButton::before,
.tocCloseButton::after {
  content:"";
  position:absolute;
  left:50%;
  top:50%;
  width:15px;
  height:2px;
  border-radius:999px;
  background:var(--text);
}

.tocCloseButton::before {
  transform:translate(-50%, -50%) rotate(45deg);
}

.tocCloseButton::after {
  transform:translate(-50%, -50%) rotate(-45deg);
}

.tocCloseButton:hover,
.tocCloseButton:focus-visible {
  background:rgba(255,255,255,.09);
  border-color:rgba(255,255,255,.12);
  outline:none;
}

.tocOverlay.open {
  display:block;
  transform:translate(-50%, 0);
}

.tocOverlayBody {
  max-height:min(680px, calc(100vh - 92px));
  overflow:auto;
  padding:12px;
}

.tocOverlayBody h2 {
  margin:4px 58px 10px 10px;
  color:var(--muted);
  font-size:14px;
  font-weight:500;
  line-height:1.3;
}

.tocOverlayBody ol,
.tocOverlayBody ul {
  list-style:none;
  margin:0;
  padding:0;
}

.tocOverlayBody li {
  margin:0 0 4px;
}

.tocOverlayItem {
  display:block;
  width:100%;
  min-height:38px;
  padding:9px 10px;
  border:none;
  border-radius:8px;
  background:transparent;
  color:var(--text);
  text-align:left;
  transform:none;
}

.tocOverlayItem:hover,
.tocOverlayItem:focus-visible {
  background:rgba(255,255,255,.09);
  outline:none;
  transform:none;
}

.tocOverlayTitle {
  display:block;
  font-size:15px;
  line-height:1.35;
}

.tocOverlayMeta {
  display:block;
  margin-top:3px;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
}

.tocOverlayEmpty {
  margin:0;
  padding:10px;
  color:var(--muted);
  line-height:1.45;
}

#leftPanel,
#rightPanel {
  position:fixed;
  top:52px;
  bottom:0;
  z-index:20;
  width:min(340px, 88vw);
  background:var(--panel-soft);
  border-color:var(--panel-border);
  box-shadow:0 20px 40px rgba(0,0,0,.35);
  backdrop-filter:blur(14px);
  display:flex;
  flex-direction:column;
  transition:transform 180ms ease;
}

#leftPanel {
  left:0;
  border-right:1px solid var(--panel-border);
  transform:translateX(-100%);
}

#rightPanel {
  right:0;
  border-left:1px solid var(--panel-border);
  transform:translateX(100%);
}

#leftPanel.open,
#rightPanel.open {
  transform:translateX(0);
}

.panelHeader {
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:10px;
  padding:14px 16px;
  border-bottom:1px solid var(--panel-border);
}

#leftPanel .panelHeader {
  display:none;
}

.panelTitle {
  margin:0;
  color:var(--muted);
  font-size:14px;
  font-weight:400;
  line-height:1.35;
}

#leftPanelControls {
  margin-left:auto;
}

#leftBack {
  width:40px;
  min-width:40px;
  height:34px;
  min-height:34px;
  padding:0;
  border-radius:8px;
  font-size:20px;
  line-height:1;
}

.panelBody {
  flex:1 1 auto;
  overflow:auto;
  padding:10px;
}

.panelControls {
  display:none;
}

.listButton {
  display:block;
  width:100%;
  margin:0 0 4px;
  padding:10px;
  border:none;
  border-radius:8px;
  background:transparent;
  color:var(--text);
  font:inherit;
  text-align:left;
  text-decoration:none;
  transform:none;
}

.listButton:hover,
.listButton:focus-visible,
.listButton.active {
  background:rgba(255,255,255,.09);
  outline:none;
  transform:none;
}

.listTitle {
  display:block;
  font-size:15px;
  line-height:1.35;
}

.listMeta {
  display:block;
  margin-top:4px;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
}

.languagePicker {
  position:relative;
  z-index:5;
  margin:0 0 10px;
}

.languagePicker.open {
  z-index:25;
}

.languageSelectButton {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  width:100%;
  min-height:36px;
  padding:7px 10px;
  border:1px solid var(--panel-border);
  border-radius:8px;
  background:rgba(255,255,255,0.04);
  color:var(--text);
  font-size:14px;
  line-height:1.2;
  text-align:left;
}

.languageSelectButton::after {
  content:"";
  width:0;
  height:0;
  border-left:5px solid transparent;
  border-right:5px solid transparent;
  border-top:6px solid var(--muted);
  flex:0 0 auto;
}

.languagePicker.open .languageSelectButton::after {
  border-top:none;
  border-bottom:6px solid var(--muted);
}

.languageMenu {
  position:absolute;
  top:calc(100% + 6px);
  left:0;
  right:0;
  z-index:30;
  display:none;
  max-height:min(320px, calc(100vh - 170px));
  overflow:auto;
  padding:4px;
  border:1px solid var(--panel-border);
  border-radius:8px;
  background:rgba(20,20,20,.98);
  box-shadow:0 18px 34px rgba(0,0,0,.42);
}

.languagePicker.open .languageMenu {
  display:block;
}

.languageOption {
  display:flex;
  width:100%;
  min-height:34px;
  padding:7px 8px;
  border:none;
  background:transparent;
  border-radius:6px;
  text-align:left;
}

.languageOption.active {
  background:rgba(255,255,255,.12);
}

.scriptToggle {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:4px;
  margin:0 0 10px;
  padding:4px;
  border:1px solid var(--panel-border);
  border-radius:8px;
  background:rgba(255,255,255,0.04);
}

.scriptOption {
  min-height:30px;
  padding:5px 8px;
  border:none;
  border-radius:6px;
  background:transparent;
  color:var(--muted);
  font-size:14px;
  line-height:1.2;
}

.scriptOption.active {
  background:rgba(255,255,255,.12);
  color:var(--text);
}

.languageNative {
  display:inline-block;
  color:var(--text);
}

.languageEnglish {
  margin-left:.35em;
  color:var(--muted);
}

.panelEmpty {
  padding:12px 10px;
  color:var(--muted);
  line-height:1.45;
}

.hidden {
  display:none !important;
}

@media (max-width: 760px) {
  #toolbar {
    min-height:52px;
    padding:8px 12px;
    flex-wrap:nowrap;
    align-items:center;
    align-content:center;
  }

  .toolbarBrand {
    flex:1 1 auto;
    min-width:0;
  }

  .toolbarMeta {
    flex:0 0 auto;
    width:auto;
  }

  .toolbarMeta .appBackLink {
    display:none;
  }

  .toolbarGroupCenter {
    display:none;
  }

  #leftPanel,
  #rightPanel {
    top:52px;
  }

  .brandLink {
    overflow:hidden;
    font-size:19px;
    text-overflow:ellipsis;
  }

  .modeToggle {
    min-height:34px;
  }

  #reader {
    padding:70px 0 0;
  }

  #bookSurface {
    width:100%;
  }

  .paper {
    min-height:calc(100vh - 160px);
    border:none;
    box-shadow:none;
  }

  .titlePage,
  .tocBlock,
  .bookBody .chapter {
    margin:0;
    padding:28px 20px 42px;
    border:none;
    box-shadow:none;
  }

  .titlePage {
    min-height:42vh;
    border-bottom:1px solid var(--paper-line);
  }

  .tocBlock {
    border-bottom:1px solid var(--paper-line);
  }

  .tocBlock ol,
  .tocBlock ul {
    columns:1;
  }

  .bookBody .chapter {
    border-bottom:1px solid var(--paper-line);
    scroll-margin-top:72px;
  }

  .bookBody {
    font-size:calc(var(--book-font-size) - 1px);
    line-height:1.68;
  }

  .panelControls {
    display:flex;
    align-items:center;
    justify-content:flex-start;
    gap:8px;
    margin:0 0 10px;
  }

  #leftPanelControls {
    width:100%;
    margin-left:0;
  }

  #leftPanel .panelHeader {
    display:block;
    padding:14px 10px;
  }

  #leftPanel .panelTitle,
  #leftPanel #leftBack {
    display:none !important;
  }

  .panelControlButton {
    width:40px;
    min-width:40px;
    padding:0;
  }

  .tocOverlay {
    top:62px;
    width:calc(100vw - 20px);
    max-height:calc(100vh - 78px);
  }

  .tocOverlayBody {
    max-height:calc(100vh - 78px);
  }

  .panelModeToggle {
    flex:0 0 auto;
  }

  #leftPanelControls .panelControls {
    justify-content:flex-start;
    margin:0;
  }
}
