/* ══════════════════════════════════════════════════
   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 : graphes empilés ────────────── */
#left-col {
  display: flex;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 10px;
}

#row-graphes {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  /* Part de hauteur laissée au graphe principal ; pilotée par le splitter. */
  --frac-courbe: 0.62;
}

/* ── Zones de graphe ─────────────────────────────── */
.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%;
  touch-action: none;   /* le glissé pilote le point M, pas le scroll */
}

#wrap-courbe { flex: 1 1 0; }

/* Le graphe de la dérivée et son séparateur n'existent qu'à la demande. */
#splitter, #wrap-deriv { display: none; }

/* ── Panneau du décollage, à droite des graphes ──────────────────────
      Il n'apparaît qu'en mode « Décollage de fusée » ; les graphes se
      resserrent alors d'autant. La largeur est bornée : trop étroite la
      fusée devient un trait, trop large elle mange la lecture du graphe. */
#wrap-fusee { display: none; }

/* Les deux zones sont ACCOLÉES : le pointillé qui relie l'extrémité de la
   courbe au centre de masse de la fusée passe d'un canevas à l'autre, et
   le moindre écart entre eux le couperait en deux. D'où le gap nul, la
   bordure partagée et les coins carrés à la jonction. */
#left-col.avec-fusee { gap: 0; }
#left-col.avec-fusee #row-graphes .chart-wrap { border-top-right-radius: 0; border-bottom-right-radius: 0; }
#left-col.avec-fusee #wrap-fusee {
  display: block;
  flex: 0 0 clamp(110px, 17vw, 230px);
  min-width: 0;
  background: #eef4fb;
  border-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* Les deux graphes se partagent la hauteur selon --frac-courbe. Le grow est
   posé propriété par propriété : un calc() en position flex-grow dans le
   raccourci `flex` n'est pas interprété partout. */
#left-col.avec-deriv #wrap-courbe {
  flex-grow: var(--frac-courbe);
  flex-shrink: 1;
  flex-basis: 0;
}
/* Séparateur : zone de préhension confortable, mais visuellement réduite à
   une petite poignée centrée (::after) qui ne coupe pas la page en deux. */
#left-col.avec-deriv #splitter {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 14px;
  background: none;
  cursor: row-resize;
  touch-action: none;
}
#left-col.avec-deriv #splitter::after {
  content: '';
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: #c8c0b4;
  transition: background 0.12s, width 0.12s;
}
#left-col.avec-deriv #splitter:hover::after,
#left-col.avec-deriv #splitter.actif::after {
  background: #9aa7b4;
  width: 64px;
}
#left-col.avec-deriv #splitter.actif::after { background: #2a6aaa; }
#left-col.avec-deriv #wrap-deriv {
  display: block;
  flex-grow: calc(1 - var(--frac-courbe));
  flex-shrink: 1;
  flex-basis: 0;
}

/* ── 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;
}

#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;
}

.panel-title {
  font-size: clamp(14px, 1.4vw, 17px);
  font-weight: 700;
  color: #2c3e50;
  text-align: center;
  padding-bottom: clamp(8px, 1vw, 12px);
  border-bottom: 1.5px solid #c8c0b4;
  margin-bottom: clamp(8px, 1vw, 12px);
  letter-spacing: 0.3px;
}

/* ── 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;
}

.sep {
  border: none;
  border-top: 1px solid #c8c0b4;
  margin: 8px 0;
}

/* ── Sélecteur de fonction ─────────────────────────
   Le <select> natif reste cliquable mais invisible (opacity 0) : son menu
   déroulant garde l'apparence par défaut du navigateur, inchangée.
   L'affichage de la case fermée est un calque par-dessus, qui ne montre
   que l'équation de la fonction (au lieu de « nom — équation »). ───── */
.fon-select-wrap {
  position: relative;
}

.fon-select-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 6px;
  font-size: clamp(15px, 1.5vw, 19px);
  font-weight: 700;
  font-family: 'Cambria', Georgia, serif;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  background: #ece8e0;
  color: #5a6a78;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fon-select-caret {
  flex: none;
  font-size: 11px;
  font-style: normal;
  opacity: 0.7;
}

.fon-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 700;
  font-family: inherit;
  background: #ece8e0;
  color: #5a6a78;
  opacity: 0;
  cursor: pointer;
}

.fon-select option {
  background: #ece8e0;
  color: #5a6a78;
}

/* ── 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-primary {
  background: #2a6aaa;
  color: #fff;
  font-size: clamp(14px, 1.4vw, 18px);
  padding: 11px 6px;
}
.btn-primary:hover { background: #1a5a9a; }

.btn-pause {
  background: #c08020;
  color: #fff;
  font-size: clamp(14px, 1.4vw, 18px);
  padding: 11px 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; }

.btn-toggle-one {
  background: #ece8e0;
  color: #5a6a78;
  border: 1px solid #c8c0b4;
  font-size: clamp(12px, 1.2vw, 15px);
  padding: 9px 6px;
  margin-top: 4px;
}
.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-play {
  background: #2a8a50;
  color: #fff;
  font-size: clamp(14px, 1.4vw, 18px);
  padding: 11px 6px;
}
.btn-play:hover { background: #1a6a38; }

/* Deux boutons côte à côte (Lancer/Pause + RAZ) : chacun garde son style,
   seule la largeur devient partagée. RAZ reste étroit — son texte ne
   change pas — pour laisser la place à Lancer/Pause/Reprendre. */
.btn-row { display: flex; gap: 6px; }
.btn-row > .btn { width: auto; }
.btn-row > .btn-play,
.btn-row > .btn-pause { flex: 1 1 auto; }
.btn-row > .btn-raz   { flex: 0 0 auto; }

