:root {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: #f4e8d2;
  background: #191612;
  color-scheme: dark;
  --edge: #443b30;
  --muted: #c8b393;
  --accent: #e6bb76;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: radial-gradient(ellipse at 50% 38%, #3a3025 0, #242019 55%, #191612 100%);
}
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0 .7rem;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: #28221b;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-size: .88rem;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: #3c3124; border-color: #91764f; }
button:disabled { opacity: .42; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem clamp(1rem, 4vw, 4rem);
  border-bottom: 1px solid var(--edge);
  background: #1c1813;
}
.edition {
  margin: 0 0 .18rem;
  font-size: .62rem;
  font-weight: 650;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent);
}
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; }
h1 { font-size: clamp(1.45rem, 3.2vw, 2.2rem); line-height: 1.12; }
.reader { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
.stage { overflow: auto; overscroll-behavior: contain; }
.surface {
  position: relative;
  display: grid;
  place-items: center;
  width: max(100%, var(--surface-width, 0px));
  height: max(100%, var(--surface-height, 0px));
  isolation: isolate;
  perspective: 1600px;
}
.frame {
  grid-area: 1 / 1;
  position: relative;
  display: flex;
  height: var(--page-height);
  box-shadow: 0 18px 42px #090603ad, 0 2px 8px #0e0a07bd;
  touch-action: pan-x pan-y pinch-zoom;
}
.frame[data-zoom="1"] { touch-action: pan-y pinch-zoom; }
.frame img {
  width: auto;
  height: 100%;
  display: block;
  background: #fffaf0;
  user-select: none;
  -webkit-user-drag: none;
}
.frame.spread::after {
  position: absolute;
  content: "";
  inset: 0 auto 0 var(--gutter);
  width: 16px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, #16100b45 50%, transparent);
  pointer-events: none;
}
.frame.cover { border-radius: 2px 5px 5px 2px; overflow: hidden; }
.frame.cover::after {
  position: absolute;
  content: "";
  inset: 0 auto 0 0;
  width: 12px;
  background: linear-gradient(90deg, #100b0870, transparent);
  pointer-events: none;
}
.loading { color: var(--muted); text-align: center; padding: 1rem; }
.loading button { margin-top: .65rem; }
.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem clamp(.5rem, 3vw, 2rem);
  padding: .65rem .45rem max(.65rem, env(safe-area-inset-bottom));
  background: #1c1813;
  border-top: 1px solid var(--edge);
}
.controls > div { display: flex; align-items: center; gap: .25rem; }
#jump, #zoom-reset { font-variant-numeric: tabular-nums; }
#jump { min-width: 103px; color: var(--accent); }
#zoom-reset { min-width: 58px; }
#zoom-out, #zoom-in { font-size: 1.25rem; }
dialog {
  width: min(26rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  border: 1px solid #69563d;
  border-radius: 12px;
  padding: 1.1rem;
  background: #221c16;
  color: inherit;
  box-shadow: 0 24px 90px #000b;
}
dialog::backdrop { background: #110d0ac9; }
.picker-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.picker-heading button { font-size: 1.4rem; }
.page-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); gap: .38rem; }
.page-list button[aria-current="page"] { border-color: var(--accent); color: var(--accent); background: #3b2c1d; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.noscript { position: fixed; inset: 35% 1rem auto; text-align: center; background: #1c1813; padding: 1rem; }
body.immersive { position: fixed; inset: 0; z-index: 10; grid-template-rows: minmax(0, 1fr); }
.immersive .masthead { position: fixed; top: .5rem; right: .5rem; z-index: 11; padding: 0; border: 0; background: transparent; }
.immersive .masthead > div { display: none; }
@media (max-width: 600px) {
  .masthead { padding: .58rem .75rem; }
  #fullscreen span { display: none; }
  .controls { gap: .4rem; }
  .controls button { padding-inline: .3rem; }
  #jump { min-width: 90px; }
  #zoom-reset { min-width: 50px; }
}
.surface { padding-top: var(--top-offset, 0px); overflow: clip; }
.turning {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  backface-visibility: hidden;
  box-shadow: 5px 8px 24px #0e090875;
}
.turning.forward { transform-origin: left center; }
.turning.backward { transform-origin: right center; }
.turning img, .turning .frame { display: block; width: 100%; height: 100%; }
.turning .frame { box-shadow: none; }
.turning > span { position: absolute; inset: 0; background: linear-gradient(90deg, #120d08a0, transparent); opacity: 0; }
.surface .loading { grid-area: 1 / 1; z-index: 2; border-radius: .5rem; background: #211a13; }
