/* Solar System (prototype)
   The sky is ink; the chrome is the Sandpit's paper and pencil. Only the canvas
   owns gestures, so every control keeps its own taps and scrolls. */

:root {
  --paper: #f1e5c8;
  --ink: #30382b;
  --ochre: #d7aa45;
  --coral: #c45d43;
  --sky: #080a0f;
  --panel: rgba(16, 19, 26, 0.72);
  /* Panels are solid, not blurred glass: the chrome sits over moving stars and
     has to hold its text contrast on its own. */
  --panel-solid: rgba(14, 16, 22, 0.9);
  --panel-line: rgba(241, 229, 200, 0.16);
  /* The deck and the card float over a moving sky, so they are a material
     rather than a painted bar: a translucent layer that blurs what is under
     it. The blur also does the contrast work, because a bright planet
     passing underneath becomes a soft glow instead of a bright shape behind
     the text. */
  --glass: rgba(17, 21, 31, 0.66);
  --glass-line: rgba(241, 229, 200, 0.13);
  /* Light catches the top edge of a raised surface. */
  --glass-edge: rgba(255, 255, 255, 0.17);
  --blur: blur(24px) saturate(150%);
  --text: #f3ecdd;
  --text-dim: #b5b0a3;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--sky);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.loading,
.fallback {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  margin: 0;
  padding: 10px 18px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: #12140f;
  color: var(--text);
  font: 600 13px/1 var(--font);
}

.loading {
  top: 50%;
}

.fallback {
  top: calc(50% + 34px);
  max-width: min(46ch, calc(100vw - 32px));
  text-align: center;
  line-height: 1.45;
}

.credit {
  margin: 10px 0 0;
  color: var(--text-dim);
  font: 500 11.5px/1.45 var(--font);
}

.credit a {
  color: var(--ochre);
}

.nojs {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--sky);
  font: 600 16px/1.5 var(--font);
}

/* ------------------------------------------------------------------ the sky */

.space {
  position: fixed;
  inset: 0;
  /* The scene is moved into the body when a shell mounts, so it can end up
     after #shell in the DOM. Order is not a reliable way to stack here. */
  z-index: 0;
  overflow: hidden;
  background: var(--sky);
}

#shell {
  position: relative;
  z-index: 1;
}

.space canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* The scene owns one-finger drags and pinch zooms. Nothing else does. */
  touch-action: none;
  cursor: grab;
}

.space canvas:active {
  cursor: grabbing;
}

.space.is-tour-locked canvas {
  pointer-events: none;
  cursor: default;
}

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

.label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 3px 8px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(8, 10, 15, 0.55);
  color: var(--text);
  font: 600 11.5px/1 var(--font);
  letter-spacing: 0.02em;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: opacity 0.2s ease;
}

.label.is-near {
  border-color: rgba(215, 170, 69, 0.6);
}

/* The world the tour is singing about. Only its name lights up, so the
   picture stays the picture. */
.label.is-sung {
  border-color: var(--ochre);
  background: rgba(215, 170, 69, 0.9);
  color: #241c10;
  font-weight: 700;
  box-shadow: 0 0 0 3px rgba(215, 170, 69, 0.22);
}

.label-moon {
  padding: 2px 6px;
  font-size: 10.5px;
  opacity: 0.92;
}

/* Shared chrome ------------------------------------------------------------ */

