/* Planet Hop: deep space with soft nebula light behind a transparent 3D canvas.
   Righteous (a 1960s space-age display face) for headings and numbers,
   Quicksand for reading. The one loud thing is the landing hatch: a riveted
   hull panel with a porthole whose doors slide open on the right answer. */

:root {
  --void: #0b0a22;
  --void-2: #14123a;
  --plum: #3b1752;
  --teal: #0d4a57;
  --sun: #ffc94a;
  --sun-deep: #f29f1f;
  --hull: #e7e4f6;
  --hull-edge: #b9b2dd;
  --hull-dark: #5b5390;
  --ink: #1d1747;
  --ink-soft: #4a4377;
  --coral: #ff7a6b;
  --mint: #4fd8b4;
  --text: #f1efff;
  --text-soft: #c4bfe6;
  --focus: var(--sun);

  --display: "Righteous", "Arial Rounded MT Bold", sans-serif;
  --body: "Quicksand", "Avenir Next", system-ui, sans-serif;
}

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

html { color-scheme: dark; height: 100%; }

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font: 600 1.0625rem/1.45 var(--body);
  background:
    radial-gradient(60% 50% at 18% 22%, rgba(122, 52, 150, 0.42), transparent 70%),
    radial-gradient(55% 45% at 85% 78%, rgba(20, 120, 140, 0.38), transparent 70%),
    radial-gradient(40% 35% at 70% 15%, rgba(255, 122, 107, 0.12), transparent 70%),
    var(--void);
}

