:root {
  --red: #c91722;
  --red-dark: #9a131d;
  --red-deep: #6f0e16;
  --ink: #181818;
  --paper: #fff;
  --sand: #efeaea;
  --line: #f9e3e4;
  --muted: #5b5b5b;
  --display: "Anton", Impact, "Arial Narrow", sans-serif;
  --body: "Saira", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

/* .btn sets display, which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--body);
  font-size: 1.125rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--paper);
}

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


a { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 24px;
  border: 1.5px solid transparent;
  border-radius: 48px;
  font: 400 1.125rem/1.2 var(--body);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:focus-visible, .buy__close:focus-visible, .buy__continue:focus-visible { outline: 3px solid #ffd400; outline-offset: 3px; }
.btn:disabled { opacity: 0.5; cursor: wait; transform: none; }
.btn--lg { padding: 16px 48px; font-size: clamp(1.125rem, 2.5vw, 1.5rem); font-weight: 500; }
.btn--block { width: 100%; }
.btn--light { background: var(--paper); color: var(--red); }
.btn--ghost { border-color: var(--paper); color: var(--paper); background: transparent; }
.btn--red { background: var(--red); color: var(--paper); }
.btn--red:hover { background: var(--red-dark); }
.btn--small { min-height: 40px; font-size: 1rem; padding: 0.3em 1em; margin-left: 0.5em; }

/* Hero: red gradient, faint graffiti wall, glow behind the book */
.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  justify-items: center;
  gap: 1.5rem;
  padding: 2rem 16px clamp(3rem, 8vw, 6rem);
  text-align: center;
  color: var(--paper);
  background: linear-gradient(var(--red-dark) 67.7%, var(--red-deep));
}
.hero::before,
.hero::after { content: ""; position: absolute; z-index: -1; pointer-events: none; }
.hero::before { inset: 0; background: url("img/bg.webp") center / cover; opacity: 0.16; }
.hero::after {
  top: 120px;
  left: 50%;
  width: min(761px, 120vw);
  aspect-ratio: 761 / 657;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, #f55, rgb(255 90 90 / 0));
}
.hero__book { width: min(85%, 632px); filter: drop-shadow(0 24px 40px rgb(0 0 0 / 0.4)); }
.hero__lead {
  max-width: 800px;
  margin: 0;
  font-family: var(--body);
  font-weight: 600;
  font-size: clamp(1.125rem, 3vw, 1.5rem);
  line-height: 1.4;
}
.hero__actions { display: flex; flex-wrap: wrap; gap: 16px 35px; justify-content: center; margin-top: 1rem; }

/* Content column. .main is full width and clips sideways, so swiped-out quiz cards
   fly to the screen edge without widening the page. */
