/* Où va le Soleil la nuit ? — épisode 2 du Petit labo d'astronomie.
   Thème sombre « espace » de la série (palette de l'épisode 3), rond et joueur (public : 5 ans).
   Zéro dépendance. Compat mobiles anciens : pas d'inset, repli @supports pour aspect-ratio. */

:root {
  --bg: #0b1020;
  --bg2: #0e1530;
  --surface: #121a33;
  --surface-2: #1c2540;
  --border: #26304f;
  --text: #e9edf8;
  --muted: #9aa5c3;
  --sun: #ffcf5c;
  --sun-deep: #ff9f1c;
  --earth: #5aa7ff;
  --night: #16335e;
  --rose: #ff6b9d;
  --teal: #46c2a5;
  --violet: #a98bff;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 700px at 72% -8%, #182450 0%, rgba(11, 16, 32, 0) 60%),
    radial-gradient(900px 600px at 8% 108%, rgba(169, 139, 255, 0.10) 0%, rgba(11, 16, 32, 0) 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.55;
}

/* ---------- entête ---------- */

.site-header { max-width: 900px; margin: 0 auto; padding: 38px 20px 22px; text-align: center; }
.kicker {
  margin: 0; color: var(--sun); font-size: .8rem; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
}
.episode {
  display: inline-block; margin-left: 8px; padding: 1px 10px; letter-spacing: .08em;
  border: 1px solid var(--sun-deep); border-radius: 999px; color: var(--sun);
  font-size: .72rem; vertical-align: 1px;
}
.site-header h1 { margin: .22em 0 .3em; font-size: clamp(2.1rem, 5.5vw, 3.1rem); line-height: 1.1; }
.tagline { margin: 0 auto; max-width: 62ch; color: var(--muted); }
.tagline strong { color: var(--sun); }

main { max-width: 1180px; margin: 0 auto; padding: 0 20px 60px; }

.panel {
  background: linear-gradient(180deg, var(--surface), var(--bg2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hint { color: var(--muted); font-weight: 400; font-size: .78em; }

/* ---------- la scène : les deux vues synchronisées ---------- */

.stage-panel { padding: 12px; }
.stage-head {
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap;
  font-size: .92rem; color: var(--muted); margin: 2px 4px 2px;
}
.stage-title { flex: 1 1 auto; font-weight: 700; }
/* les deux boutons restent groupés sur une même ligne, quelle que soit la largeur */
.stage-actions { display: flex; gap: 8px; margin-left: auto; flex: none; }
.stage-hint { margin: 0 4px 10px; }
.spin-btn { padding: 5px 12px; font-size: .8rem; border-radius: 999px; }

/* le bouton 🔇/🔊 des scénarios : ses deux libellés sont superposés dans une
   grille 1×1, si bien que le bouton garde en permanence la largeur du plus
   long — basculer la voix ne décale jamais la ligne de titre */
.scn-voice-btn { display: inline-grid; align-items: center; justify-items: center; }
.scn-voice-btn > span { grid-row: 1; grid-column: 1; white-space: nowrap; }
.scn-voice-btn[aria-pressed="false"] .scn-voice-on,
.scn-voice-btn[aria-pressed="true"] .scn-voice-off { visibility: hidden; }

.views-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.view-block { min-width: 0; }
.view-head {
  font-weight: 800; font-size: 1.02rem; margin: 0 2px 7px;
  display: flex; align-items: center; gap: 6px;
}
.view-head-garden { color: var(--teal); }
.view-head-space { color: var(--violet); }

.canvas-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #070b17; }
.ratio-garden { aspect-ratio: 5 / 4; }
.ratio-space { aspect-ratio: 1 / 1; }
/* repli pour navigateurs sans aspect-ratio (Safari iOS < 15) : hauteurs fixes */
@supports not (aspect-ratio: 1 / 1) {
  .ratio-garden { height: min(44vw, 520px); }
  .ratio-space { height: min(38vw, 460px); }
}
.canvas-wrap canvas { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; display: block; }

/* touch-action: none (le choix de « la Lune ») : le geste posé sur une vue
   appartient TOUJOURS au glisser du temps — un doigt un peu de travers ne part
   jamais en défilement de page. Étendu aux conteneurs : même les bords des
   cadres et l'interstice entre les deux minis du jeu ne défilent pas. Les
   vues sont plafonnées en hauteur : il reste de la page autour pour défiler. */
.canvas-wrap, .game-views { touch-action: none; }
#garden-view, #space-view { touch-action: none; cursor: grab; }
#garden-view:active, #space-view:active { cursor: grabbing; }

/* la petite phrase sous chaque vue : le même instant, raconté deux fois.
   La place de DEUX lignes est réservée : les phrases changent au fil du jour
   (« Nuit noire… » est bien plus longue que « Le soleil brille ») et passent
   de 1 à 2 lignes en s'étrécissant — sans réserve, tout ce qui est dessous
   sautait d'une ligne en plein glisser, pile au passage jour/nuit. */
.view-status {
  margin: 8px 2px 0; font-size: .92rem; color: var(--text);
  line-height: 1.45;
  min-height: 2.9em;
}

/* petit rappel « glisse ici », SOUS le jardin (transitoire) : rien ne recouvre
   jamais les canvas — display: table pour un centrage qui marche partout */
/* le conteneur (un bloc : max-height s'anime, ce que display: table ignore)
   s'efface ET se replie ENSEMBLE, en douceur — une bulle invisible qui
   garderait sa place ferait un trou, puis un saut au repli */
.drag-hint {
  margin: 8px 0 0; text-align: center; overflow: hidden;
  pointer-events: none; opacity: 1; max-height: 90px;
  font-size: .85rem;
  transition: opacity .3s, max-height .35s ease .05s, margin .35s ease .05s;
}
.drag-hint-pill {
  display: inline-block; max-width: 100%;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 14px; color: var(--text);
}
.drag-hint.hide { opacity: 0; max-height: 0; margin-top: 0; }

/* ---------- le grand curseur du temps ---------- */

.time-control { margin-top: 12px; padding: 0 4px 2px; }
.time-readout { font-size: 1.05rem; margin-bottom: 4px; }
.time-readout strong {
  font-size: 1.55rem; color: var(--rose); font-variant-numeric: tabular-nums;
  margin: 0 2px 0 4px;
}
.period { color: var(--muted); }

/* le curseur raconte lui-même la journée : nuit → aube → jour → crépuscule → nuit */
#time-slider {
  -webkit-appearance: none;
  appearance: none;
  display: block; width: 100%; height: 44px; margin: 2px 0 0;
  background: transparent; cursor: pointer;
}
#time-slider::-webkit-slider-runnable-track {
  height: 16px; border-radius: 9px; border: 1px solid var(--border);
  background: linear-gradient(90deg,
    #0e1a38 0%, #16335e 20%, #f2924c 28.5%, #8ec2f0 38%,
    #cfe7ff 50%, #8ec2f0 62%, #f2924c 78.5%, #16335e 87%, #0e1a38 100%);
}
#time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 34px; height: 34px; margin-top: -10px; border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fff7d6, var(--sun) 55%, var(--sun-deep));
  border: 3px solid rgba(255, 255, 255, .9);
  box-shadow: 0 0 16px rgba(255, 207, 92, .75), 0 2px 6px rgba(0, 0, 0, .5);
}
#time-slider::-moz-range-track {
  height: 16px; border-radius: 9px; border: 1px solid var(--border);
  background: linear-gradient(90deg,
    #0e1a38 0%, #16335e 20%, #f2924c 28.5%, #8ec2f0 38%,
    #cfe7ff 50%, #8ec2f0 62%, #f2924c 78.5%, #16335e 87%, #0e1a38 100%);
}
#time-slider::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fff7d6, var(--sun) 55%, var(--sun-deep));
  border: 3px solid rgba(255, 255, 255, .9);
  box-shadow: 0 0 16px rgba(255, 207, 92, .75), 0 2px 6px rgba(0, 0, 0, .5);
}
.slider-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; margin-top: 4px; }

