:root {
  color-scheme: dark;

  /* 1. Primitive: color */
  --ink-1000: #0b0d0f;
  --ink-950: #14171a;
  --storm-800: #28303b;
  --storm-700: #383d48;
  --rain-500: #59627a;
  --parchment-100: #f3eadc;
  --parchment-200: #e8dccb;
  --parchment-400: #c8b29d;
  --lantern-500: #c98b43;
  --brass-300: #d6ae62;
  --moss-500: #758044;
  --moss-300: #adb987;
  --oxblood-700: #5a2426;

  /* 1. Primitive: type */
  --font-frankie: "Kalam", "Segoe Print", cursive;
  --font-goblin: "Rubik Dirt", Impact, sans-serif;
  --font-story: "Newsreader", Georgia, serif;
  --font-meta: "Literata", Georgia, serif;
  --step--1: clamp(0.78rem, 0.74rem + 0.18vw, 0.92rem);
  --step-0: clamp(1rem, 0.95rem + 0.24vw, 1.14rem);
  --step-1: clamp(1.18rem, 1.07rem + 0.48vw, 1.48rem);

  /* 1. Primitive: space, shape, motion */
  --space-1: 0.35rem;
  --space-2: 0.65rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.25rem;
  --space-6: 3.5rem;
  --space-7: clamp(4.5rem, 9vw, 8rem);
  --page-measure: 64rem;
  --copy-measure: 63ch;
  --radius-small: 0.3rem;
  --rule: 1px solid color-mix(in srgb, var(--rain-500) 34%, transparent);
  --ease-story: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html {
  min-width: 20rem;
  background: var(--ink-1000);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--parchment-100);
  background:
    radial-gradient(circle at 18% 20%, rgba(89, 98, 122, 0.17), transparent 28rem),
    linear-gradient(145deg, var(--ink-950), var(--ink-1000) 72%);
  font-family: var(--font-story);
  font-size: var(--step-0);
  line-height: 1.72;
  text-rendering: optimizeLegibility;
}

img { display: block; max-width: 100%; }

.skip-link {
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 20;
  padding: var(--space-2) var(--space-3);
  color: var(--ink-1000);
  background: var(--parchment-100);
  border-radius: var(--radius-small);
  font: 600 var(--step-0) / 1.2 var(--font-meta);
  transform: translateY(-180%);
  transition: transform 160ms ease;
}

.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 3px solid var(--lantern-500); outline-offset: 4px; }

/* 1. Primitive: ruled meta text */
.genre-line {
  display: grid;
  grid-template-columns: minmax(1.4rem, 4rem) auto minmax(1.4rem, 4rem);
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  width: min(90%, 38rem);
  margin: var(--space-5) auto 0;
  color: var(--parchment-400);
  font: 600 var(--step--1) / 1.4 var(--font-meta);
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
}

.genre-line::before,
.genre-line::after {
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--rain-500));
}

.genre-line::after { background: linear-gradient(90deg, var(--rain-500), transparent); }

/* 2. Component: masthead */
.book-masthead {
  display: grid;
  justify-items: center;
  margin: 0;
  color: var(--parchment-100);
  line-height: 0.84;
  text-align: center;
  filter: drop-shadow(0 0.35rem 0.7rem rgba(0, 0, 0, 0.56));
}

