/* ============================================================
   TUNABLE VALUES
   Edit these first. Everything else follows from them.
   ============================================================ */

:root {
  /* Comic artwork size (do not change unless assets change) */
  --art-ratio: 2406 / 3000;

  /* Puzzle hotspot — percentages of the comic artwork.
     x/y are the TOP-LEFT corner. Make the box a little larger
     than the question-mark moth so it is easy to tap.
     Preview the box with:  ?debug=1  */
  --hotspot-x: 43%;
  --hotspot-y: 35%;
  --hotspot-w: 18%;
  --hotspot-h: 15%;

  /* How long scene changes take */
  --duration-intro: 1.15s;
  --duration-panel: 0.9s;
  --duration-reveal: 1.45s;
  --duration-hint: 0.7s;

  /* Gentle cinematic push-in on Panel 1 (about 3%) */
  --push-scale: 1.03;
  --push-duration: 9s;

  /* Colors sampled from the comics */
  --color-ink: #3d4a7a;
  --color-ink-soft: rgba(61, 74, 122, 0.72);
  --color-plum: #3b2148;
  --color-cream: #fff6e8;
  --color-caption: rgba(255, 246, 232, 0.94);
  --color-meadow: #e4f0d4;
  --color-sky: #c5e4ec;
  --color-hearth: #e6d0de;
  --color-glow: rgba(255, 236, 170, 0.75);
}

/* ============================================================
   Base
   ============================================================ */

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

html,
body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100dvh;
  font-family: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, "Times New Roman", serif;
  color: var(--color-ink);
  background: var(--color-meadow);
  -webkit-font-smoothing: antialiased;
}

button,
a {
  font-family: inherit;
}

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

/* Author `display` rules otherwise override the hidden attribute. */
[hidden] {
  display: none !important;
}

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

/* ============================================================
   Stage
   ============================================================ */

.story {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  background: var(--color-meadow);
  color: var(--color-plum);
  transition: background-color 1.2s ease;
}

.story[data-scene="panel-2"] {
  background: var(--color-sky);
}

.story[data-scene="panel-3"],
.story[data-scene="ending"] {
  background: var(--color-hearth);
}

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
}

.art-frame {
  position: relative;
  aspect-ratio: 2406 / 3000;
  height: min(100%, calc(100vw * (3000 / 2406)));
  width: auto;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
}

.art-frame picture {
  display: block;
  width: 100%;
  height: 100%;
}

.art {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
}

/* Intro: Panel 1 is recognizable but not yet revealed */
.story[data-scene="intro"] .art {
  filter: blur(10px) brightness(0.78) saturate(0.92);
  transform: scale(1.08);
  animation: intro-drift 28s ease-in-out infinite alternate;
}

.story[data-scene="panel-1"] .art {
  animation: reveal-and-push var(--push-duration) ease-out forwards;
}

/* Crossfade / zoom-out when swapping panels */
.art.is-leaving {
  animation: art-leave var(--duration-panel) ease forwards;
}

.art.is-leaving.is-slow,
.art.is-entering.is-slow {
  animation-duration: var(--duration-reveal);
}

.art.is-entering {
  animation: art-enter var(--duration-panel) ease both;
}

.art-frame.is-miss .art {
  animation: miss-wobble 0.45s ease;
}

.art-frame.is-found .hotspot {
  background: radial-gradient(circle, var(--color-glow), transparent 68%);
  transform: scale(1.18);
  box-shadow: 0 0 28px 10px rgba(255, 230, 150, 0.45);
}

@keyframes intro-drift {
  from { transform: scale(1.08) translate(0, 0); }
  to   { transform: scale(1.12) translate(-0.6%, 0.4%); }
}

@keyframes reveal-and-push {
  0% {
    filter: blur(10px) brightness(0.78);
    transform: scale(1.08);
  }
  18% {
    filter: blur(0) brightness(1);
    transform: scale(1);
  }
  100% {
    filter: blur(0) brightness(1);
    transform: scale(var(--push-scale));
  }
}

@keyframes art-leave {
  to {
    opacity: 0;
    filter: blur(8px);
    transform: scale(1.04);
  }
}

@keyframes art-enter {
  from {
    opacity: 0;
    filter: blur(8px);
    transform: scale(1.03);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }
}

@keyframes miss-wobble {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

/* ============================================================
   Hotspot (invisible in production)
   ============================================================ */

.hotspot {
  position: absolute;
  left: var(--hotspot-x);
  top: var(--hotspot-y);
  width: var(--hotspot-w);
  height: var(--hotspot-h);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 3;
  border-radius: 50%;
  transition: transform 0.45s ease, box-shadow 0.45s ease, background 0.45s ease;
}

.hotspot:focus {
  outline: none;
}

.hotspot:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.85), 0 0 16px 4px rgba(196, 170, 255, 0.7);
}

body.debug .hotspot {
  outline: 2px dashed #d45c5c;
  outline-offset: 2px;
  background: rgba(212, 92, 92, 0.28);
}

/* Full-frame hit target sits under the hotspot */
.scene-hit {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: transparent;
  font-size: 0;
}

.scene-hit:focus {
  outline: none;
}

