:root {
  --night-high: #0b1d3a;
  --night-mid: #1c3a70;
  --night-low: #4a6fb0;
  --snow: #f4f8ff;
  --snow-shadow: #d5e2f5;
  --panel: #fffdf7;
  --ink: #1d2b44;
  --red: #d62839;
  --red-dark: #a81b2a;
  --green: #23915a;
  --gold: #f6c445;
  --ground-top: 14%;
}

* { box-sizing: border-box; }

html {
  background: #1c3a70;
}

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

body {
  background: linear-gradient(var(--night-high), var(--night-mid));
  background-attachment: fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.35;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px;
}

[hidden] { display: none !important; }

h1, h2, .button, .option, .scoreboard, .notice-good, .notice-bad, .notice-turbo {
  font-family: ui-rounded, "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
}

button { -webkit-user-select: none; user-select: none; }

/* ---------- Buttons ---------- */

.button {
  min-height: 48px;
  padding: 10px 22px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.button-primary {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 0 var(--red-dark);
}

#button-next { scroll-margin-bottom: 12px; } /* breathing room when scrolled into view */

.button-primary:hover { filter: brightness(1.08); }
.button-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--red-dark); }

.button:focus-visible,
.option:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 2px;
}

/* ---------- Sound switch ---------- */

#screen-start, #screen-result { position: relative; }

.sound-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 3px 0 var(--snow-shadow);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.sound-toggle:hover { filter: brightness(0.96); }
.sound-toggle:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--snow-shadow); }
.sound-toggle:focus-visible { outline: 4px solid var(--gold); outline-offset: 2px; }

/* On the trip the switch is a pill at the right end of the scoreboard; the transparent
   ::after keeps its tappable area at 44x44. */
.scoreboard .sound-toggle {
  position: relative;
  top: auto;
  right: auto;
  width: auto;
  height: auto;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: none;
  font-size: inherit;
  line-height: inherit;
}

.scoreboard .sound-toggle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.scoreboard .sound-toggle:active { transform: translateY(1px); box-shadow: none; }

/* ---------- Start and result screens ---------- */

.cover {
  min-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  color: #fff;
}

.cover h1,
.result-title {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.4rem);
  line-height: 1.1;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.cover-text {
  margin: 0;
  font-size: 1.2rem;
  max-width: 30ch;
}

.cover-sleigh {
  position: relative;
  height: 110px;
  width: 190px;
}

.cover-sleigh .santa-body { left: 0; top: 14px; }

.result-stars {
  margin: 0;
  font-size: 3rem;
  letter-spacing: 0.1em;
  white-space: nowrap;
  color: var(--gold);
}

/* ---------- Scoreboard ---------- */

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  margin-bottom: 8px;
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
}

.scoreboard-item {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 4px 12px;
}

.scoreboard-city { margin-left: auto; }

/* ---------- Scene ---------- */

.scene {
  position: relative;
  /* Short screens give the scene what is left once the question and its four answers fit. */
  height: clamp(180px, min(40vh, 100vh - 440px), 380px);
  height: clamp(180px, min(40dvh, 100dvh - 440px), 380px);
  overflow: hidden;
  border-radius: 18px;
  background: linear-gradient(var(--night-high) 0%, var(--night-mid) 55%, var(--night-low) 100%);
  border: 3px solid rgba(255, 255, 255, 0.25);
}

.sky { position: absolute; inset: 0; }

.moon {
  position: absolute;
  top: 10%;
  right: 9%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #fff6d6;
  box-shadow: 0 0 30px 8px rgba(255, 246, 214, 0.45);
}

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 8% 18%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 21% 42%, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 33% 12%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 46% 30%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 58% 9%, #fff 50%, transparent 51%),
    radial-gradient(3px 3px at 69% 38%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 77% 22%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 93% 44%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 14% 55%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 52% 52%, #fff 50%, transparent 51%);
  animation: twinkle 3s ease-in-out infinite alternate;
}

.hills {
  position: absolute;
  left: 0;
  right: 0;
  background-repeat: repeat-x;
  background-position: 0 0;
}

.hills-far {
  bottom: calc(var(--ground-top) - 10px);
  height: 36%;
  background-size: 640px 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -6 640 126' preserveAspectRatio='none'%3E%3Cpath d='M0 70Q80 10 160 70T320 70T480 70T640 70V116H0Z' fill='%236f8fc7'/%3E%3C/svg%3E");
}