.book-masthead__frankie {
  display: inline-block;
  font-family: var(--font-frankie);
  font-size: clamp(3.4rem, 9.2cqw, 6.25rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

@supports ((background-clip: text) or (-webkit-background-clip: text)) {
  .book-masthead__frankie--dot {
    color: transparent;
    background:
      radial-gradient(ellipse 3.6% 5.5% at 79.5% 8%, var(--parchment-400) 88%, transparent 100%),
      linear-gradient(var(--parchment-100), var(--parchment-100));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

.book-masthead__bridge {
  display: grid;
  grid-template-columns: minmax(1.5rem, 3.25rem) auto minmax(1.5rem, 3.25rem);
  align-items: center;
  gap: 0.5rem;
  margin: 0.22em 0 -0.08em;
  color: var(--parchment-400);
  font: 500 italic clamp(0.95rem, 2.1cqw, 1.35rem) / 1 var(--font-meta);
  letter-spacing: 0.08em;
}

.book-masthead__bridge::before,
.book-masthead__bridge::after {
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--parchment-400));
}

.book-masthead__bridge::after {
  background: linear-gradient(90deg, var(--parchment-400), transparent);
}

.book-masthead__royal {
  --royal-fill: var(--moss-300);
  --royal-king-fill: var(--royal-fill);
  --royal-stroke: var(--ink-950);

  position: relative;
  display: block;
  width: 100%;
  height: clamp(7.25rem, 19cqw, 13rem);
  color: var(--royal-fill);
  font-family: var(--royal-font, var(--font-goblin));
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 0.84;
  text-transform: uppercase;
}

.book-masthead__goblin,
.book-masthead__king {
  position: absolute;
  display: block;
  color: var(--royal-fill);
  -webkit-text-stroke: 0.012em var(--royal-stroke);
  paint-order: stroke fill;
  filter: drop-shadow(0 0.08em 0.08em rgba(0, 0, 0, 0.32));
}

.book-masthead__goblin {
  top: 0;
  left: 3%;
  z-index: 1;
  font-size: clamp(4rem, 12.4cqw, 8.2rem);
  transform: rotate(-2.6deg);
  transform-origin: 50% 55%;
}

.book-masthead__king {
  top: 0.58em;
  left: 44%;
  z-index: 2;
  color: var(--royal-king-fill);
  font-size: clamp(4.4rem, 13.64cqw, 9.02rem);
  font-style: italic;
  transform: rotate(-3.4deg) skewX(-4deg);
  transform-origin: 50% 55%;
}

.book-masthead__royal--king-oxblood { --royal-king-fill: var(--oxblood-700); }
.book-masthead__royal--oxblood-outline { --royal-stroke: var(--oxblood-700); }
.book-masthead__royal--brass-outline { --royal-stroke: var(--brass-300); }
.book-masthead__royal--amber-outline { --royal-stroke: var(--lantern-500); }

/* 2. Component: tall hero */
.book-hero {
  container-type: inline-size;
  position: relative;
  width: min(100%, var(--page-measure));
  margin: 0 auto;
  overflow: hidden;
  border-radius: var(--radius-small);
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, 0.42);
}

.book-hero__art {
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: contain;
}

.book-hero__title {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.book-hero__masthead {
  position: absolute;
  inset: 7.5% 4% auto;
}

.book-hero__credits {
  position: absolute;
  top: 45%;
  right: 4%;
  left: 4%;
  transform: translateY(-50%);
}

.book-hero__credits .genre-line { margin-top: 0; }

.book-byline {
  margin: var(--space-3) auto 0;
  color: var(--parchment-100);
  font: 600 clamp(1.35rem, 3.4cqw, 2rem) / 1.08 var(--font-meta);
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 0.12em 0.35em rgba(0, 0, 0, 0.65);
}

.book-byline span {
  color: var(--parchment-400);
  font-size: 0.62em;
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.book-byline--moss { color: var(--moss-300); }
.book-byline--parchment { color: var(--parchment-100); }
.book-byline--amber { color: var(--lantern-500); }
.book-byline--oxblood { color: #a95d61; }

/* 2. Component: finished cover hero */
.cover-hero {
  width: min(100%, var(--page-measure));
  margin: 0 auto;
  overflow: hidden;
  border-radius: var(--radius-small);
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, 0.42);
}

.cover-hero__art {
  width: 100%;
  height: auto;
}

/* 2. Component: paired character promise */
.promise-pair {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  align-items: center;
  gap: clamp(var(--space-3), 4vw, var(--space-6));
  width: min(100%, var(--page-measure));
  margin: var(--space-5) auto 0;
  padding: var(--space-5) clamp(var(--space-3), 5vw, var(--space-6));
  background: linear-gradient(90deg, rgba(89, 98, 122, 0.08), rgba(90, 36, 38, 0.09));
  border-block: var(--rule);
}

.character-promise { margin: 0; }
.character-promise p { margin: 0; line-height: 1.32; }

.character-promise--frankie {
  color: var(--parchment-200);
  font-family: var(--font-frankie);
  font-size: clamp(1.25rem, 2.5vw, 1.8rem);
  text-align: right;
}

.character-promise--frankie .character-promise__lead {
  font-size: 1.12em;
}

.character-promise--goblin {
  color: var(--moss-300);
  font-family: var(--font-goblin);
  font-size: clamp(1.85rem, 4.1vw, 3rem);
  letter-spacing: 0.015em;
  text-align: left;
}

/* 2. Component: blurb */
.book-blurb {
  max-width: var(--copy-measure);
  margin: var(--space-7) auto 0;
  padding-inline: var(--space-3);
  color: var(--parchment-200);
  font-family: var(--font-story);
  font-size: var(--step-1);
  font-weight: 400;
  line-height: 1.72;
}

.book-blurb p { margin: 0; }

.book-blurb p::first-letter {
  float: left;
  margin: 0.14em 0.12em 0 0;
  color: var(--parchment-100);
  font-family: var(--font-frankie);
  font-size: 3.35em;
  font-weight: 700;
  line-height: 0.68;
}

/* 3. Page state: home */
.home-page {
  container-name: home-page;
  container-type: inline-size;
  width: min(calc(100% - 2rem), var(--page-measure));
  margin: 0 auto;
  padding: var(--space-5) 0 var(--space-6);
}

.book-coda {
  max-width: 48ch;
  margin: var(--space-6) auto 0;
  color: var(--parchment-400);
  font-family: var(--font-meta);
  font-size: var(--step-0);
  font-style: italic;
  text-align: center;
}

.site-footer {
  width: min(calc(100% - 2rem), var(--page-measure));
  margin: 0 auto;
  padding: var(--space-4) 0 var(--space-6);
  color: var(--parchment-200);
  border-top: var(--rule);
  font: 500 var(--step-0) / 1.5 var(--font-meta);
  text-align: center;
}

.site-footer p { margin: 0; }

.site-footer__promise a {
  color: var(--parchment-100);
  text-decoration-color: color-mix(in srgb, var(--rain-500) 70%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}

.site-footer__promise a:hover { color: var(--lantern-500); }

.site-footer__promise span {
  color: var(--lantern-500);
  font-size: var(--step--1);
  font-style: italic;
}

.site-footer__copyright {
  margin-top: var(--space-2) !important;
  color: var(--parchment-400);
  font-size: var(--step--1);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* Storybook specimen helpers */
.specimen {
  box-sizing: border-box;
  width: min(64rem, calc(100vw - 4rem));
  padding: var(--space-5);
  color: var(--parchment-100);
  background: var(--ink-950);
  border-radius: var(--radius-small);
}

.token-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-3);
}

.token-swatch { padding: var(--space-2); border: var(--rule); }
.token-swatch__color { aspect-ratio: 1.7; margin-bottom: var(--space-2); background: var(--swatch); }
.token-swatch p { margin: 0; font: var(--step--1) / 1.4 var(--font-meta); }

@media (max-width: 43rem) {
  .home-page { width: min(calc(100% - 1rem), var(--page-measure)); padding-top: 0.5rem; }
  .book-hero__masthead { inset: 6.5% 3% auto; }
  .book-hero__credits { top: 45%; right: 3%; left: 3%; }
  .book-masthead__frankie { font-size: 10cqw; }
  .book-masthead__royal { height: 20cqw; min-height: 4.7rem; }
  .book-masthead__goblin { left: 2%; font-size: 12.1cqw; }
  .book-masthead__king { left: 42%; font-size: 13.31cqw; }
  .genre-line { grid-template-columns: minmax(1rem, 2.4rem) auto minmax(1rem, 2.4rem); gap: 0.55rem; font-size: clamp(0.59rem, 2.1cqw, 0.8rem); }
  .promise-pair { grid-template-columns: 1fr; gap: var(--space-4); }
  .character-promise--frankie,
  .character-promise--goblin { text-align: center; }
  .book-blurb { margin-top: var(--space-6); }
}

@container home-page (max-width: 43rem) {
  .promise-pair {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .character-promise--frankie,
  .character-promise--goblin {
    text-align: center;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .book-hero,
  .cover-hero,
  .promise-pair,
  .book-blurb,
  .book-coda {
    animation: page-turn 760ms var(--ease-story) both;
  }
  .promise-pair { animation-delay: 90ms; }
  .book-blurb { animation-delay: 170ms; }
  .book-coda { animation-delay: 240ms; }
  @keyframes page-turn {
    from { opacity: 0; transform: translateY(0.7rem); }
    to { opacity: 1; transform: translateY(0); }
  }
}
