@font-face {
  font-family: "Dyslexie";
  src: url("assets/fonts/DyslexieRegularLP14415.ttf") format("truetype");
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

:root {
  color-scheme: dark;
  --ink: #f8f2e6;
  --muted: #bfc8d1;
  --night: #0d1724;
  --navy: #172538;
  --blue: #85b6ca;
  --blue-bright: #c6e4ec;
  --paper: #f2e6cf;
  --gold: #e5bd6b;
  --panel: rgba(8, 15, 24, 0.76);
  --panel-solid: #152333;
  --danger: #ffd7cc;
  --focus: #ffdb87;
  --radius: 1rem;
  --shadow: 0 1.25rem 4rem rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--night);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
  min-height: 100%;
  background: var(--night);
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(160deg, #18283a 0%, #0c1520 72%);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

a {
  color: inherit;
}

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.2rem;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: var(--paper);
  color: var(--night);
  font-weight: 800;
  transform: translateY(-150%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: relative;
  z-index: 2;
  max-width: 82rem;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 0 max(1.25rem, env(safe-area-inset-left));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  color: var(--gold);
  font-family: Georgia, serif;
  font-size: 1.35rem;
  font-style: italic;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.brand small {
  margin-top: 0.08rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-view {
  width: min(72rem, 100%);
  min-height: calc(100vh - 5rem);
  margin: 0 auto;
  padding: clamp(2.25rem, 5vw, 4.5rem) max(1.25rem, env(safe-area-inset-right)) max(2.5rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

.library-intro {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(15rem, 0.7fr);
  gap: 1.25rem 3rem;
  align-items: end;
  margin-bottom: clamp(2rem, 4vw, 3.5rem);
}

.eyebrow {
  margin: 0 0 1rem;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.library-intro .eyebrow {
  grid-column: 1 / -1;
  margin-bottom: -1rem;
}

.library-intro h1 {
  max-width: 15ch;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.8rem, 6vw, 5.8rem);
  font-weight: 400;
  letter-spacing: -0.055em;
  line-height: 0.89;
}

.library-description {
  max-width: 32rem;
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.55;
}

.library-status {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 5rem;
  color: var(--muted);
}

.loading-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--gold);
  animation: pulse 1.2s ease-in-out infinite alternate;
}

@keyframes pulse {
  to {
    opacity: 0.3;
    transform: scale(0.75);
  }
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(1rem, 2vw, 1.5rem);
}

.book-card {
  position: relative;
  min-width: 0;
  contain: layout style;
}

.book-link {
  display: block;
  text-decoration: none;
}

.book-cover-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.85rem;
  background: #223448;
  box-shadow: 0 0.65rem 1.6rem rgba(0, 0, 0, 0.22);
  transition: transform 160ms ease, border-color 160ms ease;
}

.book-cover-frame::after {
  content: none;
}

.book-cover-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: clamp(0.75rem, 2vw, 1.5rem);
}

.book-link:hover .book-cover-frame,
.book-link:focus-visible .book-cover-frame {
  border-color: rgba(229, 189, 107, 0.65);
  transform: translateY(-0.18rem);
}

.book-meta {
  display: block;
  padding: 0.75rem 0.15rem 0;
}

.book-meta h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 2vw, 1.55rem);
  font-weight: 400;
}

.book-meta span {
  display: block;
  margin-top: 0.25rem;
  color: var(--blue-bright);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.library-error {
  max-width: 40rem;
  padding: 2rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: var(--panel-solid);
}

.library-error h2 {
  margin-top: 0;
  font-family: Georgia, serif;
  font-weight: 400;
}

.library-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-top: clamp(2rem, 4vw, 3.5rem);
  padding-top: 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-size: 0.85rem;
}

.library-footer p {
  margin: 0;
}

.text-button {
  min-height: 2.75rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: transparent;
  color: var(--blue-bright);
  cursor: pointer;
}

.text-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.primary-button,
.secondary-button {
  min-height: 3rem;
  padding: 0.75rem 1.2rem;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: var(--gold);
  color: #1a1b1d;
}

.primary-button:hover {
  background: #f4d28c;
}

