:root {
  color-scheme: light;
  --navy: #10254a;
  --navy-dark: #08152d;
  --ink: #152a4a;
  --coral: #f5ae92;
  --paper: #fff;
  --focus: #4c96ee;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--navy-dark);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; display: flex; flex-direction: column; }
button, input, a { font: inherit; }
button, a.outline { min-height: 2.625rem; padding: .5rem .875rem; border: 1px solid transparent; border-radius: .5rem; font-weight: 650; cursor: pointer; }
button[disabled] { opacity: .45; cursor: default; }
a { color: inherit; }
a.outline { display: inline-flex; align-items: center; text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.masthead {
  padding: .625rem clamp(.875rem, 3vw, 3rem);
  min-height: 4.5rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: .75rem;
  align-items: center;
  background: #fff;
  border-bottom: 3px solid var(--coral);
}
.brand { line-height: 0; justify-self: start; }
.brand img { width: clamp(7rem, 14vw, 10.25rem); height: auto; }
.masthead h1 { margin: 0; font-size: clamp(1.125rem, 2vw, 1.45rem); font-weight: 720; letter-spacing: -.03em; }
.masthead-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.masthead-actions button { background: var(--navy); color: #fff; }
.outline { color: var(--navy); background: white; border-color: #c0ccdf; }
.outline:hover { background: #edf3fa; }
.reader {
  flex: 1;
  display: grid;
  grid-template-rows: 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  background: radial-gradient(ellipse at 52% 20%, #263c60 0, #10254a 56%, #0a1831 100%);
}
.stage {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  padding: clamp(1rem, 3vh, 2rem) 1rem;
}
.book {
  --page-width: clamp(19rem, calc((100dvh - 13rem) * .7727), 37rem);
  display: flex;
  flex: 0 0 auto;
  position: relative;
  isolation: isolate;
  width: min(var(--page-width), 100%);
  perspective: 1500px;
  perspective-origin: 50% 45%;
  touch-action: pan-y pinch-zoom;
}
.page {
  position: relative;
  width: 100%;
  aspect-ratio: 612 / 792;
  flex: 0 0 auto;
  background: var(--paper);
  box-shadow: 0 1rem 2.8rem #0007, 0 .125rem .4rem #0009;
  border-radius: .2rem;
}
.page img, .turn img { display: block; width: 100%; height: 100%; object-fit: fill; border-radius: inherit; user-select: none; }
.book.spread { width: min(calc(var(--page-width) * 2), 100%); }
.spread .page { width: 50%; }
.spread .page:first-child { border-radius: .2rem 0 0 .2rem; }
.spread .page:nth-child(2) { border-radius: 0 .2rem .2rem 0; }
.spread .page::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 5.5%;
  background: linear-gradient(to left, #0a163122, transparent);
  pointer-events: none;
}
.spread .page:nth-child(2)::after { inset: 0 auto 0 0; transform: scaleX(-1); }
.hotspot { position: absolute; z-index: 1; display: block; border-radius: .1rem; }
.hotspot:hover { background: #569bf335; }
.turn {
  position: absolute;
  top: 0;
  height: 100%;
  z-index: 5;
  border-radius: .2rem;
  transform-origin: left center;
  pointer-events: none;
  backface-visibility: hidden;
  animation: turn-forward .47s cubic-bezier(.52,.05,.28,1) both;
}
.turn.back { transform-origin: right center; animation-name: turn-back; }
@keyframes turn-forward {
  0% { transform: rotateY(0deg); opacity: 1; }
  76% { opacity: .94; }
  100% { transform: rotateY(-100deg); opacity: 0; }
}
@keyframes turn-back {
  0% { transform: rotateY(0deg); opacity: 1; }
  76% { opacity: .94; }
  100% { transform: rotateY(100deg); opacity: 0; }
}
.controls {
  min-height: 4.5rem;
  padding: .65rem max(.75rem, env(safe-area-inset-left)) max(.65rem, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: .55rem;
  background: #0b1933e8;
  color: #fff;
  border-top: 1px solid #9eafce38;
}
.controls button { color: #f6f8fc; background: #1e3459; border-color: #567097; }
.controls button:hover:not([disabled]) { background: #304d79; }
.controls button.primary { color: #142747; background: var(--coral); border-color: var(--coral); }
.controls button.primary:hover:not([disabled]) { background: #ffc8af; }
.controls button[aria-pressed="true"] { background: #e6eefb; color: #142747; }
.reader-tools { display: flex; gap: .55rem; padding-left: .7rem; margin-left: .3rem; border-left: 1px solid #567097; }
.jump { display: flex; align-items: center; gap: .375rem; padding: 0 .25rem; font-size: .875rem; }
.jump input {
  width: 2.75rem;
  padding: .35rem .25rem;
  min-height: 2.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: #fff;
  color: var(--ink);
  border: 1px solid #8aa0c1;
  border-radius: .375rem;
}
.reader.zoomed .stage { justify-content: flex-start; align-items: flex-start; overflow: auto; max-height: calc(100dvh - 9rem); }
.reader.zoomed .book { --page-width: clamp(43rem, 105vw, 74rem); width: var(--page-width); margin-inline: auto; touch-action: auto; }
.loading, .notice { color: #fff; padding: 1rem; text-align: center; }
dialog {
  max-width: calc(100vw - 1.5rem);
  max-height: min(88dvh, 54rem);
  padding: 0;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-radius: .85rem;
  box-shadow: 0 2rem 5rem #070e22aa;
}
dialog::backdrop { background: #051225b5; }
.directory { width: 34rem; }
.transcript { width: 45rem; }
.dialog-inner { padding: clamp(1rem, 4vw, 1.6rem); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.dialog-heading h2 { margin: .2rem 0 1rem; font-size: 1.5rem; line-height: 1.25; }
#search { width: 100%; padding: .75rem; border: 1px solid #a6b7ce; border-radius: .5rem; }
.directory-shortcuts { display: flex; flex-wrap: wrap; gap: .45rem; margin: .85rem 0; }
.directory-shortcuts button { color: #183762; background: #e9f0fb; font-size: .875rem; padding-inline: .6rem; }
.toc { margin: .5rem 0 0; list-style: none; padding: 0; }
.toc button {
  width: 100%;
  background: #fff;
  color: #162c50;
  font-weight: 580;
  border-bottom: 1px solid #e1e7f0;
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: .3rem;
  text-align: left;
}
.toc button:hover, .directory-shortcuts button:hover { background: #e4eefb; }
.toc button[aria-current="page"] { background: #dceaff; }
.toc span:first-child { color: #365978; font-variant-numeric: tabular-nums; }
.text-body { line-height: 1.62; }
.text-body p { white-space: pre-line; }
.text-body a { color: #0c4b96; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
@media (max-width: 680px) {
  .masthead { grid-template-columns: 1fr auto; }
  .masthead h1 { grid-row: 2; grid-column: 1 / -1; }
  .masthead-actions { grid-row: 1; }
  .masthead-actions > * { padding-inline: .6rem; font-size: .875rem; }
  .stage { padding: .75rem; }
  .book { --page-width: 32rem; }
  .reader.zoomed .stage { max-height: calc(100dvh - 11rem); }
}
@media (max-width: 440px) {
  .controls { column-gap: .4rem; row-gap: .45rem; }
  .reader-tools { margin: 0; padding-left: 0; border: 0; }
  .controls button { padding-inline: .55rem; font-size: .875rem; }
  .jump { padding-inline: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .turn { display: none; animation: none; }
}
