/* ══════════════════════════════════════════════════
   Simulation pédagogique — Physique-Chimie Lycée
   Auteur  : Mathieu Berdous
   Licence : CC BY-NC 4.0 — https://creativecommons.org/licenses/by-nc/4.0/
══════════════════════════════════════════════════ */

/* ── Reset & base ────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: #e8e4de;
  color: #2c3e50;
  /* dvh : suit la hauteur réellement visible (barres dynamiques du navigateur) ;
     vh reste le repli pour les navigateurs sans support dvh. */
  height: 100vh;
  max-height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ── Grille principale ───────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr clamp(200px, 22vw, 300px);
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

/* ── Colonne gauche : une vue par onglet ─────────── */
#left-col {
  display: flex;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 10px;
}

.tab-view {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
}

/* Onglet 3ᵉ loi : animation | graphe côte à côte */
.tab-view.duo {
  display: grid;
  grid-template-columns: 54fr 46fr;
  gap: 10px;
}

/* Graphe masqué (bouton « Afficher graphe ») : l'animation prend toute la place */
.tab-view.duo.no-graph {
  grid-template-columns: 1fr;
}
.tab-view.duo.no-graph .chart-wrap {
  display: none;
}

/* Sur fenêtre étroite, les deux zones de la 3ᵉ loi s'empilent */
@media (max-width: 950px) {
  .tab-view.duo {
    grid-template-columns: 1fr;
    grid-template-rows: 55fr 45fr;
  }
}

/* ── Zone simulation (canvas animation) ──────────── */
/* Exception assumée à la charte (fond ivoire) : ici la zone d'animation
   est un fond « espace » — simple dégradé sombre, sans étoiles (choix de
   l'utilisateur : rester sobre). Les couleurs des tracés sont éclaircies
   en conséquence ; le reste de la page garde la charte claire. */
