/* Outbreak at the North Pole: layout and animation.
   Mobile first (from 360 px). Play area max 520 px, decorative backdrop beyond.
   System fonts only: no third-party requests. All sizes in rem so that text
   scales with the browser font size. Every animation has a reduced-motion
   fallback at the bottom of this file. */

:root {
  --ink: #1b2233;
  --paper: #fdfbf6;
  --card: #ffffff;
  --accent: #b3261e;
  --accent-ink: #ffffff;
  --muted: #4d5566;
  --line: #b9c0cc;
  --sky: #1d2b4f;
  --sky-deep: #111a33;
  --focus: #1a5fd0;
  --ok: #1e6b34;
  --gold: #ffd84d;
  --placeholder: #d9dee8;
  --radius: 14px;
  --shadow: 0 3px 0 rgba(27, 34, 51, .18);
  --max: 520px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 100%;
  line-height: 1.45;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--sky); }
img { max-width: 100%; }

/* ---------- Page and decorative backdrop (visible beyond the play area) ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(ellipse at 50% 0%, #34497c 0%, var(--sky) 55%, var(--sky-deep) 100%);
}
.backdrop::before, .backdrop::after {
  content: ""; position: absolute; inset: -100% 0 0 0;
  background-image:
    radial-gradient(2px 2px at 20px 30px, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 120px 80px, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 200px 150px, rgba(255,255,255,.8) 50%, transparent 51%),
    radial-gradient(2px 2px at 60px 190px, rgba(255,255,255,.7) 50%, transparent 51%);
  background-size: 240px 240px;
  animation: snow 24s linear infinite;
  opacity: .55;
}
.backdrop::after { background-size: 170px 170px; animation-duration: 38s; opacity: .35; }
@keyframes snow { from { transform: translateY(0); } to { transform: translateY(50%); } }

.app {
  position: relative;
  max-width: var(--max);
  min-height: 100vh; min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  display: flex; flex-direction: column;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 10px 40px rgba(0,0,0,.45);
  overflow-x: clip; /* flying handle and sleigh stay inside the play area */
}
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .5rem .75rem; position: sticky; top: 0; z-index: 10;
  background: var(--paper); border-bottom: 1px solid #e6e2d8;
}
.progress { display: flex; gap: .45rem; list-style: none; margin: 0; padding: 0; }
.progress li { width: .75rem; height: .75rem; border-radius: 50%; border: 2px solid var(--ink); transition: transform .3s, background-color .3s; }
.progress li.done { background: var(--ink); }
.progress li.current { background: var(--accent); border-color: var(--accent); transform: scale(1.25); }

.stage { position: relative; flex: 1; display: flex; flex-direction: column; }
.scene { position: relative; flex: 1; display: flex; flex-direction: column; gap: 1rem; padding: 1rem 1rem 10rem; }
.scene.enter > :not(.scene-bg) { animation: scene-in .45s ease-out both; }
@keyframes scene-in { from { opacity: 0; transform: translateY(.75rem); } to { opacity: 1; transform: none; } }
.scene-bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.scene-bg > * { width: 100%; height: 100%; object-fit: cover; border: 0; }
.scene > :not(.scene-bg) { position: relative; z-index: 1; }

