/* ════════════════════════════════════════════════════
   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 lentilles 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: 12px;
  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; }

/* ════════════════════════════════════════════════════
   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 de la propagation (Rembobiner / Lancer / RAZ) ── */
.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; }

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

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

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

/* ════════════════════════════════════════════════════
   BOUTON SUPERPOSÉ AU CANVAS
════════════════════════════════════════════════════ */
.canvas-btn {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 13px;
  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-default {
  top: 10px;
  right: 10px;
  background: #e8e4de;
  border: 1px solid #b0a898;
  border-radius: 4px;
  color: #2c3e50;
}
.canvas-btn-default:hover { background: #dcd6cc; }

/* ════════════════════════════════════════════════════
   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: 320px;
}

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