.sim-area {
  flex: 1;
  min-height: 0;
  min-width: 0;
  background: radial-gradient(ellipse at center, #17202e 0%, #0a0f1a 100%);
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.sim-area canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Zone graphe (3ᵉ loi) ────────────────────────── */
.chart-wrap {
  position: relative;
  min-height: 0;
  min-width: 0;
  background: #faf9f6;
  border: 1px solid #c8c0b4;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  overflow: hidden;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Sélecteurs d'axes du graphe (T/T²/T³ et a/a²/a³) ──
   Posés en overlay sur le graphe, chacun contre l'axe qu'il pilote. */
.axis-sel {
  position: absolute;
  display: flex;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  overflow: hidden;
  background: #ece8e0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.10);
  z-index: 3;
}

.axis-sel button {
  padding: 6px 12px;
  font-size: clamp(14px, 1.4vw, 18px);
  font-weight: 700;
  font-family: inherit;
  border: none;
  background: #ece8e0;
  color: #5a6a78;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.axis-sel button:hover { background: #ddd8ce; }
.axis-sel button.active { background: #2a6aaa; color: #fff; }

/* Ordonnée : pile verticale, collée au milieu de l'axe vertical.
   Rembourrage réduit : la pile doit rester plus étroite que la marge
   gauche du graphe pour ne pas chevaucher les graduations. */
.axis-sel-y {
  flex-direction: column;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
}
.axis-sel-y button {
  padding: 6px 10px;
  font-size: clamp(13px, 1.3vw, 17px);
}
.axis-sel-y button:not(:last-child) { border-bottom: 1px solid #c8c0b4; }

/* Abscisse : rangée horizontale, centrée sous l'axe horizontal */
.axis-sel-x {
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
}
.axis-sel-x button:not(:last-child) { border-right: 1px solid #c8c0b4; }

/* ── Bouton « Modélisation linéaire » (graphe, 3ᵉ loi) ── */
#btn-model-lin-3 {
  position: absolute;
  top: 8px;
  right: 8px;
  width: auto;
  z-index: 3;
  box-shadow: 0 1px 3px rgba(0,0,0,0.10);
}

/* ── Bulle de survol des points du graphe ────────── */
#graph3-tooltip {
  position: absolute;
  display: none;
  font-size: 13px;
  font-family: monospace;
  background: #2c3e50;
  color: #fff;
  border-radius: 5px;
  padding: 5px 10px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

/* ── Panneau droit ───────────────────────────────── */
#panel {
  background: #e8e4de;
  border-left: 1.5px solid #c8c0b4;
  display: flex;
  flex-direction: column;
  height: 100%;
  font-size: clamp(11px, 1.1vw, 14px);
  overflow: hidden;
}

/* ── Onglets principaux (1ʳᵉ / 2ᵉ / 3ᵉ loi) ──────── */
.panel-main-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1.5px solid #b0a898;
}

.panel-main-tab {
  flex: 1;
  padding: 9px 4px;
  font-size: clamp(11px, 1.1vw, 14px);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: #d4d0c8;
  color: #8a9aaa;
  border-right: 1px solid #b0a898;
  transition: background 0.12s, color 0.12s;
  line-height: 1.25;
}
.panel-main-tab:last-child { border-right: none; }
.panel-main-tab:hover { background: #ccc8c0; color: #2c3e50; }
.panel-main-tab.active {
  background: #e8e4de;
  color: #2a6aaa;
  border-bottom: 1.5px solid #e8e4de;
  margin-bottom: -1.5px;
}

.tab-sub {
  display: block;
  font-size: 0.82em;
  font-weight: 600;
  opacity: 0.85;
}

/* ── Corps scrollable ────────────────────────────── */
#panel-body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(10px, 1.2vw, 16px) clamp(10px, 1.2vw, 14px);
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Section ─────────────────────────────────────── */
.panel-section { margin-bottom: 8px; }

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7a8a96;
  margin-bottom: 7px;
}

/* ── Séparateur ──────────────────────────────────── */
.sep {
  border: none;
  border-top: 1px solid #c8c0b4;
  margin: 8px 0;
}

/* ── Boutons ─────────────────────────────────────── */
.btn {
  width: 100%;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.btn:active { transform: scale(0.97); }

.btn-play {
  background: #2a8a50;
  color: #fff;
  font-size: clamp(14px, 1.4vw, 18px);
  padding: 10px 6px;
}
.btn-play:hover { background: #1a6a38; }

.btn-pause {
  background: #c08020;
  color: #fff;
  font-size: clamp(14px, 1.4vw, 18px);
  padding: 10px 6px;
}
.btn-pause:hover { background: #a06010; }

.btn-raz {
  background: #dedad2;
  color: #5a6a78;
  font-size: clamp(12px, 1.2vw, 15px);
  padding: 9px 6px;
  border: 1.5px solid #c8c0b4;
}
.btn-raz:hover { background: #ccc8c0; }

/* Ligne de boutons côte à côte (ex. Pause + RAZ) : chacun garde le style
   .btn habituel, seule la largeur devient partagée au lieu de 100%. RAZ
   reste étroit (texte court et fixe) pour laisser toute la place à
   Lancer/Pause/Reprendre, dont le texte change et ne doit pas passer à la ligne. */
.btn-row {
  display: flex;
  gap: 6px;
}
.btn-row > .btn {
  width: auto;
  flex: 1 1 0;
  white-space: nowrap;
}
.btn-row > .btn-raz {
  flex: 0 0 auto;
}

.btn-primary {
  background: #2a6aaa;
  color: #fff;
  font-size: clamp(13px, 1.3vw, 16px);
  padding: 11px 6px;
}
.btn-primary:hover { background: #1a5a9a; }

.btn-toggle-one {
  background: #ece8e0;
  color: #5a6a78;
  border: 1px solid #c8c0b4;
  font-size: clamp(12px, 1.2vw, 15px);
  padding: 9px 6px;
}
.btn-toggle-one.active {
  background: #fde8c8;
  color: #7a3a10;
  border-color: #d0a060;
}
.btn-toggle-one:hover { background: #ddd8ce; }
.btn-toggle-one.active:hover { background: #f8dcb0; }
.btn-primary:disabled {
  background: #a0b8c8;
  cursor: not-allowed;
  transform: none;
}

/* ── Paramètres ──────────────────────────────────── */
.param-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}

.param-row label {
  font-size: clamp(12px, 1.25vw, 15px);
  color: #2c3e50;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

.param-value {
  color: #2a5080;
  font-weight: 600;
  white-space: nowrap;
  font-size: clamp(12px, 1.25vw, 15px);
}

.param-row input[type="range"] {
  width: 100%;
  accent-color: #4a7aaa;
  cursor: pointer;
}

.input-hint {
  font-size: clamp(10px, 0.9vw, 13px);
  color: #7a8a96;
  line-height: 1.4;
  font-weight: 400;
}

/* Crans sous un slider : chaque label est centré exactement sous la position
   du curseur pour son cran. Le curseur natif (~16px de large) ne parcourt que
   (100% - 16px) : les labels sont donc placés à 8px + frac × (100% - 16px),
   via --tick-frac posé sur chaque span (0 pour le 1er cran, 1 pour le dernier). */
.slider-ticks {
  position: relative;
  margin-top: 3px;
  height: 1.3em;
}

.slider-ticks span {
  position: absolute;
  top: 0;
  left: calc(8px + (100% - 16px) * var(--tick-frac, 0));
  transform: translateX(-50%);
  font-size: clamp(10px, 1vw, 13px);
  color: #7a8a96;
  white-space: nowrap;
}

/* ── Cases à cocher d'affichage ──────────────────── */
.check-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: clamp(12px, 1.15vw, 15px);
  color: #2c3e50;
  cursor: pointer;
  user-select: none;
  margin-bottom: 7px;
  line-height: 1.3;
}

.check-row input[type="checkbox"] {
  accent-color: #4a7aaa;
  cursor: pointer;
  width: 1.1em;
  height: 1.1em;
  flex: 0 0 auto;
}

/* Pastille reliant la case à la couleur de l'élément sur le canvas */
.cr-swatch {
  display: inline-block;
  flex: 0 0 auto;
  width: 13px;
  height: 5px;
  border-radius: 2px;
}
.cr-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.2);
}

/* ── Afficheurs valeur ───────────────────────────── */
.readout {
  background: #fff;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  padding: 7px 9px;
  margin-bottom: 8px;
}

.ro-label {
  font-size: clamp(13.2px, 1.2vw, 15.6px);
  color: #7a8a96;
  margin-bottom: 4px;
}

.ro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
}

/* Une grandeur par ligne (mesures de la 2ᵉ loi) */
.ro-grid-1col {
  grid-template-columns: 1fr;
}

.ro-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ro-item-label {
  font-size: clamp(12px, 1.05vw, 14px);
  color: #7a8a96;
}

.ro-item-val {
  font-size: clamp(16px, 1.7vw, 20px);
  font-weight: 700;
  color: #2a5080;
  font-variant-numeric: tabular-nums;
}

/* ── Liste des aires balayées (2ᵉ loi) ───────────── */
.aires-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.aire-row {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: clamp(12px, 1.2vw, 15px);
}

.aire-swatch {
  flex: 0 0 auto;
  align-self: center;
  width: 14px;
  height: 10px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
}

.aire-val {
  font-weight: 700;
  color: #2a5080;
  font-variant-numeric: tabular-nums;
}

.aire-interval {
  font-size: clamp(10px, 0.95vw, 13px);
  color: #7a8a96;
  font-variant-numeric: tabular-nums;
}

.aires-empty {
  font-size: clamp(11px, 1.05vw, 14px);
  color: #7a8a96;
  font-style: italic;
}

/* ── Sélecteur de système (3ᵉ loi) ───────────────── */
.sys-select {
  width: 100%;
  padding: 8px 6px;
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 700;
  font-family: inherit;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  background: #ece8e0;
  color: #5a6a78;
  cursor: pointer;
}

.sys-toggle {
  display: flex;
  flex-direction: column;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  overflow: hidden;
}

.sys-btn {
  padding: 8px 6px;
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 700;
  font-family: inherit;
  border: none;
  background: #ece8e0;
  color: #5a6a78;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.sys-btn:not(:last-child) { border-bottom: 1px solid #c8c0b4; }
.sys-btn:hover { background: #ddd8ce; }
.sys-btn.active { background: #2a6aaa; color: #fff; }

/* Variante horizontale : presets de zoom du Système Solaire */
.sys-toggle-row { flex-direction: row; }
.sys-toggle-row .sys-btn { flex: 1; }
.sys-toggle-row .sys-btn:not(:last-child) {
  border-bottom: none;
  border-right: 1px solid #c8c0b4;
}

/* ── Tableau des données (3ᵉ loi) ────────────────── */
.sys-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.sys-table th {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #7a8a96;
  text-align: left;
  padding: 2px 4px 4px;
  border-bottom: 1px solid #c8c0b4;
}
.sys-table th.num { text-align: right; }

.sys-table td {
  font-size: clamp(11px, 1.05vw, 14px);
  color: #2c3e50;
  padding: 4px;
  border-bottom: 1px solid #e2ded6;
}
.sys-table tr:last-child td { border-bottom: none; }

.sys-table td.num {
  text-align: right;
  color: #2a5080;
  font-weight: 600;
}

.sys-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1px solid rgba(0,0,0,0.2);
}

/* ── Bandeau Instructions ────────────────────────── */
.panel-hint {
  flex-shrink: 0;
  color: #5a6a78;
  line-height: 1.5;
  background: #fff;
  border: 1.5px solid #b0a898;
  /* Pas de bordure gauche propre : #panel a déjà la sienne sur ce bord
     (cf. CONTEXTE_PROJET.md §5, évite le décalage sous-pixel entre deux
     bordures superposées quand la largeur du panneau est en clamp()). */
  border-left: none;
  overflow: hidden;
  transition: padding 0.2s;
}

.panel-hint strong { color: #2c3e50; }

.panel-hint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
}

.panel-hint-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7a8a96;
  margin-left: auto;
  margin-right: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-hint-menu-btn {
  background: #f0f4f7;
  border: 1px solid #c8d4dc;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: #4a5a68;
  padding: 4px 9px;
  line-height: 1.2;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.panel-hint-menu-btn:hover { background: #dde6ec; color: #2a6aaa; }

.panel-hint-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: #7a8a96;
  padding: 0 2px;
  line-height: 1;
  transition: transform 0.2s;
}
.panel-hint-toggle:hover { color: #2a6aaa; }

.panel-hint-body {
  font-size: clamp(11px, 1vw, 14px);
  padding: 0 10px 8px;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
  max-height: 280px;
}

.panel-hint.collapsed .panel-hint-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}
.panel-hint:not(.collapsed) .panel-hint-toggle { transform: rotate(180deg); }
