:root {
  --paper: #f7f4ee;
  --ink: #1e2433;
  --gold: #c99a3e;
  --muted: #5b6275;
  --line: #e3ded3;
  --civ: var(--gold);
  --serif: "Songti SC", "STSong", "SimSun", "PMingLiU", "Noto Serif SC", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --page: 1280px;
  --read: 800px;
  --toc: 220px;
  --mast: 132px;
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--mast) + 16px); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.9;
  overflow-x: clip;
}

img { max-width: 100%; }

button, input, select { font: inherit; color: inherit; }

h1, h2, h3, h4, .mast-name, .name {
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.03em;
  overflow-wrap: anywhere;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1.12;
}

h1::after {
  content: "";
  display: block;
  width: 3.2em;
  max-width: 100%;
  height: 3px;
  margin-top: 12px;
  background: var(--gold);
}

h2 { margin: 1.6em 0 0.6em; font-size: clamp(26px, 3vw, 32px); }

h3 { margin: 0 0 0.35em; font-size: clamp(22px, 2.4vw, 28px); }

p { margin: 0 0 0.95em; }

a { color: inherit; }

.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;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 8;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
}

.skip:focus { top: 12px; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.eyebrow {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  background: transparent;
  line-height: 1.2;
}

.btn-gold { background: var(--gold); color: var(--ink); }

.btn-line { border-color: var(--ink); background: var(--paper); }

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.mast {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  border-bottom: 1px solid var(--gold);
}

.mast-inner,
#catalog-view,
#reader-view,
#notice-view,
.colophon,
#status {
  width: min(var(--page), calc(100% - 48px));
  margin-inline: auto;
}

.mast-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 18px;
  min-height: 64px;
  padding: 10px 0;
}

.mast-name { margin: 0; font-size: 22px; }

.mast-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-left: auto;
}

.mast-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
  border-bottom: 1px solid var(--gold);
}

#catalog-view,
#reader-view,
#notice-view { margin-top: 28px; margin-bottom: 72px; }

.catalog-head,
.lede { max-width: 40em; }

.catalog-search,
.tools { margin: 18px 0; max-width: 40em; }

.catalog-search label,
.tools label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 15px;
}

.catalog-search input,
.tools input,
.tools select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid rgba(30, 36, 51, 0.22);
  border-radius: 999px;
  background: #fff;
  font-size: 16px;
}

.tools {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  max-width: none;
}

.status, .notice, .meta, .kind, .branch-name { color: var(--muted); }

.status {
  margin-top: 18px;
  margin-bottom: 0;
}

.status.is-error { color: #7a3b32; }

.stat-item {
  display: inline-block;
  white-space: nowrap;
}

.index {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.index-card {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  min-width: 0;
  min-height: 44px;
}

.index-card img {
  width: 84px;
  height: 64px;
  flex: 0 0 auto;
  object-fit: contain;
  background: #fff;
}

.index-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.index-card .name {
  font-size: clamp(22px, 3vw, 30px);
  box-shadow: inset 0 -3px 0 var(--civ, var(--gold));
}

.index-card.is-disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.reader-layout { min-width: 0; }

.article {
  min-width: 0;
  max-width: var(--read);
  overflow-wrap: anywhere;
}

.prose p { margin: 0 0 1.15em; }

.layer-note {
  margin: 0 0 1.4em;
  padding: 12px 14px;
  background: #fff;
  border-left: 3px solid var(--gold);
}

.layer-note p:last-child { margin-bottom: 0; }

.chapter-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 1.2em;
}

.toc-details {
  margin: 0 0 1.2em;
  min-width: 0;
}

.toc-details > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  font-family: var(--serif);
  font-size: 18px;
}

#toc-nav {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.branch-block { margin: 0 0 0.8em; }

.branch-name,
h3.branch-name {
  margin: 0.4em 0;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.article h2.chapter-title {
  scroll-margin-top: calc(var(--mast) + 16px);
}

.chapter-list {
  list-style: none;
  margin: 0 0 0.8em;
  padding: 0;
}

.chapter-list a,
#toc-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.chapter-list a::after,
#toc-nav a::after {
  content: "›";
  flex: 0 0 auto;
  color: var(--muted);
}

.chapter-list a:hover,
.chapter-list a:active,
.chapter-list a:focus-visible,
#toc-nav a:hover,
#toc-nav a:active,
#toc-nav a:focus-visible {
  background: rgba(201, 154, 62, 0.14);
}

#toc-nav a[aria-current="location"] {
  box-shadow: inset 3px 0 0 var(--civ, var(--gold));
  padding-left: 8px;
}

