@font-face { font-family: Grandstander; src: url("grandstander.woff2") format("woff2"); font-display: swap; font-weight: 600; }

:root {
  color-scheme: light;
  --ink: #241841;
  --muted: #574672;
  --lilac: #f3e9fe;
  --purple: #57279d;
  --purple-deep: #3d1b75;
  --line: #daceeb;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: #f8f2ff;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top right, #ebdcff 0, transparent 48%),
    linear-gradient(148deg, #fffbf2, #f8f2ff 69%, #f4edff);
}

[hidden] { display: none !important; }

.reader {
  width: min(100%, 1120px);
  margin-inline: auto;
  padding: clamp(12px, 3.1vw, 38px) clamp(12px, 3vw, 30px) max(16px, env(safe-area-inset-bottom));
}

.reader-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: clamp(13px, 2.5vw, 24px);
}

.reader-header h1 {
  margin: 0;
  line-height: 1.05;
  font-family: Grandstander, "Trebuchet MS", system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: -.047em;
  font-size: clamp(25px, 4.85vw, 53px);
  color: #3d226b;
}

.reader-header p {
  margin: 7px 0 0;
  font-size: clamp(13px, 2.1vw, 16px);
  line-height: 1.45;
  color: var(--muted);
}

.book { display: grid; gap: 12px; }
.stage {
  display: grid;
  place-items: center;
  isolation: isolate;
  min-height: 144px;
  touch-action: pan-y pinch-zoom;
  perspective: 1400px;
}

.sheet {
  position: relative;
  width: min(100%, var(--sheet-width, 592px));
  aspect-ratio: var(--sheet-ratio, 1);
  overflow: hidden;
  display: grid;
  place-items: center;
  background: #fff8ec;
  border: 1px solid #d6c9e7;
  border-radius: 7px 13px 13px 7px;
  box-shadow: 0 4px 0 -1px #e6daef, 0 7px 0 -2px #e1d4ec, 0 12px 26px #38215d27;
}

.sheet:has(img:not([hidden]))::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 3px 0 7px #23173519;
}

.sheet[data-spread="true"]:has(img:not([hidden]))::after {
  inset: 0 auto 0 calc(50% - 8px);
  width: 16px;
  box-shadow: none;
  background: linear-gradient(90deg, transparent, #27193914 46%, #fff9 52%, transparent);
}

.sheet img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
}

.loading { padding: 20px; color: var(--muted); text-align: center; }
.controls {
  margin: 5px auto 0;
  display: grid;
  width: min(100%, 470px);
  grid-template-columns: minmax(82px,1fr) minmax(78px,1.1fr) minmax(115px,1fr);
  align-items: center;
  gap: clamp(6px, 2vw, 12px);
}

button, .end-card a {
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, a:focus-visible, .sheet:focus-visible {
  outline: 3px solid #1985aa;
  outline-offset: 3px;
}

.page-button {
  height: 46px;
  border-radius: 99px;
  border: 1px solid #cdb9e9;
  background: #fffdfd;
  color: var(--purple-deep);
  font-size: clamp(12px, 3.4vw, 15px);
  font-weight: 750;
  padding: 0 8px;
  white-space: nowrap;
}

.page-button span { padding-inline: 2px; }
.page-button.next { background: var(--purple); color: #fff; border-color: var(--purple); }
.page-button:hover:not(:disabled) { background: #eaddfc; }
.page-button.next:hover:not(:disabled) { background: var(--purple-deep); }
.page-button:disabled { color: #756889; border-color: var(--line); background: #f6effa; cursor: default; }

.progress { display: grid; gap: 6px; justify-items: center; color: var(--muted); }
.progress output { text-align: center; font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 700; }
.progress progress {
  height: 4px;
  width: min(100%, 110px);
  border: 0;
  border-radius: 99px;
  overflow: hidden;
  background: #e1d1f3;
  appearance: none;
  accent-color: var(--purple);
}
progress::-webkit-progress-bar { background: #e1d1f3; }
progress::-webkit-progress-value { background: var(--purple); }
progress::-moz-progress-bar { background: var(--purple); }

.reader-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px 10px; }
.quiet {
  min-height: 42px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--purple-deep);
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}
.quiet:hover { background: var(--lilac); }
.fullscreen { white-space: nowrap; border: 1px solid var(--line); }
.transcript, .end-card {
  margin: 0 auto;
  width: min(100%, 505px);
  padding: 15px 20px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fffdf7;
}

.transcript p { margin: 4px 0 9px; line-height: 1.55; }
.transcript p:last-child { margin-bottom: 4px; }
.end-card { text-align: center; display: grid; justify-items: center; gap: 10px; }
.end-card a { color: var(--purple-deep); font-weight: 720; }

.shelf-navigation { margin-bottom: 12px; }
.shelf-navigation a { display: inline-flex; align-items: center; text-decoration: none; }
.shelf-navigation a:hover { text-decoration: underline; }

.embed .reader { padding-top: clamp(8px, 2vw, 20px); }
.embed .reader-header { display: none; }
.reader:fullscreen { width: 100%; max-width: none; overflow: auto; background: #fbf6ff; }
.reader:fullscreen .reader-header p { display: none; }

@media (min-width: 740px) {
  .sheet { width: min(100%, var(--sheet-width, 592px), var(--sheet-height-limit, 1120px)); }
}

@media (max-width: 410px) {
  .reader { padding-inline: 9px; }
  .reader-header h1 { letter-spacing: -.035em; }
  .reader-header { align-items: flex-start; }
  .fullscreen { font-size: 12px; padding-inline: 8px; }
  .book { gap: 8px; }
}
