/* The Amber Accord: one page of the book at a time on a candlelit table, laid out as it will print. */
:root {
  --table: #100b07;
  --table-warm: #2a1c11;
  --cream: #f4e9cf;
  --paper: #f3e7cb;
  --ink: #2b1d11;
  --ink-soft: #7a634a;
  --ink-cap: #6b3d14;
  --amber: #c9892d;
  --amber-glow: rgba(222, 160, 62, 0.4);
  --mist: 244, 233, 207;
  --ui-text: #ecdfc2;
  --ui-dim: #a8957a;
  --ui-line: rgba(244, 233, 207, 0.28);
  --serif: "IM Fell English", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --serif-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
  --aspect: 1;
  --bleed: 0px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body {
  margin: 0;
  min-height: 100svh;
  overflow-x: clip;
  background: radial-gradient(110% 70% at 50% 18%, var(--table-warm) 0%, var(--table) 62%) fixed, var(--table);
  color: var(--ui-text);
  font-family: var(--serif);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.reader {
  width: min(100%, calc((100svh - 206px) * var(--aspect)), 860px);
  min-width: min(100%, 300px);
  margin-inline: auto;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(28px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.topbar { margin-bottom: -6px; font-size: 16px; }
.topbar a { color: var(--ui-dim); text-decoration: none; font-family: var(--serif-sc); letter-spacing: 0.06em; }
.topbar a:hover { color: var(--ui-text); }
.topbar a:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }

/* ------------------------------------------------------------------ the page on the table */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: var(--aspect);
  background: var(--paper);
  border-radius: 0 3px 3px 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.62), 0 2px 6px rgba(0, 0, 0, 0.4);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* the edges of the pages still to come */
.stage::before {
  content: ""; position: absolute; top: 0.6%; bottom: 0.6%; right: -5px; width: 5px; border-radius: 0 2px 2px 0;
  background: repeating-linear-gradient(to right, #efe3c6 0 1px, #c4ae84 1px 1.7px);
  box-shadow: 3px 5px 10px rgba(0, 0, 0, 0.45);
}
.book { position: absolute; inset: 0; perspective: 2600px; perspective-origin: 0% 50%; }
.page { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 0 50%; visibility: hidden; }
.page.show { visibility: visible; }
.face {
  position: absolute; inset: 0; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--paper) radial-gradient(120% 90% at 50% 40%, rgba(255, 250, 235, 0.55), rgba(190, 150, 90, 0.16));
}
.front { border-radius: 0 3px 3px 0; }
.back { transform: rotateY(180deg); border-radius: 3px 0 0 3px; }
/* where the page curves into the spine */
.front::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background: linear-gradient(to right, rgba(60, 35, 12, 0.3), rgba(60, 35, 12, 0.09) 2.6%, rgba(60, 35, 12, 0) 7%);
}
.back::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to left, rgba(60, 35, 12, 0.3), rgba(60, 35, 12, 0) 7%);
}
.shade, .cast { position: absolute; inset: 0; pointer-events: none; opacity: 0; z-index: 6; }
.front .shade { background: linear-gradient(to left, rgba(30, 18, 6, 0.5), rgba(30, 18, 6, 0.18) 55%, rgba(30, 18, 6, 0.05)); }
.back .shade { background: linear-gradient(to right, rgba(30, 18, 6, 0.42), rgba(30, 18, 6, 0) 75%); }
.cast { background: linear-gradient(to right, rgba(20, 12, 4, 0.55), rgba(20, 12, 4, 0.12) 30%, rgba(20, 12, 4, 0) 60%); }

