:root {
  --paper: #efe4cb;
  --card: #fbf6e9;
  --note: #fdf1bd;
  --ink: #1f2b26;
  --ink-soft: #5d6658;
  --line: #b9a77f;
  --accent: #b5382b;
  --accent-deep: #8c271d;
  --olive: #55673a;
  --tile: #fffdf6;
  --shadow: #1f2b26;
  --on-accent: #fff8ea;
  --tape: rgba(214, 186, 110, 0.6);
  --display: 'Gloock', 'Amiri', serif;
  --body: 'Crimson Pro', 'Amiri', serif;
  --hand: 'Caveat', 'Amiri', cursive;
  color-scheme: light;
}

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

[hidden] {
  display: none !important;
}

html {
  /* The page shake moves things sideways, which would otherwise add a sideways scroll. */
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

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

/* iOS Safari ignores background-attachment: fixed, so the map texture sits on fixed layers. */
body::before,
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  inset: -4%;
  z-index: -1;
  background:
    url('contours.svg') center top / cover no-repeat,
    radial-gradient(ellipse at 15% 0%, #fbf3dd, transparent 60%),
    radial-gradient(ellipse at 100% 100%, #dbc798, transparent 55%);
}

body::after {
  z-index: 5;
  background: url('grain.svg') 0 0 / 220px 220px;
  mix-blend-mode: multiply;
}

.map {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 1.9rem;
  max-width: 34rem;
  margin: 0 auto;
  padding:
    calc(1.6rem + env(safe-area-inset-top))
    calc(1.25rem + env(safe-area-inset-right))
    calc(3.5rem + env(safe-area-inset-bottom))
    calc(1.25rem + env(safe-area-inset-left));
}

.masthead,
.trail,
.card,
.memories {
  animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.trail {
  animation-delay: 0.12s;
}

.card {
  animation-delay: 0.24s;
}

.compass {
  float: right;
  width: 3.9rem;
  height: 3.9rem;
  margin: 0 0 0.4rem 1rem;
  color: var(--ink);
  animation: settle 1.8s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}

.compass-north {
  fill: var(--accent);
}

.eyebrow,
.card-label {
  margin: 0 0 0.9rem;
  color: var(--accent-deep);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 1rem;
  font-family: var(--display);
  font-size: clamp(2.7rem, 12vw, 4.4rem);
  font-weight: 400;
  line-height: 1;
  text-wrap: balance;
}

.intro {
  max-width: 30ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: 1.2rem;
  font-style: italic;
  white-space: pre-line;
}

.trail {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.trail li {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  min-width: 0;
}

.trail li::after {
  content: '';
  flex: 1 1 0.5rem;
  min-width: 0.25rem;
  border-top: 2px dashed var(--line);
}

.trail li:last-child {
  flex: 0 1 auto;
}

.trail li:last-child::after {
  display: none;
}

.pin {
  display: grid;
  flex: 0 1 2.3rem;
  place-items: center;
  min-width: 1.5rem;
  aspect-ratio: 1;
  border: 2px dashed var(--line);
  border-radius: 50%;
  color: var(--ink-soft);
  font-family: var(--display);
  font-size: 1rem;
  line-height: 1;
}

.trail .is-done .pin {
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--card);
}

.trail .is-done::after {
  border-top: 2px solid var(--ink);
}

.trail .is-current .pin {
  border: 2px solid var(--accent);
  background: var(--card);
  color: var(--accent-deep);
  animation: pulse 2.2s ease-in-out infinite;
}

.trail .treasure .pin {
  border: 0;
  color: var(--accent);
  font-family: var(--hand);
  font-size: 2.3rem;
  font-weight: 700;
  transform: rotate(-8deg);
}

.trail .treasure.is-done .pin {
  background: none;
  animation: pulse-x 1.4s ease-in-out infinite;
}

.card {
  position: relative;
  min-height: 15rem;
  overflow: hidden;
  padding: 1.6rem 1.4rem 1.7rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.9rem;
  background: var(--card);
  box-shadow: 5px 6px 0 var(--ink);
}

.screen {
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

/* Stops iPhone Safari from zooming in when pieces and tiles are tapped quickly. */
button {
  touch-action: manipulation;
}

.status {
  margin: 3.5rem 0 1.5rem;
  color: var(--ink-soft);
  font-size: 1.3rem;
  font-style: italic;
  text-align: center;
}

#screen-offline {
  text-align: center;
}

.clue {
  margin: 0 0 1.2rem;
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: pre-line;
  text-wrap: pretty;
}

.text-button {
  padding: 0.4rem 0 0.15rem;
  border: 0;
  border-bottom: 2px dotted currentColor;
  background: none;
  color: var(--olive);
  font-family: var(--hand);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.hint {
  margin: 1rem 0 0;
  padding: 0.7rem 0.9rem;
  background: var(--note);
  font-family: var(--hand);
  font-size: 1.4rem;
  line-height: 1.3;
  white-space: pre-line;
  transform: rotate(-0.6deg);
}

.code-form {
  margin-top: 1.6rem;
  padding-top: 1.3rem;
  border-top: 2px dashed var(--line);
}

.code-form label {
  display: block;
  margin-bottom: 0.55rem;
  color: var(--ink-soft);
  font-style: italic;
}

.answer-row {
  display: flex;
  gap: 0.7rem;
}

.answer-row input {
  flex: 1;
  min-width: 0;
  padding: 0.75rem 0.85rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.6rem;
  background: var(--tile);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.2;
}

input:focus-visible,
button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.button {
  padding: 0.8rem 1.15rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.6rem;
  background: var(--accent);
  box-shadow: 3px 3px 0 var(--shadow);
  color: var(--on-accent);
  font-family: var(--display);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}

.button:active {
  box-shadow: 0 0 0 var(--ink);
  transform: translate(3px, 3px);
}

.button:disabled {
  opacity: 0.6;
}

.feedback {
  min-height: 1.6rem;
  margin: 0.7rem 0 0;
  color: var(--accent-deep);
  font-family: var(--hand);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
}

.game-question {
  margin: 0 0 1.2rem;
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.35;
  white-space: pre-line;
}

.game {
  margin-bottom: 0.4rem;
}

#game-back-button {
  margin-top: 0.6rem;
}

.round-label {
  margin: 0 0 0.5rem;
  color: var(--ink-soft);
  font-style: italic;
}

.game-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.quiz-image {
  display: block;
  width: 100%;
  height: 13rem;
  margin: 0 0 1.1rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.5rem;
  background: var(--paper);
  object-fit: contain;
}

.match {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}

.match-column {
  display: grid;
  align-content: start;
  gap: 0.5rem;
}

.match-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 3.1rem;
  padding: 0.4rem 0.5rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.5rem;
  background: var(--tile);
  color: var(--ink);
  font-family: var(--body);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.15;
  text-align: start;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.match-item.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(181, 56, 43, 0.25);
}

.match-item.is-paired {
  background: var(--note);
}

.match-badge {
  display: grid;
  flex: 0 0 1.5rem;
  place-items: center;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--ink);
  color: var(--card);
  font-family: var(--display);
  font-size: 0.85rem;
  line-height: 1;
}

.match-badge:empty {
  border: 1.5px dashed var(--line);
  background: none;
}

.sequence {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}

.sequence-tile {
  display: grid;
  place-items: center;
  min-width: 3.1rem;
  height: 3.1rem;
  padding: 0 0.6rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.5rem;
  background: var(--tile);
  font-family: var(--display);
  font-size: 1.4rem;
  line-height: 1;
}

.sequence-tile.is-missing {
  border: 2px dashed var(--accent);
  color: var(--accent);
  animation: pulse 2.2s ease-in-out infinite;
}

.choices {
  display: grid;
  gap: 0.75rem;
}

.choice {
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.6rem;
  background: var(--tile);
  box-shadow: 3px 3px 0 var(--shadow);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.2rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: start;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}

.choice:disabled {
  opacity: 0.6;
}

.choice:active {
  box-shadow: 0 0 0 var(--ink);
  transform: translate(3px, 3px);
}

.game-status {
  min-height: 1.9rem;
  margin: 0 0 0.9rem;
  color: var(--accent-deep);
  font-family: var(--hand);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.versus {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.versus-side {
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  padding: 1.1rem 0.4rem 1.3rem;
  border: 1.5px solid var(--ink);
  border-radius: 0.9rem;
  background: var(--tile);
  box-shadow: 4px 4px 0 var(--shadow);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}

.versus-side:active {
  box-shadow: none;
  transform: translate(4px, 4px);
}

.versus-side.is-winner {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  animation: pulse-x 0.9s ease-in-out infinite;
}

.versus-name {
  font-family: var(--stage-font, var(--display));
  font-size: 1.4rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.versus-score {
  font-family: var(--display);
  font-size: 4.6rem;
  line-height: 1;
}

.versus-mark {
  color: var(--accent);
  font-family: var(--stage-font, var(--display));
  font-size: 1.5rem;
}

.scramble-slots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem 1.1rem;
  margin-bottom: 1.3rem;
}

.scramble-word {
  display: flex;
  gap: 0.2rem;
}

.scramble-slot {
  display: grid;
  place-items: center;
  width: 1.45rem;
  height: 2.1rem;
  border-bottom: 2px solid var(--ink);
  font-family: var(--display);
  font-size: 1.3rem;
  line-height: 1;
}

.scramble-tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.letter-tile {
  width: 2.7rem;
  height: 2.7rem;
  padding: 0;
  border: 1.5px solid var(--ink);
  border-radius: 0.5rem;
  background: var(--tile);
  box-shadow: 2px 3px 0 var(--shadow);
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
}

.letter-tile:disabled {
  box-shadow: none;
  opacity: 0.25;
  transform: translate(2px, 3px);
}

.puzzle {
  display: grid;
  gap: 2px;
  max-width: 24rem;
  aspect-ratio: 1;
  margin: 0 auto 1rem;
  padding: 2px;
  border-radius: 0.4rem;
  background: var(--ink);
}

.puzzle-piece {
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0.15rem;
  background-color: var(--paper);
  cursor: pointer;
}

.puzzle-piece.is-selected {
  outline: 4px solid var(--accent);
  outline-offset: -4px;
  transform: scale(0.9);
}

.reaction {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(31, 43, 38, 0.8);
  animation: fade 0.2s both;
}

.polaroid {
  position: relative;
  width: min(100%, 21rem);
  margin: 0;
  padding: 0.9rem 0.9rem 1.1rem;
  background: var(--tile);
  box-shadow: 0 26px 40px -18px rgba(0, 0, 0, 0.7);
  transform: rotate(-3deg);
  animation: drop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}

.reaction[data-kind='wrong'] .polaroid {
  animation:
    drop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) both,
    wobble 0.5s 0.45s;
}

/* Phone photos are tall, so the frame is taller than wide and keeps the upper part, where faces are. */
.polaroid img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  background: var(--paper);
  object-fit: cover;
  object-position: 50% 30%;
}

.polaroid figcaption {
  margin-top: 0.8rem;
  font-family: var(--hand);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
}

.stamp {
  position: absolute;
  right: -0.9rem;
  bottom: 3.2rem;
  display: grid;
  place-items: center;
  width: 8.5rem;
  height: 8.5rem;
  padding: 0.6rem;
  border: 6px double var(--accent);
  border-radius: 50%;
  background: rgba(255, 253, 246, 0.85);
  color: var(--accent);
  font-family: var(--display);
  font-size: 1.5rem;
  line-height: 1.05;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  transform: rotate(-14deg);
  animation: stamp 0.5s 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.note {
  position: relative;
  margin: 0;
  padding: 1.3rem 1.1rem 1.1rem;
  background: var(--note);
  box-shadow: 0 8px 14px -9px rgba(60, 40, 10, 0.55);
  font-family: var(--hand);
  font-size: 1.45rem;
  line-height: 1.3;
  white-space: pre-line;
}

.note::before {
  content: '';
  position: absolute;
  top: -0.6rem;
  left: 50%;
  width: 5rem;
  height: 1.3rem;
  background: var(--tape);
  transform: translateX(-50%) rotate(-3deg);
}

.note-large {
  margin: 1.4rem 0 1.8rem;
  font-size: 1.7rem;
  transform: rotate(-1deg);
}

.note-stop {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--accent-deep);
  font-family: var(--body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.note-text {
  display: block;
}

.page-footer {
  text-align: center;
}

.photo-box {
  margin: 0 0 1.2rem;
  padding: 1rem;
  border: 2px dashed var(--line);
  border-radius: 0.7rem;
  text-align: center;
}

.photo-note {
  margin: 0 0 0.9rem;
  color: var(--ink-soft);
  font-style: italic;
}

.photo-taken {
  display: block;
  width: 100%;
  max-height: 18rem;
  margin: 0 0 1rem;
  padding: 0.5rem 0.5rem 1.6rem;
  background: #fffdf6;
  box-shadow: 0 8px 14px -9px rgba(60, 40, 10, 0.55);
  object-fit: contain;
  transform: rotate(-1.5deg);
}

.photo-box .button {
  display: inline-block;
}

/* The real file picker is kept out of sight, and the button next to it opens it. */
.photo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.memory-media {
  display: grid;
  gap: 1.2rem;
  margin: 1.2rem 0 1.6rem;
}

.memory-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.5rem 1.6rem;
  background: #fffdf6;
  box-shadow: 0 8px 14px -9px rgba(60, 40, 10, 0.55);
}

.memory-media .memory-item:nth-child(odd) {
  transform: rotate(-1.2deg);
}

.memory-media .memory-item:nth-child(even) {
  transform: rotate(1deg);
}

.note .memory-item {
  margin: 0.3rem 0 0.5rem;
  padding: 0;
  box-shadow: none;
}

.memories ol {
  display: grid;
  gap: 1.7rem;
  margin: 1.4rem 0 0;
  padding: 0;
  list-style: none;
}

.memories li:nth-child(odd) {
  transform: rotate(-1.2deg);
}

.memories li:nth-child(even) {
  transform: rotate(1deg);
}

.ending-mark {
  display: block;
  width: 11rem;
  margin: 0 0 1.2rem;
  color: var(--line);
}

.ending-x {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  transform-origin: 198px 35px;
  animation: stamp-x 0.6s 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.4) both;
}

.ending h2 {
  margin: 0 0 1rem;
  font-family: var(--display);
  font-size: clamp(2.1rem, 9vw, 3rem);
  font-weight: 400;
  line-height: 1.05;
  text-wrap: balance;
}

.ending-message {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.45;
  white-space: pre-line;
}

body[data-look='magic'] {
  --stage-accent: #f0c75e;
  --stage-dark: #0d0b26;
  --stage-text: #f7efd9;
  --stage-soft: #cbbf9f;
  --stage-panel: rgba(13, 11, 38, 0.8);
  --stage-mark: rgba(240, 199, 94, 0.28);
  --stage-shade-top: rgba(9, 8, 32, 0.4);
  --stage-shade-bottom: rgba(9, 8, 32, 0.93);
  --stage-font: 'Cinzel Decorative', 'Amiri', serif;
  --on-accent: #1a1430;
}

body[data-look='ice'] {
  --stage-accent: #a8dcef;
  --stage-dark: #07131c;
  --stage-text: #eef6fa;
  --stage-soft: #a9bcc6;
  --stage-panel: rgba(8, 20, 30, 0.82);
  --stage-mark: rgba(168, 220, 239, 0.25);
  --stage-shade-top: rgba(6, 16, 26, 0.35);
  --stage-shade-bottom: rgba(6, 16, 26, 0.93);
  --stage-font: 'Cinzel', 'Amiri', serif;
  --on-accent: #06202b;
}

body[data-look='smoke'] {
  --stage-accent: #e04a38;
  --stage-dark: #120d0a;
  --stage-text: #f1e7d3;
  --stage-soft: #b8a98e;
  --stage-panel: rgba(18, 13, 10, 0.86);
  --stage-mark: rgba(224, 74, 56, 0.3);
  --stage-shade-top: rgba(24, 14, 6, 0.45);
  --stage-shade-bottom: rgba(14, 9, 6, 0.95);
  --stage-font: 'Bebas Neue', 'Amiri', sans-serif;
  --on-accent: #fff3e6;
}

body[data-look='quiz'] {
  --stage-accent: #ffd23f;
  --stage-dark: #160a3a;
  --stage-text: #fdf7ff;
  --stage-soft: #cdbdee;
  --stage-panel: rgba(30, 12, 78, 0.84);
  --stage-mark: rgba(255, 210, 63, 0.28);
  --stage-shade-top: rgba(58, 16, 130, 0.6);
  --stage-shade-bottom: rgba(16, 6, 50, 0.95);
  --stage-font: 'Bungee', 'Amiri', sans-serif;
  --on-accent: #1b0b3a;
}

body[data-look='love'] {
  --stage-accent: #ff7d9c;
  --stage-dark: #2b0716;
  --stage-text: #fff1f3;
  --stage-soft: #f2c1cb;
  --stage-panel: rgba(58, 10, 30, 0.8);
  --stage-mark: rgba(255, 125, 156, 0.3);
  --stage-shade-top: rgba(150, 30, 70, 0.55);
  --stage-shade-bottom: rgba(40, 6, 22, 0.94);
  --stage-font: 'Pacifico', 'Amiri', cursive;
  --on-accent: #3b0a1a;
}

body[data-look='hands'] {
  --stage-accent: #ffb347;
  --stage-dark: #052a2e;
  --stage-text: #f4fffb;
  --stage-soft: #a9d6cf;
  --stage-panel: rgba(4, 46, 52, 0.84);
  --stage-mark: rgba(255, 179, 71, 0.3);
  --stage-shade-top: rgba(12, 120, 120, 0.6);
  --stage-shade-bottom: rgba(3, 30, 36, 0.95);
  --stage-font: 'Bungee', 'Amiri', sans-serif;
  --on-accent: #2b1500;
}

body[data-look='arena'] {
  --stage-accent: #ffd23f;
  --stage-dark: #0b0b18;
  --stage-text: #ffffff;
  --stage-soft: #d6d6ea;
  --stage-panel: rgba(10, 10, 26, 0.84);
  --stage-mark: rgba(255, 210, 63, 0.32);
  --stage-shade-top: rgba(0, 0, 0, 0.15);
  --stage-shade-bottom: rgba(0, 0, 0, 0.72);
  --stage-font: 'Bungee', 'Amiri', sans-serif;
  --on-accent: #1a1200;
  --backdrop: linear-gradient(115deg, #c9182f 0 50%, #1549c9 50% 100%);
}

body[data-look='eyes'] {
  --stage-accent: #a6ef5f;
  --stage-dark: #04070f;
  --stage-text: #f2fbea;
  --stage-soft: #a9b8a0;
  --stage-panel: rgba(6, 12, 22, 0.88);
  --stage-mark: rgba(166, 239, 95, 0.28);
  --stage-shade-top: rgba(10, 40, 30, 0.5);
  --stage-shade-bottom: rgba(3, 6, 12, 0.96);
  --stage-font: 'Bebas Neue', 'Amiri', sans-serif;
  --on-accent: #0c1a02;
}

.stage-backdrop,
.curtain {
  background:
    linear-gradient(var(--stage-shade-top), var(--stage-shade-bottom)),
    var(--backdrop, none) center / cover no-repeat,
    var(--stage-dark);
}

.stage-backdrop {
  position: fixed;
  inset: -4%;
  z-index: -1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}

body.in-game .stage-backdrop {
  opacity: 1;
  animation: slow-zoom 24s ease-in-out infinite alternate;
}

body[data-look='quiz'] .stage-backdrop::after {
  content: '';
  position: absolute;
  inset: -50%;
  background: conic-gradient(
    transparent 0 8%,
    rgba(255, 210, 63, 0.2) 10% 14%,
    transparent 16% 48%,
    rgba(255, 255, 255, 0.14) 50% 54%,
    transparent 56%
  );
  animation: spin 14s linear infinite;
}

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

.particle {
  position: absolute;
  bottom: -12%;
  left: var(--x);
  color: var(--stage-accent);
  font-size: var(--size);
  line-height: 1;
  opacity: 0;
  text-shadow: 0 0 12px var(--stage-accent);
  animation: float-up var(--time) linear var(--delay) infinite;
}

body[data-look='ice'] .particle {
  top: -12%;
  bottom: auto;
  color: #fff;
  animation-name: float-down;
}

body[data-look='smoke'] .particle {
  width: calc(var(--size) * 6);
  height: calc(var(--size) * 6);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(220, 205, 185, 0.2), transparent 68%);
}

body[data-look='quiz'] .particle {
  font-family: 'Bungee', sans-serif;
}

body.in-game .masthead,
body.in-game .trail,
body.in-game .memories,
body.in-game .page-footer {
  display: none;
}

body.in-game .map {
  display: block;
  max-width: 36rem;
}

body.in-game .card {
  --ink: var(--stage-text);
  --ink-soft: var(--stage-soft);
  --line: var(--stage-soft);
  --card: var(--stage-dark);
  --accent: var(--stage-accent);
  --accent-deep: var(--stage-accent);
  --olive: var(--stage-soft);
  --note: var(--stage-mark);
  --tile: rgba(255, 255, 255, 0.09);
  --shadow: var(--stage-accent);
  position: relative;
  top: auto;
  border-color: var(--stage-accent);
  background: var(--stage-panel);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 0 46px -8px var(--stage-accent);
  color: var(--stage-text);
  animation: stage-in 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.stage-header {
  position: relative;
  margin-bottom: 1.3rem;
  padding-right: 5.6rem;
}

.stage-kicker {
  margin: 0 0 0.35rem;
  color: var(--stage-soft);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.stage-title {
  margin: 0;
  color: var(--stage-accent);
  font-family: var(--stage-font);
  font-size: clamp(2rem, 9.5vw, 3.2rem);
  font-weight: 700;
  line-height: 1.08;
  text-shadow: 0 0 24px var(--stage-mark), 0 2px 0 rgba(0, 0, 0, 0.5);
}

.stage-music {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.4rem 0.7rem;
  border: 1.5px solid var(--stage-soft);
  border-radius: 999px;
  background: none;
  color: var(--stage-soft);
  font-family: var(--body);
  font-size: 0.85rem;
  cursor: pointer;
}

.curtain {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.7rem;
  padding: 2rem 1.5rem;
  color: var(--stage-text);
  text-align: center;
  cursor: pointer;
  transition: opacity 0.5s;
}

.curtain.is-leaving {
  opacity: 0;
}

.curtain-kicker {
  margin: 0;
  color: var(--stage-soft);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  animation: rise 0.6s 0.2s both;
}

.curtain-title {
  margin: 0;
  color: var(--stage-accent);
  font-family: var(--stage-font);
  font-size: clamp(3rem, 15vw, 6.5rem);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 44px var(--stage-accent), 0 4px 0 rgba(0, 0, 0, 0.55);
  animation: slam 0.7s 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.curtain-tagline {
  max-width: 24ch;
  margin: 0.4rem 0 0;
  font-size: 1.4rem;
  font-style: italic;
  animation: rise 0.7s 1.2s both;
}

.curtain-skip {
  margin: 1.6rem 0 0;
  color: var(--stage-soft);
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  animation: blink 1.4s 2s infinite both;
}

.flash {
  position: fixed;
  inset: 0;
  z-index: 4;
  opacity: 0;
  pointer-events: none;
}

body.is-shaking .flash {
  animation: flash 0.7s both;
}

body.is-shaking::before,
body.is-shaking .map,
body.is-shaking .stage-backdrop,
body.is-shaking .curtain {
  animation: quake 0.7s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

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

.confetti {
  position: absolute;
  top: 45%;
  left: 50%;
  width: 0.6rem;
  height: 1rem;
  background: var(--color);
  animation: confetti 1.6s cubic-bezier(0.15, 0.7, 0.3, 1) both;
}

/* The height check keeps a phone held sideways on the phone layout. */
@media (min-width: 768px) and (min-height: 600px) {
  .map {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      'masthead card'
      'trail card'
      'memories card';
    align-items: start;
    column-gap: clamp(2rem, 4.5vw, 3.5rem);
    row-gap: 2.4rem;
    max-width: 66rem;
    padding: 4rem clamp(2rem, 4vw, 3rem) 5rem;
  }

  .masthead {
    grid-area: masthead;
  }

  .trail {
    grid-area: trail;
  }

  .memories {
    grid-area: memories;
  }

  .card {
    position: sticky;
    top: 3rem;
    grid-area: card;
    min-height: 22rem;
    padding: 2.4rem 2.3rem 2.6rem;
    box-shadow: 8px 9px 0 var(--ink);
  }

  h1 {
    font-size: clamp(3.4rem, 6.5vw, 5rem);
  }

  .intro {
    font-size: 1.35rem;
  }

  .clue {
    font-size: 1.8rem;
  }

  .answer-row input,
  .button {
    font-size: 1.3rem;
  }

  .game-question {
    font-size: 1.6rem;
  }

  .note-large {
    font-size: 2rem;
  }

  .ending-message {
    font-size: 1.5rem;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

@keyframes settle {
  from {
    opacity: 0;
    transform: rotate(-140deg);
  }
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 7px rgba(181, 56, 43, 0.16);
  }
}

@keyframes pulse-x {
  50% {
    transform: rotate(-8deg) scale(1.25);
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-3rem) rotate(9deg) scale(0.8);
  }
}

@keyframes wobble {
  20%,
  60% {
    transform: rotate(-10deg);
  }

  40%,
  80% {
    transform: rotate(4deg);
  }
}

@keyframes stamp {
  from {
    opacity: 0;
    transform: rotate(-14deg) scale(2.6);
  }
}

@keyframes stamp-x {
  from {
    opacity: 0;
    transform: scale(2.4);
  }
}

@keyframes slow-zoom {
  to {
    transform: scale(1.12);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(0deg);
  }

  12%,
  85% {
    opacity: 0.9;
  }

  100% {
    opacity: 0;
    transform: translate(var(--sway), -125vh) rotate(var(--spin));
  }
}

@keyframes float-down {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(0deg);
  }

  12%,
  85% {
    opacity: 0.9;
  }

  100% {
    opacity: 0;
    transform: translate(var(--sway), 125vh) rotate(var(--spin));
  }
}

@keyframes stage-in {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.94);
  }
}

@keyframes slam {
  from {
    opacity: 0;
    transform: scale(3.2);
  }
}

@keyframes blink {
  0%,
  100% {
    opacity: 0.25;
  }

  50% {
    opacity: 1;
  }
}

@keyframes flash {
  8% {
    opacity: 0.85;
  }

  30% {
    opacity: 0.1;
  }

  42% {
    opacity: 0.5;
  }

  100% {
    opacity: 0;
  }
}

@keyframes quake {
  10%,
  90% {
    transform: translate(-4px, 2px) rotate(-0.4deg);
  }

  20%,
  80% {
    transform: translate(7px, -4px) rotate(0.6deg);
  }

  30%,
  50%,
  70% {
    transform: translate(-13px, 6px) rotate(-1deg);
  }

  40%,
  60% {
    transform: translate(13px, -5px) rotate(1deg);
  }
}

@keyframes confetti {
  from {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg);
  }

  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) rotate(var(--spin));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
