:root {
  --paper: #f3e6c8;
  --paper-deep: #e8d5a8;
  --ink: #16110c;
  --ink-dim: rgba(22, 17, 12, 0.62);
  --yellow: #ffd400;
  --red: #e23d2b;
  --cyan: #3aa0ff;
  --white: #fffaf1;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-display: "Bangers", "Impact", "Arial Black", sans-serif;
  --font-hand: "Patrick Hand", "Segoe Print", cursive;
  --font-ui: "Comic Neue", "Comic Sans MS", system-ui, sans-serif;
}

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

html,
body {
  height: 100%;
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 700;
  background: var(--paper);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
}

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.paper {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255, 212, 0, 0.18), transparent 42%),
    radial-gradient(ellipse at 90% 80%, rgba(226, 61, 43, 0.08), transparent 40%),
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(22, 17, 12, 0.035) 28px),
    var(--paper);
}

.halftone {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.22;
  background-image: radial-gradient(rgba(22, 17, 12, 0.45) 1px, transparent 1.2px);
  background-size: 7px 7px;
  mix-blend-mode: multiply;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0.12;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#stage {
  position: relative;
  z-index: 2;
  height: 100dvh;
  height: 100svh;
}

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.7s var(--ease), transform 0.8s var(--ease);
}

.scene.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.kicker {
  margin: 0 0 10px;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--red);
}

.display {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 9vw, 5rem);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: 0.02em;
  text-wrap: balance;
  color: var(--ink);
  text-shadow: 3px 3px 0 var(--yellow);
}

.hint {
  margin: 16px 0 0;
  font-family: var(--font-hand);
  font-size: 1.15rem;
  color: var(--ink-dim);
}

.text-btn {
  appearance: none;
  background: var(--yellow);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  margin-top: 16px;
  padding: 10px 18px;
  color: var(--ink);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.85rem;
  font-weight: 700;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.text-btn:hover,
.text-btn:focus-visible {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ink);
}

.text-btn.is-hidden,
.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  transition: opacity 0.8s var(--ease), visibility 0.8s;
}

.loader.is-gone {
  opacity: 0;
  visibility: hidden;
}

.loader__burst {
  font-family: var(--font-display);
  font-size: 2.4rem;
  background: var(--yellow);
  border: 3px solid var(--ink);
  padding: 10px 16px;
  transform: rotate(-8deg);
  box-shadow: 5px 5px 0 var(--ink);
}

.loader__text {
  margin: 22px 0 0;
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.gate-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
  background: var(--paper);
}

.gate-screen .issue__title {
  max-width: none;
  margin-bottom: 8px;
}

.gate-screen__copy {
  font-family: var(--font-hand);
  font-size: 1.25rem;
  margin: 0 0 18px;
  max-width: 22rem;
}