.hills-near {
  bottom: calc(var(--ground-top) - 10px);
  height: 22%;
  background-size: 520px 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -6 520 126' preserveAspectRatio='none'%3E%3Cpath d='M0 60Q65 5 130 60T260 60T390 60T520 60V116H0Z' fill='%23b9cdec'/%3E%3C/svg%3E");
}

.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--ground-top);
  background: linear-gradient(var(--snow), var(--snow-shadow));
}

.world {
  position: absolute;
  left: 0;
  bottom: calc(var(--ground-top) - 6px);
  width: 0;
  height: 0;
  will-change: transform;
}

.prop {
  position: absolute;
  bottom: 0;
  font-size: 34px;
  line-height: 1;
  transform: translateX(-50%);
}

.prop.big { font-size: 46px; }

.city {
  position: absolute;
  bottom: 0;
}

.city-house {
  position: absolute;
  bottom: 0;
  left: -56px; /* the chimney sits exactly at the city's position */
  width: 80px;
  height: 80px;
}

.city-landmark {
  position: absolute;
  bottom: 0;
  left: 34px;
  width: 130px;
  height: 156px;
}

.city-sign {
  position: absolute;
  bottom: -26px; /* the sign sits on the snow, below the monument */
  left: -56px;
  width: 220px;
  display: flex;
  justify-content: center;
}

.city-sign span {
  background: var(--gold);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  padding: 3px 10px;
  border-radius: 8px;
  white-space: nowrap;
}

/* ---------- Santa ---------- */

.santa {
  position: absolute;
  left: 28%;
  top: 12%;
  width: 0;
  height: 0;
}

.santa-body {
  position: absolute;
  left: -70px; /* the sleigh's centre sits on Santa's anchor point */
  top: 0;
  width: 190px;
  height: 80px;
  animation: bob 2.4s ease-in-out infinite;
}

.santa.circling { animation: circling 3.2s linear infinite; }

.santa-sleigh {
  position: absolute;
  left: 0;
  top: 22px;
  width: 104px;
  height: 58px;
}

.santa-person {
  position: absolute;
  left: 34px;
  top: -4px;
  font-size: 40px;
  line-height: 1;
}

.santa-sack {
  position: absolute;
  left: 6px;
  top: 12px;
  font-size: 26px;
  line-height: 1;
}

.santa-reindeer {
  position: absolute;
  left: 128px;
  top: 14px;
  font-size: 44px;
  line-height: 1;
  transform: scaleX(-1); /* the emoji faces left; flip it so it pulls the sleigh */
}

.santa-reins {
  position: absolute;
  left: 98px;
  top: 44px;
  width: 44px;
  height: 3px;
  background: #7a4a21;
  border-radius: 2px;
  transform: rotate(-6deg);
}

.santa-trail {
  position: absolute;
  left: -64px;
  top: 30px;
  font-size: 22px;
  white-space: nowrap;
  opacity: 0;
}

.santa.turbo .santa-trail {
  opacity: 1;
  animation: trail 0.5s linear infinite;
}

.santa-bubble {
  position: absolute;
  left: 150px;
  top: -18px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
  white-space: nowrap;
  opacity: 0;
}

.santa.sneezing .santa-bubble { animation: bubble 2.4s ease-out forwards; }
.santa.sneezing .santa-reindeer { animation: sneeze 0.5s ease-in-out 4; }

/* ---------- Effects ---------- */

.effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.gift-delivered,
.gift-lost {
  position: absolute;
  font-size: 30px;
  line-height: 1;
  margin-left: -15px;
}

.gift-lost { left: 28%; }

.gift-delivered { animation: deliver 0.9s ease-in forwards; }
.gift-lost { animation: lose 1.6s ease-in forwards; }

.spark {
  position: absolute;
  bottom: 62px;
  margin-left: -16px;
  font-size: 30px;
  opacity: 0;
  animation: spark 0.8s ease-out 0.85s forwards;
}

.flake {
  position: absolute;
  top: -30px;
  font-size: 22px;
  animation: snowfall 2.2s linear infinite;
}

/* ---------- Distance bar ---------- */

