:root {
  color-scheme: dark;
  --ink: #101210;
  --sheet: #191b18;
  --text: #e6dfd1;
  --dim: #b0aea2;
  --faint: #93968b;
  --gold: #c99e5a;
  --celadon: #91ada5;
  --rule: rgb(211 202 176 / .19);
  --gutter: clamp(20px, 4vw, 78px);
  --head: 72px;
  --serif: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", SimSun, serif;
}
* { box-sizing: border-box }
body { margin: 0; background: var(--ink); color: var(--text); font: 14px/1.6 system-ui, "Microsoft YaHei", sans-serif }
a { color: inherit; text-decoration: none }
button { padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer }
button, a { -webkit-tap-highlight-color: transparent }
:where(a, button, input, summary):focus-visible { outline: 2px solid var(--gold); outline-offset: 4px }
a:hover, button:hover { color: #fff4d8 }

header { height: var(--head); padding: 0 var(--gutter); display: flex; align-items: center; gap: 19px; border-bottom: 1px solid var(--rule); position: relative; z-index: 4 }
.brand { font: 500 26px/1.4 var(--serif); letter-spacing: .11em; white-space: nowrap }
.mast-rule { height: 16px; width: 1px; background: var(--rule) }
.folio, header nav, .finder-open, .overline, footer { font-size: 12px; color: var(--dim); letter-spacing: .09em }
header nav { display: flex; margin-left: auto; align-items: center; gap: clamp(16px, 2.6vw, 40px); white-space: nowrap }
header nav a { padding: 8px 0 }
header nav a[aria-current] { color: var(--text); text-decoration: underline; text-decoration-color: #ab925f; text-underline-offset: 7px; text-decoration-thickness: 1px }
#finder-slot { padding-left: 18px; border-left: 1px solid var(--rule) }
.finder-open { display: flex; gap: 9px; align-items: center; min-height: 36px }
.finder-open i { display: block; position: relative; width: 13px; height: 13px; border: 1px solid currentColor; border-radius: 50%; margin-right: 3px }
.finder-open i::after { content: ""; position: absolute; right: -5px; bottom: -2px; width: 6px; border-top: 1px solid; transform: rotate(43deg) }
#reader { position: relative; isolation: isolate; height: calc(100vh - var(--head)); height: calc(100svh - var(--head)); min-height: 350px; overflow: hidden; background: #040507 }
.stage { position: absolute; inset: -12% 0 9% 21%; z-index: -1 }
.absolute.inset-0 { position: absolute; inset: 0 }
.stage canvas { touch-action: none }
.intro, .reader-card { position: absolute; left: var(--gutter); bottom: clamp(72px, 9vh, 112px) }
.intro { max-width: min(400px, 35vw); pointer-events: none }
.intro button { pointer-events: auto }
.overline { display: flex; gap: 12px; align-items: center; color: #c5bfac; font-size: 11px; letter-spacing: .18em }
.overline > i { width: 28px; height: 1px; background: #a68755 }
.intro h1 { font: 500 clamp(42px, 4.5vw, 72px)/1.35 var(--serif); letter-spacing: .10em; margin: 10px 0 13px }
.opening-question { text-align: left; text-wrap: balance; font: 18px/1.85 var(--serif) }
.opening-question span { color: var(--gold); white-space: nowrap }
.intro-actions { margin-top: 16px; display: flex; align-items: center; gap: 22px }
.intro-actions button, .next { padding: 4px 0; font-size: 12px; color: var(--dim) }
.intro-actions .primary { color: #d7c49e; border-bottom: 1px solid #9c815944 }

.reader-card, .lookup { background: rgb(25 28 24 / .95); border-top: 1px solid #a6885f88 }
.reader-card { width: min(388px, 36vw); padding: 22px 25px 20px; max-height: calc(100% - 105px); overflow-y: auto; scrollbar-width: thin }
.panel-line, .actions { display: flex; align-items: center; gap: 13px }
.panel-line { justify-content: space-between }
.close { min-width: 25px; min-height: 27px; color: var(--dim); font: 20px/1 system-ui }
.reader-card h2, .lookup h2 { margin: 9px 0 7px; font: 500 23px/1.8 var(--serif); letter-spacing: .08em }
.reader-card p { margin: 5px 0 10px; color: #d6d2c5; line-height: 1.85 }
.reader-card .quote { margin: 10px 0; padding: 2px 0 2px 13px; border-left: 1px solid var(--gold); color: var(--text); font: 19px/1.85 var(--serif) }
.reader-card small { font-size: 12px; color: var(--dim); display: block }
.source-line a { margin-left: .65em; color: var(--celadon); white-space: nowrap }
.progress { display: inline-flex; align-items: center; gap: 5px }
.progress i { width: 5px; height: 5px; border-radius: 50%; background: #62665a }
.progress .now { background: #d6b479; box-shadow: 0 0 0 1px #d6b479 }
.progress .passed { background: #af9f7e }
.actions { margin-top: 15px; flex-wrap: wrap }
.text-link { padding: 5px 13px; background: #ccb990; color: #24261f; font-size: 13px; letter-spacing: .04em }
.text-link:hover { color: #161811; background: #decca4 }
.next:hover, .intro-actions button:hover { color: var(--text) }
.related { border-top: 1px solid var(--rule); margin-top: 12px; padding-top: 7px; display: flex; flex-wrap: wrap; gap: 2px 13px; max-height: 24vh; overflow: auto }
.related button { font: 14px/1.8 var(--serif); padding: 3px 0; text-align: left }
.case-peek { margin: 8px 0 3px; padding: 1px 0 0 12px; border-left: 1px solid #77958b; text-align: left }
.case-peek strong { font: 500 18px/1.8 var(--serif); display: block }
.case-peek span, .margin-note { font-size: 13px; color: var(--dim) }
.margin-note { margin: 8px 0 }
.margin-note summary { cursor: pointer; width: fit-content }
.lookup { position: absolute; z-index: 3; right: var(--gutter); top: 12px; width: min(365px, calc(100% - 28px)); max-height: calc(100% - 70px); overflow: auto; padding: 17px 23px 25px; scrollbar-width: thin; animation: unroll .22s ease-out }
@keyframes unroll { from { opacity: .2; transform: translateY(-8px) } }
.lookup h2 { margin: 0 }
.search-label { display: block; margin: 12px 0 4px }
.lookup input[type=search] { width: 100%; padding: 8px; border: 0; border-bottom: 1px solid #988765; color: var(--text); background: #111510; font: inherit }
.verified-filter { display: flex; gap: 8px; align-items: center; min-height: 35px; font-size: 12px; color: var(--dim) }
.verified-filter input { accent-color: var(--celadon) }
.lookup h3 { color: #c4b18c; font: 12px/1.6 system-ui; letter-spacing: .09em; margin: 12px 0 4px }
.listitem { width: 100%; text-align: left; border-bottom: 1px solid var(--rule); padding: 6px 0; font: 15px/1.6 var(--serif) }
.lookup p a, .fallback a { color: #deccaa; text-decoration: underline }
footer { position: absolute; inset: auto 0 0; display: flex; justify-content: space-between; align-items: center; padding: 8px var(--gutter) 14px; pointer-events: none; color: var(--faint) }
footer a, footer button { pointer-events: auto }
.canvas-controls { display: flex; align-items: center; gap: 18px }
.canvas-controls button { font-size: 12px; color: var(--dim); min-height: 32px }
.touch-hint { display: none }
.loading, .fallback { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); text-align: center }
@media(max-width:720px) {
  :root { --head: 56px; --gutter: 16px }
  header { gap: 10px }
  .brand { font-size: 20px; letter-spacing: .07em }
  .folio, .mast-rule, .finder-open span, .gesture { display: none }
  header nav { gap: 12px; font-size: 12px; letter-spacing: 0 }
  #finder-slot { padding-left: 9px }
  .finder-open { justify-content: center; min-width: 24px }
  .touch-hint { display: inline }
  .stage { inset: -4% 0 23% }
  .intro, .reader-card { bottom: 58px }
  .intro { max-width: min(27em, 90vw) }
  .intro h1 { font-size: 40px; margin: 5px 0 7px }
  .opening-question { font-size: 16px }
  .intro-actions { margin-top: 6px }
  .intro-actions button { min-height: 32px }
  .reader-card { width: calc(100% - 2 * var(--gutter)); max-height: 45%; padding: 13px 17px }
  .reader-card h2 { font-size: 20px; margin: 4px 0 }
  .reader-card .quote { font-size: 17px }
  .reader-card .related { max-height: none }
  .lookup { top: 6px; padding: 12px 18px 20px }
  footer { padding-bottom: max(7px, env(safe-area-inset-bottom)); font-size: 11px; letter-spacing: 0 }
  .canvas-controls { gap: 10px }
}
@media(max-width:410px) {
  :root { --gutter: 12px }
  header { gap: 6px }
  header nav { gap: 7px; font-size: 11px }
  .brand { font-size: 18px }
  .touch-hint { display: none }
}
@media(max-height:560px) {
  #reader { min-height: 0 }
  .reader-card, .intro { bottom: 42px }
  .reader-card { max-height: calc(100% - 55px); padding: 10px 17px }
  .intro h1 { font-size: 32px; margin: 3px 0 }
  .intro-actions { margin-top: 3px }
}
@media(prefers-reduced-motion:reduce) { .lookup { animation: none } }

/* The opening plate is all canvas. The menu brings its reading controls back into view. */
body:has(.map-menu) header { position: absolute; inset: 0 0 auto; padding-right: 76px; background: var(--ink) }
body:has(.map-menu[aria-expanded="false"]) header,
#reader:has(.map-menu[aria-expanded="false"]) :is(.intro, footer) { display: none }
#reader:has(.map-menu) { height: 100vh; height: 100svh }
#reader .stage { inset: 0 }
.map-menu { position: fixed; top: 12px; right: 16px; width: 44px; height: 44px; z-index: 6; color: var(--dim); font: 20px/1 system-ui }
body:has(.map-menu[aria-expanded="true"]) #reader { isolation: auto; z-index: auto }
body:has(.map-menu[aria-expanded="true"]) .stage { z-index: 0 }
body:has(.map-menu[aria-expanded="true"]) :is(.reader-card,.intro,footer) { z-index: 1 }
@media(max-width:720px) {
  body:has(.map-menu) header { flex-wrap: wrap; height: auto; min-height: 58px; padding: 8px 58px 8px 12px; gap: 6px 10px }
  .map-menu { top: 4px; right: 5px }
  #reader:has(.reader-card) .stage { bottom: 25% }
}


#reader:has(.map-light[aria-pressed="true"]) {
  background: radial-gradient(ellipse 43% 47% at 36% 43%, #192526 0%, #11191c 36%, #090d10 67%, transparent 100%), #040507;
}
.map-light { position: absolute; z-index: 3; right: 62px; top: 12px; width: 44px; height: 44px; display: grid; place-items: center; color: var(--dim) }
.map-light i { width: 14px; height: 14px; border-radius: 50%; border: 1px solid currentColor; background: linear-gradient(90deg,currentColor 50%, transparent 50%); transform: rotate(-35deg) }
.map-light[aria-pressed="false"] i { background: transparent }
#reader:has(.map-menu[aria-expanded="true"]) .map-light { visibility: hidden }
@media(max-width:720px) {
  .map-light { top: 4px; right: 47px }
  #reader .stage { top: -6%; bottom: 6% }
  #reader:has(.map-light[aria-pressed="true"]) {
    background: radial-gradient(ellipse 72% 33% at 30% 40%, #192526 0%, #11191c 36%, #090d10 67%, transparent 100%), #040507;
  }
}