.main { overflow-x: clip; }
/* Full-width sand band behind the quiz */
.band { background: var(--sand); padding: clamp(3rem, 6vw, 4.5rem) 16px clamp(4rem, 8vw, 6rem); }
.band__inner { max-width: 800px; margin: 0 auto; }
.rail {
  display: grid;
  gap: 50px;
  max-width: 832px;
  margin: 0 auto;
  padding: clamp(4rem, 8vw, 6rem) 16px 3rem;
}
.section-head { display: grid; gap: 20px; margin-bottom: 50px; }
.section-head--center { gap: 0; text-align: center; }
.section-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.25rem, 7vw, 3.35rem);
  line-height: 1.2;
  text-transform: uppercase;
  text-align: center;
  color: var(--red);
}
.section-intro { margin: 0; font-size: clamp(1.125rem, 2.6vw, 1.375rem); color: #000; }
.section-sub { margin: 0; font-weight: 500; color: #000; }

/* Cards */
.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px clamp(20px, 4vw, 32px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  filter: drop-shadow(0 4px 7px rgb(0 0 0 / 0.03));
}
.quiz { scroll-margin-top: 1rem; }
.card__kicker,
.card__chapter { margin: 0; font-family: var(--display); line-height: 1.2; color: var(--red); }
.card__kicker { font-size: 1rem; }
.card__chapter { font-size: clamp(1.375rem, 4vw, 1.625rem); text-transform: uppercase; }
.card__divider { width: 100%; margin: 10px 0; border: 0; border-top: 1px solid #ece6e6; }
.card__prompt { margin: 0; font-weight: 700; }
.card__question { margin: 0; color: #000; overflow-wrap: anywhere; }
.card[data-state="loading"] .card__question { color: var(--muted); }
/* Card stack: up to 4 blank cards peek out under the quiz card, one fewer per answered card. */
.stack { position: relative; isolation: isolate; padding-bottom: 48px; }
.stack__layer {
  position: absolute;
  inset: 0 0 48px;
  z-index: -1;
  border: 1px solid #ead4d5;
  border-radius: 24px;
  background: #fbf5f5;
  box-shadow: 0 4px 10px rgb(111 14 22 / 0.06);
  transform-origin: 50% 100%;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.stack__layer[data-n="1"] { transform: translateY(12px) scale(0.97); }
.stack__layer[data-n="2"] { transform: translateY(24px) scale(0.94); z-index: -2; background: #f7eded; }
.stack__layer[data-n="3"] { transform: translateY(36px) scale(0.91); z-index: -3; background: #f2e5e5; }
.stack__layer[data-n="4"] { transform: translateY(48px) scale(0.88); z-index: -4; background: #eddcdc; }
.stack__layer.is-gone { opacity: 0; transform: translateY(0) scale(0.97); }

.flip.is-leaving { animation: swipe-out 0.4s ease-in forwards; pointer-events: none; }
.flip.is-entering { animation: lift-in 0.35s ease-out; }
.flip.no-anim .flip__inner { transition: none; }
@keyframes swipe-out {
  to { transform: translateX(110vw) rotate(14deg); opacity: 0; }
}
@keyframes lift-in {
  from { transform: translateY(12px) scale(0.97); }
}

/* Flip card: both faces share one grid cell, so the card is as tall as the taller face.
   No filter/overflow on .flip or its ancestors — those flatten the 3D. */
.flip { display: block; padding: 0; border: 0; background: none; filter: none; perspective: 1400px; }
.flip__inner {
  display: grid;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.flip.is-flipped .flip__inner { transform: rotateY(180deg); }
.flip__face {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 300px;
  padding: 24px clamp(20px, 4vw, 32px);
  border-radius: 24px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
/* Safari only culls the back of a face that has its own transform, and ignores the
   face's backface-visibility for a button on its own layer — hence both rules. */
.flip__front { transform: rotateY(0deg); }
.flip__face .btn { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip__front { background: var(--paper); border: 1px solid var(--line); box-shadow: 0 10px 30px rgb(0 0 0 / 0.06); }
.flip__back {
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  color: var(--paper);
  background: linear-gradient(160deg, var(--red), var(--red-deep));
  transform: rotateY(180deg);
}
.flip__label { margin: 0; font-family: var(--display); font-size: 1.125rem; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.8; }
.flip__answer {
  margin: 0;
  max-width: 100%;
  font-family: var(--display);
  font-size: clamp(2.5rem, 9vw, 4.5rem);
  line-height: 1.05;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}
.flip__answer[data-size="m"] { font-size: clamp(1.75rem, 5vw, 2.5rem); }
.flip__answer[data-size="l"] { font-family: var(--body); font-weight: 700; font-size: clamp(1.125rem, 3vw, 1.375rem); line-height: 1.4; text-transform: none; }
.card__error { margin: 0; color: var(--red-dark); font-weight: 600; }
.card__actions { display: flex; padding: 20px 0 0; margin-top: auto; }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Category list */
.cats__table { width: 100%; border-collapse: collapse; color: #000; }
.cats__table th,
.cats__table td { padding: 16px 0; text-align: left; vertical-align: top; }
.cats__table tr + tr > *, .cats__table tbody tr:first-child > * { border-top: 1px solid #ece6e6; }
.cats__table th { padding-top: 8px; font-family: var(--display); font-weight: 400; }
.cats__table :is(th, td):first-child { width: 2.6em; padding-right: 16px; }
.cats__table td:first-child { font-weight: 900; }
.cats__table :is(th, td):last-child { padding-left: 16px; text-align: right; font-variant-numeric: tabular-nums; }

/* About */
.about {
  display: grid;
  gap: 29px;
  padding: 32px clamp(20px, 9vw, 77px) clamp(32px, 8vw, 96px);
  background: var(--sand);
  border-radius: clamp(24px, 5vw, 43px);
}
.about__img { width: min(100%, 593px); }
.about__logo { margin: 0; }
/* logo.svg is the white lockup; turn it near-black here. */
.about__logo img { width: 100%; filter: brightness(0) opacity(0.9); }
.about__text { font-size: clamp(1.0625rem, 2.6vw, 1.375rem); }
.about__text p { margin: 0 0 1.4em; }
.about__text p:last-child { margin: 0; }
.about__lead strong { font-family: var(--body); font-weight: 600; }

/* Footer */
.footer { text-align: center; padding: 1rem 16px 3rem; font-size: 0.95rem; color: var(--muted); }

/* Buy popup */
.buy {
  width: min(92vw, 420px);
  max-height: 92vh;
  padding: 2rem 1.5rem 1.5rem;
  border: 0;
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.5);
}
/* The dialog itself takes focus on open (quiz.js), so ✕ shows no ring until someone tabs to it. */
.buy:focus { outline: none; }
.buy::backdrop { background: rgb(0 0 0 / 0.7); }
.buy[open] { animation: pop 0.2s ease-out; }
.buy__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.3rem;
  cursor: pointer;
}
.buy__img { width: min(220px, 60vw); margin: 0 auto 1rem; filter: drop-shadow(0 12px 20px rgb(0 0 0 / 0.3)); }
.buy__title {
  margin: 0 0 0.5rem;
  font-family: var(--display);
  font-weight: 400;
  font-size: 2rem;
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--red);
}
.buy__text { margin: 0 0 1.25rem; }
.buy__cta { width: 100%; }
.buy__continue {
  margin-top: 0.75rem;
  min-height: 44px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