.distance {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 2px;
  font-size: 20px;
}

.distance-bar {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.distance-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--gold);
}

/* ---------- Question ---------- */

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prompt {
  margin: 0;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.option {
  min-height: 48px;
  padding: 8px 12px;
  border: 3px solid #c9d4e8;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.option:hover:not(:disabled) { border-color: var(--night-low); background: #eef4ff; }
.option:disabled { cursor: default; opacity: 0.75; }
.option.correct { border-color: var(--green); background: #dcf5e7; opacity: 1; }
.option.wrong { border-color: var(--red); background: #fde3e6; opacity: 1; }
.option.correct::after { content: " ✔"; color: var(--green); }
.option.wrong::after { content: " ✘"; color: var(--red); }

.notice {
  min-height: 1.4em;
  font-weight: 700;
}

.notice p { margin: 0 0 4px; }
.notice .notice-good { color: var(--green); font-size: 1.15rem; }
.notice .notice-turbo { color: #b07b00; }
.notice .notice-bad { color: var(--red-dark); font-size: 1.1rem; }
.notice .notice-normal { font-weight: 400; }
.notice .notice-waiting { color: #4b5d7e; font-weight: 400; font-style: italic; }

@media (min-width: 600px) {
  .options { grid-template-columns: 1fr 1fr; }
  #app { padding: 18px; }
  .scene {
    height: clamp(200px, min(40vh, 100vh - 400px), 380px);
    height: clamp(200px, min(40dvh, 100dvh - 400px), 380px);
  }
}

/* Narrow screens stack the four answers, so everything around them is tighter. */
@media (max-width: 599px) {
  #app { padding: 8px; }
  .panel { padding: 10px; gap: 8px; }
  .prompt { font-size: 1.1rem; }
  .options { gap: 6px; }
  .option { min-height: 44px; padding: 6px 12px; }
  /* An empty notice takes no room, but stays rendered: it is the live region that screen
     readers listen to, and hiding it would silence the feedback written into it. */
  .notice { min-height: 0; }
  .notice:empty { margin-top: -8px; } /* cancels the panel's gap */
}

/* ---------- Animations ---------- */

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-9px) rotate(2deg); }
}

@keyframes circling {
  0% { transform: translate(0, 0); }
  25% { transform: translate(34px, -16px); }
  50% { transform: translate(0, -30px); }
  75% { transform: translate(-34px, -16px); }
  100% { transform: translate(0, 0); }
}

@keyframes twinkle {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

@keyframes trail {
  from { transform: translateX(8px); opacity: 1; }
  to { transform: translateX(-22px); opacity: 0.2; }
}

@keyframes deliver {
  0% { bottom: var(--fall-from, 180px); transform: rotate(0) scale(1); opacity: 1; }
  85% { opacity: 1; }
  100% { bottom: 58px; transform: rotate(200deg) scale(0.4); opacity: 0; }
}

@keyframes lose {
  0% { bottom: 62%; transform: translateX(0) rotate(0); opacity: 1; }
  100% { bottom: -12%; transform: translateX(-140px) rotate(-420deg); opacity: 0.9; }
}

@keyframes spark {
  0% { opacity: 0; transform: scale(0.4); }
  40% { opacity: 1; transform: scale(1.5); }
  100% { opacity: 0; transform: scale(2) translateY(-18px); }
}

@keyframes snowfall {
  from { transform: translate(0, 0) rotate(0); }
  to { transform: translate(-60px, 440px) rotate(260deg); }
}

@keyframes sneeze {
  0%, 100% { transform: scaleX(-1) translate(0, 0) rotate(0); }
  50% { transform: scaleX(-1) translate(-4px, 6px) rotate(14deg); }
}

@keyframes bubble {
  0% { opacity: 0; transform: scale(0.5); }
  15%, 75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

/* With reduced motion there is no flying, circling, falling or trails. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .gift-delivered, .gift-lost, .spark, .flake { display: none; }
  .santa-bubble { opacity: 0; }
}

/* The release stamp on the cover: there for whoever looks, never in the player's way. */
.version {
  position: absolute;
  right: 10px;
  bottom: 6px;
  margin: 0;
  font-size: 10px;
  color: #fff;
  opacity: 0.5;
  pointer-events: none;
}
