/* ════════════════════════════════════════════════════
   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 {
  background: #e8e4de;
  color: #2c3e50;
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  /* 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;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ════════════════════════════════════════════════════
   GRILLE PRINCIPALE : canvas | panneau
════════════════════════════════════════════════════ */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr clamp(200px, 22vw, 300px);
  overflow: hidden;
}

/* ════════════════════════════════════════════════════
   ZONE CANVAS
════════════════════════════════════════════════════ */
#canvas-area {
  background: #fdf8f0;
  border-right: 1px solid #c8c0b4;
  overflow: hidden;
  position: relative;
}
#canvas-area canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  /* évite que le drag des éléments optiques ne déclenche le scroll tactile */
  touch-action: none;
}

/* ════════════════════════════════════════════════════
   PANNEAU DROIT
════════════════════════════════════════════════════ */
#panel {
  background: #e8e4de;
  border-left: 1.5px solid #c8c0b4;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  font-size: clamp(11px, 1.1vw, 14px);
}

#panel-body {
  flex: 1;
  min-height: 0;
  padding: clamp(8px, 1.2vw, 16px) clamp(6px, 1vw, 14px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

/* Titre du panneau */
.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;
  letter-spacing: 0.3px;
}

/* ════════════════════════════════════════════════════
   TITRES DE SECTION
════════════════════════════════════════════════════ */
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7a8a96;
  border-bottom: 1px solid #c8c0b4;
  padding-bottom: 4px;
}

/* Bouton collé directement sous un titre de section : il lui faut le même
   dégagement que les blocs qui portent un margin-top:8px inline. */
.section-title + .btn-toggle-one { margin-top: 10px; }

