: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: var(--mast); }

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 { 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); }

h4 { margin: 1.15em 0 0.35em; font-size: 18px; }

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

.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 {
  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 { text-decoration: none; border-bottom: 1px solid var(--gold); }

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

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

.catalog-search { 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 {
  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;
}

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

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

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

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

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

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

.banner {
  width: 100%;
  margin: 0 0 22px;
  aspect-ratio: 3 / 2;
  overflow: hidden;
}

.banner img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 35%;
}

.lede { max-width: 40em; }

.stats { color: var(--ink); }

.event,
.compare,
.notes,
.front,
.branches,
#toc-nav a,
#toc-nav button {
  scroll-margin-top: var(--mast);
}

.event { margin: 0 0 2.4em; }

.event + .event {
  padding-top: 1.5em;
  border-top: 1px solid var(--line);
}

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

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

.field h4 { color: var(--ink); }

.plate {
  margin: 1.5em 0 2em;
  max-width: 100%;
}

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

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

.plate .img-miss {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 3 / 2;
  margin: 0;
}

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

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

.sources { margin: 0.4em 0 1em; }

.sources summary {
  min-height: 44px;
  cursor: pointer;
  color: var(--ink);
}

.source-item {
  margin: 0 0 1em;
  padding-top: 0.6em;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.source-line { overflow-wrap: anywhere; }

.compare {
  margin-top: 2.5em;
  padding-top: 0.4em;
  border-top: 1px solid var(--gold);
}

.compare-item { margin-bottom: 1.8em; }

.tools { margin: 1.4em 0 1.6em; }

.branch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  min-height: 44px;
  max-width: 100%;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  text-align: left;
  overflow-wrap: anywhere;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  box-shadow: inset 0 -3px 0 var(--civ, var(--gold));
}

.back-row { margin-top: 2em; }

.toc-details { min-width: 0; margin-bottom: 18px; }

.toc-details > summary {
  min-height: 44px;
  cursor: pointer;
  font-family: var(--serif);
  font-size: 20px;
}

#toc-nav {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: 220px;
  margin: 0;
  padding: 0;
}

#toc-nav a,
#toc-nav button {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  max-width: 220px;
  margin: 0;
  padding: 10px 8px 10px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1.45;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  overflow-wrap: anywhere;
  white-space: normal;
}

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

.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;
  gap: 0;
  background: #0e121c;
}

.light-actions {
  display: flex;
  flex-wrap: wrap;
  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-close { margin-left: auto; }

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

.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-cap {
  flex: 0 0 auto;
  margin: 0;
  padding: 12px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.55);
  color: var(--paper);
  overflow-wrap: anywhere;
}

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

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

.img-miss { color: var(--muted); }

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

  .banner { max-height: 420px; }

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

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

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

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

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

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