.turn-zone {
  position: absolute; top: 0; bottom: 0; width: 22%; z-index: 20;
  border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer;
}
.turn-zone.prev { left: 0; }
.turn-zone.next { right: 0; }
.turn-zone::after {
  content: ""; position: absolute; top: 50%; width: 14px; height: 14px;
  border: solid var(--ink); border-width: 0 2px 2px 0;
  opacity: 0; transition: opacity 0.2s;
}
.turn-zone.next::after { right: 18px; transform: translateY(-50%) rotate(-45deg); }
.turn-zone.prev::after { left: 18px; transform: translateY(-50%) rotate(135deg); }
.turn-zone:focus-visible { outline: none; }
.turn-zone:focus-visible::after { opacity: 0.8; }
@media (hover: hover) { .turn-zone:hover::after { opacity: 0.6; } }

/* ------------------------------------------------------------------ inside a page (shared with the print proof) */
.trim { position: absolute; inset: var(--bleed); container-type: inline-size; }
.pic { position: absolute; overflow: hidden; background: #3a2a1b; }
.pic > img, .pic > video { display: block; width: 100%; height: 100%; object-fit: cover; }
.words { margin: 0; font-size: 3.6cqw; line-height: 1.42; color: var(--ink); text-wrap: pretty; hyphens: none; }
.w { border-radius: 0.18em; transition: background-color 0.12s ease, box-shadow 0.12s ease; }
.w.now { background: var(--amber-glow); box-shadow: 0 0 0 0.1em var(--amber-glow); }
/* the drop cap is sized from the text beside it so it spans exactly two lines at any type size */
.drop { float: left; font-family: var(--serif-sc); font-size: 3.05em; line-height: 0.82; margin: 0.06em 0.05em 0 0; color: var(--ink-cap); font-style: normal; }

/* the world map: the whole picture across the page, nothing cropped (the box takes the picture's own shape) */
.map { position: absolute; inset: 0; }
.map-pic {
  left: calc(-1 * var(--bleed)); right: calc(-1 * var(--bleed)); top: 50%; aspect-ratio: var(--ar, 16 / 9); transform: translateY(-50%);
  box-shadow: 0 0.5cqw 2.2cqw rgba(43, 29, 17, 0.3);
}

/* fade-in: the picture fills the page and fades into the paper, and the words sit on the faded part */
.fade { position: absolute; inset: 0; }
.fade-pic {
  left: calc(-1 * var(--bleed)); right: calc(-1 * var(--bleed)); bottom: calc(-1 * var(--bleed)); top: var(--pt, calc(-1 * var(--bleed)));
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 var(--pf, 0%));
  mask-image: linear-gradient(to bottom, transparent, #000 var(--pf, 0%));
}
.fade.bottom .fade-pic {
  top: calc(-1 * var(--bleed)); bottom: var(--pt, calc(-1 * var(--bleed)));
  -webkit-mask-image: linear-gradient(to top, transparent, #000 var(--pf, 0%));
  mask-image: linear-gradient(to top, transparent, #000 var(--pf, 0%));
}
.fade .mist {
  position: absolute; inset: calc(-1 * var(--bleed)); pointer-events: none;
  background: linear-gradient(to bottom, rgba(var(--mist), 0.96) 0%, rgba(var(--mist), 0.88) var(--m1, 31%), rgba(var(--mist), 0) var(--m2, 50%));
}
.fade.bottom .mist { background: linear-gradient(to top, rgba(var(--mist), 0.96) 0%, rgba(var(--mist), 0.88) var(--m1, 31%), rgba(var(--mist), 0) var(--m2, 50%)); }
/* the haze over a whole picture's top edge: its own colours rising into the paper (hazed() in pages.js); the page
   shows as much of the haze picture's top as its fade needs */
.haze {
  position: absolute; left: calc(-1 * var(--bleed)); right: calc(-1 * var(--bleed));
  top: calc(var(--pt) - var(--hz)); height: calc(var(--hz) + var(--ho)); overflow: hidden;
}
.haze > img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 100%; }
.fade-words { position: absolute; left: 6.4%; right: 6.4%; top: var(--wt, 4.9%); }
.fade.bottom .fade-words { top: auto; bottom: var(--wt, 4.9%); }
/* words centred in the paper above a whole picture (a long page runs down onto the misted top of the picture) */
.fade-words.centred { top: 0; bottom: calc(100% - var(--pt, 40%)); display: flex; flex-direction: column; padding-block: 4.5% 3.5%; }
.fade-words.centred > * { margin-block: auto; }
.fade-words .words { font-size: var(--fs, 3.6cqw); }
.fade-words.titled { text-align: center; }
.kicker { margin-bottom: 1.8cqw; text-align: center; font-family: var(--serif-sc); font-size: 2.3cqw; letter-spacing: 0.22em; color: var(--ink-soft); }
.heading { margin: 0; font-weight: 400; font-size: var(--fs, 7cqw); line-height: 1.08; color: var(--ink); text-wrap: balance; }
.plain-words { position: absolute; left: 9%; right: 9%; top: 0; bottom: 0; display: grid; align-content: center; }

/* ------------------------------------------------------------------ cover and end pages (web only) */
.cover-pic { inset: 0; }
.cover-pic > img, .cover-pic > video { object-position: 50% 50%; }
.cover-back { display: none; }

/* ------------------------------------------------------------------ phones held upright (book.js adds .tall and --tall)
   The page is taller than the printed square: plain paper above the picture, --tall hundredths of the page width,
   and the words a size up. The picture keeps its printed square, fade and crop at the foot of the page. */
.reader.tall .fade { top: auto; height: 100cqw; }
.reader.tall .fade.bottom { top: 0; bottom: auto; }
.reader.tall .fade-words { top: calc(var(--wt, 4.9%) - var(--tall) * 1cqw); }
.reader.tall .fade.bottom .fade-words { top: auto; bottom: calc(var(--wt, 4.9%) - var(--tall) * 1cqw); }
.reader.tall .fade-words.centred { top: calc(var(--tall) * -1cqw); }
.reader.tall .fade-words .words { font-size: calc(var(--fs, 3.6cqw) * (1 + var(--tall) / 120)); }
.reader.tall .kicker { font-size: 3cqw; }
/* a title sits in the middle of the paper above its picture */
.reader.tall .fade-words.titled {
  top: calc(var(--tall) * -1cqw); bottom: calc(100% - var(--pt, 40%)); display: flex; flex-direction: column; justify-content: center;
}
/* the cover keeps its square at the top, over a dark, softened copy of its own foot */
.reader.tall .cover-back {
  display: block; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 100%;
  filter: blur(18px) brightness(0.42) sepia(0.45) saturate(1.5); transform: scale(1.2);
}
.reader.tall .cover-pic { inset: 0 0 auto; height: 100cqw; box-shadow: 0 1.5cqw 5cqw rgba(0, 0, 0, 0.55); }
.end-page {
  position: absolute; inset: 0; padding: 8cqw; display: grid; align-content: center; justify-items: center; gap: 2.4cqw;
  text-align: center; color: var(--ink);
}
.end-line { margin: 0; font-size: 4.3cqw; font-style: italic; }
.end-page .choice { background: var(--ink); color: var(--cream); font-size: max(15px, 2.3cqw); }
@media (hover: hover) { .end-page .choice:hover { background: #4a3320; } }
.end-sub { margin: 0; max-width: 30em; font-size: max(14.5px, 2.5cqw); line-height: 1.4; color: var(--ink-soft); }
.end-page a.choice { text-decoration: none; display: inline-flex; align-items: center; }
.credit { margin: 1cqw 0 0; font-size: max(12.5px, 1.9cqw); color: var(--ink-soft); font-style: italic; }

/* the gate: Part Two's title leaf, which holds the sign-up until Part Two is open (web only) */
.gate {
  position: absolute; inset: 0; padding: 7cqw 9cqw; display: grid; align-content: center; justify-items: center; gap: 2.4cqw;
  text-align: center; color: var(--ink);
  background: radial-gradient(90% 70% at 50% 45%, rgba(255, 248, 228, 0.7), rgba(255, 248, 228, 0) 70%);
}
.gate .kicker { margin: 0; font-size: max(12px, 2.3cqw); }
.gate .heading { font-size: 7cqw; }
.gate-lock { display: grid; justify-items: center; gap: 2.2cqw; width: 100%; max-width: 34em; }
.gate-line { margin: 0; font-size: max(15px, 3.1cqw); line-height: 1.35; font-style: italic; text-wrap: balance; }
.gate-form { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; }
.gate-email {
  flex: 1 1 15em; min-width: 0; max-width: 24em; min-height: 46px; padding: 0.4em 0.9em;
  font: inherit; font-size: max(16px, 2.6cqw); color: var(--ink); background: #fffaf0;
  border: 1px solid rgba(43, 29, 17, 0.4); border-radius: 999px;
  -webkit-user-select: text; user-select: text;
}
.gate-email::placeholder { color: #9c8a70; }
.gate-email:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.gate .choice { background: var(--ink); color: var(--cream); font-size: max(15px, 2.4cqw); }
@media (hover: hover) { .gate .choice:hover { background: #4a3320; } }
.gate .msg { flex-basis: 100%; margin: 0; font-size: max(14px, 2.3cqw); }
.gate .msg:empty { display: none; }
.gate .msg.ok { color: #2f5d2a; }
.gate .msg.err { color: #8a2f17; }
.gate-small { margin: 0; font-size: max(12.5px, 1.95cqw); color: var(--ink-soft); max-width: 32em; }
.gate-small a { color: var(--ink-cap); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ------------------------------------------------------------------ who reads, and the controls */
.start { display: grid; justify-items: center; gap: 10px; text-align: center; }
.start .ask { margin: 0; font-size: clamp(19px, 0.8vw + 15px, 23px); font-style: italic; }
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.choice {
  font: inherit; font-size: 17px; color: var(--ink); background: var(--cream);
  border: 0; border-radius: 999px; padding: 0.6em 1.35em; min-height: 46px; cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.choice:active { transform: translateY(1px); }
.choice:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
@media (hover: hover) { .start .choice:hover { background: #fff6e0; } }

.controls {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px 12px;
  font-family: var(--serif-sc);
}
.nav-btn, .tog, .voices button {
  font: inherit; font-size: 16px; letter-spacing: 0.04em; color: var(--ui-text);
  background: transparent; border: 1px solid var(--ui-line); border-radius: 999px;
  min-height: 44px; padding: 0.35em 1.05em; cursor: pointer;
}
.nav-btn:disabled { opacity: 0.35; cursor: default; }
.nav-btn:focus-visible, .tog:focus-visible, .voices button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.mid { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; min-width: 0; }
.voices { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--ui-line); border-radius: 999px; }
.voices button { border: 0; min-height: 38px; padding: 0.25em 0.95em; }
.voices button[aria-checked="true"] { background: var(--cream); color: var(--ink); }
.tog[aria-pressed="true"]#pauseBtn { background: var(--cream); color: var(--ink); }
#musicBtn[aria-pressed="false"] { color: var(--ui-dim); }
@media (hover: hover) {
  .nav-btn:not(:disabled):hover, .tog:hover, .voices button:hover { border-color: rgba(244, 233, 207, 0.6); }
}
.hint { grid-column: 1 / -1; margin: 2px 0 0; text-align: center; font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--ui-dim); }
.noscript { text-align: center; font-style: italic; color: var(--ui-dim); }

@media (max-width: 600px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .mid { grid-column: 1 / -1; order: 3; }
  .nav-btn.next { justify-self: end; }
  .nav-btn:first-child { justify-self: start; }
  .hint { order: 4; }
  /* the two voices side by side and reading it yourself below, so the page above can be as tall as the screen allows */
  .start .choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 380px; }
  .start .choice { padding-inline: 0.6em; }
  .start .choice[data-voice="off"] { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  .w { transition: none; }
}
