:root {
  color-scheme: light;
  --ink: #302c24;
  --muted: #655e4e;
  --paper: #f4eddb;
  --edge: #aa9b7b;
  --seal: #863e2e;
  --white: #fff9eb;
  --song: "Songti SC", STZhongsong, "华文中宋", "Noto Serif CJK SC", SimSun, "宋体", serif;
  --kai: "Kaiti SC", STKaiti, KaiTi, "楷体", var(--song);
  --brush: STXingkai, "华文行楷", var(--kai);
  --gutter: clamp(20px, 3.4vw, 60px);
  --shadow: 0 1px 2px #151713, 0 2px 6px #171b17c9;
  background: #c4cecb;
  color: var(--ink);
  font-family: var(--song);
}
* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; }
button, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid #ae502f; outline-offset: 2px;
}
#viewport { position: fixed; inset: 0; }
#opening { display: block; width: 100%; height: 100%; object-fit: cover; }
body:not([data-ready="true"]) #viewport canvas { visibility: hidden; }
#viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.masthead, footer { position: fixed; left: 0; right: 0; pointer-events: none; }
.masthead {
  top: 0; padding: clamp(24px, 3.4vh, 44px) var(--gutter) 0;
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px 24px; align-items: start;
}
.identity {
  --title-size: clamp(50px, 4vw, 62px);
  display: grid; grid-template-areas: ". era" "seal title";
  grid-template-columns: max-content max-content; align-items: center;
  gap: 3px 13px; color: var(--white); text-shadow: var(--shadow);
}
.identity small { grid-area: era; justify-self: center; font: 500 15px/1.3 var(--kai); letter-spacing: .12em; word-spacing: .12em; white-space: nowrap; }
.identity h1 {
  grid-area: title; height: var(--title-size); margin: 0; padding-top: .07em;
  font: 400 var(--title-size)/1 var(--brush); letter-spacing: .055em; white-space: nowrap;
}
.seal {
  grid-area: seal; display: grid; place-content: center;
  width: calc(var(--title-size) * .56); height: var(--title-size);
  border: 1px solid #f5e4c6; outline: 1px solid #893e2b; box-shadow: inset 0 0 0 3px #973e2c, inset 0 0 0 4px #ead5af;
  background: #973e2c; color: #fff3dc; text-shadow: none;
  text-align: center; font: 400 calc(var(--title-size) * .35)/1.05 var(--kai);
}
.site-intro {
  grid-column: 1 / -1; margin: 0; width: min(30em, 100%); text-wrap: pretty;
  font: 400 clamp(13px, .95vw, 14px)/1.7 var(--song); color: #fff; text-shadow: var(--shadow);
}
.actions { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.actions button, .close-folio, #chapter {
  border: 1px solid #b3a387; background: var(--paper); color: var(--ink);
  min-height: 42px; padding: 0 16px; font: 500 17px/1 var(--kai);
}
.actions button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; box-shadow: 0 2px 6px #211c1926; }
.actions #expand { width: 42px; padding: 0; }
.actions button:hover, .close-folio:hover { background: #fff9eb; color: var(--seal); }
.book-mark, .catalog-mark, .frame-mark { position: relative; display: inline-block; flex: none; }
.book-mark { width: 17px; height: 16px; border: 1.5px solid currentColor; border-radius: 1px; }
.book-mark::before { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; border-left: 1px solid; }
.book-mark::after { content: ""; position: absolute; top: 4px; left: 7px; width: 6px; height: 3px; border-block: 1px solid; }
.frame-mark { width: 18px; height: 18px; background:
  linear-gradient(currentColor,currentColor) left top / 7px 1.5px, linear-gradient(currentColor,currentColor) left top / 1.5px 7px,
  linear-gradient(currentColor,currentColor) right top / 7px 1.5px, linear-gradient(currentColor,currentColor) right top / 1.5px 7px,
  linear-gradient(currentColor,currentColor) left bottom / 7px 1.5px, linear-gradient(currentColor,currentColor) left bottom / 1.5px 7px,
  linear-gradient(currentColor,currentColor) right bottom / 7px 1.5px, linear-gradient(currentColor,currentColor) right bottom / 1.5px 7px;
  background-repeat: no-repeat;
}
:fullscreen .frame-mark { transform: scale(.75); outline: 1px solid; outline-offset: 4px; }
footer { bottom: 0; color: var(--white); background: linear-gradient(to top,#211f19b8 16%,#211f1980 55%,transparent); }
.view-info { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 42px var(--gutter) 18px; text-shadow: var(--shadow); }
.view-info h2 { margin: 0; font: 400 clamp(27px,2.5vw,37px)/1.15 var(--kai); letter-spacing: .09em; }
.view-info p { margin: 5px 0 0; max-width: 52em; font: 400 15px/1.7 var(--song); }
.gesture { white-space: nowrap; font: 13px/1.6 var(--song); }
.touch-hint { display: none; }
.view-bar {
  display: flex; align-items: stretch; gap: clamp(12px,2vw,32px); padding: 7px var(--gutter) 9px;
  background: var(--paper); color: var(--ink); border-top: 3px double var(--edge);
  pointer-events: auto; box-shadow: 0 -2px 8px #2a251b26;
}
#open-atlas { display: flex; align-items: center; justify-content: center; gap: 10px; flex: none; align-self: center; padding: 0 20px 0 0; min-height: 42px; border: 0; border-right: 1px solid var(--edge); background: none; color: var(--seal); font: 500 21px var(--kai); }
#open-atlas:hover { color: #5f2619; }
#open-atlas:disabled { opacity: .55; cursor: wait; }
.catalog-mark { width: 18px; height: 16px; border-block: 1.5px solid currentColor; }
.catalog-mark::before { content: ""; position: absolute; inset: 3px 0; border-block: 1px solid; }
#views { flex: 1; min-width: 0; display: flex; align-items: stretch; gap: 2px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: #a79b84 transparent; }
#views button {
  position: relative; flex: 1 0 auto; display: flex; justify-content: center; align-items: center; gap: clamp(6px,.8vw,12px);
  --fret-size: 15px;
  padding: 8px calc(var(--fret-size) + 2px); border: 0; background: none; font: 500 clamp(16px,1.4vw,20px)/1.25 var(--kai); white-space: nowrap;
}
.view-print { display: block; background: #d3c9b7 url("./assets/view-index.webp") no-repeat; background-size: 600% 400%; aspect-ratio: 8/5; }
#views .view-print { width: clamp(40px,4vw,76px); flex: none; box-shadow: inset 0 0 0 1px #493e2e35; }
#views button:hover, .atlas-entries button:hover { background-color: #e5d9c1; }
#views button[aria-current="true"] { color: #fff6e3; background: var(--seal); }
#views button[aria-current="true"]::before {
  content: ""; position: absolute; inset: 3px; pointer-events: none;
  border: var(--fret-size) solid transparent;
  /* Four fixed corners. Only the straight rails of the 4× artwork stretch. */
  border-image: url("./assets/view-fret.png") 64 stretch;
}
#views button:focus-visible { outline-offset: -3px; }
#views button[aria-current="true"]:focus-visible { outline: 2px solid #ffe1a6; outline-offset: -2px; }
#loading { position: fixed; left: 50%; top: 48%; transform: translate(-50%,-50%); margin: 0; padding: 14px 24px; border: 3px double #ae9670; background: var(--paper); font: 18px/1.5 var(--kai); }
#loading[hidden], .clean .masthead, .clean footer { display: none; }

dialog { width: min(930px,calc(100vw - 44px)); max-height: min(86dvh,840px); padding: 0; overflow: hidden; border: 1px solid #8d8067; color: var(--ink); background: var(--paper); box-shadow: 0 12px 52px #16140f52; }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #201f1bb8; }
.dialog-head { display: flex; align-items: center; gap: 12px; flex: none; padding: 17px 28px; border-bottom: 3px double var(--edge); }
.dialog-head h2 { margin: 0 auto 0 0; font: 400 32px/1.2 var(--kai); letter-spacing: .1em; }
.close-folio, #chapter { min-height: 36px; font-size: 16px; }
.close-folio { border-color: var(--seal); color: var(--seal); white-space: nowrap; }
#chapter { max-width: 13em; cursor: pointer; padding: 0 6px; }
.folio-scroll { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #aa9876 var(--paper); }
.atlas-groups { padding: 4px 28px 24px; }
.atlas-groups section { display: grid; grid-template-columns: 34px 1fr; gap: 16px; padding: 16px 0; border-bottom: 1px solid #c8baa0; }
.atlas-groups section:last-child { border-bottom: 0; padding-bottom: 0; }
.atlas-groups h3 { justify-self: start; align-self: start; margin: 0; padding: 4px 0; writing-mode: vertical-rl; font: 500 19px/1.5 var(--kai); letter-spacing: .12em; color: var(--seal); }
.atlas-entries { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 8px; align-content: start; }
.atlas-entries button { border: 1px solid transparent; background: transparent; padding: 3px 3px 5px; font: 500 16px/1.3 var(--kai); }
.atlas-entries .view-print { width: 100%; margin-bottom: 5px; }
.atlas-entries button[aria-current="true"] { color: var(--seal); border-color: var(--seal); }
#notes { max-width: 790px; }
.paper { margin: 6px 8px 9px; padding: 20px clamp(18px,5vw,64px) 32px; }
.paper > h2 { margin: 0 0 12px; font: 400 32px/1.3 var(--kai); }
.paper h3 { scroll-margin-top: 14px; margin: 26px 0 8px; padding-left: 10px; border-left: 3px solid var(--seal); color: var(--seal); font: 500 22px/1.3 var(--kai); }
.paper p, .paper li { margin: 0; font: 400 16px/1.9 var(--song); overflow-wrap: anywhere; }
.paper p + p { margin-top: 8px; }
.paper .lead { color: var(--muted); }
.paper ol { padding-left: 24px; }
.paper a { color: #703e2f; text-underline-offset: 3px; }
.paper details { border-block: 1px solid #cbbfa6; margin: 18px 0; padding: 12px 0; }
.paper summary { cursor: pointer; color: var(--seal); font: 18px/1.4 var(--kai); }
.reference-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px 12px; margin: 14px 0; }
.reference-grid a { min-width: 0; text-decoration: none; font-size: 13px; line-height: 1.6; }
.reference-grid img { width: 100%; aspect-ratio: 1.7; object-fit: contain; display: block; margin-bottom: 4px; background: #e5ddca; }
#supplements img { aspect-ratio: 1.3; }
@media (hover: none) and (pointer: coarse) {
  .mouse-hint { display: none; }
  .touch-hint { display: inline; }
}
@media (max-width: 990px) {
  #views button { --fret-size: 10px; flex-direction: column; padding: 6px 12px; gap: 4px; }
  #views .view-print { width: 48px; }
  #open-atlas { padding-right: 12px; font-size: 18px; }
  .view-bar { gap: 12px; }
}
@media (max-width: 680px) {
  :root { --gutter: 16px; }
  .masthead { padding-top: max(16px,env(safe-area-inset-top)); gap: 12px 6px; }
  .identity { --title-size: clamp(34px, 8.9vw, 46px); gap: 2px 9px; }
  .identity small { font-size: 12px; }
  .actions { gap: 4px; }
  .actions button { min-height: 40px; font-size: 15px; padding: 0 8px; gap: 6px; }
  .actions #expand { width: 40px; }
  .site-intro { font-size: 12.5px; line-height: 1.65; }
  .view-info { display: block; padding: 28px var(--gutter) 10px; }
  .view-info h2 { font-size: 25px; }
  .view-info p { font-size: 13px; line-height: 1.5; }
  .gesture { display: none; }
  .view-bar { padding: 5px 8px max(5px,env(safe-area-inset-bottom)); gap: 4px; }
  #open-atlas { padding: 3px 10px 3px 4px; flex-direction: column; font-size: 14px; gap: 4px; min-height: 48px; }
  #views { scrollbar-width: none; }
  #views button { --fret-size: 9px; min-width: 64px; font-size: 15px; padding: 5px 10px; }
  #views button[aria-current="true"]::before { inset: 2px; }
  #views .view-print { width: 42px; }
  dialog { width: calc(100vw - 20px); max-height: 90dvh; }
  .dialog-head { padding: 12px; gap: 6px; }
  .dialog-head h2 { font-size: 24px; }
  .close-folio, #chapter { min-height: 40px; font-size: 14px; }
  .close-folio { padding: 0 10px; }
  #chapter { max-width: 8em; }
  .atlas-groups { padding: 0 12px 12px; }
  .atlas-groups section { grid-template-columns: 22px 1fr; gap: 5px; padding: 10px 0; }
  .atlas-groups h3 { font-size: 17px; }
  .atlas-entries { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 4px; }
  .atlas-entries button { font-size: 15px; }
  .paper { margin: 0; padding: 18px; }
  .paper p,.paper li { font-size: 15px; }
  .reference-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 360px) {
  .actions .book-mark { display: none; }
}
@media (max-height: 520px) {
  .masthead { padding-top: 8px; gap: 6px; }
  .identity { --title-size: 32px; }
  .identity small { font-size: 11px; }
  .site-intro { width: min(44em,100%); font-size: 12px; line-height: 1.5; }
  .view-info { padding-top: 12px; padding-bottom: 6px; }
  .view-info h2 { font-size: 22px; }
  .view-info p { margin-top: 2px; font-size: 12px; }
  #views button { --fret-size: 9px; flex-direction: row; min-height: 36px; }
  #views .view-print { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color .15s ease-out,color .15s ease-out; }
  dialog[open] { animation: open-folio .18s ease-out; }
  @keyframes open-folio { from { opacity: 0; transform: translateY(5px); } }
}