/* ---------- boutons-scénarios + histoire ---------- */

.scenario-panel { margin-top: 16px; padding: 14px 16px 16px; }
.scenario-title {
  font-weight: 700; font-size: 1.05rem; margin: 2px 2px 10px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px 12px; flex-wrap: wrap;
}
.scenario-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 860px) { .scenario-buttons { grid-template-columns: 1fr 1fr; } }

.scn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 72px; padding: 10px 8px; border-radius: 16px; cursor: pointer;
  font: inherit; font-weight: 700; font-size: .95rem; text-align: center; line-height: 1.25;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  transition: filter .15s, transform .05s, box-shadow .15s;
}
.scn:hover { filter: brightness(1.2); }
.scn:active { transform: translateY(1px); }
.scn.active { box-shadow: 0 0 0 3px rgba(255, 207, 92, .55); }
.scn-emoji { font-size: 1.6rem; line-height: 1; }
.scn-sub { font-weight: 400; font-size: .76rem; opacity: .8; }
.scn-lever { background: linear-gradient(180deg, #4a1d33, #2d1122); border-color: var(--rose); color: #ffb3cd; }
.scn-midi { background: linear-gradient(180deg, #1c3a63, #132644); border-color: #3f6db3; color: #bcd9ff; }
.scn-coucher { background: linear-gradient(180deg, #4a3a0d, #332807); border-color: var(--sun-deep); color: var(--sun); }
.scn-minuit { background: linear-gradient(180deg, #2b1e52, #1c1433); border-color: #5f43b3; color: #cabcff; }

.story { margin-top: 12px; }
.story-invite { margin: 4px 2px; color: var(--muted); }
.story-line { display: flex; gap: 10px; align-items: flex-start; margin: 9px 0; font-size: 1.03rem; }
.story-chip {
  flex: none; padding: 3px 11px; border-radius: 999px; font-weight: 700; font-size: .85rem;
  white-space: nowrap;
}
.story-chip-jardin { background: rgba(70, 194, 165, .14); color: var(--teal); border: 1px solid rgba(70, 194, 165, .5); }
.story-chip-espace { background: rgba(169, 139, 255, .14); color: var(--violet); border: 1px solid rgba(169, 139, 255, .5); }
.story-text { margin: 2px 0 0; }

/* ---------- la grande révélation (à lire… ou à écouter) ---------- */

.explain-panel { margin-top: 16px; padding: 16px 20px 18px; }
.explain-head { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-bottom: 8px; }
.explain-head h2 { margin: 0; font-size: 1.15rem; color: var(--sun); }
/* le résumé repliable ne sert que sur mobile : sur ordinateur il est masqué
   et main.js garde la boîte ouverte (le titre reste celui de .explain-head) —
   même mécanique que l'épisode 3 */
.explain-summary { display: none; }
@media (max-width: 640px) {
  .explain-panel { padding: 4px 16px 6px; }
  .explain-panel[open] { padding-bottom: 16px; }
  .explain-summary { display: block; cursor: pointer; padding: 12px 4px; list-style: none; }
  .explain-summary::-webkit-details-marker { display: none; }
  .explain-summary::before { content: '▸ '; color: var(--sun); font-weight: 700; }
  .explain-panel[open] .explain-summary::before { content: '▾ '; }
  .explain-summary h2 { display: inline; margin: 0; font-size: 1.15rem; color: var(--sun); }
  .explain-summary .hint { display: block; margin: 3px 0 0 1.35em; font-size: .8rem; }
  /* sur mobile, le titre vit dans le résumé : celui de la rangée disparaît */
  .explain-head h2 { display: none; }
}
.listen-btn {
  margin-left: auto; border-radius: 999px; padding: 8px 16px; font-weight: 700;
  background: linear-gradient(180deg, #4a3a0d, #332807); border: 1px solid var(--sun-deep);
  color: var(--sun);
}
.listen-btn[aria-pressed="true"] { background: #243158; border-color: #3b4c86; color: var(--text); }
.voice-pick {
  font-family: inherit; font-size: .85rem; font-weight: 600;
  color: var(--muted); background: #131c3f;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 12px; max-width: 230px;
}
.voice-pick:focus { outline: 2px solid var(--sun-deep); }
.voice-hint { margin: 0 0 8px; font-size: .82rem; color: var(--muted); }
.explain-text p { margin: .55em 0; color: #c9d2ea; font-size: 1.02rem; line-height: 1.7; }
.explain-text strong { color: var(--text); }

/* ---------- le jeu « Fais tourner la Terre ! » ---------- */

.game-panel { margin-top: 16px; padding: 14px 16px 16px; }
.game-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px 12px; flex-wrap: wrap;
}
.game-head h2 { margin: 0; font-size: 1.15rem; color: var(--teal); }
.game-btn {
  border-radius: 999px; padding: 8px 18px; font-weight: 700;
  background: linear-gradient(180deg, #14434a, #0d2f35);
  border: 1px solid var(--teal); color: #8fe0cb;
}
.game-intro { margin: 12px 2px 2px; color: var(--muted); }
.game-defi { margin: 2px 2px 12px; font-size: 1.25rem; font-weight: 800; color: var(--sun); }
/* les deux mini-vues restent côte à côte, même sur mobile : le défi, les deux
   regards et le bravo tiennent ensemble sur un écran de téléphone */
.game-views {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 10px; align-items: start;
  /* sur grand écran, le jeu reste compact : les grandes vues vivent plus haut */
  max-width: 860px;
}
.game-bravo {
  margin: 12px 2px 4px; padding: 10px 14px; border-radius: 12px;
  background: rgba(255, 207, 92, .12); border: 1px solid rgba(255, 207, 92, .55);
  color: var(--sun); font-weight: 700; font-size: 1.05rem;
}
#btn-encore { margin-top: 2px; }
#game-garden, #game-space { touch-action: none; cursor: grab; }
#game-garden:active, #game-space:active { cursor: grabbing; }

/* ---------- le pont vers l'épisode 3 ---------- */

.bridge-panel {
  margin-top: 16px; padding: 16px 20px;
  display: flex; align-items: center; gap: 14px;
  color: var(--text); text-decoration: none;
  transition: filter .15s, transform .05s;
}
.bridge-panel:hover { filter: brightness(1.2); }
.bridge-panel:active { transform: translateY(1px); }
.bridge-emoji { font-size: 2rem; flex: none; }
.bridge-text { flex: 1; font-size: .98rem; color: var(--muted); }
.bridge-text strong { color: var(--text); font-size: 1.05rem; }
.bridge-arrow { flex: none; font-size: 1.6rem; color: var(--sun); }

/* ---------- note aux parents (repliée) ---------- */

.parents { margin-top: 22px; }
.parents summary {
  cursor: pointer; padding: 14px 20px; font-weight: 700; color: var(--sun);
  list-style: none;
}
.parents summary::-webkit-details-marker { display: none; }
.parents summary::before { content: '▸ '; }
.parents[open] summary::before { content: '▾ '; }
.parents ul { margin: 0; padding: 0 24px 18px 2.6em; }
.parents li { margin: 8px 0; color: #c9d2ea; font-size: .93rem; }
.parents strong { color: var(--text); }

/* ---------- boutons génériques ---------- */

button {
  font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 14px; cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.25); }
button:active { transform: translateY(1px); }

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

/* ---------- pied de page ---------- */

.site-footer {
  max-width: 1180px; margin: 40px auto 0; padding: 22px 20px 34px;
  border-top: 1px solid var(--border); color: var(--muted); font-size: .88rem;
}
.site-footer a { color: var(--sun); }

/* ---------- petits écrans ---------- */

/* sous 640 px : les deux vues s'empilent (jardin d'abord), rien ne recouvre les canvas */
@media (max-width: 640px) {
  /* en-tête compact : un bout de jardin doit se voir dès le premier écran */
  .site-header { padding: 18px 16px 10px; }
  .site-header h1 { font-size: clamp(1.65rem, 7.5vw, 2.2rem); }
  .tagline { font-size: .92rem; }
  main { padding: 0 12px 48px; }
  /* le fond fixe force des repeints à chaque défilement sur Android */
  body { background-attachment: scroll; }

  .views-grid { grid-template-columns: 1fr; }
  /* les deux vues, plafonnées en hauteur d'écran : après un appui-scénario,
     jardin ET espace tiennent ensemble dans le viewport d'un téléphone.
     Hauteurs EXPLICITES, jamais aspect-ratio + max-height : quand le plafond
     mord, WebKit réduit alors la LARGEUR de la boîte (vue espace rétrécie
     sur iPhone/Safari). */
  .views-grid .ratio-garden { aspect-ratio: auto; height: min(55vw, 34vh); }
  .views-grid .ratio-space { aspect-ratio: auto; height: min(88vw, 40vh); }
  /* les mini-vues du jeu, plus étroites, gardent leurs proportions — écart
     resserré et colonne espace élargie : chaque pixel compte pour le disque
     que l'enfant fait tourner du doigt */
  .game-views { gap: 8px; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  .game-views .ratio-garden { aspect-ratio: 16 / 10; }
  @supports not (aspect-ratio: 1 / 1) {
    .game-views .ratio-garden { height: 30vw; }
    .game-views .ratio-space { height: 38vw; }
  }
  .drag-hint { font-size: .8rem; }

  /* des cibles tactiles d'au moins ~44 px pour les petits doigts */
  .spin-btn, .listen-btn, .game-btn, .voice-pick { min-height: 44px; padding-top: 8px; padding-bottom: 8px; }
}

@media (max-width: 480px) {
  .time-readout strong { font-size: 1.35rem; }
  .scn { min-height: 64px; }
  .stage-head { font-size: .82rem; }
  .bridge-panel { padding: 14px 14px; gap: 10px; }
  /* les histoires : la pastille au-dessus du texte, qui garde toute la largeur */
  .story-line { display: block; }
  .story-chip { display: inline-block; }
  .story-text { margin: 4px 0 0; }
}

/* ---------- accessibilité : mouvement réduit ---------- */

@media (prefers-reduced-motion: reduce) {
  .drag-hint { transition: none; }
  .scn, button, .bridge-panel { transition: none; }
  html { scroll-behavior: auto; }
}
