:root {
  --paper: #f7f4ee;
  --ink: #25362f;
  --gold: #b49760;
  --muted: #6a7169;
  --line: #dfded4;
  --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;
  --content: 1360px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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, .card-name, .node-name, .pano-name h2 {
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-size: clamp(40px, 5vw, 72px);
  font-weight: 900;
  line-height: 1.08;
}

h2 { margin: 0 0 8px; font-size: clamp(28px, 3vw, 36px); }

h3 { margin: 0; font-size: 22px; }

p { margin: 0 0 0.8em; }

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: 5;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
}

.skip:focus { top: 12px; z-index: 30; }

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

.wrap {
  width: min(var(--content), calc(100% - 96px));
  margin-inline: auto;
}

.site-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(247, 244, 238, 0.95);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(37, 54, 47, 0.12);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 78px; }
.nav-identity { display: flex; align-items: center; gap: 24px; min-width: 0; }
.site-nav a { text-decoration: none; }
.nav-back { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.nav-back:hover { color: var(--ink); }
.nav-divider { width: 1px; height: 28px; background: var(--line); }
.nav-brand { display: flex; align-items: baseline; gap: 14px; }
.nav-brand > span { font: 600 23px/1.25 var(--serif); letter-spacing: 0.06em; white-space: nowrap; }
.nav-brand small { font-size: 11px; color: var(--muted); letter-spacing: 0.12em; white-space: nowrap; }
.nav-links { display: flex; align-items: center; gap: 30px; }
.nav-links a { display: inline-flex; align-items: center; min-height: 44px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.nav-links a:hover { color: var(--ink); }
#atlas, #relations { scroll-margin-top: 84px; }

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

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(350px, 0.9fr);
  min-height: clamp(540px, 66svh, 760px);
  background: #efede5;
  border-bottom: 1px solid var(--line);
}

.hero-media { position: relative; min-width: 0; }

.hero-media img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 42%;
}

.hero-copy {
  align-self: center;
  min-width: 0;
  padding: 56px clamp(32px, 4.5vw, 80px);
}

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