.secondary-button {
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

.reader-view,
.reader-stage {
  min-height: 100vh;
  min-height: 100dvh;
}

.reader-stage {
  position: relative;
  display: grid;
  overflow: hidden;
  place-items: center;
  background: #0c1016;
  isolation: isolate;
}

.page-art,
.page-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.page-art {
  z-index: 0;
  object-fit: fill;
  opacity: 0;
  transition: opacity 320ms ease;
}

.page-art.is-loaded {
  opacity: 1;
}

.page-shade {
  z-index: 1;
  background: transparent;
  pointer-events: none;
}

.reader-header {
  position: absolute;
  z-index: 4;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: center;
  padding: max(0.9rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left));
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.75rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

.reader-stage.controls-visible .reader-header,
.reader-header:focus-within {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.reader-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0 1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(6, 12, 18, 0.58);
  color: var(--ink);
  text-decoration: none;
  backdrop-filter: blur(12px);
}

.reader-heading {
  justify-self: end;
  width: min(13.5rem, 35vw);
  min-width: 0;
  padding: 0.55rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.75rem;
  background: rgba(6, 12, 18, 0.58);
  text-align: right;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
}

.reader-heading h1 {
  overflow: hidden;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 3vw, 1.35rem);
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-heading p {
  margin: 0.2rem 0 0;
  color: #dce4e7;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.reader-header-spacer {
  display: none;
}

.story-panel {
  position: absolute;
  z-index: 2;
  top: 2.9296875%;
  left: 3.90625%;
  width: 68%;
  height: 68%;
  margin: 0;
  padding: 0.7rem;
  padding: clamp(0.55rem, 1.5cqi, 0.9rem);
  overflow-y: auto;
  border: 0;
  border-radius: 0.875rem;
  border-radius: clamp(0.65rem, 1.8cqi, 0.875rem);
  background: rgba(0, 0, 0, 0.4);
  box-shadow: none;
  scrollbar-color: rgba(255, 255, 255, 0.45) transparent;
  transition: opacity 220ms ease, transform 220ms ease;
}

.story-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
  transform: translateY(0.75rem);
  pointer-events: none;
}

.story-panel.is-credits {
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 2rem;
  padding: clamp(1.25rem, 5cqi, 3rem);
  border-radius: 0;
  text-align: center;
}

.story-text {
  margin: 0;
  color: #fff;
  font-family: "Dyslexie", ui-rounded, "Arial Rounded MT Bold", sans-serif;
  font-size: 0.8125rem;
  font-size: clamp(0.8125rem, 2.2cqi, 1.0625rem);
  line-height: 1.45;
  white-space: pre-wrap;
}

.story-panel.is-credits .story-text {
  position: relative;
  top: 50%;
  font-family: "Dyslexie", ui-rounded, "Arial Rounded MT Bold", sans-serif;
  font-size: clamp(0.8125rem, 2.2cqi, 1.0625rem);
  line-height: 1.45;
  transform: translateY(-50%);
}