/* ── Ligne « vitesse d'animation » : rembobinage puis curseur ──
      Le bouton garde sa largeur d'icône, le curseur prend tout le reste,
      et les graduations partagent sa colonne pour rester sous les crans. */
.speed-line {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}
.speed-col {
  flex: 1 1 auto;
  min-width: 0;   /* sans quoi le curseur refuse de se comprimer */
}

.btn-rewind {
  flex: 0 0 auto;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  background: #ede9e2;
  color: #5a6a78;
  font-family: inherit;
  font-size: clamp(11px, 1.1vw, 14px);
  line-height: 1;
  padding: 5px 8px;
  cursor: pointer;
  opacity: 0.75;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
  touch-action: none;   /* l'appui maintenu ne doit pas faire défiler la page */
}
.btn-rewind:hover  { opacity: 1; background: #dedad2; }
.btn-rewind:active { transform: scale(0.97); }
.btn-rewind.active {
  opacity: 1;
  background: #fde8c8;
  color: #7a3a10;
  border-color: #d0a060;
}

.speed-ticks {
  display: grid;
  grid-template-columns: repeat(3, 1fr) 0fr;
  font-size: clamp(9px, 0.85vw, 11px);
  color: #7a8a96;
  padding: 0 7px;
  line-height: 1;
  margin-top: 1px;
}
.speed-ticks span:not(:last-child) { text-align: left; }
.speed-ticks span:last-child { text-align: right; white-space: nowrap; }

/* ── Sélecteur segmenté (deux choix exclusifs, ex. définition du taux) ── */
.seg-toggle {
  display: flex;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  overflow: hidden;
}

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

/* ── 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;
}

.p-unite {
  color: #7a8a96;
  font-weight: 400;
  font-size: 0.88em;
}

/* Paramètre de la fonction : nom, slider, saisie et unité sur une ligne. */
.param-inline {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.param-inline .p-nom {
  display: inline-block;
  font-size: clamp(12px, 1.25vw, 15px);
  color: #2c3e50;
  font-weight: 600;
  flex: 0 0 auto;
}

.param-inline input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
}

/* Champ de saisie + unité, en bout de ligne. */
.param-field {
  display: flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
}

.param-num {
  width: clamp(46px, 5vw, 62px);
  padding: 2px 5px;
  border: 1px solid #c3d0da;
  border-radius: 5px;
  background: #fff;
  color: #2a5080;
  font-family: inherit;
  font-weight: 600;
  font-size: clamp(12px, 1.25vw, 15px);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.param-num:focus {
  outline: none;
  border-color: #4a7aaa;
  box-shadow: 0 0 0 2px rgba(74, 122, 170, 0.18);
}

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

.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;
}

/* ── Cases à cocher ──────────────────────────────── */
.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 graphe */
.cr-swatch {
  display: inline-block;
  flex: 0 0 auto;
  width: 13px;
  height: 5px;
  border-radius: 2px;
}

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

/* Les deux afficheurs clés portent la couleur de l'objet qu'ils mesurent :
   la sécante (terracotta) et la tangente (vert). */
.ro-secante  { border-left: 4px solid #b04020; }
.ro-tangente { border-left: 4px solid #2a8a50; }

.ro-label {
  font-size: clamp(11px, 1vw, 13px);
  color: #7a8a96;
  margin-bottom: 4px;
}
.ro-label b { color: #2c3e50; font-family: 'Cambria', Georgia, serif; }

.ro-sens {
  color: #7a8a96;
  font-style: italic;
}

.ro-value {
  font-size: clamp(15px, 1.7vw, 21px);
  font-weight: 700;
  color: #2a5080;
  font-variant-numeric: tabular-nums;
}

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

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

.ro-item-label {
  font-size: clamp(10px, 1vw, 13px);
  color: #7a8a96;
}

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

/* Écart entre taux de variation et nombre dérivé */
.ecart-txt {
  margin-top: 3px;
  font-size: clamp(10px, 0.95vw, 13px);
  color: #7a8a96;
  font-variant-numeric: tabular-nums;
}
.ecart-txt.proche { color: #2a8a50; font-weight: 600; }
.ecart-txt.exact  { color: #2a8a50; font-weight: 700; }

/* ── Bandeau Informations ────────────────────────── */
.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;
  /* Le texte peut dépasser la hauteur allouée : on le rend défilable
     plutôt que rogné (overflow-x caché pour éviter une barre parasite). */
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  transition: max-height 0.25s ease, padding 0.25s ease;
  max-height: 300px;
}

/* Barre de défilement discrète du bandeau Informations. */
.panel-hint-body::-webkit-scrollbar { width: 8px; }
.panel-hint-body::-webkit-scrollbar-track { background: transparent; }
.panel-hint-body::-webkit-scrollbar-thumb {
  background: #c8d4dc;
  border-radius: 4px;
}
.panel-hint-body::-webkit-scrollbar-thumb:hover { background: #a8b8c4; }
.panel-hint-body { scrollbar-width: thin; scrollbar-color: #c8d4dc transparent; }

.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); }

/* Unité de largeur mini : les sliders des paramètres restent alignés
   entre eux même quand les unités ont des longueurs différentes. */
.param-inline .p-unite {
  flex: 0 0 auto;
  min-width: clamp(18px, 2.2vw, 30px);
}

/* Bouton de remise à zéro sous les sliders de paramètres. */
#params-box .btn-raz { margin-top: 2px; }

/* ── Paramètre figé par le mode décollage (b = 0 : départ du repos) ──
      Il reste lisible — l'élève doit voir que b vaut zéro, c'est une
      hypothèse du modèle — mais il n'est plus réglable. */
.param-fige { opacity: 0.55; }
.param-fige input { cursor: not-allowed; }