.hero .eyebrow { margin-bottom: 24px; color: #8c743e; font-size: 11px; letter-spacing: 0.18em; }
.hero h1 { margin-bottom: 24px; font-size: clamp(40px, 3.7vw, 60px); font-weight: 600; line-height: 1.28; letter-spacing: 0.06em; }
.hero h1 span { display: block; }
.hero .lede { margin: 0; max-width: 28em; color: var(--muted); font-size: 15px; line-height: 1.9; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px; margin-top: 30px; }
.hero-actions a { display: inline-flex; align-items: center; gap: 18px; min-height: 48px; font-size: 14px; text-decoration: none; }
.hero-primary { padding: 0 20px; border: 1px solid var(--ink); border-radius: 4px; background: var(--ink); color: var(--paper); }
.hero-primary:hover { background: #3b5145; border-color: #3b5145; }
.hero-secondary { color: var(--ink); }
.hero-secondary:hover { text-decoration: underline; text-underline-offset: 5px; }
.hero-note { max-width: 25em; margin: 36px 0 0; padding-top: 20px; border-top: 1px solid #d8d8cc; font-size: 11px; letter-spacing: 0.13em; color: var(--muted); }

.atlas { padding: 72px 0 24px; }

.atlas-head { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.atlas-head h2 { flex-shrink: 0; }
.atlas-head p { margin: 0; font-size: 14px; color: var(--muted); }

.tools { display: grid; grid-template-columns: minmax(240px, 1fr) auto; align-items: center; gap: 14px 24px; margin-bottom: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.tools .result-count { grid-column: 1 / -1; margin: 0; font-size: 12px; }
.tools .btn { border-radius: 5px; font-size: 14px; }

.search-row, #search-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

#q {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid rgba(30, 36, 51, 0.22);
  border-radius: 5px;
  background: #fbfaf6;
  font-size: 14px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: #edeae1;
  font-size: 13px;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.result-count, .status, .empty, .disclaimer { color: var(--muted); }

.group { margin-top: 120px; }

.group:first-child { margin-top: 28px; }

.group-head { max-width: 42em; margin-bottom: 24px; }

.group-head p:last-child { color: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
}

.card { min-width: 0; border-bottom: 3px solid var(--civ, var(--gold)); }

.card.is-lead { grid-column: span 2; }

.card-hit {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  padding: 0 0 14px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.frame {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: 6px;
  overflow: hidden;
  background: var(--line);
}

.card.is-lead .frame { aspect-ratio: 3 / 2; }

.frame img, .frame .img-miss {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-miss {
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.pano img[data-zoom], .shot img[data-zoom] { cursor: zoom-in; }

.card-name { display: block; font-size: 22px; font-weight: 600; }

.card-tagline {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.type {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  line-height: 1.6;
}

.type.is-vision { border-color: var(--gold); color: #7a5b1e; }

.type.is-lore { border-color: var(--ink); color: var(--ink); }

.relations { padding: 120px 0 72px; }

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

.legend .type { margin-top: 0; }

.rel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 1.4fr) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  padding: 20px 0;
  border-top: 1px solid var(--line);
}

.node {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
}

.node img, .node .img-miss {
  position: relative;
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--civ, var(--gold));
  background: var(--line);
}

.node-name { min-width: 0; font-size: 20px; overflow-wrap: anywhere; }

.rel-label { flex-wrap: wrap; }

.rel-mid p { overflow-wrap: anywhere; }

.rel-mid { min-width: 0; }

.rel-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 20px;
}

.rel-label::before, .rel-label::after {
  content: "";
  height: 1px;
  width: 28px;
  background: var(--gold);
  flex: 0 0 28px;
}

.rel-end { justify-content: flex-end; text-align: right; }

.rel-end .node { flex-direction: row-reverse; }

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

.detail {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--paper);
  color: var(--ink);
}

.detail[open] { display: flex; flex-direction: column; }

.detail::backdrop { background: rgba(30, 36, 51, 0.45); }

.detail-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.detail-bar .btn { min-height: 38px; padding-inline: 12px; border-radius: 4px; font-size: 13px; }
.detail-home { display: inline-flex; align-items: center; min-height: 44px; margin-right: 12px; color: var(--muted); font-size: 13px; text-decoration: none; }
.detail-home:hover { color: var(--ink); }

#detail-history { margin-right: auto; }

.detail-scroll { flex: 1; overflow: auto; scroll-behavior: auto; overflow-anchor: none; }

.detail-inner {
  width: min(var(--content), calc(100% - 96px));
  margin: 24px auto 72px;
}

.pano {
  position: relative;
  aspect-ratio: 21 / 9;
  border-radius: 6px;
  overflow: hidden;
  background: var(--line);
  margin-bottom: 28px;
}

.pano img, .pano .img-miss { width: 100%; height: 100%; object-fit: cover; }

.pano .img-miss { position: absolute; inset: 0; }

.zoom-fab {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 1;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(247, 244, 238, 0.94);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.pano-name {
  margin: -8px 0 28px;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--gold);
}

.pano-name h2 { margin: 0 0 8px; font-size: clamp(32px, 4vw, 52px); }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr);
  gap: 36px;
  align-items: start;
}

.prose { width: 100%; max-width: 40em; min-width: 0; }

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

.plate-count { color: var(--muted); font-size: 15px; }

.jump-wrap {
  position: sticky;
  top: 0;
  z-index: 2;
  isolation: isolate;
  max-width: 100%;
  min-width: 0;
  margin: 8px 0 28px;
  background: var(--paper);
}

.jump {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
  padding: 8px 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  background: var(--paper);
  scrollbar-width: none;
}

.jump::-webkit-scrollbar { display: none; }

.jump button {
  flex: 0 0 auto;
  white-space: nowrap;
  min-height: 44px;
  height: 44px;
  padding: 0 12px;
  border: 2px solid var(--gold);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
}

.jump button[aria-current="true"] {
  background: var(--gold);
  color: var(--ink);
}

.jump-fade {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28px;
  pointer-events: none;
  opacity: 0;
}

.jump-fade-left {
  left: 0;
  background: linear-gradient(to right, var(--paper) 20%, rgba(247, 244, 238, 0));
}

.jump-fade-right {
  right: 0;
  background: linear-gradient(to left, var(--paper) 20%, rgba(247, 244, 238, 0));
}

.jump-wrap.can-left .jump-fade-left,
.jump-wrap.can-right .jump-fade-right { opacity: 1; }

.section { margin: 0 0 40px; scroll-margin-top: 128px; }

.plate { margin: 1.2em 0 1.6em; }

.plate-frame {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--gold);
  background: var(--paper);
}

.plate-frame img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  background: var(--paper);
}

.plate-frame.has-ratio img,
.plate-frame.has-ratio .img-miss {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.plate-frame .img-miss {
  position: relative;
  min-height: 180px;
}

.plate figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-top: 8px;
  color: rgba(30, 36, 51, 0.72);
  font-size: 14px;
  line-height: 1.5;
}

.plate figcaption .type { margin: 0; }

.plate-caption { display: inline; }

.section .type { margin: 6px 0 10px; }

.facts {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 16px 16px;
  background: rgba(255, 255, 255, 0.45);
}

.facts summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-family: var(--serif);
  list-style: none;
}