/* ---------- Controls ---------- */
button {
  font: inherit; color: var(--ink); background: var(--card);
  border: 2px solid var(--ink); border-radius: var(--radius);
  padding: .7rem 1rem; min-height: 44px; cursor: pointer; text-align: left;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, background-color .2s;
}
button:not(:disabled):hover { background: #f3f6fd; }
button:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(27, 34, 51, .18); }
button:disabled { cursor: default; box-shadow: none; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); text-align: center; font-weight: 600; }
button.primary:not(:disabled):hover { background: #9c1f18; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.mute { padding: .3rem .8rem; min-height: 36px; font-size: .9rem; box-shadow: none; }

/* Placeholder for any image that has not been supplied yet. */
.placeholder {
  display: flex; align-items: center; justify-content: center;
  background: var(--placeholder); border: 2px dashed var(--muted);
  color: var(--muted); font: .75rem/1.2 ui-monospace, monospace;
  text-align: center; padding: .25rem; overflow-wrap: anywhere;
  min-height: 3rem;
}

/* ---------- Speech bubbles ---------- */
.bubble-layer {
  position: fixed; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max); z-index: 5; cursor: pointer;
  background: linear-gradient(to top, rgba(17, 26, 51, .45), rgba(17, 26, 51, .1) 60%);
  display: flex; align-items: flex-end; padding: .75rem;
}
.bubble-layer[hidden] { display: none; }
.bubble {
  width: 100%; display: grid; grid-template-columns: 3.75rem 1fr; gap: .25rem .75rem; align-items: start;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius);
  padding: .85rem; box-shadow: 0 5px 0 rgba(0,0,0,.25);
  animation: pop .25s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(.8rem) scale(.96); } to { opacity: 1; transform: none; } }
