:root {
  --bg: #f4f8fa;
  --card-bg: #ffffff;
  --text: #103b4a;
  --text-muted: #587683;
  --primary: #0a4d68;
  --accent: #17a2b8;
  --border: #d7e4e8;
  --danger-bg: #fdecea;
  --danger-text: #8a2b1f;
  --tile-bg: #eaf6f8;
  --header-grad: linear-gradient(135deg, #0e7d90 0%, #0a4d68 100%);
  --chart-path: #17a2b8;
  --chart-stop: #eda100;
  --chart-ceiling: #8a4fd1;
  --chart-surface: #ffffff;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --meter-track: #dcebee;
  --on-primary: #ffffff;
  --time-descent: #3366cc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1d24;
    --card-bg: #122b34;
    --text: #e8f3f5;
    --text-muted: #9db8c0;
    --primary: #4fc3d9;
    --accent: #4fc3d9;
    --border: #1d3d47;
    --danger-bg: #3a1f1c;
    --danger-text: #ffb4a6;
    --tile-bg: #0f333c;
    --header-grad: linear-gradient(135deg, #146f82 0%, #0b2f3a 100%);
    --chart-path: #1a8fa8;
    --chart-stop: #c98500;
    --chart-ceiling: #b48af0;
    --chart-surface: #122b34;
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-critical: #d03b3b;
    --meter-track: #1a3a44;
    --on-primary: #04262d;
    --time-descent: #5c8fe0;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* ---- Focus clavier : visible partout, jamais sur simple clic souris/tactile
   (:focus-visible). Les pastilles reposent sur un <input> invisible
   (opacity:0) qui porte le vrai focus : un outline dessus serait lui aussi
   invisible, donc on le reporte explicitement sur l'élément visuel associé. ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.seg-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  padding-bottom: 2rem;
}

.app-header {
  position: relative;
  overflow: hidden;
  background: var(--header-grad);
  color: #fff;
  padding: calc(1.25rem + env(safe-area-inset-top)) 1.5rem 1.5rem;
  text-align: center;
}

.info-btn {
  position: absolute;
  top: calc(.35rem + env(safe-area-inset-top));
  right: .55rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  z-index: 2;
}
.info-btn:active { background: rgba(255, 255, 255, 0.3); }

/* Bouton "Retour au menu" : n'existe que dans les paquets qui offrent un choix
   entre plusieurs apps (portable, NAS combiné) — injecté au moment de la
   construction de ces paquets, absent des déploiements autonomes. Pastille
   libellée (pas juste une icône) pour rester repérable au premier coup d'œil. */
.menu-back-btn {
  position: absolute;
  top: calc(.35rem + env(safe-area-inset-top));
  left: .55rem;
  height: 40px;
  padding: 0 .9rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  text-decoration: none;
  white-space: nowrap;
  z-index: 2;
}
.menu-back-btn:active { background: rgba(255, 255, 255, 0.3); }

.info-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 50;
}
.info-card {
  position: relative;
  max-width: 380px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 1.5rem 1.25rem 1.25rem;
  text-align: center;
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.info-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  margin-bottom: .5rem;
}
.info-card h2 { margin: .25rem 0; color: var(--primary); }
.info-version { color: var(--text-muted); font-size: .82rem; margin: 0; }
.info-author { color: var(--accent); font-size: .85rem; font-weight: 600; margin: .15rem 0 .9rem; text-align: center; }
.info-card p { text-align: left; font-size: .9rem; }
.info-copyright { text-align: center; color: var(--text-muted); font-size: .75rem; margin: .75rem 0 0; }
.disclaimer-accept { display: block; width: 100%; margin-top: 1rem; }
.info-close {
  position: absolute;
  top: .5rem;
  right: .5rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  font-size: .9rem;
}
.app-header h1 {
  margin: 0;
  font-size: 1.4rem;
  position: relative;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.app-header .subtitle {
  margin: .25rem 0 0;
  font-size: .85rem;
  opacity: .95;
  position: relative;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

/* En-tête plus spacieux sur grand écran : la base (téléphone) ci-dessus reste
   inchangée, cette règle vient uniquement l'agrandir quand la place le permet. */
@media (min-width: 700px) {
  .app-header { padding: 2.5rem 2rem 2.25rem; }
  .app-header h1 { font-size: 2.1rem; }
  .app-header .subtitle { font-size: 1.05rem; margin-top: .4rem; }
  .menu-back-btn, .info-btn { width: auto; height: 46px; font-size: .95rem; }
  .info-btn { width: 46px; padding: 0; }
  .menu-back-btn { padding: 0 1.1rem; }
}

.bubbles { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.bubble {
  position: absolute;
  bottom: -20px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  animation: bubble-float linear infinite;
}
@keyframes bubble-float {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  15% { opacity: .9; }
  100% { transform: translateY(-120px) translateX(var(--drift, 8px)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .bubble { animation: none; display: none; }
}

/* ---- Optimisé desktop 1080p en priorité, avec un repli correct sur téléphone ---- */
main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1rem;
}
@media (min-width: 700px) {
  main { padding: 1.5rem 2rem 2rem; }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.field-hint {
  margin: .35rem 0 .75rem;
  font-size: .78rem;
  font-style: italic;
  color: var(--text-muted);
}

fieldset.card { border: 1px solid var(--border); }

legend {
  font-weight: 600;
  color: var(--primary);
  padding: 0 .35rem;
}

/* ---- Pavé à molette (wheel picker) ---- */
.wheel-row {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: .75rem;
}
.wheel-field { flex: 1 1 130px; min-width: 0; }
.wheel-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.wheel-picker {
  position: relative;
  height: 168px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.wheel-picker:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.wheel-scroll {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.wheel-scroll::-webkit-scrollbar { display: none; }
.wheel-item {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  /* Sans ça, un grand delta de défilement (ex. un cran de molette de souris sur
     PC, souvent ~100px, soit presque 2 crans de 56px) peut sauter un repère de
     snap au lieu de s'arrêter dessus. */
  scroll-snap-stop: always;
  font-size: 1.25rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.wheel-item.is-selected {
  color: var(--primary);
  font-weight: 800;
  font-size: 1.6rem;
}
.wheel-selection-bar {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 56px;
  transform: translateY(-50%);
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  background: rgba(23, 162, 184, 0.08);
  pointer-events: none;
}

.group-title {
  margin: 1rem 0 .25rem;
  font-size: .82rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.seg-control {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.seg-option {
  flex: 1 1 auto;
  position: relative;
}

.seg-option input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.seg-option span {
  display: block;
  text-align: center;
  padding: .6rem .5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .9rem;
  white-space: nowrap;
}

.seg-option input:checked + span {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.seg-control .seg-option span { white-space: normal; }

.btn-primary {
  width: 100%;
  padding: .9rem;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #04262d;
  cursor: pointer;
}
.btn-primary:active { opacity: .85; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.result-tile {
  background: var(--tile-bg);
  border-radius: 10px;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.result-label {
  font-size: .78rem;
  color: var(--text-muted);
}
.result-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
}

.stops-detail { margin-top: 1rem; }
.stops-detail table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.stops-detail th, .stops-detail td {
  text-align: left;
  padding: .4rem .3rem;
  border-bottom: 1px solid var(--border);
}

.btn-secondary {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--primary);
  font-weight: 600;
  padding: .55rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-secondary:active { opacity: .8; }

/* ---- Profil de plongée (SVG) ---- */
.profile-chart { margin-top: 1.25rem; }
.profile-svg { width: 100%; height: auto; display: block; }
.profile-baseline { stroke: var(--border); stroke-width: 1; }
.profile-grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2.5 3; opacity: .7; }
.profile-axis-label {
  font-size: 9.5px;
  fill: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
/* Profondeur max : mise en évidence sur l'échelle (trait plein + texte gras, couleur
   accent) pour se distinguer des graduations rondes habituelles, recessives. */
.profile-grid-line-max { stroke: var(--accent); stroke-width: 1.2; opacity: .8; }
.profile-axis-label-max {
  font-size: 10.5px;
  font-weight: 700;
  fill: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
/* Étiquette "à côté" du temps de décollage, reliée par une courte ligne de rappel
   plutôt que posée dessus ou en bulle. */
.profile-callout-line { stroke-width: 1.2; opacity: .6; }
.profile-callout-line-path { stroke: var(--chart-path); }
.profile-callout-text {
  font-size: 11px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  paint-order: stroke fill;
  stroke: var(--chart-surface);
  stroke-width: 4px;
  stroke-linejoin: round;
}
.profile-callout-text-path { fill: var(--chart-path); }
.profile-area { fill: url(#profileAreaGrad); stroke: none; }
.profile-grad-start { stop-color: var(--chart-path); stop-opacity: .3; }
.profile-grad-end { stop-color: var(--chart-path); stop-opacity: 0; }
.profile-path-seg { stroke: var(--chart-path); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.profile-stop-seg { stroke: var(--chart-stop); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.profile-ceiling-line {
  fill: none;
  stroke: var(--chart-ceiling);
  stroke-width: 1.75;
  stroke-dasharray: 4 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.profile-dot { fill: var(--chart-path); stroke: var(--chart-surface); stroke-width: 2; }
.profile-stop-dot { fill: var(--chart-stop); stroke: var(--chart-surface); stroke-width: 1.5; }
.profile-label {
  font-size: 12px;
  fill: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* halo derrière le texte : évite que la ligne du profil "coupe" les infos affichées dessus */
  paint-order: stroke fill;
  stroke: var(--chart-surface);
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* ---- Repères interactifs (tap → popup avec le détail) ---- */
.profile-hit { cursor: pointer; }
.profile-hit-target { fill: transparent; stroke: none; }
.profile-hit-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 2.5 2.5;
  opacity: .55;
}
.profile-hit.is-active .profile-hit-ring {
  opacity: 1;
  stroke-dasharray: none;
}
.profile-hint {
  margin: .5rem 0 0;
  font-size: .78rem;
  color: var(--text-muted);
  text-align: center;
}
.profile-popup {
  position: relative;
  margin-top: .6rem;
  padding: .7rem 2.2rem .7rem .9rem;
  border-radius: 12px;
  background: var(--tile-bg);
  border: 1px solid var(--border);
}
.profile-popup-title { margin: 0; font-weight: 700; color: var(--text); font-size: .92rem; }
.profile-popup-detail { margin: .2rem 0 0; color: var(--text-muted); font-size: .85rem; }
.profile-popup-close {
  position: absolute;
  top: .5rem;
  right: .5rem;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  font-size: .8rem;
  line-height: 1;
}

/* ---- Répartition des temps (descente / fond / remontée+paliers) ---- */
.profile-time-breakdown { margin-top: 1rem; }
.ptb-bar {
  display: flex;
  gap: 2px;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--border);
}
.ptb-seg { flex-shrink: 0; flex-basis: 0; height: 100%; }
.ptb-seg-descent { background: var(--time-descent); }
.ptb-seg-bottom { background: var(--chart-path); }
.ptb-seg-ascent { background: var(--chart-stop); }

.ptb-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  margin-top: .65rem;
}
.ptb-item {
  display: flex;
  align-items: center;
  gap: .35rem;
}
.ptb-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.ptb-dot-descent { background: var(--time-descent); }
.ptb-dot-bottom { background: var(--chart-path); }
.ptb-dot-ascent { background: var(--chart-stop); }
.ptb-item-label { font-size: .82rem; color: var(--text-muted); }
.ptb-item-value { font-size: .95rem; font-weight: 700; color: var(--text); }

.meter-overflow-like {
  font-size: .9rem;
  font-weight: 600;
  border-radius: 10px;
  padding: .7rem .85rem;
  line-height: 1.4;
}
.status-good-box { background: rgba(12, 163, 12, 0.12); color: var(--status-good); }
.status-critical-box { background: rgba(208, 59, 59, 0.12); color: var(--status-critical); }
.status-warning-box { background: rgba(250, 178, 25, 0.15); color: var(--text); }

/* ---- Mode Instruction : comparaison à chaud modèle / GF / gaz ---- */
.instruction-scenario-card { max-width: 480px; margin-left: auto; margin-right: auto; }

/* Chaque configuration = 3 cartes (sélection / graphique / tissus) insérées
   dans le DOM dans cet ordre. grid-auto-flow:column + un nombre de rangées
   fixe (3) les répartit automatiquement en colonnes alignées, sans avoir à
   calculer une position explicite par carte : la 1ère carte va en rangée 1 de
   la colonne 1, la 2e en rangée 2 de la colonne 1, la 3e en rangée 3 de la
   colonne 1, la 4e repart en rangée 1 de la colonne 2, etc. */
.instruction-board {
  display: grid;
  grid-template-rows: repeat(4, auto);
  grid-auto-flow: column;
  grid-auto-columns: minmax(340px, 400px);
  align-items: stretch;
  gap: 1.25rem;
  margin-top: 1rem;
  overflow-x: auto;
  padding-bottom: .75rem;
}
/* Téléphone : les colonnes de comparaison défilent horizontalement (comme un
   carrousel) plutôt que de s'écraser illisiblement ou de casser la mise en
   page — chaque configuration reste pleinement lisible, juste une à la fois. */
@media (max-width: 640px) {
  .instruction-scenario-card { max-width: 100%; }
  .instruction-board { grid-auto-columns: minmax(85vw, 340px); gap: .85rem; }
}
.instruction-select-card,
.instruction-results-card,
.instruction-chart-card,
.instruction-tissue-card {
  margin-bottom: 0;
  /* align-items:stretch étire chaque carte à la hauteur de la plus grande de
     sa rangée (ex. la carte tissus MN90, sans graphique, aussi haute que la
     carte tissus Bühlmann d'à côté) : display:flex + column pour que le
     contenu reste collé en haut plutôt que centré/écartelé dans l'espace en trop. */
  display: flex;
  flex-direction: column;
}

.instruction-card-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  font-size: .72rem;
  font-weight: 700;
}

.instruction-card-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}
.instruction-card-toolbar .seg-control { flex: 1; margin: 0; }

.instruction-add-tile {
  grid-row: 1 / span 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 240px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  padding: 1rem;
  text-align: center;
}
.instruction-add-tile:hover { background: var(--tile-bg); border-color: var(--accent); }
.instruction-add-tile:disabled { opacity: .4; cursor: not-allowed; }
.instruction-add-icon { font-size: 2rem; line-height: 1; }

.instruction-card-remove {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: .85rem;
  cursor: pointer;
}
.instruction-card-remove:disabled { opacity: .35; cursor: not-allowed; }

.instruction-select-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: .6rem 0 .3rem;
}
.instruction-select {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .5rem .6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: .9rem;
}

.instruction-gf-custom, .instruction-gas-custom {
  display: flex;
  gap: .6rem;
  margin-top: .5rem;
  flex-wrap: wrap;
}
.instruction-num-field {
  flex: 1 1 100px;
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
}
.instruction-num-field input {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .45rem .55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: .9rem;
}

.instruction-seg-gas { margin-top: .75rem; }

.instruction-card-summary {
  margin: .85rem 0 .25rem;
  font-weight: 700;
  color: var(--primary);
}

.instruction-mini-profile { margin-top: .75rem; }

.instruction-tissue-block { margin-top: .9rem; }

/* ---- Barres de saturation tissulaire (16 compartiments ZHL-16C) ---- */
.tissue-bars-svg { width: 100%; height: auto; display: block; margin-top: .4rem; }
.tissue-bar-track { fill: var(--meter-track); }
.tissue-bar-fill-ok { fill: var(--accent); }
.tissue-bar-fill-warn { fill: var(--status-warning); }
.tissue-bar-fill-crit { fill: var(--status-critical); }
.tissue-bar-label { font-size: 9px; fill: var(--text-muted); }
.tissue-bar-pct { font-size: 9px; fill: var(--text-muted); }
.tissue-gf-marker { stroke: var(--primary); stroke-width: 1.5; stroke-dasharray: 3 2; }

.tissue-bars-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin: .4rem 0 0;
  font-size: .75rem;
  color: var(--text-muted);
}
.tissue-legend-item { display: inline-flex; align-items: center; gap: .35rem; }
.tissue-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.app-footer {
  max-width: 560px;
  margin: 1rem auto 0;
  padding: 0 1rem;
  font-size: .75rem;
  color: var(--text-muted);
  text-align: center;
}