.facts summary::-webkit-details-marker { display: none; }

.facts summary::marker { content: ""; }

.facts summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-right: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  transform: translateY(-2px) rotate(45deg);
  flex: 0 0 auto;
}

.facts[open] summary::after { transform: translateY(2px) rotate(225deg); }

.swatch {
  display: inline-block;
  width: 28px;
  height: 14px;
  border-radius: 99px;
  border: 1px solid var(--line);
  vertical-align: middle;
}

.facts dt { margin-top: 12px; color: var(--muted); font-size: 13px; }

.facts dd { margin: 0; }

.related { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.related a {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.related img, .related .img-miss {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--civ, var(--gold));
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.gallery figure { margin: 0; min-width: 0; }

.shot {
  position: relative;
  aspect-ratio: 3 / 2;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--gold);
  background: var(--line);
}

.shot img, .shot .img-miss { width: 100%; height: 100%; object-fit: cover; }

.gallery figcaption { margin-top: 8px; color: var(--muted); font-size: 14px; line-height: 1.5; }

.gallery figcaption .btn { margin-top: 8px; }

.sources { margin-top: 28px; }

.sources summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }

.sources li { overflow-wrap: anywhere; }

.sources code { font-family: var(--mono); font-size: 13px; }

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

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 5;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  padding: 12px;
  overflow: hidden;
  background: rgba(30, 36, 51, 0.92);
}

.lightbox-panel {
  width: min(1100px, 100%);
  max-height: 100%;
  min-height: 0;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lightbox-actions { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.lightbox-scroll {
  min-height: 0;
  overflow: auto;
  max-height: calc(100dvh - 88px);
}

.lightbox img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 150px);
  margin: 0 auto;
  object-fit: contain;
  background: transparent;
}

#light-cap {
  margin: 8px 0 0;
  color: #f7f4ee;
  text-align: center;
  overflow-wrap: anywhere;
}

