:root {
  color-scheme: dark;
  --gold: #efd197;
  --cream: #f7e9c9;
  --ink: #192e27;
  --serif: Georgia, 'Songti SC', 'Noto Serif CJK SC', serif;
  font-family: system-ui, sans-serif;
  background: #142c27;
  color: var(--cream);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 51% 48%, #4a6350 0%, #2e4c3e 44%, #142a24 89%);
}
main {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto minmax(340px, 1fr) auto;
  padding: clamp(18px, 2.6vh, 34px) clamp(24px, 4vw, 76px) max(24px, env(safe-area-inset-bottom));
}
header, footer, .controls, .legend, .dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
header { z-index: 2; }
.brand { display: flex; gap: 11px; align-items: center; text-decoration: none; font: 700 23px var(--serif); color: var(--cream); }
.stamp {
  display: grid;
  place-items: center;
  width: 41px;
  aspect-ratio: 1;
  background: #d7bc83;
  color: #294133;
  border: 1px solid #f4dca0;
  border-radius: 5px;
  transform: rotate(-6deg);
  font: 28px Georgia, serif;
  box-shadow: 1px 4px 8px #09171355;
}
.brand small { display: block; font: 10px ui-monospace, monospace; letter-spacing: .15em; margin-top: 4px; }
.tools { display: flex; gap: 7px; }
button {
  font: inherit;
  font-size: 14px;
  color: inherit;
  cursor: pointer;
  border: 1px solid #ead7a462;
  background: #213c33e6;
  border-radius: 99px;
  padding: 7px 14px;
  min-height: 44px;
}
button:hover { background: #41614d; }
button:focus-visible, input:focus-visible, a:focus-visible, #stage:focus-visible {
  outline: 2px solid #ffe099;
  outline-offset: 4px;
}
button:disabled { opacity: .4; cursor: default; }
.intro { z-index: 1; pointer-events: none; align-self: start; margin-top: clamp(24px, 4.8vh, 56px); width: fit-content; }
small { font-size: 13px; letter-spacing: .14em; color: var(--gold); }
.intro small::before { content: ''; display: inline-block; width: 20px; height: 1px; margin-right: 9px; vertical-align: middle; background: #e2cb90a8; }
h1 { margin: 5px 0 0; font: 750 clamp(42px, 4.8vw, 80px)/1.12 var(--serif); letter-spacing: .025em; text-shadow: 0 3px 17px #132c23; }
.intro p { margin: 9px 0 0; color: #f1e1b8; font-size: 14px; letter-spacing: .16em; text-shadow: 0 2px 8px #10271f; }
#stage {
  position: absolute;
  inset: max(74px, 8svh) 0 6px;
  min-width: 0;
  touch-action: none;
  cursor: grab;
  overflow: hidden;
}
#stage[data-dragging] { cursor: grabbing; }
canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
}
.marker[hidden] { display: none; }
.marker::before {
  content: '';
  width: 19px;
  aspect-ratio: 1;
  border: 1px solid #ffe6a2;
  border-radius: 50%;
  background: radial-gradient(circle, #fff0b4 0 2px, #52381980 3px, #463d21a0 70%);
  box-shadow: 0 0 0 3px #eac87b55, 0 2px 10px #23180f90;
}
.marker:hover { background: transparent; }
.marker:hover::before { box-shadow: 0 0 0 6px #ffe0a380, 0 2px 14px #27181190; }
footer { grid-row: 4; position: relative; align-items: end; gap: 24px; z-index: 1; pointer-events: none; }
footer::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: -48px calc(-1 * clamp(24px, 4vw, 76px)) calc(-1 * max(24px, env(safe-area-inset-bottom)));
  background: linear-gradient(transparent, #142a23db 55%, #142a23);
  pointer-events: none;
}
.story { max-width: 485px; }
.story p { margin: 5px 0 3px; font: clamp(19px, 1.9vw, 27px)/1.48 var(--serif); text-shadow: 0 2px 7px #1a2a21; }
.story-actions { display: flex; align-items: center; gap: 22px; }
.text-button {
  pointer-events: auto;
  padding: 0 1px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--gold);
  text-decoration: underline;
  text-decoration-color: #f3de9c87;
  text-underline-offset: .35em;
}
.text-button:hover { background: transparent; color: #fff2c5; }
nav {
  width: min(390px, 43%);
  pointer-events: auto;
  border: 1px solid #ebdbab59;
  background: #142d26ed;
  padding: 10px 14px;
  border-radius: 13px;
  box-shadow: 0 9px 24px #081a1944;
}
.legend { font-size: 13px; color: var(--gold); margin-bottom: 3px; }
#page { white-space: nowrap; font-variant-numeric: tabular-nums; }
.controls button { flex: 0 0 44px; padding: 0; font-size: 29px; line-height: 1; }
.controls input { flex: 1; min-width: 45px; margin: 0; accent-color: #e6c582; cursor: ew-resize; }
dialog {
  max-width: min(92vw, 470px);
  width: 100%;
  border: 1px solid #bd9f6b;
  border-radius: 14px;
  padding: 22px;
  background: #1c392f;
  color: var(--cream);
}
dialog::backdrop { background: #0a1512c2; }
.dialog-head h2 { margin: 0; font: 700 29px var(--serif); }
.dialog-head button { width: 44px; padding: 0; font-size: 23px; }
#links { display: grid; gap: 9px; margin: 18px 0; }
.chapterLink { display: flex; align-items: center; gap: 16px; text-align: left; border-radius: 7px; }
.chapterLink[aria-current=true] { border-color: #dec181; background: #3c5641; }
.chapterLink b { color: var(--gold); }
.credit { margin-bottom: 0; font-size: 14px; line-height: 1.7; color: #ded4ba; }
.credit a { color: var(--gold); }
#reading-text { font: 20px/1.8 var(--serif); margin: 16px 0 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 720px) {
  main { padding: 16px 16px max(16px, env(safe-area-inset-bottom)); grid-template-rows: auto auto minmax(278px, min(48svh, 420px)) auto; align-content: start; }
  .brand { font-size: 18px; gap: 7px; }
  .brand small { font-size: 8px; letter-spacing: .07em; }
  .stamp { width: 32px; }
  .tools { gap: 5px; }
  .tools button { padding: 4px 8px; font-size: 13px; }
  .intro { margin-top: 24px; }
  .intro h1 { font-size: clamp(37px, 10vw, 54px); }
  .intro p { font-size: 13px; }
  #stage { position: relative; inset: auto; align-self: stretch; margin: 4px -16px 0; }
  footer { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; }
  footer::before { display: none; }
  .story p { font-size: 19px; }
  nav { width: 100%; padding: 8px 12px; }
}
@media (max-width: 360px) {
  .brand small { display: none; }
  header { gap: 6px; }
  .brand { font-size: 15px; gap: 5px; }
  .stamp { width: 26px; }
  .tools button { padding-inline: 6px; font-size: 12px; }
}
