:root {
  color-scheme: dark;
  --night: #12091d;
  --night-soft: #26143a;
  --ink: #f8f3ff;
  --gold: #ffd166;
  --violet: #bca7ff;
  --pink: #ff93cc;
  --bar-height: 76px;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 22%, #38205a 0, #1b0d2a 34rem, var(--night) 70rem),
    var(--night);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, sans-serif;
}

button { font: inherit; }

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

.sky::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .18;
  background-image:
    radial-gradient(circle, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle, #d9ceff 0 1px, transparent 1.5px);
  background-position: 0 0, 42px 68px;
  background-size: 96px 96px, 137px 137px;
}

.moon {
  position: absolute;
  width: min(34vw, 440px);
  aspect-ratio: 1;
  top: 8vh;
  right: -8vw;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff9dd, #ffd98a 54%, #ffa85b 77%);
  box-shadow: 0 0 70px #ffc66b55, 0 0 180px #a678ff33;
  opacity: .7;
  animation: moonBreath 8s ease-in-out infinite;
}

.mist {
  position: absolute;
  width: 70vw;
  height: 16vh;
  border-radius: 50%;
  filter: blur(42px);
  background: #a98bdb22;
  animation: mistDrift 18s ease-in-out infinite alternate;
}

.mist-one { top: 26%; left: -20%; }
.mist-two { top: 68%; right: -30%; animation-delay: -8s; }

.sparkle {
  position: absolute;
  width: var(--size);
  height: var(--size);
  left: var(--left);
  top: var(--top);
  border-radius: 50%;
  background: var(--color);
  box-shadow: 0 0 14px var(--color);
  animation: sparkle var(--speed) ease-in-out var(--delay) infinite;
}

.reader-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  min-height: var(--bar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid #ffffff1a;
  background: #130a20d9;
  box-shadow: 0 12px 40px #09030f55;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.identity, .reader-actions { display: flex; align-items: center; }
.identity { gap: .7rem; min-width: 0; }
.hat-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50% 50% 45% 55%;
  color: #271436;
  background: var(--gold);
  box-shadow: 0 0 24px #ffd16644;
  transform: rotate(-8deg);
}