.lightbox .btn-line { color: #f7f4ee; border-color: #f7f4ee; background: transparent; }

@media (min-width: 1024px) {
  .jump {
    flex-wrap: wrap;
    row-gap: 8px;
    overflow: visible;
  }
  .jump-fade { display: none; }
}

@media (min-width: 768px) {
  .frame,
  .card.is-lead .frame {
    aspect-ratio: auto;
    height: clamp(260px, 28vw, 420px);
  }
}

@media (max-width: 1099px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .wrap, .detail-inner { width: min(var(--content), calc(100% - 48px)); }
}

@media (max-width: 980px) {
  .hero { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .hero-media { height: clamp(260px, 55vw, 500px); }
  .hero-media img { object-position: center 42%; }
  .hero-copy { padding: 36px 32px 40px; }
  .hero h1 { font-size: 40px; }
  .hero h1 span { display: inline; }
  .hero .eyebrow { margin-bottom: 16px; }
  .hero-note { margin-top: 28px; }
  .tools { grid-template-columns: minmax(0, 1fr); }
  .nav-brand small { display: none; }
  .nav-links { gap: 20px; }
}

@media (max-width: 767px) {
  .wrap, .detail-inner { width: calc(100% - 32px); }
  .nav-inner { min-height: 66px; gap: 16px; }
  .nav-identity { gap: 14px; }
  .nav-brand > span { font-size: 20px; }
  .nav-links { gap: 14px; }
  .nav-links .nav-wide { display: none; }
  .nav-back { font-size: 12px; gap: 4px; }
  .hero-copy { padding: 30px 24px 36px; }
  .hero h1 { font-size: clamp(30px, 7.8vw, 40px); margin-bottom: 18px; }
  .hero h1 span { display: block; }
  .hero-actions { margin-top: 24px; gap: 16px 20px; }
  .hero-note { margin-top: 24px; padding-top: 16px; }
  .atlas-head { display: block; margin-bottom: 24px; }
  .atlas-head p { margin-top: 12px; }
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 4px;
  }
  .chip { flex: 0 0 auto; }
  .atlas { padding-top: 36px; }
  .group { margin-top: 72px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .card-name { font-size: 18px; }
  .card.is-lead .card-name { font-size: 22px; }
  .relations { padding-top: 72px; }
  .rel, .rel-end .node, .rel-end { display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
  .rel { align-items: stretch; gap: 10px; }
  .pano { aspect-ratio: 16 / 9; }
  .detail-inner { margin-top: 16px; }
  .lightbox {
    padding: 0;
    background: rgba(14, 18, 30, 0.97);
  }
  .lightbox-panel {
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    margin: 0;
    gap: 16px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .lightbox-actions { padding: 0 12px; }
  .lightbox-scroll {
    flex: 1 1 auto;
    max-height: none;
  }
  .lightbox img {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: none;
  }
}

@media (max-width: 959px) {
  .detail-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .facts {
    order: -1;
    width: 100%;
    border: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 0 0 8px;
    background: transparent;
  }
  .facts summary { width: 100%; padding: 0 2px; }
  .pano-name { border-bottom-width: 1px; }
}

@media (min-width: 960px) {
  .facts { position: sticky; top: 12px; }
  .facts summary { display: none; }
  .facts summary::after { display: none; }
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .frame img { transition: transform 240ms ease-out; }
  .card-hit:hover .frame img { transform: scale(1.04); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .frame img { transform: none !important; }
}

/* Portrait covers stay whole so their city silhouette and printed text remain visible. */
.portal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; }
.card.is-portal { grid-column: auto; }
.card.is-portal { border-bottom: 1px solid var(--line); }
.card.is-portal .frame { width: 100%; height: auto; aspect-ratio: 3 / 4; }
.card.is-portal .frame img { object-fit: contain; transform: none; }
.card.is-portal .card-body { width: 100%; }
.card-enter { display: block; margin-top: 14px; color: var(--ink); font-size: 14px; }
.card-hit:hover .card-enter { text-decoration: underline; text-underline-offset: 4px; }

@media (max-width: 1099px) {
  .portal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
}
@media (max-width: 540px) {
  .portal-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .card.is-portal .card-name { font-size: 22px; }
}

@media (max-width: 380px) {
  .nav-links a[href="chronicles/books/"] { display: none; }
}