/* ════════════════════════════════════════════════════
   PARAMÈTRES (charte : .param-row)
════════════════════════════════════════════════════ */
.param-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.param-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.param-label {
  display: flex;
  justify-content: space-between;
  font-size: clamp(12px, 1.15vw, 15px);
  color: #2c3e50;
}
.param-label span { font-weight: 600; color: #2a5080; font-variant-numeric: tabular-nums; }
input[type=range] {
  width: 100%;
  accent-color: #4a7aaa;
  cursor: pointer;
}

/* ════════════════════════════════════════════════════
   SLIDER DÉSACTIVÉ
════════════════════════════════════════════════════ */
.param-row.disabled .param-label { color: #b0b8c0; }
.param-row.disabled .param-label span { color: #b0b8c0; }
.param-row.disabled input[type=range] {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

/* ════════════════════════════════════════════════════
   AFFICHEURS VALEUR (charte : .readout)
════════════════════════════════════════════════════ */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.readout {
  background: #fff;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.readout .ro-label { font-size: clamp(11px, 1vw, 13px); color: #7a8a96; }
.readout .ro-value {
  font-size: clamp(13px, 1.35vw, 17px);
  font-weight: 700;
  color: #2a5080;
  font-variant-numeric: tabular-nums;
}
.readout.wide { grid-column: span 2; }
.readout .ro-value.reel { color: #2a6aaa; }
.readout .ro-value.virt { color: #b04020; }

/* ════════════════════════════════════════════════════
   ONGLETS DE MODE (charte : .mode-tabs / .mode-tab)
════════════════════════════════════════════════════ */
.mode-tabs {
  display: flex;
  gap: 0;
  border: 1px solid #c8c0b4;
  border-radius: 6px;
  overflow: hidden;
}
.mode-tab {
  flex: 1;
  padding: 8px 4px;
  font-size: clamp(12px, 1.2vw, 15px);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: #dedad2;
  color: #5a6a78;
  text-align: center;
  transition: background 0.15s, color 0.15s;
}
.mode-tab.active { background: #2a6aaa; color: #fff; }
.mode-tab:disabled { opacity: 0.4; cursor: default; }

/* ── Boutons d'action appariés (Play/Reset, Animation/Pause) ── */
.mode-row { display: flex; gap: 6px; }
.mode-btn {
  flex: 1;
  padding: 7px 6px;
  font-size: clamp(11px, 1.1vw, 13px);
  font-weight: 600;
  border: 1px solid #c8c0b4;
  border-radius: 4px;
  cursor: pointer;
  background: #fdf8f0;
  color: #2c3e50;
  transition: background 0.15s, color 0.15s;
}
.mode-btn.active {
  background: #2a6aaa;
  color: #fff;
  border-color: #2a6aaa;
}
.mode-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ════════════════════════════════════════════════════
   BOUTONS BASCULE (charte : .btn-toggle-one)
════════════════════════════════════════════════════ */
.btn-toggle-one {
  width: 100%;
  background: #ece8e0;
  color: #5a6a78;
  font-size: clamp(12px, 1.2vw, 15px);
  padding: 8px 6px;
  border: 1.5px solid #c8c0b4;
  border-radius: 6px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s, background 0.15s;
}
.btn-toggle-one:hover { background: #dedad2; }
.btn-toggle-one:active { transform: scale(0.97); }
.btn-toggle-one.active {
  background: #fde8c8;
  color: #7a3a10;
  border-color: #d0a060;
}

/* ── Bouton rembobinage : hérite de .mode-btn (y compris l'état .active),
      mais reste à sa largeur d'icône au lieu de prendre un tiers de la ligne. ── */
#speed-rewind {
  flex: 0 0 auto;
  padding: 7px 12px;
  opacity: 0.75;
}
#speed-rewind:hover  { opacity: 1; }
#speed-rewind.active { opacity: 1; }

/* ════════════════════════════════════════════════════
   LÉGENDE
════════════════════════════════════════════════════ */
.legend { display: flex; flex-direction: column; gap: 5px; }
#legend-main { display: flex; flex-direction: column; gap: 5px; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.87em;
  color: #2c3e50;
}

/* ════════════════════════════════════════════════════
   TABLEAU RELATION DE CONJUGAISON (overlay bas-gauche du canvas)
════════════════════════════════════════════════════ */
#conjugaison-table {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 10;
  background: #fdf8f0;
  border: 1px solid #c8c0b4;
  border-radius: 5px;
  border-collapse: collapse;
  font-size: 14px;
  color: #2c3e50;
  max-width: clamp(280px, 62vw, 1100px);
  pointer-events: none;
  table-layout: auto;
}
#conjugaison-table.visible { display: table; }
#conjugaison-table th, #conjugaison-table td {
  border: 1px solid #c8c0b4;
  padding: 0 clamp(6px, 0.9vw, 14px);
  white-space: nowrap;
  text-align: center;
  vertical-align: middle;
}
#conjugaison-table th {
  background: #e8e4de;
  font-weight: 700;
  color: #7a8a96;
}
#conjugaison-table td:first-child {
  background: #e8e4de;
  font-weight: 600;
  color: #2c3e50;
  text-align: left;
}
/* Colonne de gauche : volontairement étroite, le texte peut passer à la ligne. */
#conjugaison-table .cj-label {
  white-space: normal;
  width: 1px;              /* force la colonne au minimum utile */
  max-width: 10em;
  text-align: center;
  font-size: 0.8em;
  line-height: 1.27;
  letter-spacing: 0.01em;
}
#conjugaison-table .cj-unit {
  font-weight: 500;
  font-size: 0.85em;
  color: #6b7a86;
}
#conjugaison-table .td-verif {
  text-align: left;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #2c3e50;
  background: #fdf8f0;
  padding-left: clamp(6px, 0.9vw, 14px);
  /* Un peu d'air entre la dernière ligne du calcul et la bordure du bas. */
  padding-top: 0.35em;
  padding-bottom: 0.55em;
}
/* Calcul détaillé : 3 colonnes (membre de gauche | = | membre de droite)
   pour aligner verticalement tous les signes « = ». */