.icons { position: absolute; width: 0; height: 0; overflow: hidden; }
/* custom properties inherit into <use> copies; plain selectors can't reach them */
.r1 { stroke: var(--r1, #ff5a6e); }
.r2 { stroke: var(--r2, #ffc94a); }
.r3 { stroke: var(--r3, #4fb4ff); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* ---- frame */

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.5rem 1.1rem;
  padding: 0.55rem max(1rem, env(safe-area-inset-left)) 0.55rem max(1rem, env(safe-area-inset-right));
  background: linear-gradient(rgba(11, 10, 34, 0.85), rgba(11, 10, 34, 0));
}
.back {
  color: var(--text-soft);
  font-weight: 700;
  text-underline-offset: 3px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.back:hover { color: var(--text); }
h1 {
  margin: 0;
  flex: 1;
  font: 400 clamp(1.45rem, 3.2vw, 2.1rem)/1 var(--display);
  color: var(--sun);
  letter-spacing: 0.02em;
  text-shadow: 0 0 18px rgba(255, 201, 74, 0.45);
}
.book-open {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.35rem 0.95rem 0.35rem 0.7rem;
  border: 2px solid rgba(255, 201, 74, 0.55);
  border-radius: 999px;
  background: rgba(20, 18, 58, 0.7);
  font-weight: 700;
}
.book-open svg { width: 1.3rem; height: 1.3rem; color: var(--sun); }
.book-open .count { color: var(--sun); font-family: var(--display); font-weight: 400; }
.book-open:hover { border-color: var(--sun); }

.stage { grid-row: 2; position: relative; overflow: hidden; min-height: 0; }
.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}
.scene.grab { cursor: grab; }
.scene.pointing { cursor: pointer; }

.loading {
  position: absolute;
  inset: 40% 0 auto;
  margin: 0;
  text-align: center;
  color: var(--text-soft);
  font-size: 1.1rem;
}
.loading[hidden] { display: none; }

/* ---- labels that follow the worlds */

.labels { position: absolute; inset: 0; pointer-events: none; }
.tag {
  position: absolute;
  left: 0;
  top: 0;
  padding: 0.12rem 0.6rem;
  border: 0;
  border-radius: 999px;
  background: rgba(11, 10, 34, 0.62);
  color: var(--text);
  font: 700 1rem/1.3 var(--body);
  white-space: nowrap;
  pointer-events: auto;
  will-change: transform;
}
.tag small { font-weight: 500; color: var(--text-soft); font-size: 1rem; margin-left: 0.3em; }
.tag:hover { background: rgba(59, 23, 82, 0.9); }
.app.away .labels,
.app.landed .labels { display: none; }

/* ---- the world list */

.worlds {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 1.6rem max(0.75rem, env(safe-area-inset-left)) max(0.8rem, env(safe-area-inset-bottom));
  /* a dark band so a planet label drifting low passes under the list, not through it */
  background: linear-gradient(rgba(10, 8, 30, 0), rgba(10, 8, 30, 0.92) 1.4rem);
  transition: transform 0.4s ease, opacity 0.3s ease;
}
.worlds-hint {
  margin: 0 0 0.45rem;
  text-align: center;
  color: var(--text-soft);
  font-size: 1rem;
}
.worlds ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
}
.world {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 46px;
  padding: 0.3rem 0.9rem 0.3rem 0.45rem;
  border: 2px solid rgba(241, 239, 255, 0.18);
  border-radius: 999px;
  background: rgba(20, 18, 58, 0.72);
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.world:hover:not(:disabled) { border-color: var(--sun); background: rgba(59, 23, 82, 0.85); }
.world:disabled { opacity: 0.6; }
.world .dwarf { font-weight: 500; color: var(--text-soft); }
.dot {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset -4px -4px 8px rgba(0, 0, 0, 0.45);
}
.app.away .worlds,
.app.landed .worlds { transform: translateY(120%); opacity: 0; pointer-events: none; visibility: hidden; }

.w-mercury { --swatch: radial-gradient(circle at 35% 35%, #c9c4c0, #807b77 60%, #5c5855); }
.w-venus { --swatch: radial-gradient(circle at 35% 35%, #fff1c4, #e8c47a 60%, #b98a3f); }
.w-earth { --swatch: radial-gradient(circle at 30% 35%, #5cb85a 0 18%, transparent 19%), radial-gradient(circle at 65% 60%, #6fae4a 0 14%, transparent 15%), radial-gradient(circle at 35% 35%, #7fc0ff, #2f7fd0 60%, #1b4f8f); }
.w-mars { --swatch: radial-gradient(circle at 35% 35%, #f09060, #c4532a 60%, #7d2f15); }
.w-ceres { --swatch: radial-gradient(circle at 60% 40%, #f4f1e8 0 6%, transparent 7%), radial-gradient(circle at 35% 35%, #8b8784, #514e4c 60%, #333130); }
.w-jupiter { --swatch: radial-gradient(ellipse 14% 9% at 60% 66%, #c4552f 90%, transparent), repeating-linear-gradient(180deg, #e9d3ae 0 12%, #b98b5a 12% 20%, #f4ead8 20% 30%, #a8724a 30% 36%); }
.w-saturn { --swatch: repeating-linear-gradient(180deg, #f2dfaa 0 14%, #d9bd7c 14% 24%, #f7ead0 24% 34%); }
.w-uranus { --swatch: radial-gradient(circle at 35% 35%, #e1fbff, #9fe0e8 60%, #5aa9b6); }
.w-neptune { --swatch: radial-gradient(ellipse 14% 9% at 40% 45%, #1a2a7a 90%, transparent), radial-gradient(circle at 35% 35%, #7fa2ff, #3150c8 60%, #1a2a7a); }
.w-pluto { --swatch: radial-gradient(circle at 55% 55%, #f6ece0 0 18%, transparent 19%), radial-gradient(circle at 35% 35%, #e3c7a3, #a77e5c 60%, #6d4e37); }

/* ---- the landing hatch */

.hatch,
.fact,
.found,
.book {
  --focus: #7a3fe0;
  color: var(--ink);
  background:
    radial-gradient(circle at 14px 14px, var(--hull-edge) 0 4px, transparent 5px),
    radial-gradient(circle at calc(100% - 14px) 14px, var(--hull-edge) 0 4px, transparent 5px),
    radial-gradient(circle at 14px calc(100% - 14px), var(--hull-edge) 0 4px, transparent 5px),
    radial-gradient(circle at calc(100% - 14px) calc(100% - 14px), var(--hull-edge) 0 4px, transparent 5px),
    linear-gradient(170deg, #f4f2fd, var(--hull));
  border: 3px solid var(--hull-edge);
  border-radius: 26px;
  box-shadow: 0 0 0 6px rgba(11, 10, 34, 0.35), 0 24px 60px rgba(0, 0, 0, 0.5);
}

.hatch {
  position: absolute;
  z-index: 4;
  right: clamp(1rem, 4vw, 3.5rem);
  top: 50%;
  width: min(25rem, calc(100% - 2rem));
  max-height: calc(100% - 1.5rem);
  overflow-y: auto;
  padding: 4.6rem 1.4rem 1.2rem;
  margin-top: 1.5rem;
  text-align: center;
  transform: translateY(-50%);
  animation: rise 0.35s ease-out;
}
.hatch[hidden] { display: none; }
.hatch.leaving { opacity: 0; transform: translateY(-50%) scale(0.92); transition: opacity 0.35s ease, transform 0.35s ease; }

.porthole {
  position: absolute;
  top: -1.4rem;
  left: 50%;
  width: 92px;
  height: 92px;
  margin-left: -46px;
  border-radius: 50%;
  overflow: hidden;
  background: #0b0a22;
  border: 7px solid var(--hull-dark);
  box-shadow: 0 0 0 3px var(--hull-edge), 0 6px 16px rgba(0, 0, 0, 0.35);
}
.planet-swatch {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 22px rgba(255, 201, 74, 0.55);
}
.door {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background: repeating-linear-gradient(135deg, #6c64a6 0 8px, #5b5390 8px 16px);
  transition: transform 0.7s cubic-bezier(0.6, 0, 0.3, 1);
}
.door.left { left: 0; border-right: 2px solid #2f2a5c; }
.door.right { right: 0; border-left: 2px solid #2f2a5c; }
.hatch.open .door.left { transform: translateX(-100%); }
.hatch.open .door.right { transform: translateX(100%); }

.hatch h2 {
  margin: 0;
  font: 400 1.7rem/1.1 var(--display);
  color: var(--ink);
}
.hatch h2 .small { display: block; font: 700 1rem/1.4 var(--body); color: var(--ink-soft); }
.sum {
  margin: 0.6rem 0 0.8rem;
  font: 400 clamp(2.4rem, 7vw, 3.2rem)/1.1 var(--display);
  color: var(--ink);
  letter-spacing: 0.03em;
}
.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
}
.choice {
  min-height: 66px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  font: 400 2rem/1 var(--display);
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}
.choice:hover:not([aria-disabled="true"]) { background: #fff5d6; }
.choice:active:not([aria-disabled="true"]) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.choice[aria-disabled="true"] {
  background: #d9d5ec;
  color: #6f6896;
  border-color: #8f88ba;
  box-shadow: 0 5px 0 #8f88ba;
  text-decoration: line-through;
  text-decoration-thickness: 3px;
  cursor: default;
}
.choices .choice.right { background: var(--mint); text-decoration: none; }
.feedback {
  min-height: 3em;
  margin: 0.8rem 0 0.4rem;
  color: var(--ink);
  font-weight: 700;
}
.feedback .count-on { display: block; font-family: var(--display); font-weight: 400; color: #6b3fd6; letter-spacing: 0.02em; }
.mode {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.3rem;
  padding: 0.3rem;
  border-radius: 18px;
  background: #d6d1ee;
}
.mode button {
  min-height: 44px;
  padding: 0.3rem 0.4rem;
  border: 0;
  border-radius: 14px;
  line-height: 1.15;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  font-size: 1rem;
}
.mode button[aria-pressed="true"] { background: var(--ink); color: var(--hull); }
.link-button {
  min-height: 44px;
  margin-top: 0.5rem;
  padding: 0.3rem 0.6rem;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- on the surface */

.surface-ui[hidden] { display: none; }
.compass {
  position: absolute;
  z-index: 2;
  top: 0.4rem;
  left: 50%;
  width: 64px;
  height: 64px;
  margin-left: -32px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 18, 58, 0.85) 55%, rgba(255, 201, 74, 0.4) 56% 60%, rgba(20, 18, 58, 0.85) 61%);
  border: 2px solid rgba(255, 201, 74, 0.6);
}
.needle {
  position: absolute;
  inset: 0;
  transition: transform 0.15s linear;
}
.needle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  margin-left: -11px;
  border: 11px solid transparent;
  border-bottom: 26px solid var(--sun);
  border-top: 0;
  filter: drop-shadow(0 0 6px rgba(255, 201, 74, 0.7));
}
.seek {
  position: absolute;
  z-index: 2;
  top: 4.7rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.2rem 0.85rem;
  border-radius: 999px;
  background: rgba(11, 10, 34, 0.6);
  font-weight: 700;
  white-space: nowrap;
}
.to-orbit {
  position: absolute;
  z-index: 2;
  top: 0.6rem;
  right: max(0.8rem, env(safe-area-inset-right));
  min-height: 46px;
  padding: 0.35rem 1rem;
  border: 2px solid var(--sun);
  border-radius: 999px;
  background: rgba(20, 18, 58, 0.8);
  font-weight: 700;
}
.to-orbit:hover { background: rgba(59, 23, 82, 0.95); }
.walk-help {
  position: absolute;
  left: 50%;
  bottom: max(0.8rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 0.25rem 0.9rem;
  width: max-content;
  max-width: calc(100% - 2rem);
  text-align: center;
  border-radius: 999px;
  background: rgba(11, 10, 34, 0.55);
  color: var(--text-soft);
  font-size: 1rem;
}
.jump,
.stick { display: none; }
.touch .walk-help { display: none; }
.touch .jump {
  display: block;
  position: absolute;
  z-index: 2;
  right: max(1.2rem, env(safe-area-inset-right));
  bottom: max(1.6rem, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border: 3px solid var(--sun);
  border-radius: 50%;
  background: rgba(20, 18, 58, 0.72);
  font: 400 1.1rem/1 var(--display);
  color: var(--sun);
  touch-action: none;
}
.touch .stick {
  display: block;
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  border: 3px solid rgba(241, 239, 255, 0.35);
  background: rgba(20, 18, 58, 0.35);
  pointer-events: none;
  opacity: 0;
}
.touch .stick.on { opacity: 1; }
.stick span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 201, 74, 0.85);
}
.touch .stick-home {
  position: absolute;
  left: max(1.4rem, env(safe-area-inset-left));
  bottom: max(1.6rem, env(safe-area-inset-bottom));
}

.warm {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 110px 30px rgba(255, 190, 70, 0.75);
  transition: opacity 0.4s ease;
}

.fact {
  position: absolute;
  z-index: 3;
  left: max(1rem, env(safe-area-inset-left));
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: min(23rem, calc(100% - 2rem));
  padding: 1.1rem 1.3rem 1.2rem;
  animation: rise 0.35s ease-out;
}
.fact[hidden] { display: none; }
.fact h2 { margin: 0 0 0.4rem; font: 400 1.45rem/1.15 var(--display); }
.fact p { margin: 0 0 0.6rem; }
.fact .gas-note { color: var(--ink-soft); }
.fact button,
.found button {
  min-height: 46px;
  padding: 0.35rem 1.1rem;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-weight: 700;
  color: var(--ink);
}
.fact button,
.found .primary { background: var(--sun); box-shadow: 0 4px 0 var(--ink); }

.found {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: min(22rem, calc(100% - 2rem));
  padding: 1.3rem 1.3rem 1.4rem;
  text-align: center;
  transform: translate(-50%, -50%);
  animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.found[hidden] { display: none; }
.found-icon { width: 76px; height: 76px; }
.found-icon.flag { color: #e8453c; }
.found-icon.star { color: var(--sun-deep); }
.found-icon.heart { color: #ff5b8a; }
.found h2 { margin: 0.2rem 0 0.3rem; font: 400 1.6rem/1.15 var(--display); }
.found p { margin: 0 0 0.9rem; }
.found-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }

.fade {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: var(--void);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}
.fade.on { opacity: 1; }

/* ---- sticker book */

.book {
  width: min(36rem, calc(100% - 1.5rem));
  max-height: calc(100% - 1.5rem);
  padding: 1.1rem 1.3rem 1.3rem;
}
.book::backdrop { background: rgba(5, 4, 15, 0.7); }
.book-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.book h2 { margin: 0; font: 400 1.7rem/1.1 var(--display); }
.book .close {
  min-height: 44px;
  padding: 0.3rem 1rem;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-weight: 700;
}
.book-total { margin: 0.3rem 0 0.8rem; color: var(--ink-soft); }
.pages { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.35rem; }
.page {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.6rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.6);
}
.page .dot { width: 28px; height: 28px; }
.page .name { font-weight: 700; }
.page .name small { display: block; font-weight: 500; font-size: 0.9rem; color: var(--ink-soft); }
.slots { display: flex; gap: 0.25rem; }
.slot { width: 34px; height: 34px; color: #c3bddf; }
.slot svg { width: 100%; height: 100%; }
.slot.got.flag { color: #e8453c; }
.slot.got.star { color: var(--sun-deep); }
.slot.got.heart { color: #ff5b8a; }
.slot:not(.got) { --r1: #c3bddf; --r2: #c3bddf; --r3: #c3bddf; }
.grownups { margin-top: 1rem; }
.grownups summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.grownups p { margin: 0.3rem 0 0; color: var(--ink-soft); font-weight: 500; }

/* ---- no WebGL */

.fallback {
  grid-row: 2;
  overflow-y: auto;
  padding: 1rem max(1rem, 4vw) 2rem;
  max-width: 44rem;
}
.fallback h2 { font: 400 1.8rem/1.1 var(--display); color: var(--sun); }
.fallback dt { margin-top: 1rem; font: 400 1.3rem/1.2 var(--display); }
.fallback dd { margin: 0.2rem 0 0; color: var(--text-soft); }
.no-3d .stage { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(calc(-50% + 18px)); } }
.fact { animation-name: rise-plain; }
@keyframes rise-plain { from { opacity: 0; transform: translateY(18px); } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -50%) scale(0.7); } }

/* ---- phones */

@media (max-width: 640px) {
  .bar { gap: 0.4rem 0.7rem; padding-top: 0.35rem; padding-bottom: 0.35rem; }
  h1 { white-space: nowrap; font-size: 1.3rem; }
  .back { white-space: nowrap; font-size: 1rem; }
  .book-open { padding: 0.3rem 0.75rem 0.3rem 0.6rem; }
  .book-open > span:not(.count) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .worlds ul {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    mask-image: linear-gradient(90deg, transparent, #000 4%, #000 90%, transparent);
  }
  .worlds ul::-webkit-scrollbar { display: none; }
  .worlds li { scroll-snap-align: start; }
  .hatch {
    left: 0.6rem;
    right: 0.6rem;
    top: auto;
    bottom: max(0.6rem, env(safe-area-inset-bottom));
    width: auto;
    max-height: calc(100% - 4.5rem);
    padding: 3.9rem 1rem 0.8rem;
    transform: none;
    animation-name: rise-plain;
  }
  .hatch.leaving { transform: scale(0.94); }
  .porthole { width: 80px; height: 80px; margin-left: -40px; top: -1.6rem; }
  .sum { margin: 0.3rem 0 0.6rem; }
  .choices { grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
  .choice { min-height: 60px; font-size: 1.7rem; }
  .feedback { min-height: 2.6em; margin: 0.5rem 0 0.3rem; }
  .fact { left: 0.6rem; right: 0.6rem; width: auto; bottom: 7.5rem; }
  .touch .fact { bottom: 8rem; }
  .seek { top: 4.6rem; }
}

@media (max-width: 380px) {
  .choices { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { animation: none !important; transition: none !important; }
}