.shell-a {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.shell-a button {
  pointer-events: auto;
  font-family: var(--font);
  cursor: pointer;
  touch-action: manipulation;
}

.kicker {
  margin: 0 0 2px;
  color: var(--ochre);
  font: 700 10.5px/1 var(--font);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.fact {
  margin: 0 0 8px;
  font: 500 14.5px/1.42 var(--font);
}

.note {
  margin: 0;
  color: var(--text-dim);
  font: 500 13px/1.42 var(--font);
}

.distance {
  margin: 0 0 8px;
  color: var(--text-dim);
  font: 500 12.5px/1.35 var(--font);
}

.moons {
  margin-top: 12px;
}

.grown-up {
  margin-top: 12px;
  border-top: 1px solid var(--panel-line);
  padding-top: 8px;
}

.grown-up summary {
  color: var(--text-dim);
  font: 600 12px/1 var(--font);
  cursor: pointer;
}

.grown-up-body {
  padding-top: 8px;
}

.grown-up-body .scale-note {
  margin-top: 8px;
}



.moon-caption {
  margin: 0 0 6px;
  color: var(--text-dim);
  font: 700 10.5px/1 var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.moon-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.moon-list button {
  padding: 7px 11px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(241, 229, 200, 0.08);
  color: var(--text);
  font: 600 12.5px/1 var(--font);
}

.moon-list button:focus-visible {
  border-color: rgba(215, 170, 69, 0.7);
}

/* The toddler's shell: moon buttons are a child's tap target too, so they get
   the same 56px floor as the world chips and the music controls. */
.shell-a .moon-list button {
  min-height: 56px;
  min-width: 56px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 16px;
}

.moon-none {
  color: var(--text-dim);
  font: 500 12.5px/1 var(--font);
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(241, 229, 200, 0.08);
  color: var(--text);
  font: 600 12.5px/1 var(--font);
}

.tool[aria-pressed="true"] {
  background: var(--ochre);
  border-color: var(--ochre);
  color: #241c10;
}

.scale-note {
  margin: 0;
  max-width: 40ch;
  color: var(--text-dim);
  font: 500 11.5px/1.4 var(--font);
}

/* Songs -------------------------------------------------------------------- */

.songs {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.songs h2 {
  margin: 0;
  color: var(--text-dim);
  font: 700 10.5px/1 var(--font);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.songs-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.song-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(241, 229, 200, 0.08);
  color: var(--text);
  font: 600 13px/1 var(--font);
}

.song-button[aria-pressed="true"] {
  background: var(--ochre);
  border-color: var(--ochre);
  color: #241c10;
}

.song-play {
  font-size: 10px;
}

.songs-player {
  position: fixed;
  right: 16px;
  bottom: 78px;
  z-index: 80;
  width: min(480px, calc(100vw - 32px));
  padding: 8px;
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  background: #12100c;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

/* YouTube's player needs room: 16:9 up to 480 wide, never under 200 high. */
.songs-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 200px;
  overflow: hidden;
  border-radius: 8px;
  background: #000;
}

.songs-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.songs-foot {
  margin: 8px 2px 0;
  color: var(--text-dim);
  font: 500 12px/1.4 var(--font);
}

.songs-foot a {
  color: var(--ochre);
}

.songs-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(8, 10, 15, 0.7);
  color: var(--text);
  font: 600 16px/1 var(--font);
}

/* Variant A: Orrery ------------------------------------------------------- */

.shell-a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 322px;
  /* Two rows: the card and the mid row share the top band, the deck spans it.
     There is no header row: the drawing runs behind everything. */
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "mid card"
    "deck deck";
  gap: 12px;
  padding: 16px;
}

.a-card {
  grid-area: card;
  align-self: start;
  max-height: 100%;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  pointer-events: auto;
}

.shell-a.is-tour-locked .a-card,
.shell-a.is-tour-locked .a-chips,
.shell-a.is-tour-locked .view-controls {
  opacity: 0.45;
}

.a-card h2 {
  margin: 0 0 4px;
  font: 700 24px/1 var(--font);
}

.a-deck {
  grid-area: deck;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  padding: 10px;
  /* A floating material over the sky, not a painted bar. The bright top edge
     is light catching a raised surface, which is what tells the eye this
     layer sits above the picture rather than being cut out of it. */
  border: 1px solid var(--glass-line);
  border-top-color: var(--glass-edge);
  border-radius: var(--radius);
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
  pointer-events: auto;
}

.a-chips {
  display: flex;
  /* One row that scrolls sideways, so the deck keeps a fixed, low height
     instead of growing a second line of chips on a wide screen. */
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 2px;
  gap: 7px;
}

.a-side {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  /* A two-year-old aims with a whole hand: nothing here is shorter than 56px. */
  min-height: 56px;
  padding: 0 18px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(241, 229, 200, 0.07);
  color: var(--text);
  font: 600 15px/1 var(--font);
  white-space: nowrap;
  /* Feedback lives on the press, not on the click. A button that only reacts
     when the finger lifts feels dead, and a child will press again. */
  transition:
    transform 120ms cubic-bezier(0.2, 0, 0, 1),
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.chip[aria-current="true"] {
  background: var(--paper);
  border-color: var(--paper);
  color: var(--ink);
}

/* Pressed, the control shrinks a touch under the finger. The transform is
   compositor-friendly, so it stays smooth without layout work. */
.chip:active {
  transform: scale(0.96);
  transition-duration: 90ms;
}

.chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot, var(--paper));
}

.chip-count {
  color: inherit;
  opacity: 0.6;
  font-size: 11px;
}

/* Songs ------------------------------------------------------------------- */

.audio {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Four equal columns of transport and tour, filling the deck without stretching it
     across a wide screen. */
  width: min(100%, 360px);
  pointer-events: auto;
}

.audio-now {
  margin: 0;
  color: var(--text-dim);
  font: 600 12.5px/1.3 var(--font);
}

.audio-controls {
  /* One row, four equal columns: the controls must never wrap into two rows
     and push the deck up over the planets. */
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.audio-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  /* Big enough for a toddler's hand, and reachable on a tablet. */
  min-height: 56px;
  min-width: 0;
  padding: 0 5px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(241, 229, 200, 0.1);
  color: var(--text);
  font: 700 14px/1 var(--font);
  white-space: nowrap;
  /* The same press feedback as the world chips. */
  transition:
    transform 120ms cubic-bezier(0.2, 0, 0, 1),
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.audio-btn:active {
  transform: scale(0.96);
  transition-duration: 90ms;
}

.audio-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.audio-btn:disabled:active {
  transform: none;
}

.audio-play[aria-pressed="true"],
.audio-sound[aria-pressed="true"] {
  background: var(--ochre);
  border-color: var(--ochre);
  color: #241c10;
}

.audio-tour {
  background: var(--ochre);
  border-color: var(--ochre);
  color: #241c10;
}

/* The tour is a toggle, so it says which way it is pointing. Off means the
   child has the camera; on means the song does. */
.audio-tour.is-on {
  background: transparent;
  border-color: var(--ochre);
  color: var(--ochre);
  box-shadow: inset 0 0 0 1px rgba(215, 170, 69, 0.35);
}

/* "Song tour" is the only control here with a name a two-year-old can read
   out loud, so it gets a wider column than the transport buttons. The name is
   the point: "Tour" alone did not say what would happen. */
.audio-controls {
  grid-template-columns: repeat(3, minmax(0, 1fr)) 1.45fr;
}

.audio-tour {
  font-size: 15px;
  letter-spacing: 0.01em;
}

.audio-ico {
  font-size: 15px;
}

.audio-status {
  margin: 0;
  min-height: 1em;
  color: var(--coral);
  font: 600 12px/1.3 var(--font);
}

.chip-more {
  border-style: dashed;
}

.chip-home {
  background: var(--ochre);
  border-color: var(--ochre);
  color: #241c10;
}

/* Narrow screens ---------------------------------------------------------- */

@media (max-width: 900px) {
  .shell-a {
    grid-template-columns: minmax(0, 1fr);
    /* Portrait: the card sits on top, the deck underneath, and the drawing
       fills the window between them rather than being cropped to it. */
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "card"
      "mid"
      "deck";
    padding-bottom: 16px;
  }

  .a-card {
    max-height: 34vh;
  }

  .a-deck {
    flex-direction: column;
    align-items: stretch;
  }

  .a-side {
    align-items: center;
  }





  .songs-player {
    right: 12px;
    bottom: 66px;
    width: min(480px, calc(100vw - 24px));
  }
}

@media (max-width: 560px) {


}

/* Tablet navigation: every world is present, in the order of its song. */
.view-controls { display: flex; gap: 6px; align-items: center; }
.view-controls .chip { justify-content: center; padding: 0 14px; }
.view-controls .chip:first-child, .view-controls .chip:last-child { min-width: 56px; font-size: 28px; }
.a-chips { display: flex; flex-direction: column; overflow: visible; gap: 6px; padding: 0; }
.world-row { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px; }
.world-row + .world-row { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.world-row .chip { justify-content: center; min-width: 0; padding: 0 6px; gap: 5px; font-size: 14px; }
.moon-list button:active { transform: scale(0.96); }
.a-side { justify-content: flex-start; }
.audio-status:empty { display: none; }
.a-card { max-height: 40vh; }
@media (max-width: 900px) {
  .shell-a { gap: 8px; padding: 12px; }
  .a-card { padding: 12px; max-height: 30vh; }
  .world-row .chip { font-size: 13px; padding: 0 3px; gap: 3px; }
  .world-row .chip-dot { width: 7px; height: 7px; flex-shrink: 0; }
  .a-deck { padding: 8px; }
}
@media (max-width: 600px) {
  .world-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .world-row + .world-row { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .world-row + .world-row .chip { font-size: 11px; gap: 0; padding: 0 2px; }
  .world-row + .world-row .chip-dot { display: none; }
  .moon-list button { padding: 0 10px !important; }
}

/* Reduced motion and reduced transparency. The controls still respond, they
   just stop moving and stop being see-through. */
@media (prefers-reduced-motion: reduce) {
  .chip,
  .audio-btn,
  .moon-list button {
    transition-duration: 1ms;
  }

  .chip:active,
  .audio-btn:active,
  .moon-list button:active {
    transform: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .a-deck {
    background: #11151f;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .a-deck {
    background: #0b0e15;
    border-color: rgba(241, 229, 200, 0.4);
  }

  .chip,
  .audio-btn {
    border-color: rgba(241, 229, 200, 0.45);
  }
}