#conjugaison-table .cj-calc {
  display: grid;
  /* membre gauche | = | terme 1 | opérateur | terme 2 */
  grid-template-columns: auto auto auto auto auto;
  align-items: center;
  justify-content: start;
  column-gap: 0.42em;
  row-gap: 0.38em;
  line-height: 1.12;
}
#conjugaison-table .cj-calc .cj-lhs { text-align: right; }
#conjugaison-table .cj-calc .cj-eq,
#conjugaison-table .cj-calc .cj-op,
#conjugaison-table .cj-calc .cj-t1,
#conjugaison-table .cj-calc .cj-t2 { text-align: center; }
/* Lignes de résultat : le membre de droite occupe les 3 dernières colonnes. */
#conjugaison-table .cj-calc .cj-rhs { grid-column: span 3; text-align: left; }
/* Respiration avant la ligne de conclusion sur OA'. */
#conjugaison-table .cj-calc .cj-gap { margin-top: 0.45em; }

/* Vraies barres de fraction : numérateur / trait / dénominateur empilés. */
#conjugaison-table .frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  line-height: 1.05;
  margin: 0 0.06em;
}
#conjugaison-table .frac .frac-n {
  /* Trait de fraction nettement plus long que le dénominateur, pour ne pas
     le confondre avec la barre de longueur algébrique juste en dessous. */
  align-self: stretch;
  text-align: center;      /* le « 1 » hérite sinon du text-align de la case */
  padding: 0 0.5em 0.06em;
  border-bottom: 0.08em solid currentColor;
}
#conjugaison-table .frac .frac-d {
  padding: 0.3em 0.5em 0;
}
#conjugaison-table .val-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #2c3e50;
}
#conjugaison-table .col-OA  { color: #c05020; }
#conjugaison-table .col-OA2 { color: #2a6aaa; }
#conjugaison-table .col-OF  { color: #2a9a4a; }

/* ════════════════════════════════════════════════════
   BOUTONS SUPERPOSÉS AU CANVAS
   Position et taille de police posées par layoutCanvasButtons().
════════════════════════════════════════════════════ */
.canvas-btn {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: inherit;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.canvas-btn:focus-visible { outline: 2px solid #2a6aaa; outline-offset: 2px; }

.canvas-btn-collapse {
  background: #c8c0b4;
  border: 1px solid #a8a098;
  border-radius: 3px;
  color: #2c3e50;
}
.canvas-btn-collapse:hover { background: #b6ada0; }

.canvas-btn-auto {
  background: #e8e4de;
  border: 1px solid #c8c0b4;
  border-radius: 4px;
  color: #7a8a96;
}
.canvas-btn-auto:hover { background: #dcd6cc; color: #2c3e50; }
.canvas-btn-auto.active {
  background: #2a6aaa;
  border-color: #1a4a8a;
  color: #fff;
}
.canvas-btn-auto.active:hover { background: #1f5a95; color: #fff; }

/* ════════════════════════════════════════════════════
   BULLE D'AIDE AU DRAG
════════════════════════════════════════════════════ */
#drag-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(44,62,80,0.75);
  color: #fff;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  pointer-events: none;
  opacity: 1;
  transition: opacity 1s;
}
#drag-hint.hidden { opacity: 0; }

/* ════════════════════════════════════════════════════
   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 (border-left,
     1.5px) sur ce bord. Avec la largeur de #panel en clamp() (donc
     fractionnaire en px), deux bordures superposées à cet endroit
     arrondissent chacune de leur côté et laissent un décalage d'~1px
     entre elles — en confiant ce bord à #panel seul, une seule bordure
     le trace, sans place pour ce décalage. */
  border-left: none;
  overflow: hidden;
  transition: padding 0.2s;
}

.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(12px, 1.15vw, 15px);
  padding: 0 10px 8px;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
  max-height: 250px;
}

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