.identity h1 { margin: 0; font-size: clamp(1rem, 2.2vw, 1.35rem); line-height: 1.1; }
.identity p { margin: .18rem 0 0; color: #d7c9e7; font-size: .78rem; }
.reader-actions { gap: .45rem; }

.icon-button, .play-button {
  min-height: 44px;
  border: 1px solid #ffffff22;
  color: var(--ink);
  background: #ffffff0d;
  cursor: pointer;
  transition: transform .2s ease, background .2s ease, border-color .2s ease;
}

.icon-button:hover, .play-button:hover { transform: translateY(-1px); background: #ffffff18; border-color: #ffffff44; }
.icon-button:focus-visible, .play-button:focus-visible, .dot:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.icon-button { width: 44px; border-radius: 50%; font-size: 1.75rem; line-height: 1; }
.icon-button:disabled { opacity: .35; cursor: default; transform: none; }
.page-status { min-width: 3.5rem; text-align: center; font-variant-numeric: tabular-nums; }
.status-divider { padding: 0 .28rem; color: #a993bd; }
.play-button { display: flex; align-items: center; gap: .55rem; margin-left: .35rem; padding: .55rem .9rem; border-radius: 999px; }
.play-icon { color: var(--gold); font-size: .72rem; }

.comic { padding-top: var(--bar-height); }

.comic-spread {
  position: relative;
  min-height: 100svh;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  justify-items: center;
  gap: clamp(.2rem, .8vw, .8rem);
  padding: calc(var(--bar-height) + .35rem) .4rem .35rem;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  perspective: 1500px;
}

.comic-page {
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
  perspective: inherit;
}

.comic-spread:last-child .comic-page:only-child { grid-column: 1 / -1; }

.paper {
  position: relative;
  width: min(48vw, 80vh, 780px);
  aspect-ratio: 1191 / 1684;
  overflow: hidden;
  border-radius: 8px 12px 10px 7px;
  background: #fff;
  box-shadow: 0 30px 90px #050108aa, 0 2px 0 #ffffff66 inset;
  transform: translateY(60px) rotateX(5deg) scale(.94);
  opacity: .35;
  transition: transform 1s cubic-bezier(.2, .8, .2, 1), opacity .8s ease, box-shadow .8s ease;
}

.comic-page:nth-child(even) .paper { transform: translateY(60px) rotateX(5deg) rotate(-1deg) scale(.94); }
.comic-page.is-active .paper { transform: translateY(0) rotateX(0) rotate(0) scale(1); opacity: 1; box-shadow: 0 38px 110px #050108cc, 0 0 0 1px #ffffff44; }
.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, #fff9 49%, transparent 62%);
  transform: translateX(-150%);
}
.comic-page.is-active .paper::after { animation: pageGlimmer 1.35s .35s ease-out both; }

.page-art, .motion-layer { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.page-art { z-index: 1; }
.motion-layer { z-index: 2; pointer-events: none; clip-path: var(--clip); transform-origin: center; opacity: 0; }
.comic-page.is-active .motion-layer { opacity: 1; animation-delay: var(--delay); }
.comic-page.is-active .layer-drift,
.comic-page.is-active .layer-float,
.comic-page.is-active .layer-bob { animation: float 3.8s ease-in-out var(--delay) infinite; }
.comic-page.is-active .layer-swoop,
.comic-page.is-active .layer-fly,
.comic-page.is-active .layer-climb,
.comic-page.is-active .layer-finale { animation: swoop 3.2s ease-in-out var(--delay) infinite; }
.comic-page.is-active .layer-pop,
.comic-page.is-active .layer-idea,
.comic-page.is-active .layer-startle { animation: pop 2.7s ease-in-out var(--delay) infinite; }
.comic-page.is-active .layer-nod,
.comic-page.is-active .layer-pant,
.comic-page.is-active .layer-cheer { animation: nod 2.2s ease-in-out var(--delay) infinite; }
.comic-page.is-active .layer-rattle,
.comic-page.is-active .layer-charge,
.comic-page.is-active .layer-thump,
.comic-page.is-active .layer-blast,
.comic-page.is-active .layer-boom { animation: rattle 1.5s ease-in-out var(--delay) infinite; }

.page-glow {
  position: absolute;
  width: min(72vw, 680px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #bb8cff28, transparent 66%);
  filter: blur(30px);
  opacity: 0;
  transition: opacity 1s ease;
}
.comic-page.is-active .page-glow { opacity: 1; animation: glowPulse 5s ease-in-out infinite; }

.magic-ring {
  position: absolute;
  z-index: 3;
  border: 2px solid #b47cff99;
  border-radius: 50%;
  box-shadow: 0 0 16px #b47cffaa, inset 0 0 10px #b47cff66;
  opacity: 0;
}
.ring-one { width: 16%; aspect-ratio: 1; left: 42%; top: 57%; }
.ring-two { width: 10%; aspect-ratio: 1; left: 55%; top: 63%; }
.comic-page.is-active .magic-ring { animation: ringCast 3s ease-out infinite; }
.comic-page.is-active .ring-two { animation-delay: 1.2s; }

.spell-burst { position: absolute; z-index: 4; left: 59%; top: 61%; width: 15%; aspect-ratio: 1; pointer-events: none; }
.spell-burst i { position: absolute; left: 50%; top: 50%; width: 5px; height: 50%; border-radius: 8px; transform-origin: 50% 0; background: linear-gradient(var(--gold), transparent); opacity: 0; }
.spell-burst i:nth-child(2) { transform: rotate(90deg); }
.spell-burst i:nth-child(3) { transform: rotate(180deg); }
.spell-burst i:nth-child(4) { transform: rotate(270deg); }
.comic-page.is-active .spell-burst i { animation: ray 2s .6s ease-out infinite; }

.bubble { position: absolute; z-index: 4; border: 2px solid #bd7dffbb; border-radius: 50%; box-shadow: inset 0 0 8px #ff9bdc99; opacity: 0; }
.bubble-a { width: 5%; aspect-ratio: 1; left: 48%; top: 73%; }
.bubble-b { width: 3.2%; aspect-ratio: 1; left: 54%; top: 70%; }
.bubble-c { width: 4%; aspect-ratio: 1; left: 58%; top: 76%; }
.comic-page.is-active .bubble { animation: bubbleUp 3.4s ease-in infinite; }
.comic-page.is-active .bubble-b { animation-delay: .9s; }
.comic-page.is-active .bubble-c { animation-delay: 1.7s; }

.music-notes { position: absolute; z-index: 4; left: 12%; top: 34%; color: #7d43bb; font-weight: 800; text-shadow: 0 0 10px #c37cff; pointer-events: none; }
.music-notes span { position: absolute; opacity: 0; font-size: clamp(1rem, 3vw, 2.25rem); }
.music-notes span:nth-child(2) { left: 2.4rem; top: -1rem; }
.music-notes span:nth-child(3) { left: 4.2rem; top: 1.4rem; }
.comic-page.is-active .music-notes span { animation: noteFly 3s ease-out infinite; }
.comic-page.is-active .music-notes span:nth-child(2) { animation-delay: .7s; }
.comic-page.is-active .music-notes span:nth-child(3) { animation-delay: 1.4s; }

.finale-stars { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.finale-stars i { position: absolute; width: 9px; aspect-ratio: 1; background: var(--gold); clip-path: polygon(50% 0, 61% 38%, 100% 50%, 61% 62%, 50% 100%, 39% 62%, 0 50%, 39% 38%); opacity: 0; }
.finale-stars i:nth-child(1) { left: 19%; top: 10%; }
.finale-stars i:nth-child(2) { left: 50%; top: 7%; }
.finale-stars i:nth-child(3) { left: 82%; top: 12%; }
.finale-stars i:nth-child(4) { left: 68%; top: 35%; }
.finale-stars i:nth-child(5) { left: 27%; top: 31%; }
.comic-page.is-active .finale-stars i { animation: starPop 2.5s ease-in-out infinite; }
.comic-page.is-active .finale-stars i:nth-child(2) { animation-delay: .5s; }
.comic-page.is-active .finale-stars i:nth-child(3) { animation-delay: 1s; }
.comic-page.is-active .finale-stars i:nth-child(4) { animation-delay: 1.5s; }
.comic-page.is-active .finale-stars i:nth-child(5) { animation-delay: 2s; }

.ending { margin: 1.1rem 0 0; color: #f4dcff; font-size: clamp(1.2rem, 3vw, 2rem); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: 0; transform: translateY(15px); transition: opacity .8s 1s ease, transform .8s 1s ease; }
.finale.is-active .ending { opacity: 1; transform: translateY(0); }
.ending span { color: var(--gold); }

.page-dots {
  position: fixed;
  z-index: 20;
  top: 50%;
  right: clamp(.65rem, 2.5vw, 1.8rem);
  display: flex;
  flex-direction: column;
  gap: .62rem;
  transform: translateY(-50%);
}
.dot { width: 12px; height: 12px; padding: 0; border: 1px solid #ffffff80; border-radius: 50%; background: #ffffff1f; cursor: pointer; transition: transform .25s ease, background .25s ease, box-shadow .25s ease; }
.dot:hover { transform: scale(1.3); }
.dot.is-current { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 14px #ffd166aa; transform: scale(1.2); }

@keyframes moonBreath { 50% { transform: scale(1.04); filter: brightness(1.08); } }
@keyframes mistDrift { to { transform: translateX(35vw) translateY(-4vh); } }
@keyframes sparkle { 0%, 100% { opacity: .15; transform: scale(.5); } 50% { opacity: .9; transform: scale(1.35); } }
@keyframes pageGlimmer { to { transform: translateX(150%); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-5px) rotate(.25deg); } }
@keyframes swoop { 0%, 100% { transform: translate(0, 0) rotate(0); } 50% { transform: translate(5px, -4px) rotate(-.35deg); } }
@keyframes pop { 0%, 100% { transform: scale(1); } 45% { transform: scale(1.013); } 60% { transform: scale(1.005); } }
@keyframes nod { 0%, 100% { transform: rotate(0); } 45% { transform: rotate(.4deg) translateY(2px); } }
@keyframes rattle { 0%, 100% { transform: translate(0); } 25% { transform: translate(-2px, 1px); } 50% { transform: translate(2px, -1px); } 75% { transform: translate(-1px, -1px); } }
@keyframes glowPulse { 50% { transform: scale(1.1); opacity: .72; } }
@keyframes ringCast { 0% { opacity: 0; transform: scale(.35); } 25% { opacity: .75; } 100% { opacity: 0; transform: scale(1.8); } }
@keyframes ray { 0%, 20% { opacity: 0; transform: scaleY(.2); } 45% { opacity: .85; } 100% { opacity: 0; transform: scaleY(1.4); } }
@keyframes bubbleUp { 0% { opacity: 0; transform: translateY(10px) scale(.6); } 20% { opacity: .8; } 100% { opacity: 0; transform: translate(15px, -90px) scale(1.25); } }
@keyframes noteFly { 0% { opacity: 0; transform: translate(0, 10px) rotate(-12deg); } 20% { opacity: .85; } 100% { opacity: 0; transform: translate(70px, -55px) rotate(15deg); } }
@keyframes starPop { 0%, 100% { opacity: 0; transform: rotate(0) scale(.3); } 45% { opacity: .95; transform: rotate(90deg) scale(1.4); } 65% { opacity: .4; } }

@media (max-width: 720px) {
  :root { --bar-height: 68px; }
  .reader-bar { padding: .55rem .75rem; }
  .hat-mark { width: 38px; height: 38px; }
  .identity p { display: none; }
  .play-label { display: none; }
  .play-button { width: 44px; justify-content: center; padding: 0; }
  .comic-spread { gap: .2rem; padding: calc(var(--bar-height) + .2rem) .2rem .2rem; }
  .paper { width: min(48vw, 80vh); border-radius: 4px; }
  .page-dots { right: .65rem; gap: .55rem; }
  .dot { width: 10px; height: 10px; }
  .moon { width: 55vw; right: -20vw; }
}

@media (max-width: 420px) {
  .identity h1 { max-width: 9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page-status { min-width: 2.7rem; font-size: .9rem; }
  .reader-actions { gap: .2rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .motion-layer, .magic-ring, .bubble, .spell-burst, .music-notes, .finale-stars { display: none; }
  .paper, .comic-page:nth-child(even) .paper { transform: none; opacity: 1; }
}