.gate-screen video {
  width: min(100%, 280px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  background: #111;
  margin-bottom: 16px;
  transform: scaleX(-1);
}

.gate-screen__input {
  appearance: none;
  font-family: var(--font-ui);
  font-size: 1.1rem;
  letter-spacing: 0.28em;
  text-align: center;
  width: min(100%, 220px);
  padding: 12px 10px;
  border: 3px solid var(--ink);
  background: var(--white);
  margin-bottom: 8px;
}

.gate-screen__err {
  color: var(--red);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.sound {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 40;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--white);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

.sound .sound__off {
  display: block;
}

.sound .sound__notes {
  opacity: 0.4;
}

.sound[aria-pressed="true"] .sound__off {
  display: none;
}

.sound[aria-pressed="true"] .sound__notes {
  opacity: 1;
}

/* ---------- cover ---------- */
.scene--cover {
  justify-content: center;
}

.issue {
  appearance: none;
  position: relative;
  width: min(100%, 420px);
  padding: 22px 18px 20px;
  border: 5px solid var(--ink);
  background: var(--white);
  box-shadow: 10px 10px 0 var(--ink);
  text-align: center;
}

.issue__kicker {
  margin: 0 0 8px;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.issue__title {
  position: relative;
  z-index: 1;
  margin: 0 auto;
  max-width: 11ch;
  font-family: var(--font-display);
  font-size: clamp(2.15rem, 9.4vw, 3.5rem);
  line-height: 0.9;
  letter-spacing: 0.02em;
  text-wrap: balance;
  color: var(--ink);
  text-shadow: 4px 4px 0 var(--yellow);
}

.issue__byline {
  position: relative;
  z-index: 1;
  margin: 8px 0 14px;
  font-family: var(--font-hand);
  font-size: 1.2rem;
}

.issue__starring {
  margin: 12px 0 0;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.issue__starring em {
  font-family: var(--font-hand);
  font-style: normal;
  font-size: 1.15rem;
  letter-spacing: 0;
  text-transform: none;
}

.burst {
  position: absolute;
  left: 50%;
  top: 58px;
  width: 240px;
  height: 240px;
  transform: translateX(-50%);
  background: var(--yellow);
  clip-path: polygon(
    50% 0%,
    63% 22%,
    90% 12%,
    78% 38%,
    100% 50%,
    78% 62%,
    90% 88%,
    63% 78%,
    50% 100%,
    37% 78%,
    10% 88%,
    22% 62%,
    0% 50%,
    22% 38%,
    10% 12%,
    37% 22%
  );
  z-index: 0;
  opacity: 0.95;
}

.burst--sm {
  position: absolute;
  width: 220px;
  height: 220px;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0.7;
  z-index: -1;
}

.panel {
  position: relative;
  margin: 0;
  border: 4px solid var(--ink);
  background: #16110c;
  overflow: hidden;
  box-shadow: 5px 5px 0 var(--ink);
}

.panel img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  filter: contrast(1.08) saturate(1.08);
}

.panel--cover {
  height: 240px;
  transform: rotate(-1.4deg);
}

.panel__caption {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  margin: 0;
  padding: 8px 10px 6px;
  background: var(--yellow);
  border: 3px solid var(--ink);
  font-family: var(--font-hand);
  font-size: 1.05rem;
  line-height: 1.25;
  text-align: left;
  color: var(--ink);
}

.bubble {
  position: absolute;
  top: 12px;
  right: 10px;
  max-width: 62%;
  padding: 8px 12px 10px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 18px 18px 18px 4px;
  font-family: var(--font-hand);
  font-size: 1.05rem;
  line-height: 1.2;
  color: var(--ink);
  z-index: 2;
}

.bubble--cover {
  top: auto;
  bottom: 14px;
  right: 12px;
  left: auto;
}

.sfx {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  color: var(--red);
  -webkit-text-stroke: 4px var(--white);
  paint-order: stroke fill;
  transform: rotate(-8deg);
  pointer-events: none;
}

/* ---------- comic pages ---------- */
.scene--comic {
  justify-content: flex-start;
  gap: 10px;
}

.comic__pager {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.comic__stage {
  width: min(100%, 440px);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.comic__stage.is-turn {
  animation: page-in 0.45s var(--ease);
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateX(28px) rotate(1.2deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.comic-title {
  border: 4px solid var(--ink);
  background: var(--white);
  padding: 28px 22px;
  box-shadow: 8px 8px 0 var(--ink);
  min-height: 52%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.comic-title h2 {
  margin: 6px 0 14px;
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  line-height: 0.95;
  text-shadow: 3px 3px 0 var(--yellow);
}

.comic-title p {
  margin: 0;
  font-family: var(--font-hand);
  font-size: 1.35rem;
  line-height: 1.4;
}

.panel--hero {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel--hero img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

.duo {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
}

.duo .panel {
  min-height: 0;
}

.duo .panel img {
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

.scene--comic .text-btn {
  margin-top: auto;
}

/* ---------- letter ---------- */
.letter {
  user-select: text;
  width: min(100%, 440px);
  max-height: min(64vh, 600px);
  overflow: auto;
  padding: 32px 26px 26px;
  color: var(--ink);
  background: var(--white);
  border: 4px solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  transform: rotate(-0.4deg);
}

.letter__greet,
.letter__body p,
.letter__close {
  font-family: var(--font-hand);
  font-size: 1.25rem;
  line-height: 1.45;
  margin: 0 0 0.9em;
  overflow-wrap: break-word;
}

.letter__close {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.letter__sign {
  font-family: var(--font-hand);
  font-size: 1.8rem;
  color: var(--red);
  line-height: 1.2;
}

/* ---------- question / ending ---------- */
.question {
  position: relative;
  text-align: center;
  max-width: 40rem;
}

.question__hint {
  margin: 12px 0 0;
  font-family: var(--font-hand);
  font-size: 1.2rem;
  color: var(--ink-dim);
}

.choices {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-top: 32px;
  min-height: 64px;
}

.btn {
  appearance: none;
  border: 3px solid var(--ink);
  border-radius: 0;
  padding: 12px 28px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.btn--yes {
  background: var(--yellow);
  color: var(--ink);
}

.btn--yes:hover,
.btn--yes:focus-visible {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 var(--ink);
}

.btn--shy {
  background: var(--white);
  color: var(--ink-dim);
  position: relative;
}

.ending {
  text-align: center;
  max-width: 36rem;
  padding: 24px;
}

.scene--yes.is-active .ending,
.scene--wait.is-active .ending {
  animation: rise 0.9s var(--ease) both;
}

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

.ending__body {
  margin: 14px 0 0;
  font-family: var(--font-hand);
  font-size: 1.35rem;
  color: var(--ink-dim);
}

.ending__sign {
  display: block;
  margin-top: 22px;
}

.petals {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  overflow: hidden;
}

.petal {
  position: absolute;
  top: -8%;
  width: 14px;
  height: 18px;
  background: var(--red);
  border: 2px solid var(--ink);
  opacity: 0.9;
  animation: fall var(--dur, 8s) linear var(--delay, 0s) infinite;
}

.petal:nth-child(3n) {
  background: var(--yellow);
}

.petal:nth-child(4n) {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

@keyframes fall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0;
  }
  8% {
    opacity: 0.95;
  }
  100% {
    transform: translate3d(var(--drift, 40px), 110vh, 0) rotate(360deg);
    opacity: 0.15;
  }
}

@media (max-width: 640px) {
  .issue {
    width: min(100%, 360px);
    padding: 18px 14px 16px;
  }

  .panel--cover {
    height: 190px;
  }

  .letter {
    padding: 26px 20px 22px;
  }

  .duo .panel__caption,
  .panel__caption {
    font-size: 0.95rem;
  }
}

@media (max-height: 700px) {
  .panel--cover {
    height: 150px;
  }

  .issue__title {
    font-size: clamp(1.9rem, 9vw, 2.8rem);
  }
}

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

  .scene {
    transform: none;
  }
}
