/*
 * style.css
 * Feuille de style de l'interface de la simulation du système solaire.
 *
 * Principes :
 *  - sobriété : panneaux sombres translucides, bordures fines, une seule couleur d'accent ;
 *  - lisibilité : police système, contrastes élevés, chiffres à chasse fixe pour les valeurs
 *    qui changent (pas de saut de mise en page) ;
 *  - performance : pas de flou d'arrière-plan (backdrop-filter), coûteux au-dessus d'un canevas
 *    WebGL redessiné à chaque image ;
 *  - les calques (#ui, #labels) laissent passer les gestes vers la scène : seuls les panneaux
 *    captent le pointeur.
 *
 * Sommaire : 1. variables et base, 2. calques, 3. éléments communs, 4. panneau latéral
 * (navigation, affichage), 5. barre de temps, 6. fiche d'information, 7. aide et messages,
 * 8. écran de chargement, 9. adaptations aux petits écrans.
 */

/* ---------- 1. Variables et base ---------- */

:root {
  --bg: #05070c;
  --panel: rgba(13, 17, 26, 0.86);
  --panel-solid: #0f141e;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text: #e6eaf2;
  --muted: #98a3b6;
  --faint: #6d7789;
  --accent: #8ab4ff;
  --accent-soft: rgba(138, 180, 255, 0.16);
  --danger: #ff9d8a;
  --hover: rgba(255, 255, 255, 0.07);
  --radius: 10px;
  --gap: 12px;
  --side-width: 216px;
  --info-width: 344px;
  --timebar-space: 92px; /* hauteur réservée à la barre de temps, marges comprises */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

h1, h2, h3, p, ul, dl, dd, fieldset, legend { margin: 0; padding: 0; }
ul { list-style: none; }
fieldset { border: 0; min-width: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Texte réservé aux lecteurs d'écran. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------- 2. Calques ---------- */

.scene, .labels, .ui { position: absolute; inset: 0; }
.scene { touch-action: none; -webkit-user-select: none; user-select: none; }
.scene canvas { display: block; width: 100%; height: 100%; outline: none; }
.labels { overflow: hidden; pointer-events: none; }
.ui { pointer-events: none; overflow: hidden; }
.ui > * { pointer-events: none; }

/* ---------- 3. Éléments communs ---------- */

.panel {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

.icon { display: block; flex: none; }

/* Bouton avec texte. */
.button {
  height: 32px; padding: 0 12px;
  background: transparent; border: 1px solid var(--border-strong); border-radius: 7px;
  color: var(--text); white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.button:hover { background: var(--hover); border-color: rgba(255, 255, 255, 0.32); }
.button:active { background: rgba(255, 255, 255, 0.12); }
.button--primary { background: var(--accent-soft); border-color: rgba(138, 180, 255, 0.5); color: #dbe8ff; }
.button--primary:hover { background: rgba(138, 180, 255, 0.26); border-color: var(--accent); }

/* Bouton réduit à une icône. */
.iconbutton {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; padding: 0;
  background: transparent; border: 1px solid var(--border-strong); border-radius: 50%;
  color: var(--text);
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.iconbutton:hover { background: var(--hover); border-color: rgba(255, 255, 255, 0.32); }
.iconbutton:active { background: rgba(255, 255, 255, 0.12); }
.iconbutton[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.iconbutton--quiet { width: 28px; height: 28px; border-color: transparent; color: var(--muted); }
.iconbutton--quiet:hover { color: var(--text); border-color: transparent; }

/* Curseur (input range) : piste fine, poignée ronde. */
.slider {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: 20px; margin: 0;
  background: transparent; cursor: pointer;
}
.slider::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.2); }
.slider::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.2); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-top: -5px;
  border: 0; border-radius: 50%; background: var(--text);
  box-shadow: 0 0 0 3px rgba(5, 7, 12, 0.6);
  transition: background-color 0.12s ease, transform 0.12s ease;
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--text);
  box-shadow: 0 0 0 3px rgba(5, 7, 12, 0.6);
}
.slider:hover::-webkit-slider-thumb, .slider:focus-visible::-webkit-slider-thumb { background: var(--accent); transform: scale(1.15); }
.slider:hover::-moz-range-thumb, .slider:focus-visible::-moz-range-thumb { background: var(--accent); }
.slider:focus-visible { outline-offset: 4px; border-radius: 4px; }

/* Champ de saisie. */
.field {
  width: 100%; height: 34px; padding: 0 8px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-strong); border-radius: 7px;
  color: var(--text); color-scheme: dark; font-variant-numeric: tabular-nums;
}
.field[aria-invalid="true"] { border-color: var(--danger); }

/* Case à cocher. */
.check { display: flex; align-items: center; gap: 8px; min-height: 26px; cursor: pointer; color: var(--text); }
.check__input { position: absolute; opacity: 0; width: 16px; height: 16px; margin: 0; cursor: pointer; }
.check__box {
  flex: none; width: 16px; height: 16px; border: 1px solid rgba(255, 255, 255, 0.38); border-radius: 4px;
  background: transparent center / 12px 12px no-repeat;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.check:hover .check__box { border-color: rgba(255, 255, 255, 0.65); }
.check__input:checked + .check__box {
  background-color: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.3 5 8.7l4.6-5.2' fill='none' stroke='%2305070c' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.check__input:focus-visible + .check__box { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Pastille cliquable (lunes, planète parente). */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px 0 8px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border); border-radius: 13px;
  color: var(--text); font-size: 12px;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.chip:hover { background: rgba(255, 255, 255, 0.11); border-color: var(--border-strong); }
.chip__dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

/* Panneau repliable : en-tête cliquable et corps. */
.panel__heading { font-size: inherit; font-weight: inherit; }
.panel__toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; height: 36px; padding: 0 10px 0 12px;
  background: transparent; border: 0; border-radius: var(--radius);
  color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.panel__toggle:hover { color: var(--text); }
.panel__toggle .icon { transition: transform 0.15s ease; transform: rotate(180deg); }
.panel--collapsed .panel__toggle .icon { transform: none; }

/* ---------- 4. Panneau latéral : navigation et affichage ---------- */

.ui__side {
  position: absolute; top: var(--gap); left: var(--gap); bottom: var(--gap);
  width: var(--side-width);
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--gap);
}
.ui__side > .panel { flex: none; display: flex; flex-direction: column; min-height: 0; }
.ui__side > #nav { flex: 0 1 auto; }
.ui__side > .panel > .panel__body { min-height: 0; }

#nav > .panel__body { overflow-y: auto; padding: 0 6px 6px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.2) transparent; }
.nav__item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; height: 28px; padding: 0 8px;
  background: transparent; border: 0; border-radius: 6px;
  color: var(--text); text-align: left;
  transition: background-color 0.12s ease;
}
.nav__item:hover { background: var(--hover); }
.nav__item[aria-current="true"] { background: var(--accent-soft); color: #ffffff; }
.nav__dot { flex: none; width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4); }
.nav__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav__count { flex: none; color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.nav__moons { margin: 1px 0 3px 11px; padding-left: 8px; border-left: 1px solid var(--border); }
.nav__item--moon { height: 24px; gap: 8px; color: var(--muted); font-size: 12px; }
.nav__item--moon:hover { color: var(--text); }
.nav__item--moon .nav__dot { width: 6px; height: 6px; }

#display > .panel__body { padding: 2px 12px 12px; }
.scale__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.scale__label { color: var(--text); font-weight: 600; }
.scale__value { color: var(--accent); font-variant-numeric: tabular-nums; }
.scale__ends { display: flex; justify-content: space-between; margin-top: -1px; }
.scale__end { padding: 0; background: none; border: 0; color: var(--muted); font-size: 11px; }
.scale__end:hover { color: var(--text); }
.scale__hint { margin-top: 7px; min-height: 2.8em; color: var(--muted); font-size: 11.5px; line-height: 1.4; }

.layers { margin-top: 8px; padding-top: 9px; border-top: 1px solid var(--border); }
.layers__legend { margin-bottom: 3px; color: var(--text); font-weight: 600; }

/* ---------- 5. Barre de temps ---------- */

.timebar {
  position: absolute; left: 50%; bottom: calc(var(--gap) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px;
  height: 64px; padding: 0 14px 0 8px;
  white-space: nowrap;
}

.timebar__clock { position: relative; }
.timebar__date {
  display: flex; align-items: center; gap: 12px;
  height: 48px; padding: 0 10px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--text); text-align: left;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.timebar__date:hover, .timebar__date[aria-expanded="true"] { background: var(--hover); border-color: var(--border); }
.timebar__date .icon { color: var(--muted); }
.timebar__date:hover .icon { color: var(--text); }
.timebar__datetext { display: flex; flex-direction: column; width: 152px; line-height: 1.25; }
.timebar__day { font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }
.timebar__time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.timebar__transport { display: flex; align-items: center; gap: 8px; }
.iconbutton--main { width: 40px; height: 40px; border-color: rgba(255, 255, 255, 0.34); }
.iconbutton--main .icon { width: 18px; height: 18px; }
.iconbutton--main .icon--play { display: none; }
.timebar--paused .iconbutton--main { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.timebar--paused .iconbutton--main .icon--play { display: block; }
.timebar--paused .iconbutton--main .icon--pause { display: none; }

.timebar__speed { width: 176px; }
.timebar__speedhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.timebar__speedlabel { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.timebar__speedvalue { color: var(--text); font-variant-numeric: tabular-nums; }
.timebar--reversed .timebar__speedlabel { color: var(--accent); }

/* Saisie d'une date : bulle au-dessus de la barre. */
.datepop {
  position: absolute; left: 0; bottom: calc(100% + 16px);
  width: 264px; padding: 12px;
  background: var(--panel-solid);
  white-space: normal;
}
.datepop__label { display: block; margin-bottom: 6px; font-weight: 600; }
.datepop__hint { margin-top: 6px; color: var(--muted); font-size: 11.5px; }
.datepop__hint--error { color: var(--danger); }
.datepop__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* ---------- 6. Fiche d'information ---------- */

.info {
  position: absolute; top: var(--gap); right: var(--gap);
  width: var(--info-width); max-height: calc(100% - var(--gap) - var(--timebar-space));
  display: flex; flex-direction: column;
}
.info__header { flex: none; display: flex; align-items: center; gap: 10px; padding: 12px 10px 10px 14px; border-bottom: 1px solid var(--border); }
.info__swatch { flex: none; width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.07); }
.info__heading { flex: 1; min-width: 0; }
.info__title { font-size: 18px; font-weight: 600; line-height: 1.2; letter-spacing: 0.01em; }
.info__kind { color: var(--muted); font-size: 12px; }
.info__content { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 14px 14px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.2) transparent; }
.info__content:focus-visible { outline-offset: -2px; border-radius: 0 0 var(--radius) var(--radius); }
.info__description { color: #c9d0dc; line-height: 1.5; }
.info__section { margin-top: 14px; }
.info__subtitle { margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.info__note { margin-bottom: 7px; color: #c9d0dc; }

.info__table { width: 100%; border-collapse: collapse; }
.info__table th, .info__table td { padding: 4px 0; border-top: 1px solid rgba(255, 255, 255, 0.06); vertical-align: baseline; }
.info__table tr:first-child th, .info__table tr:first-child td { border-top: 0; }
.info__table th { width: 1%; padding-right: 14px; white-space: nowrap; color: var(--muted); font-weight: 400; text-align: left; }
.info__table td { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.info__table sup { font-size: 0.72em; line-height: 0; }
.info__table--live td { color: #cfe0ff; }

/* ---------- 7. Aide et messages ---------- */

.help { position: absolute; right: var(--gap); bottom: calc(var(--gap) + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.help__button { width: 36px; height: 36px; border-color: var(--border); color: var(--muted); box-shadow: none; }
.help__button:hover, .help__button[aria-expanded="true"] { color: var(--text); background: var(--panel-solid); border-color: var(--border-strong); }
.help__bubble { width: 336px; padding: 12px 14px; background: var(--panel-solid); }
.help__title { margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.help__list { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.help__list dt { color: var(--text); font-weight: 600; white-space: nowrap; }
.help__list dd { color: var(--muted); }

.toast {
  position: absolute; top: var(--gap); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  max-width: min(520px, calc(100% - 2 * var(--gap))); padding: 8px 8px 8px 14px;
  background: var(--panel-solid); border-color: rgba(255, 157, 138, 0.5);
}
.toast__text { color: #ffd9d1; }

/* ---------- 8. Écran de chargement ---------- */

.loading {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity 0.6s ease;
}
.loading--done { opacity: 0; pointer-events: none; }
.loading__box { width: min(300px, calc(100% - 48px)); text-align: center; }
.loading__title { margin-bottom: 18px; font-size: 20px; font-weight: 300; letter-spacing: 0.22em; text-transform: uppercase; }
.loading__track { height: 2px; overflow: hidden; border-radius: 1px; background: rgba(255, 255, 255, 0.14); }
.loading__bar { height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left center; transition: transform 0.25s ease; }
.loading__label { margin-top: 12px; min-height: 1.5em; color: var(--muted); font-size: 12px; }
.loading--error .loading__track { display: none; }
.loading--error .loading__label { color: #ffd9d1; font-size: 13px; line-height: 1.5; }

/* ---------- 9. Adaptations aux petits écrans ---------- */

/* Écrans étroits : la barre de temps s'étend sous les panneaux latéraux, qui s'arrêtent au-dessus. */
@media (max-width: 1100px) {
  .ui__side { bottom: var(--timebar-space); }
  .ui--info-open .help { display: none; }
}

/* Fenêtres peu hautes : la liste et les réglages se tassent. */
@media (max-height: 800px) and (min-width: 721px) {
  .nav__item { height: 26px; }
  .nav__item--moon { height: 22px; }
}
@media (max-height: 640px) and (min-width: 721px) {
  .scale__hint { display: none; }
}

/* Téléphones : panneaux repliés en haut, barre de temps sur deux lignes, fiche en bas. */
@media (max-width: 720px) {
  :root { --gap: 8px; --timebar-space: 122px; }

  .ui__side {
    top: calc(var(--gap) + env(safe-area-inset-top, 0px)); left: var(--gap); right: 52px; bottom: auto; width: auto;
    flex-direction: row; justify-content: flex-start; align-items: flex-start;
    max-height: calc(100% - var(--timebar-space) - 2 * var(--gap));
  }
  .ui__side > .panel { flex: none; max-height: calc(100vh - var(--timebar-space) - 64px); }
  .ui__side > .panel:not(.panel--collapsed) { flex: 0 1 232px; min-width: 0; }
  .panel__toggle { height: 38px; }
  .nav__item { height: 34px; }
  .nav__item--moon { height: 30px; }
  .check { min-height: 32px; }

  .help { top: calc(var(--gap) + env(safe-area-inset-top, 0px)); right: var(--gap); bottom: auto; flex-direction: column-reverse; }
  .help__button { width: 40px; height: 40px; }
  .help__bubble { width: min(336px, calc(100vw - 2 * var(--gap))); }
  .ui--info-open .help { display: flex; }

  .timebar {
    left: var(--gap); right: var(--gap); transform: none;
    display: grid; grid-template-columns: auto 1fr; grid-template-areas: "clock now" "transport speed";
    gap: 6px 12px; height: auto; padding: 6px 10px 8px 6px;
  }
  .timebar__clock { grid-area: clock; }
  .timebar__now { grid-area: now; justify-self: end; }
  .timebar__transport { grid-area: transport; padding-left: 4px; }
  .timebar__speed { grid-area: speed; width: auto; min-width: 0; }
  .timebar__date { height: 44px; padding: 0 8px; }
  .datepop { width: min(264px, calc(100vw - 2 * var(--gap) - 14px)); }

  .info {
    top: auto; left: var(--gap); right: var(--gap); bottom: calc(var(--timebar-space) + env(safe-area-inset-bottom, 0px));
    width: auto; max-height: min(32%, 300px);
  }
  .info__header { padding: 9px 8px 8px 12px; }
  .info__title { font-size: 16px; }
  .info__content { padding: 10px 12px 12px; }
}

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