.reader-controls {
  position: absolute;
  z-index: 4;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  left: 50%;
  display: flex;
  width: min(58rem, calc(100% - 1.5rem));
  margin: 0;
  padding: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 1.1rem;
  background: rgba(8, 15, 24, 0.87);
  box-shadow: 0 0.8rem 3rem rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(20px);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 0.75rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

.reader-stage.controls-visible .reader-controls,
.reader-controls:focus-within {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.control-button {
  position: relative;
  display: grid;
  flex: 1 1 0;
  min-width: 3.2rem;
  min-height: 3.5rem;
  padding: 0.35rem 0.3rem;
  place-content: center;
  place-items: center;
  gap: 0.15rem;
  border: 0;
  border-radius: 0.75rem;
  background: transparent;
  color: var(--blue-bright);
  cursor: pointer;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.control-button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
}

.control-button[aria-pressed="false"] {
  color: #8c969f;
}

.control-button[aria-pressed="false"]::after {
  position: absolute;
  top: 0.75rem;
  width: 1.7rem;
  height: 0.12rem;
  background: #d08e80;
  content: "";
  transform: rotate(-38deg);
}

.control-button:disabled {
  color: #69727a;
  cursor: not-allowed;
  opacity: 0.55;
}

.control-symbol {
  min-height: 1.35rem;
  font-size: 1.2rem;
  line-height: 1;
}

.play-button {
  min-width: 4.2rem;
  background: var(--paper);
  color: #111923;
}

.play-button:hover:not(:disabled) {
  background: #fff5e4;
}

.play-symbol {
  min-height: 1.35rem;
  font-size: 1rem;
}

.reader-message,
.audio-warning {
  position: absolute;
  z-index: 6;
  left: 50%;
  width: min(34rem, calc(100% - 2rem));
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: #182737;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.reader-message {
  top: 50%;
  padding: 2rem;
  transform: translate(-50%, -50%);
}

.reader-message h2 {
  margin-top: 0;
  font-family: Georgia, serif;
  font-weight: 400;
}

.reader-message a {
  display: inline-block;
  margin-left: 1rem;
}

.audio-warning {
  top: 5.5rem;
  padding: 0.7rem 1rem;
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
}

@media (max-width: 58rem) {
  .library-intro {
    grid-template-columns: 1fr;
  }

  .library-intro .eyebrow {
    margin-bottom: -0.5rem;
  }

}

@media (max-width: 42rem) {
  .site-header {
    padding-top: max(0.9rem, env(safe-area-inset-top));
  }

  .library-view {
    padding-top: 2rem;
  }

  .library-intro {
    margin-bottom: 1.75rem;
  }

  .library-intro h1 {
    font-size: clamp(2.5rem, 11vw, 3.5rem);
  }

  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem 1rem;
  }

  .book-cover-frame {
    aspect-ratio: 1;
  }

  .book-cover-frame img {
    padding: clamp(0.65rem, 3vw, 1rem);
  }

  .library-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .reader-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .reader-back {
    width: 2.9rem;
    padding: 0;
    justify-content: center;
  }

  .reader-back span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .reader-controls {
    width: calc(100% - 0.75rem);
    bottom: max(0.35rem, env(safe-area-inset-bottom));
  }

  .control-button {
    min-width: 2.6rem;
    min-height: 3.35rem;
    font-size: 0.55rem;
    letter-spacing: 0;
  }

  .page-button span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .play-button {
    min-width: 3.5rem;
  }

}

@media (max-width: 24rem) {
  .control-button span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .control-symbol,
  .play-symbol {
    min-height: auto;
  }
}

@media (hover: none) {
  .book-cover-frame {
    transition: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/*
 * StPageFlip is vendored locally. Keep the host to one portrait-page width
 * and let the library own the root, wrapper, turn layers, and their sizing.
 */
.reader-stage {
  --book-width: min(100vw, calc(100vh * 0.7451171875), 39.3125rem);
  --book-width: min(100vw, calc(100dvh * 0.7451171875), 39.3125rem);
}

.flipbook-host {
  position: relative;
  width: var(--book-width);
  aspect-ratio: 1526 / 2048;
  overflow: visible;
  container-type: inline-size;
}

.flip-page {
  overflow: hidden;
  background:
    repeating-linear-gradient(7deg, rgba(92, 67, 40, 0.025) 0 1px, transparent 1px 9px),
    #f3ead8;
  color: var(--ink);
}

.page-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform-origin: center;
}

.story-page.is-page-reverse .page-face {
  transform: scaleX(-1);
}

.story-page {
  box-shadow: inset 0 0 1.5rem rgba(68, 49, 29, 0.08);
}

.flip-cover-page {
  background: #0a1119;
}

.flip-cover-art {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  background: #080d13;
}

.cover-details {
  position: absolute;
  z-index: 90;
  top: 50%;
  right: max(1rem, env(safe-area-inset-right));
  width: min(19rem, calc((100vw - var(--book-width)) / 2 - 1.5rem));
  padding: 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 1rem;
  background:
    linear-gradient(120deg, rgba(117, 161, 180, 0.14), transparent 58%),
    rgba(23, 37, 56, 0.96);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.42);
  transform: translateY(-50%);
  backdrop-filter: blur(16px);
}

.cover-details[hidden] {
  display: none;
}

.cover-details .eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
}

.cover-details h2 {
  max-width: none;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1;
}

.cover-details > p:not(.eyebrow) {
  max-width: none;
  margin: 0.65rem 0 0.9rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.cover-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.cover-details .start-button {
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
}

.cover-details .cover-actions > a {
  margin: 0;
  color: var(--blue-bright);
  font-size: 0.8rem;
}

.reader-header,
.reader-controls {
  z-index: 100;
}

.reader-message,
.audio-warning {
  z-index: 110;
}

@media (max-width: 70rem), (max-aspect-ratio: 1 / 1) {
  .cover-details {
    top: auto;
    right: 50%;
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    width: min(34rem, calc(100% - 1.5rem));
    padding: 0.85rem 1rem;
    transform: translateX(50%);
  }
}