.period {
  font-family: var(--serif);
  letter-spacing: 0.04em;
}

.plate {
  margin: 1.2em 0 1.6em;
  max-width: 100%;
}

.plate-open {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  min-height: 44px;
}

.plate-open img {
  display: block;
  width: 100%;
  height: auto;
}

.img-miss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 3 / 2;
  margin: 0;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.plate figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.plate figcaption p { margin: 0 0 0.35em; }

.plate-title,
.plate-title strong { color: var(--ink); }

.plate-kind {
  font-size: 13px;
  letter-spacing: 0.08em;
}

.plate-boundary > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  color: var(--ink);
}

details.sources,
.evidence,
.compare,
.limits,
.gallery {
  margin: 1.6em 0;
  min-width: 0;
}

details.sources > summary,
.chapter-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
}

.source-item,
.ev-item {
  margin: 0 0 1.1em;
  padding-top: 0.8em;
  border-top: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.source-item a,
.ev-item a {
  display: inline-block;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

.kicker {
  display: block;
  margin-bottom: 0.2em;
  color: var(--ink);
  font-family: var(--serif);
}

.notice-view { max-width: 40em; }

.notice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.colophon {
  padding: 8px 0 48px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.light {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  padding: 0;
  background: rgba(14, 18, 28, 0.97);
}

.light-panel {
  display: flex;
  flex-direction: column;
  width: min(1100px, 100%);
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  background: #0e121c;
}

.light-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(0, 0, 0, 0.55);
}

#light-title {
  flex: 1 1 12em;
  min-width: 0;
  max-height: 2.8em;
  margin: 0;
  overflow: auto;
  color: var(--paper);
}

#light-close { margin-left: auto; }

.light .btn {
  min-width: 44px;
  min-height: 44px;
  color: var(--paper);
  border-color: var(--paper);
  background: transparent;
}

.light-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.light-copy {
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-width: 0;
  min-height: 0;
  max-height: 34%;
  background: rgba(0, 0, 0, 0.55);
}

.light-scroll-hint {
  display: none;
  margin: 0;
}

.light-stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #0e121c;
}

.light-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center center;
  background: transparent;
}

.light-stage .img-miss {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  background: #0e121c;
  border: 0;
  color: var(--paper);
}

#light-cap {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 12px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow: auto;
  color: var(--paper);
  overflow-wrap: anywhere;
}

#light-cap:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

#light-cap p { margin: 0 0 0.6em; }

.light[hidden] { display: none !important; }

html.light-lock,
html.light-lock body { overflow: hidden; }

@media (min-width: 880px) {
  .reader-layout {
    display: grid;
    grid-template-columns: var(--toc) minmax(0, var(--read));
    column-gap: 48px;
    justify-content: center;
    align-items: start;
  }

  .toc-details {
    position: sticky;
    top: var(--mast);
    max-height: calc(100vh - var(--mast) - 24px);
    max-height: calc(100dvh - var(--mast) - 24px);
    overflow: auto;
    margin: 0;
  }

  #toc-nav a { width: 220px; max-width: 220px; }

  .tools { grid-template-columns: 200px minmax(0, 1fr); }
}

@media (max-width: 879px) {
  .mast-nav { margin-left: 0; }

  #toc-nav a {
    width: 100%;
    max-width: none;
  }
}

@media (max-width: 720px) {
  body { font-size: 16.5px; }

  .mast-inner,
  #catalog-view,
  #reader-view,
  #notice-view,
  .colophon,
  #status { width: calc(100% - 32px); }
}

@media (max-height: 320px) {
  .mast-inner { padding: 4px 0; gap: 2px 12px; }
}

@media (max-height: 480px) and (orientation: landscape) {
  .light-actions { width: 100%; }

  .light-body {
    flex-direction: row;
    min-height: 0;
  }

  .light-stage {
    flex: 1 1 64%;
    width: 64%;
    max-width: 64%;
    height: auto;
  }

  .light-copy {
    flex: 1 1 36%;
    width: 36%;
    max-width: 36%;
    max-height: none;
    min-height: 0;
    overflow: hidden;
  }

  .light-scroll-hint {
    display: block;
    flex: 0 0 auto;
    padding: 8px 12px 0;
    color: var(--paper);
    font-size: 13px;
  }

  #light-cap {
    min-height: 0;
    overflow: auto;
  }

  .light .btn { min-width: 44px; min-height: 44px; }
}

@media (max-width: 390px) {
  :root { --mast: 168px; }
  body { font-size: 16px; }

  .index-card { gap: 10px; }

  .index-card img { width: 64px; height: 48px; }

  h1 { font-size: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