.portrait { width: 3.75rem; height: 3.75rem; border-radius: 50%; overflow: hidden; background: #eef1f6; border: 2px solid var(--ink); }
.portrait > * { width: 100%; height: 100%; min-height: 0; object-fit: cover; font-size: .45rem; border: 0; }
.bubble-body p { margin: .15rem 0 0; font-size: 1.05rem; }
.bubble .speaker { font-weight: 700; color: var(--accent); }
.bubble-next { grid-column: 2; justify-self: end; padding: .3rem 1rem; min-height: 36px; }

/* ---------- Choices ---------- */
.prompt {
  margin: 0; padding: .7rem .9rem; background: rgba(255,255,255,.95);
  border-left: 5px solid var(--accent); border-radius: 6px; font-weight: 600;
}
.options { display: flex; flex-direction: column; gap: .65rem; }
.option.chosen-wrong, .accuse.chosen-wrong { border-style: dashed; color: var(--muted); box-shadow: none; }
.option.chosen-wrong::before, .accuse.chosen-wrong::before { content: "✗ "; font-weight: 700; }
.option.chosen-correct, .accuse.chosen-correct { border-color: var(--ok); border-width: 3px; animation: correct .5s ease-out; }
.option.chosen-correct::before, .accuse.chosen-correct::before { content: "✓ "; font-weight: 700; color: var(--ok); }
@keyframes correct { 40% { transform: scale(1.03); } }
.hint { margin: 0; font-style: italic; }

/* ---------- Scene 1: envelope and telegram ---------- */
.envelope-btn {
  position: relative; align-self: center; padding: 0; border: none; background: none; box-shadow: none;
  width: min(80%, 320px); margin-top: 3rem; text-align: center;
  animation: wiggle 3s ease-in-out 1s infinite;
}
.envelope-btn:not(:disabled):hover { background: none; }
.envelope-btn > img, .envelope-btn > .placeholder { width: 100%; aspect-ratio: 4 / 3; height: auto; }
.envelope-logo { position: absolute; left: 50%; top: 62%; transform: translate(-50%, -50%); width: 40%; }
.envelope-logo > * { width: 100%; min-height: 2rem; }
.envelope-btn.opening { animation: open-envelope .45s ease-in forwards; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-3deg); } 90% { transform: rotate(3deg); } 95% { transform: rotate(-2deg); } }
@keyframes open-envelope { to { transform: scale(1.15) translateY(-1rem); opacity: 0; } }
.telegram { position: relative; align-self: center; width: min(94%, 400px); margin-top: 1rem; }
.telegram > .paper { position: absolute; inset: 0; width: 100%; height: 100%; box-shadow: 0 6px 16px rgba(0,0,0,.25); }
.telegram p {
  position: relative; margin: 0; padding: 2.25rem 1.5rem;
  font-family: ui-monospace, "Courier New", monospace; text-transform: uppercase; letter-spacing: .04em;
  font-size: 1.05rem; line-height: 1.6;
}
.telegram.unfold { transform-origin: top center; animation: unfold .6s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes unfold { from { transform: perspective(600px) rotateX(-75deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Scene 3: epidemic curve ---------- */
.current-case { min-height: 2.8rem; display: flex; align-items: center; }
.block-to-place {
  display: inline-block; padding: .5rem .85rem; border: 2px solid var(--ink); border-radius: 8px;
  background: repeating-linear-gradient(45deg, #f2c94c 0 4px, #fff3c4 4px 8px); font-weight: 700;
  box-shadow: var(--shadow); animation: pop .3s both;
}
.block-to-place.gone { visibility: hidden; }
.bounce { animation: bounce .45s; }
@keyframes bounce { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-.6rem); } 40% { transform: translateX(.5rem); } 60% { transform: translateX(-.3rem); } 80% { transform: translateX(.2rem); } }
.curve {
  background: rgba(255,255,255,.95); border: 2px solid var(--ink); border-radius: var(--radius);
  padding: .6rem .5rem .5rem; display: grid; grid-template-columns: 1.7rem minmax(0, 1fr); gap: .3rem; box-shadow: var(--shadow);
}
.party-marker {
  grid-row: 1 / 3; writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: .72rem; font-weight: 600; color: var(--accent);
  border-left: 3px dashed var(--accent); padding-left: .25rem; text-align: center;
}
.cols { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .2rem; align-items: end; }
.col {
  height: 100%; min-height: 11.5rem; min-width: 0; padding: .15rem; border: 1px solid var(--line); border-radius: 6px;
  background: transparent; display: flex; align-items: flex-end; justify-content: center; box-shadow: none;
}
.col:not(:disabled):hover { background: #eef3ff; border-color: var(--focus); }
.col:not(:disabled):active { transform: none; }
.stack { display: flex; flex-direction: column-reverse; gap: 2px; width: 100%; }
.block { display: block; height: 1.45rem; border-radius: 4px; background: #8a94a8; border: 1px solid var(--ink); }
.block.drop { animation: drop .45s cubic-bezier(.3, 1.4, .5, 1) both; }
@keyframes drop { from { transform: translateY(-6rem); opacity: 0; } to { transform: none; opacity: 1; } }
.block.placed { background: repeating-linear-gradient(45deg, #f2c94c 0 4px, #fff3c4 4px 8px); }
.col-labels { grid-column: 2; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .2rem; font-size: .62rem; text-align: center; line-height: 1.15; overflow-wrap: anywhere; }
.patterns { display: flex; flex-direction: column; gap: .65rem; }
.pattern-option { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .75rem; }
.pattern-option > span { min-width: 0; }
.thumb { width: 5rem; height: 2.5rem; flex: none; }

/* ---------- Scene 4: interviews ---------- */
.people { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; }
.person { display: flex; flex-direction: column; align-items: center; gap: .3rem; padding: .5rem; text-align: center; }
.person > img, .person > .placeholder { width: 100%; aspect-ratio: 1; height: auto; object-fit: contain; }
.person-name { font-weight: 600; }
.person.heard { border-style: dashed; box-shadow: none; }
.person.heard .person-name::after { content: " ✓"; color: var(--ok); }
.tray {
  position: sticky; bottom: .5rem; background: var(--card); border: 2px solid var(--ink);
  border-radius: var(--radius); padding: .5rem .75rem; box-shadow: var(--shadow);
}
.tray h3 { margin: 0 0 .3rem; font-size: 1rem; }
.tray-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem .9rem; }
.tray-list li { display: flex; align-items: center; gap: .3rem; animation: pop .35s both; }
.tray-list li.tray-empty { animation: none; color: var(--muted); font-style: italic; }
.tray-list li > img, .tray-list li > .placeholder { width: 2.5rem; height: 2.5rem; min-height: 0; font-size: .45rem; object-fit: contain; }

/* ---------- Scene 5: cohort study ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: .55rem; }
.card { display: flex; flex-direction: column; gap: .3rem; }
.card-test { display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .45rem; text-align: center; font-weight: 600; }
.card-test > img, .card-test > .placeholder { width: 4rem; height: 4rem; min-height: 0; object-fit: contain; font-size: .5rem; }
.card-test.current { border-color: var(--focus); border-width: 3px; }
.tested-mark { font-size: .8rem; font-weight: 400; color: var(--ok); min-height: 1.1em; }
.accuse { text-align: center; padding: .3rem; min-height: 36px; font-weight: 600; }
.accuse:disabled { opacity: .45; }
.compare { background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); padding: .7rem .8rem; box-shadow: var(--shadow); scroll-margin: 4rem; }
.compare h3 { margin: 0 0 .5rem; }
.cohort-row { margin-bottom: .75rem; }
.row-head { display: flex; gap: .75rem; align-items: baseline; }
.row-head .pct { margin-left: auto; font-weight: 700; font-size: 1.1rem; }
.bar { display: block; height: .7rem; background: #e3e6ec; border: 1px solid var(--ink); border-radius: 4px; margin: .25rem 0 .35rem; overflow: hidden; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--ink); transition: width .9s cubic-bezier(.2, .8, .2, 1) .35s; }
.elves { display: flex; flex-wrap: wrap; gap: 1px; }
.elf { width: 1.15rem; height: 1.5rem; }
.rr { font-size: 1.2rem; font-weight: 700; margin: .2rem 0 0; padding-top: .5rem; border-top: 1px solid var(--line); animation: pop .4s .6s both; }

/* ---------- Scene 6: pump ---------- */
.pump { position: relative; align-self: center; width: min(70%, 260px); margin-top: .5rem; }
.pump > img, .pump > .placeholder { width: 100%; aspect-ratio: 3 / 4; height: auto; }
.pump-handle {
  position: absolute; right: -8%; top: 20%; width: 40%; padding: 0; border: none; background: none; box-shadow: none;
  transition: transform .35s cubic-bezier(.3, 1.4, .5, 1), opacity .5s; touch-action: none;
}
.pump-handle:not(:disabled):hover { background: none; }
.pump-handle > * { width: 100%; min-height: 2.5rem; pointer-events: none; }
.pump-handle.ready { outline: 3px dashed var(--accent); outline-offset: 4px; animation: tug 1.6s ease-in-out infinite; cursor: grab; }
.pump-handle.dragging { transition: none; animation: none; cursor: grabbing; }
.pump-handle.off { animation: handle-off .8s cubic-bezier(.3, .1, .7, 1) forwards; outline: none; }
@keyframes tug { 50% { transform: translate(4px, -4px) rotate(4deg); } }
@keyframes handle-off { 30% { transform: translate(1rem, -3rem) rotate(25deg); } to { transform: translate(8rem, 10rem) rotate(200deg); opacity: 0; } }

/* ---------- Finale ---------- */
.scene.finale { color: #fff; align-items: center; background: var(--sky-deep); overflow: hidden; }
.stars {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 30px 40px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 90px 120px, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 160px 70px, var(--gold) 50%, transparent 51%),
    radial-gradient(1px 1px at 220px 160px, #fff 50%, transparent 51%);
  background-size: 250px 200px;
  animation: twinkle-bg 3s ease-in-out infinite alternate;
}
@keyframes twinkle-bg { from { opacity: .5; } to { opacity: 1; } }
.skip { align-self: flex-end; background: rgba(255,255,255,.92); }
.finale-elves { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; max-width: 20rem; margin-top: 2rem; }
.finale-elves .elf { width: 1.9rem; height: 2.5rem; }
.elf.hop { animation: hop .45s ease-out both; }
@keyframes hop { 40% { transform: translateY(-.6rem) scale(1.1); } }
.sleigh { position: absolute; top: 5rem; left: 0; width: 55%; z-index: 2; transform: translateX(-110%); }
.sleigh > * { width: 100%; min-height: 3rem; }
.sleigh.fly { animation: fly 2.4s ease-in forwards; }
@keyframes fly {
  0% { transform: translate(-110%, 4rem) rotate(-6deg); }
  60% { transform: translate(60%, 0) rotate(-10deg); }
  100% { transform: translate(200%, -5rem) rotate(-14deg); opacity: 0; }
}
.finale-curve { width: 100%; max-width: 24rem; margin-top: 3rem; overflow: visible; }
.finale-block { fill: #8a94a8; stroke: rgba(255,255,255,.6); stroke-width: .8; transform-box: fill-box; transform-origin: bottom; opacity: 0; transition: fill .6s; }
.finale-curve.built .finale-block { animation: rise .4s cubic-bezier(.3, 1.4, .5, 1) both; }
@keyframes rise { from { transform: scaleY(0); opacity: 0; } to { transform: none; opacity: 1; } }
.finale-curve.green .finale-block { fill: #2e9e4f; }
.finale-light { opacity: 0; transition: opacity .4s; }
.finale-light.hue-0 { fill: var(--gold); }
.finale-light.hue-1 { fill: #ff8a80; }
.finale-light.hue-2 { fill: #9ad8ff; }
.finale-curve.lit .finale-light { opacity: 1; animation: blink 1.4s ease-in-out infinite alternate; }
.finale-curve.lit .finale-light.hue-1 { animation-delay: .45s; }
.finale-curve.lit .finale-light.hue-2 { animation-delay: .9s; }
@keyframes blink { from { opacity: 1; } to { opacity: .35; } }
.finale-star { fill: var(--gold); stroke: #fff; stroke-width: 1; opacity: 0; transform-box: fill-box; transform-origin: center; }
.finale-curve.lit .finale-star { animation: land 1s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes land { from { transform: translateY(-12rem) rotate(-180deg); opacity: 0; } 60% { opacity: 1; } to { transform: none; opacity: 1; } }

/* ---------- Greeting ---------- */
.scene.greeting { justify-content: center; background: var(--sky-deep); overflow: hidden; }
.snowfall {
  position: absolute; inset: -100% 0 0 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(3px 3px at 20px 30px, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 110px 90px, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 70px 160px, rgba(255,255,255,.8) 50%, transparent 51%);
  background-size: 180px 200px;
  animation: snow 18s linear infinite;
}
.greeting-card {
  background: rgba(253, 251, 246, .97); border-radius: var(--radius); padding: 1.4rem 1.2rem;
  text-align: center; display: flex; flex-direction: column; gap: .55rem; align-items: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); animation: pop .5s both;
}
.greeting-card h1 { font-size: 1.55rem; line-height: 1.25; margin: 0; }
h1:focus, h2:focus { outline: none; } /* headings focused by script on scene change */
.greeting-card p { margin: 0; }
.signature { font-style: italic; }
.flakes { display: flex; gap: .35rem; justify-content: center; margin-top: .3rem; }
.flake { width: 2.1rem; height: 2.1rem; animation: flake-in .6s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes flake-in { from { transform: scale(0) rotate(-120deg); opacity: 0; } to { transform: none; opacity: 1; } }
.result .title { font-weight: 700; font-size: 1.2rem; color: var(--accent); }
.logo-link { display: block; width: 10rem; margin-top: .3rem; }
.logo-link > * { width: 100%; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: center; margin-top: .3rem; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Reduced motion: no movement, end states shown at once ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important;
    transition-duration: .01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important;
  }
  .backdrop::before, .backdrop::after, .snowfall, .stars { animation: none !important; }
  .sleigh.fly { animation: none !important; opacity: 0; }
  .scene.enter > :not(.scene-bg) { animation: fade .2s both !important; animation-duration: .2s !important; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
}