.scene-hit:focus-visible {
  box-shadow: inset 0 0 0 3px rgba(61, 74, 122, 0.45);
}

/* ============================================================
   Storybook captions
   Sit in the empty page margin on wide screens; compact
   below the comic when side space is not available.
   ============================================================ */

.caption-rail {
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  width: 100%;
  padding: 0.4rem 0.8rem max(0.7rem, env(safe-area-inset-bottom));
  pointer-events: none;
}

.caption-rail:not(:has(> :not([hidden]))) {
  display: none;
  padding: 0;
}

.caption-card {
  width: min(24rem, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  padding: 0.65rem 0.95rem;
  color: var(--color-plum);
  background: var(--color-caption);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(45, 22, 48, 0.14);
  text-align: center;
  pointer-events: auto;
}

.intro-kicker,
.ending-copy,
.hint,
.miss-note,
.puzzle-hint-main {
  margin: 0;
  max-width: 18em;
  font-size: clamp(1.05rem, 2.6vw, 1.35rem);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: var(--color-plum);
}

.puzzle-hint-sub {
  margin: 0;
  max-width: 18em;
  font-size: clamp(0.9rem, 2.1vw, 1.05rem);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.35;
  color: var(--color-plum);
}

.puzzle-hint {
  gap: 0.2rem;
}

.text-btn,
.hotspot,
.scene-hit,
.begin-btn,
.replay-btn {
  touch-action: manipulation;
}

.text-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0.1em 0;
  margin: 0;
  color: var(--color-plum);
  cursor: pointer;
  font-size: clamp(1.05rem, 2.5vw, 1.35rem);
  letter-spacing: 0.06em;
  line-height: 1.3;
  border-bottom: 1px solid currentColor;
  border-radius: 0;
  pointer-events: auto;
}

.text-btn:hover {
  opacity: 0.78;
}

.text-btn:focus {
  outline: none;
}

.text-btn:focus-visible {
  opacity: 1;
  border-bottom-width: 2px;
  box-shadow: 0 2px 0 currentColor;
}

.replay-btn,
.community-link {
  text-decoration: none;
}

.replay-btn:focus-visible,
.community-link:focus-visible {
  box-shadow: 0 2px 0 currentColor;
}

/* Wide / landscape: keep the comic full-height and use the side gutter */
@media (min-aspect-ratio: 6 / 5) {
  .story {
    display: block;
  }

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

  .art-frame {
    width: min(100vw, calc(100dvh * (2406 / 3000)));
    height: min(100dvh, calc(100vw * (3000 / 2406)));
    max-height: 100dvh;
  }

  .caption-rail {
    position: absolute;
    top: 50%;
    left: calc(50% + min(50vw, 50dvh * 2406 / 3000) + 0.9rem);
    right: max(0.85rem, env(safe-area-inset-right));
    transform: translateY(-50%);
    width: auto;
    max-width: 17.5rem;
    padding: 0;
    align-items: stretch;
  }

  .caption-card {
    width: auto;
  }
}

/* ============================================================
   Mute
   ============================================================ */

.mute-btn {
  position: absolute;
  top: max(0.7rem, env(safe-area-inset-top));
  right: max(0.7rem, env(safe-area-inset-right));
  z-index: 6;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-plum);
  font-size: 1.15rem;
  cursor: pointer;
  opacity: 0.7;
  touch-action: manipulation;
}

.mute-btn span {
  position: relative;
  display: inline-block;
}

.mute-btn:hover,
.mute-btn:focus-visible {
  opacity: 1;
}

.mute-btn:focus {
  outline: none;
}

.mute-btn:focus-visible {
  outline: 2px solid var(--color-ink);
  outline-offset: 3px;
}

.mute-btn.is-muted span::after {
  content: "";
  position: absolute;
  width: 1.4rem;
  height: 2px;
  background: currentColor;
  transform: rotate(-45deg);
  margin-left: -1.15rem;
  margin-top: 0.7rem;
}

/* ============================================================
   Debug readout
   ============================================================ */

.debug-readout {
  position: absolute;
  left: 0.6rem;
  top: 0.6rem;
  z-index: 7;
  margin: 0;
  padding: 0.4rem 0.55rem;
  background: rgba(255, 255, 255, 0.88);
  color: #7a2a2a;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  white-space: pre;
  pointer-events: none;
}

/* ============================================================
   Reduced motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .story[data-scene="intro"] .art,
  .story[data-scene="panel-1"] .art,
  .art.is-leaving,
  .art.is-entering,
  .art-frame.is-miss .art {
    animation: none !important;
    filter: none;
    transform: none;
  }

  .story[data-scene="intro"] .art {
    filter: brightness(0.82);
    transform: none;
  }

  .art,
  .story,
  .hint,
  .hotspot,
  .caption-card {
    transition: none !important;
  }

  .caption-card {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (max-width: 420px) {
  .intro-kicker,
  .ending-copy,
  .hint,
  .puzzle-hint-main {
    font-size: 1.05rem;
  }

  .puzzle-hint-sub {
    font-size: 0.92rem;
  }

  .text-btn {
    font-size: 1.05rem;
  }
}
