:root {
  --paper: #f4efe6;
  --paper-2: #ebe3d6;
  --ink: #2b2420;
  --ink-2: #6b5f57;
  --line: #d9cfbf;
  --line-strong: #a08d78;
  --accent: #b8433c;
  --accent-2: #4a62b8;
  --card: #fffdf9;
  /* six jetons sémantiques partagés avec js/heart.js (COL) et js/data.js (couleur) */
  --sang-riche: #c43a33;
  --sang-pauvre: #3e519e;
  --muscle: #b4544f;
  --graisse: #eed8a8;
  --coronaire: #c96c70;
  --veine-coeur: #a194b6;
  --vaisseau-riche: #f3dac6;
  --vaisseau-pauvre: #d5daf0;
  --valve: #e8d3a2;
  --conduction: #f3c23b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(43, 36, 32, .12);
  --topbar: 58px;
  --sans: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-family: var(--sans);
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(120% 90% at 30% 20%, #fbf7f0 0%, var(--paper) 55%, var(--paper-2) 100%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
/* grain papier très léger */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .045; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ── barre du haut ── */
.topbar {
  position: relative; z-index: 2;
  height: var(--topbar);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 249, .75); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 30px; height: 30px; fill: var(--accent); }
.title { font-family: var(--serif); font-weight: 600; font-size: 18px; letter-spacing: .1px; }
.subtitle { font-size: 12.5px; color: var(--ink-2); margin-top: -2px; }
.btn { border: 1px solid var(--line-strong); background: var(--card); border-radius: 999px; padding: 9px 16px; cursor: pointer; min-height: 40px; }
.btn.ghost:hover { border-color: var(--ink); }
.only-mobile { display: none; }

/* ── disposition ── */
.layout { position: relative; z-index: 1; height: calc(100% - var(--topbar)); display: grid; grid-template-columns: 1fr; }
/* fond de studio : dégradé gris-bleu très clair, comme en animation médicale (le modèle s'en détache par contre-jour) */
.scene { position: relative; overflow: hidden; cursor: grab;
  background: radial-gradient(75% 70% at 45% 42%, #fbfcfd 0%, #e2e8ef 45%, #c4ced9 100%); }
.scene:not(.ready)::after {
  content: "Chargement du modèle…"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 15px; color: var(--ink-2); letter-spacing: .02em;
}
.scene canvas { display: block; }
.labels { position: absolute; inset: 0; z-index: 1; } /* étiquettes sous la barre d'outils */

/* ── outils flottants ── */
.tools { position: absolute; top: 14px; left: 14px; right: 14px; z-index: 5; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; pointer-events: none; }
.tools > * { pointer-events: auto; }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tool-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.tool-sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 6px; opacity: .6; }
.tool {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-strong); background: rgba(255, 253, 249, .92); border-radius: 999px;
  padding: 9px 15px; min-height: 40px; cursor: pointer; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.06);
  transition: background .15s, color .15s, border-color .15s;
}
.tool svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { border-color: var(--ink); }
.tool.mode.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.tool.option.on { background: #e9dfd0; border-color: var(--ink); }
.tool.option.on::before { content: "✓"; font-size: 12px; margin-right: -2px; }
.cut-tools {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: rgba(255, 253, 249, .94); border: 1px solid var(--line-strong); border-radius: 12px; padding: 8px 10px;
  font-size: 13.5px; box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; max-width: 100%; }
.seg button { white-space: nowrap; flex: none; }
.seg button { border: 0; background: transparent; padding: 9px 12px; min-height: 40px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.active { background: var(--ink); color: #fff; }
.cut-tools label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.cut-tools input[type=range] { width: 140px; accent-color: var(--accent); }

/* ── barre basse : légende + orientation ── */
.bottombar {
  position: absolute; left: 14px; right: 14px; bottom: 14px; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center;
  font-size: 13px; color: var(--ink-2); background: rgba(255, 253, 249, .88); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px;
}
.legend-item i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(43,36,32,.25); }
.legend-sep { width: 1px; height: 16px; background: var(--line-strong); opacity: .6; }
.orient { color: var(--ink); }
.orient b { font-weight: 700; }
.only-cut, .only-flow { display: none; }
.scene.is-cut .only-cut, .scene.is-flow .only-flow { display: inline; }
.scene.is-flow .not-flow, .scene.is-flow .only-cut { display: none; }
/* circulation : les réglages de coupe ne servent pas, place au panneau des étapes */
.scene.is-flow .cut-tools { display: none; }

/* ── étiquettes 3D (survol / sélection) ── */
.label {
  pointer-events: auto; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 10px; /* l'ancrage (centre de CSS2DObject) est réglé dans app.js */
  font-size: 14px; color: var(--ink);
  background: rgba(255, 253, 249, .95); border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px 10px 2px 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.label::before { content: ""; position: absolute; left: -10px; top: 50%; width: 10px; height: 1px; background: var(--ink); }
.label.flip { margin-left: -10px; }
.label.flip::before { left: auto; right: -10px; }
.label.selected { background: var(--ink); color: #fff; border-color: var(--ink); }
.label.hover { border-color: var(--ink); }
.num {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; flex: none; font-variant-numeric: tabular-nums;
}
.num.dark { color: var(--ink); box-shadow: inset 0 0 0 1px rgba(43,36,32,.35); }
.num.big { width: 36px; height: 36px; font-size: 16px; }
/* pastille d'étiquette : encre sur papier (monochrome, comme un numéro d'atlas) */
.label .num { background: var(--card) !important; color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-family: var(--sans); width: 20px; height: 20px; font-size: 11.5px; }

/* ── vues des valves ── */
/* barre basse réduite au repère d'orientation */
.bottombar { left: auto; right: 14px; width: auto; }
/* bouton du battement : pause pendant l'animation, lecture à l'arrêt */
.beat-btn .ic-play { display: none; fill: currentColor; stroke: none; }
.beat-btn:not(.on) .ic-play { display: inline; }
.beat-btn:not(.on) .ic-pause { display: none; }
.tool.option.beat-btn.on::before { content: none; }
.ao-label.marker { font-weight: 600; border-color: var(--ink); }
.ao-label {
  font-size: 13px; color: var(--ink); white-space: nowrap; pointer-events: none;
  background: rgba(255, 253, 249, .9); border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px 9px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ── circulation guidée ── */
.flow-guide {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 64px; z-index: 6;
  width: min(560px, calc(100% - 32px));
  background: rgba(255, 253, 249, .96); border: 1px solid var(--line-strong); border-radius: 12px; padding: 10px 14px 8px;
  box-shadow: var(--shadow);
}
.fg-head { display: flex; align-items: baseline; gap: 10px; }
.fg-num { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; flex: none; }
.fg-title { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.fg-text { margin: 4px 0 2px; font-size: 15px; line-height: 1.45; }
.fg-note { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.fg-note[hidden] { display: none; }
.fg-ctrl { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.fg-ctrl button { border: 1px solid var(--line-strong); background: var(--paper); border-radius: 8px; min-width: 40px; min-height: 36px; cursor: pointer; font-size: 16px; line-height: 1; }
.fg-ctrl button:hover { border-color: var(--ink); }
.fg-dots { display: flex; gap: 5px; flex: 1; justify-content: center; }
.fg-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.fg-dots i.on { background: var(--ink); }

/* ── panneau ── */
.panel { background: var(--card); border-left: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; }
.panel-inner { overflow-y: auto; padding: 18px 20px 30px; flex: 1; }
.fiche h2 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 22px; line-height: 1.15; }
.fiche .latin { font-style: italic; color: var(--ink-2); font-size: 13.5px; margin-top: 2px; }
.fiche-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.fiche p { line-height: 1.5; font-size: 15.5px; }
.fiche .resume { font-size: 16.5px; }
.fiche .hint { color: var(--ink-2); font-size: 14px; border-left: 3px solid var(--line-strong); padding-left: 10px; }
.fiche h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-2); margin: 16px 0 6px; }
.fiche ul { margin: 0; padding-left: 18px; line-height: 1.5; font-size: 15px; }
.fiche li + li { margin-top: 6px; }
.chiffres { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chiffres span { background: var(--paper); border: 1px solid var(--line-strong); border-radius: 8px; padding: 5px 10px; font-size: 13.5px; }
.link { border: 0; background: none; color: var(--accent-2); cursor: pointer; padding: 6px 0; margin-top: 12px; font-size: 14.5px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-2); margin: 22px 0 8px; }
.views { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.view-btn { border: 1px solid var(--line-strong); background: var(--paper); border-radius: 8px; padding: 11px 6px; min-height: 40px; cursor: pointer; font-size: 13px; }
.view-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.structures details { border-top: 1px solid var(--line); }
.structures summary { cursor: pointer; padding: 12px 0; font-weight: 600; font-size: 14.5px; list-style: none; display: flex; justify-content: space-between; }
.structures summary::after { content: "+"; color: var(--ink-2); }
.structures details[open] summary::after { content: "–"; }
.struct-list { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; }
.struct-btn { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: none; padding: 9px 8px; min-height: 40px; border-radius: 8px; cursor: pointer; font-size: 14.5px; }
.struct-btn:hover { background: var(--paper); }
.struct-btn.active { background: var(--ink); color: #fff; }
.footnote { color: var(--ink-2); font-size: 12.5px; margin-top: 24px; line-height: 1.45; }
.handle { display: none; }

/* ── tactile : cibles ≥ 44 px ── */
@media (pointer: coarse) {
  .tool, .view-btn, .struct-btn, .seg button, .btn { min-height: 44px; }
  .fg-ctrl button { min-height: 44px; }
}

/* ── mobile : panneau en tiroir bas ── */
@media (max-width: 900px) {
  .only-mobile { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; height: 62%;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 20px rgba(43,36,32,.10);
    transform: translateY(calc(100% - 46px)); transition: transform .28s ease; z-index: 10;
  }
  .panel.open { transform: translateY(0); }
  .handle { display: block; width: 100%; height: 46px; border: 0; background: transparent; cursor: pointer; }
  .handle span { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto; }
  .panel-inner { padding: 0 16px 24px; }
  .bottombar { bottom: 56px; font-size: 12.5px; gap: 4px 12px; }
  .cut-tools input[type=range] { width: 110px; }
}
@media (max-width: 700px) {
  .flow-guide { bottom: 112px; padding: 8px 12px 6px; }
  .seg { overflow-x: auto; scrollbar-width: none; }
  .seg button { padding: 9px 10px; }
  .cut-tools { max-width: 100%; }
  .fg-text { font-size: 14px; }
}

/* ── modèle visuel : plein écran, sans panneau, sans texte ni repère ── */
.panel, #panel-toggle, .bottombar { display: none !important; }
.flow-guide .fg-live, .flow-guide .fg-note { display: none; }
.flow-guide { width: auto; padding: 6px 10px; }
.flow-guide .fg-ctrl { margin-top: 0; }
