:root {
  --paper: #f8f5ef; --paper-2: #f1ede4; --ink: #1c232b; --ink-2: #3a4450; --muted: #667085; --line: #e0d9ca;
  --accent: #17636d; --accent-2: #0f4a52; --accent-soft: #dcecee; --warn: #8a5a00; --warn-soft: #fbf0d6;
  --stage-a: #2b333e; --stage-b: #161b22; --ok: #2f7d4f;
  --ui: -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --read: "Iowan Old Style", "Charter", "Palatino Linotype", Georgia, serif;
  --panel-w: 460px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--ui); color: var(--ink); background: var(--paper); display: grid; grid-template-rows: 52px 1fr; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
#webgl canvas:focus-visible { outline: 2px solid rgba(124,199,208,.7); outline-offset: -4px; }

/* ---------- barre ---------- */
#bar { display: flex; align-items: center; gap: 18px; padding: 0 18px; background: var(--paper); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 190px; }
.brand-main { font-weight: 650; letter-spacing: .01em; }
.brand-sub { font-size: 12px; color: var(--muted); letter-spacing: .08em; }
#where { flex: 1; font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#where b { font-weight: 600; color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }
button.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; font-size: 14px; }
button.ghost:hover:not(:disabled) { background: var(--paper-2); }
button.ghost:disabled { color: #9aa1ab; cursor: not-allowed; }
button.ghost.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- mise en page ---------- */
#layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); min-height: 0; }
body.capture #layout { grid-template-columns: minmax(0, 1fr) 0; }
body.capture #panel, body.capture #bar { display: none; }
body.capture { grid-template-rows: 0 1fr; }

#stage { position: relative; min-height: 0; background: radial-gradient(120% 90% at 50% 38%, var(--stage-a) 0%, var(--stage-b) 100%); overflow: hidden; }
#webgl { position: absolute; inset: 0; }
#webgl canvas { display: block; touch-action: none; cursor: grab; }
#webgl canvas:active { cursor: grabbing; }
#webgl.pointer canvas { cursor: pointer; }
#stage-ui { position: absolute; inset: 0; pointer-events: none; color: #e9edf2; font-size: 13px; }
#stage-ui > * { pointer-events: auto; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(22, 27, 34, .9); font-size: 15px; letter-spacing: .02em; }
#loading.done { display: none; }

#topleft { position: absolute; top: 14px; left: 14px; max-width: calc(100% - 320px); pointer-events: none; }
#topleft > * { pointer-events: auto; }
#views { display: flex; flex-wrap: wrap; gap: 4px; }
#views button { background: rgba(18,23,30,.72); border: 1px solid rgba(255,255,255,.2); color: #e9edf2; border-radius: 7px; padding: 5px 9px; font-size: 12.5px; }
#views button:hover { background: rgba(255,255,255,.16); }
#views button[aria-pressed="true"] { background: #eef3f6; color: #16202a; border-color: #eef3f6; font-weight: 600; }
#orient-caption { margin-top: 10px; font-size: 13px; color: #c7d0da; pointer-events: none; }
#orient-caption b { color: #fff; font-weight: 600; }
#tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.tool-switch { display: flex; align-items: center; gap: 7px; background: rgba(18,23,30,.72); border: 1px solid rgba(255,255,255,.2); border-radius: 7px; padding: 6px 10px; cursor: pointer; user-select: none; }
.tool-switch input { accent-color: #7cc7d0; }
button.mini { background: rgba(18,23,30,.72); border: 1px solid rgba(255,255,255,.2); color: #e9edf2; border-radius: 7px; padding: 6px 10px; font-size: 13px; }
button.mini:hover { background: rgba(255,255,255,.16); }

#compass { position: absolute; left: 16px; bottom: 16px; width: 112px; height: 112px; }
#compass .ax { position: absolute; transform: translate(-50%, -50%); font-size: 11px; font-weight: 600; letter-spacing: .03em; padding: 2px 5px; border-radius: 5px; background: rgba(255,255,255,.1); color: #dfe6ee; pointer-events: auto; cursor: pointer; border: 0; }
#compass .ax.back { opacity: .38; }
#compass .ax.main { background: #e8eef3; color: #16202a; }
#compass .ax:hover { background: #fff; color: #000; }
#compass .core { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,.4); }
#zoom { position: absolute; left: 150px; bottom: 16px; display: flex; flex-direction: column; gap: 4px; }
#zoom button { width: 34px; height: 34px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16); color: #fff; border-radius: 8px; font-size: 18px; line-height: 1; }
#zoom button:hover { background: rgba(255,255,255,.22); }

#namecard { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: min(560px, calc(100% - 330px)); background: #f8f5ef; color: var(--ink); border-radius: 12px; padding: 10px 16px 12px; box-shadow: 0 8px 28px rgba(0,0,0,.35); border-left: 6px solid var(--c, #17636d); }
#namecard[hidden], #toast[hidden] { display: none; }
#namecard .nm { font-family: var(--read); font-size: 20px; font-weight: 600; line-height: 1.25; }
#namecard .sy { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
#namecard .fid { display: inline-block; margin-top: 6px; font-size: 12px; background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 2px 9px; }
#toast { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); background: rgba(248,245,239,.96); color: var(--ink); border-radius: 10px; padding: 9px 16px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: min(520px, calc(100% - 330px)); }

/* ---------- panneau ---------- */
#panel { display: grid; grid-template-rows: 1fr auto; min-height: 0; background: var(--paper); border-left: 1px solid var(--line); }
#panel-body { overflow-y: auto; padding: 22px 26px 18px; scroll-behavior: smooth; }
#nav { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line); background: var(--paper); }
#nav .sp { flex: 1; text-align: center; font-size: 13px; color: var(--muted); }
button.btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 9px 15px; font-size: 14.5px; }
button.btn:hover:not(:disabled) { background: var(--paper-2); }
button.btn:disabled { color: #a3a9b3; cursor: not-allowed; }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
button.btn.quiet { border-color: transparent; background: transparent; color: var(--accent-2); padding-left: 4px; padding-right: 4px; text-decoration: underline; text-underline-offset: 3px; }

.eyebrow { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.steps { display: flex; gap: 5px; margin: 0 0 16px; }
.steps button { flex: 1; height: 6px; border: 0; padding: 0; border-radius: 3px; background: var(--line); }
.steps button.done { background: #8bb8bd; }
.steps button.cur { background: var(--accent); }
h1.step-title { font-family: var(--read); font-size: 25px; line-height: 1.22; margin: 0 0 14px; font-weight: 600; letter-spacing: -.005em; }
.read p { font-family: var(--read); font-size: 17px; line-height: 1.62; margin: 0 0 12px; color: #222a33; }
.block { margin: 18px 0 0; padding: 12px 14px; background: var(--paper-2); border-radius: 10px; border: 1px solid var(--line); }
.block h3 { margin: 0 0 4px; font-family: var(--ui); font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.block p { margin: 0; font-family: var(--read); font-size: 16px; line-height: 1.55; }
.block.look { background: var(--accent-soft); border-color: #bcd7da; }
.block.look h3 { color: var(--accent-2); }
.block .linkrow { margin-top: 8px; }

.refs { margin: 20px 0 0; }
.refs h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.pills { display: flex; flex-direction: column; gap: 6px; }
.pill { display: block; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 8px 11px; }
.pill .row { display: flex; align-items: center; gap: 10px; }
.pill .dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--c); }
.pill .nm { font-size: 15px; }
.pill.hidden-name .nm { color: var(--muted); letter-spacing: .12em; }
.pill.sel { border-color: var(--c); background: #fff; box-shadow: inset 4px 0 0 var(--c); }
.pill .fidtag { margin-left: auto; font-size: 11.5px; background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.pill .nogeo { margin-left: auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.detail { margin: 9px 0 3px 24px; font-size: 14px; line-height: 1.5; color: var(--ink-2); }
.detail dt { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-top: 6px; }
.detail dd { margin: 1px 0 0; }

.sources { margin-top: 18px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.sources a { color: var(--accent-2); }
.sources .src { display: block; }

/* intro de chapitre, exercice, fin */
.lead { font-family: var(--read); font-size: 18px; line-height: 1.6; }
.prereq { margin-top: 16px; padding: 12px 14px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; font-size: 15px; line-height: 1.5; }
.prereq b { font-weight: 600; }
.card { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 16px 18px; margin-top: 16px; }
.card h2 { margin: 0 0 6px; font-family: var(--read); font-size: 19px; }
.q-prompt { font-family: var(--read); font-size: 19px; line-height: 1.45; margin: 4px 0 14px; }
.found { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.found .chip { font-size: 13.5px; border: 1px dashed #b9b3a3; border-radius: 999px; padding: 3px 11px; color: var(--muted); }
.found .chip.ok { border: 1px solid var(--ok); background: #e5f3ea; color: #1b5a37; }
.feedback { margin: 10px 0; padding: 10px 13px; border-radius: 10px; font-size: 15px; line-height: 1.5; background: var(--paper-2); border: 1px solid var(--line); }
.feedback.good { background: #e5f3ea; border-color: #b5dac4; }
.feedback.miss { background: var(--warn-soft); border-color: #ecd9a8; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.correction { margin-top: 12px; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; font-family: var(--read); font-size: 16.5px; line-height: 1.55; }
.progress-q { font-size: 13px; color: var(--muted); }
.banner-revisit { margin: -4px 0 14px; padding: 8px 12px; border-radius: 9px; background: var(--warn-soft); color: var(--warn); font-size: 14px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.notice { font-size: 13px; color: var(--warn); background: var(--warn-soft); border-radius: 8px; padding: 6px 10px; margin: 0 0 14px; }
.howto { list-style: none; margin: 16px 0; padding: 0; display: grid; gap: 8px; }
.howto li { padding-left: 24px; position: relative; font-size: 15px; line-height: 1.5; }
.howto li::before { content: "›"; position: absolute; left: 6px; color: var(--accent); font-weight: 700; }

/* mode libre */
.libre-search { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; font: inherit; font-size: 15px; background: #fff; }
.libre-group { margin-top: 14px; }
.libre-group h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.libre-list { display: flex; flex-wrap: wrap; gap: 6px; }
.libre-list button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 11px; font-size: 14px; }
.libre-list button:hover { background: var(--paper-2); }
.libre-list button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.libre-controls { display: grid; gap: 10px; margin-top: 14px; }
.libre-controls label { display: flex; align-items: center; gap: 10px; font-size: 14.5px; }
.libre-controls input[type=range] { flex: 1; accent-color: var(--accent); }

/* plan du cours */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, 92vw); max-height: 86vh; box-shadow: 0 20px 60px rgba(0,0,0,.35); background: var(--paper); color: var(--ink); }
dialog::backdrop { background: rgba(10, 14, 20, .55); }
#plan-body { padding: 22px 26px 22px; overflow-y: auto; max-height: 86vh; }
#plan-body h2 { margin: 0 0 4px; font-family: var(--read); font-size: 22px; }
.plan-ch { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 13px; margin-top: 7px; }
.plan-ch:hover { background: var(--paper-2); }
.plan-ch .n { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--paper-2); border: 1px solid var(--line); }
.plan-ch.done .n { background: var(--ok); color: #fff; border-color: var(--ok); }
.plan-ch.cur { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.plan-ch .t { flex: 1; font-size: 15px; line-height: 1.3; }
.plan-ch .s { font-size: 12.5px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media (max-width: 1100px) { :root { --panel-w: 400px; } #topleft { max-width: calc(100% - 28px); } #namecard, #toast { max-width: calc(100% - 28px); } }

/* ---------- coupe IRM ---------- */
#slice-ui { position: absolute; bottom: 16px; right: 14px; width: 270px; background: rgba(22,27,34,.82); border: 1px solid rgba(255,255,255,.16); border-radius: 10px; padding: 10px 12px 10px; color: #e9edf2; backdrop-filter: blur(6px); }
#slice-ui[hidden] { display: none; }
#slice-label { font-size: 13px; margin-bottom: 8px; }
#slice-label b { color: #fff; }
#slice-planes { display: flex; gap: 4px; margin-bottom: 8px; }
#slice-planes button { flex: 1; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); color: #e9edf2; border-radius: 6px; padding: 4px 0; font-size: 12.5px; }
#slice-planes button[aria-pressed="true"] { background: #eef3f6; color: #16202a; font-weight: 600; }
.slice-row { display: flex; align-items: center; gap: 6px; }
.slice-row input[type=range] { flex: 1; accent-color: #7cc7d0; }
.slice-row button { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16); color: #fff; border-radius: 6px; width: 28px; height: 26px; font-size: 11px; }
#slice-hint { margin-top: 8px; font-size: 11.5px; color: #aab6c3; line-height: 1.4; }
.tool-switch[hidden] { display: none; }


/* ---------- planche source (histologie) ---------- */
#plate { position: absolute; top: 14px; right: 14px; bottom: 14px; width: min(56%, 700px); background: #f8f5ef; color: var(--ink); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.45); display: flex; flex-direction: column; overflow: hidden; }
#plate[hidden] { display: none; }
#plate .plate-tabs { display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#plate .plate-tabs button { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 4px 10px; font-size: 13px; }
#plate .plate-tabs button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
#plate .plate-view { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; background: #1b1f24; }
#plate .plate-fig { position: relative; max-width: 100%; max-height: 100%; line-height: 0; }
#plate .plate-fig img { display: block; max-width: 100%; max-height: 100%; }
#plate .hs { position: absolute; border: 2px dashed var(--c); background: transparent; border-radius: 4px; cursor: pointer; padding: 0; }
#plate .hs:hover, #plate .hs:focus-visible { background: color-mix(in srgb, var(--c) 22%, transparent); }
#plate .hs.on { border-style: solid; background: color-mix(in srgb, var(--c) 28%, transparent); }
#plate .plate-cap { padding: 8px 12px 9px; font-size: 12.5px; line-height: 1.45; color: var(--ink-2); border-top: 1px solid var(--line); }
#plate .plate-cap b { color: var(--ink); }

.about-p { font-size: 14px; line-height: 1.55; margin: 8px 0; color: var(--ink-2); }
#about-body { padding: 22px 26px; overflow-y: auto; max-height: 86vh; }
#about-body h2 { margin: 0 0 8px; font-family: var(--read); font-size: 22px; }

#capture-legend { position: absolute; left: 16px; top: 16px; background: rgba(248,245,239,.94); color: var(--ink); border-radius: 10px; padding: 10px 14px; min-width: 190px; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
#capture-legend .cap-title { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
#capture-legend .cap-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 3px 0; }
#capture-legend .cap-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#capture-legend .mini { margin-top: 8px; background: #fff; color: var(--ink); border-color: var(--line); }

#plate .plate-close { margin-left: auto; border: 1px solid var(--line); background: #fff; border-radius: 7px; width: 28px; height: 26px; font-size: 13px; line-height: 1; }
#plate .plate-close:hover { background: var(--paper-2); }
#plate .plate-lim { color: var(--warn); }
#plate .plate-cap { max-height: 38%; overflow-y: auto; }

#stage.plate-open #topleft { max-width: calc(44% - 28px); }
#stage.plate-open #namecard, #stage.plate-open #toast { left: 16px; transform: none; bottom: 150px; max-width: calc(44% - 32px); }

#vues-seq { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 4px; background: rgba(18,23,30,.78); border: 1px solid rgba(255,255,255,.2); border-radius: 10px; padding: 4px; }
#vues-seq[hidden] { display: none; }
#vues-seq button { background: transparent; border: 0; color: #dfe6ee; border-radius: 7px; padding: 6px 11px; font-size: 13px; }
#vues-seq button[aria-pressed="true"] { background: #eef3f6; color: #16202a; font-weight: 600; }
#stage.plate-open #vues-seq { left: 16px; transform: none; bottom: 100px; }


/* ---------- v2 : barre, IRM « vraie image », objectifs, compléments, liens, test ---------- */
#btn-pan[aria-pressed="true"] { background: #eef3f6; color: #16202a; border-color: #eef3f6; font-weight: 600; }
.real-row { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 13px; cursor: pointer; }
.real-row input { accent-color: #7cc7d0; }
.real-row[hidden], .contrast-row[hidden] { display: none; }
.contrast-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: #c9d3de; }
.contrast-row input { flex: 1; accent-color: #7cc7d0; }
#slice-mark { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 2px solid #ffd27a; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.5); pointer-events: none; z-index: 4; }
#slice-mark[hidden] { display: none; }
button.ghost.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.bullets { margin: 4px 0 0; padding-left: 20px; font-family: var(--read); font-size: 16px; line-height: 1.5; }
.bullets li { margin: 4px 0; }
.obj-global { margin: 18px 0 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.obj-global summary { cursor: pointer; font-weight: 600; font-size: 14.5px; }
.obj-global .bullets { font-size: 14.5px; font-family: var(--ui); }
.obj-ch { color: var(--muted); font-size: 13px; }
button.btn.small { font-size: 12.5px; padding: 0 2px; }

.compl { margin: 16px 0 0; padding: 12px 15px; border-radius: 10px; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--accent); }
.compl.prec { border-left-color: #b9b3a3; background: var(--paper-2); }
.compl h3 { margin: 0 0 6px; font-family: var(--read); font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.compl p { margin: 0 0 8px; font-family: var(--read); font-size: 16px; line-height: 1.55; }
.compl p:last-child { margin-bottom: 0; }
details.link { margin: 14px 0 0; padding: 10px 14px; border-radius: 10px; background: #fbf7e9; border: 1px solid #eadfb9; }
details.link.complement { background: var(--paper-2); border-color: var(--line); }
details.link summary { cursor: pointer; font-size: 15px; font-weight: 600; line-height: 1.35; }
details.link .tag { display: block; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
details.link p { margin: 8px 0 0; font-family: var(--read); font-size: 15.5px; line-height: 1.55; }
.linkrow { display: flex; flex-wrap: wrap; gap: 4px 12px; }

.grade { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; font-size: 14px; }
.plan-ch.test { margin-top: 12px; border-style: dashed; }
.plan-ch:disabled { opacity: .6; cursor: not-allowed; }
.feedback b { font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 1100px) { #bar { gap: 10px; } .brand { min-width: 0; } }

#stage.has-slice #namecard, #stage.has-slice #toast { bottom: auto; top: 190px; left: 16px; transform: none; max-width: min(360px, calc(100% - 32px)); }


/* =====================================================================
   V3 : consigne sur la scène, figures pendant l'explication, épingles, menu libre, calques
   ===================================================================== */
:root { --coach-h: 0px; --gap: 16px; }
#stage { --plate-w: 0px; }
#stage.plate-open { --plate-w: min(46%, 560px); }
#compass, #zoom { bottom: calc(var(--coach-h) + var(--gap)); }
#slice-ui { bottom: calc(var(--coach-h) + var(--gap)); }
#stage.plate-open #slice-ui { right: calc(var(--plate-w) + 28px); }
#plate { width: var(--plate-w); bottom: calc(var(--coach-h) + var(--gap) + 6px); }
#namecard { bottom: calc(var(--coach-h) + 22px); }
#toast { bottom: calc(var(--coach-h) + 22px); }
#vues-seq { bottom: calc(var(--coach-h) + var(--gap)); }
#stage.plate-open #namecard, #stage.plate-open #toast { bottom: calc(var(--coach-h) + 22px); max-width: calc(100% - var(--plate-w) - 40px); }
#stage.plate-open #vues-seq { bottom: calc(var(--coach-h) + 100px); }
#stage.plate-open #topleft { max-width: calc(100% - var(--plate-w) - 40px); }

/* bandeau de consigne */
#coach { position: absolute; left: var(--gap); right: var(--gap); bottom: var(--gap); max-width: 880px; margin: 0 auto; z-index: 7; background: rgba(250, 247, 241, .985); color: var(--ink); border-radius: 14px; border: 1px solid rgba(255,255,255,.5); border-left: 6px solid var(--accent); box-shadow: 0 10px 34px rgba(0,0,0,.45); padding: 10px 16px 11px; display: flex; flex-direction: column; gap: 6px; max-height: 58%; }
#coach[hidden] { display: none; }
#stage.plate-open #coach { right: calc(var(--plate-w) + 28px); }
#coach .coach-top { display: flex; align-items: baseline; gap: 10px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#coach #coach-title { font-size: 13.5px; letter-spacing: 0; text-transform: none; color: var(--accent-2); font-weight: 650; }
#coach .coach-fold { margin-left: auto; border: 1px solid var(--line); background: #fff; border-radius: 7px; width: 26px; height: 24px; line-height: 1; font-size: 15px; padding: 0; }
#coach-text { margin: 0; font-family: var(--read); font-size: 16.5px; line-height: 1.42; }
#coach.folded #coach-text, #coach.folded #coach-action, #coach.folded #coach-feedback { display: none; }
#coach-feedback { font-size: 14px; line-height: 1.4; padding: 6px 10px; border-radius: 8px; background: var(--paper-2); border: 1px solid var(--line); }
#coach-feedback.ok { background: #e5f3ea; border-color: #b5dac4; color: #1b5a37; }
#coach-feedback.demo { background: #eef5f6; border-color: #bcd7da; color: var(--ink); font-family: var(--read); font-size: 15px; }
#coach-feedback[hidden], #coach-action[hidden] { display: none; }
#coach-action { overflow-y: auto; min-height: 0; padding: 4px 0 0; }
#coach-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
#coach-controls .cbtn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 11px; font-size: 13.5px; }
#coach-controls .cbtn:hover:not(:disabled) { background: var(--paper-2); }
#coach-controls .cbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#coach-controls .cbtn.primary:hover { background: var(--accent-2); }
#coach-controls .cbtn.warn { background: var(--warn-soft); border-color: #ecd9a8; color: var(--warn); }
#coach-controls .cbtn:disabled { color: #a3a9b3; cursor: default; }
#coach-controls .sp { flex: 1; }
#coach-controls .pager { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
#coach-controls .pager button { border: 1px solid var(--line); background: #fff; border-radius: 7px; width: 28px; height: 26px; padding: 0; }
#coach-controls .dots { display: flex; gap: 4px; }
#coach-controls .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); display: block; }
#coach-controls .dots i.cur { background: var(--accent); }
#coach-controls .dots i.done { background: #8bb8bd; }
.tool-pulse { animation: toolpulse 1.4s ease-out 3; box-shadow: 0 0 0 2px #ffd27a; }
@keyframes toolpulse { 0% { box-shadow: 0 0 0 0 rgba(255,210,122,.95); } 70% { box-shadow: 0 0 0 10px rgba(255,210,122,0); } 100% { box-shadow: 0 0 0 0 rgba(255,210,122,0); } }
@media (prefers-reduced-motion: reduce) { .tool-pulse { animation: none; box-shadow: 0 0 0 2px #ffd27a; } }

/* choix, ordre dans le bandeau et dans le panneau */
.opts { display: grid; gap: 6px; margin: 8px 0; }
.opt { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; font-size: 15px; line-height: 1.35; }
.opt:hover:not(:disabled) { background: var(--paper-2); }
.opt .mk { flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #9aa4b0; display: grid; place-items: center; font-size: 12px; color: #fff; }
.opt.multi .mk { border-radius: 5px; }
.opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.opt[aria-pressed="true"] .mk { background: var(--accent); border-color: var(--accent); }
.opt[aria-pressed="true"] .mk::after { content: "✓"; }
.opt.tried { color: var(--muted); }
.opt.right { border-color: var(--ok); background: #e5f3ea; }
.opt.right .mk { background: var(--ok); border-color: var(--ok); }
.opt.right .mk::after { content: "✓"; }
.opt:disabled { cursor: default; }
.ord { display: grid; gap: 6px; margin: 8px 0; }
.ord-row { display: flex; align-items: center; gap: 8px; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 8px 6px 12px; font-size: 15px; }
.ord-row .t { flex: 1; }
.ord-row button { border: 1px solid var(--line); background: var(--paper-2); border-radius: 7px; width: 28px; height: 26px; padding: 0; line-height: 1; }
.ord-row button:disabled { opacity: .35; cursor: default; }
.ord-pos { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--paper-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.ord-row.right .ord-pos { background: var(--ok); color: #fff; border-color: var(--ok); }

/* épingles ancrées sur la scène */
#pins { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pin { position: absolute; transform: translate(-50%, -50%); width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid #fff; background: var(--c, #17636d); box-shadow: 0 0 0 1.5px rgba(0,0,0,.65), 0 3px 10px rgba(0,0,0,.5); pointer-events: auto; cursor: pointer; padding: 0; }
.pin::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: #fff; opacity: .92; }
.pin.behind { opacity: .34; filter: saturate(.6); }
.pin.behind::after { background: transparent; }
.pin.named { width: auto; height: auto; min-width: 26px; padding: 3px 10px 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); white-space: nowrap; transform: translate(-50%, -135%); }
.pin.named::after { display: none; }
.pin .tag { font-size: 10.5px; opacity: .85; margin-left: 6px; font-weight: 500; }
@media (prefers-reduced-motion: no-preference) { .pin { transition: opacity .2s; } }

/* planche de figure pendant l'explication */
#plate .plate-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#plate .plate-head .plate-tabs { padding: 0; border: 0; flex: 1; display: flex; gap: 5px; flex-wrap: wrap; }
#plate .plate-tool { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 4px 9px; font-size: 13px; }
#plate .plate-tool:hover { background: var(--paper-2); }
#plate .plate-fig img { background: #fff; }
#plate .plate-cap .plate-role { display: inline-block; font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
#plate .plate-cap p { margin: 0 0 4px; }
#plate .plate-q { margin-top: 8px; padding: 8px 10px; background: var(--paper-2); border-radius: 8px; border: 1px solid var(--line); }
#plate .plate-q .opts { margin: 6px 0 0; }
#zoom-body { padding: 14px; display: grid; gap: 10px; max-width: 94vw; max-height: 90vh; overflow: auto; }
#dlg-zoom { width: min(1100px, 94vw); }
#zoom-body img { width: 100%; height: auto; background: #fff; border-radius: 6px; image-rendering: auto; }
#zoom-body .zoom-head { display: flex; align-items: center; gap: 8px; }
#zoom-body .zoom-cap { font-size: 14px; line-height: 1.5; color: var(--ink-2); }

/* panneau : pour approfondir */
details.deeper { margin: 16px 0 0; border: 1px dashed #c9c1ac; border-radius: 10px; padding: 8px 12px; background: #fcfaf5; }
details.deeper > summary { cursor: pointer; font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
details.deeper > .deeper-note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.moments-strip { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.moments-strip button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 11px; font-size: 13px; }
.moments-strip button.cur { background: var(--accent); color: #fff; border-color: var(--accent); }
.moments-strip .lbl { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); align-self: center; margin-right: 2px; }

/* mode libre : menu contextuel, calques, état */
#ctxmenu { position: absolute; z-index: 20; min-width: 236px; background: #fbf9f4; color: var(--ink); border-radius: 12px; box-shadow: 0 14px 44px rgba(0,0,0,.5); border: 1px solid var(--line); padding: 6px; font-size: 14.5px; }
#ctxmenu[hidden] { display: none; }
#ctxmenu .cm-head { padding: 6px 10px 7px; font-family: var(--read); font-weight: 600; font-size: 15.5px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
#ctxmenu .cm-head small { display: block; font-family: var(--ui); font-weight: 400; font-size: 12px; color: var(--muted); }
#ctxmenu button[role="menuitem"] { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 18px; text-align: left; background: transparent; border: 0; border-radius: 8px; padding: 7px 10px; }
#ctxmenu button[role="menuitem"]:hover, #ctxmenu button[role="menuitem"]:focus-visible { background: var(--accent-soft); }
#ctxmenu button[role="menuitem"]:disabled { color: #a3a9b3; cursor: default; background: transparent; }
#ctxmenu .kbd { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
#ctxmenu .cm-sep { height: 1px; background: var(--line); margin: 4px 2px; }
#ctxmenu .cm-op { display: flex; gap: 4px; padding: 4px 6px 6px; align-items: center; font-size: 12.5px; color: var(--muted); }
#ctxmenu .cm-op button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 4px 0; font-size: 13px; }
#ctxmenu .cm-op button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.layers { display: grid; gap: 6px; margin: 10px 0; }
.layer { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 10px; }
.layer .nm { font-size: 14.5px; }
.layer .nm small { display: block; color: var(--muted); font-size: 11.5px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 4px 9px; font-size: 12.5px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.libre-state { margin: 10px 0; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.libre-state.empty { background: #fde8e6; color: #8a2b22; border: 1px solid #f1b9b3; }
.libre-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.libre-chips .chip2 { font-size: 12.5px; border: 1px solid #ecd9a8; background: #fff; border-radius: 999px; padding: 2px 4px 2px 10px; display: inline-flex; gap: 5px; align-items: center; color: var(--ink-2); }
.libre-chips .chip2 button { border: 0; background: transparent; padding: 0 5px; font-size: 14px; line-height: 1; color: var(--muted); }
#stage-ui .libre-banner { position: absolute; top: 14px; right: 14px; background: rgba(18,23,30,.82); border: 1px solid rgba(255,255,255,.25); color: #e9edf2; border-radius: 10px; padding: 6px 10px; font-size: 12.5px; z-index: 5; }

/* audio */
.speak { border: 1px solid var(--line); background: #fff; border-radius: 999px; font-size: 12.5px; padding: 2px 10px; margin-left: 8px; vertical-align: middle; }
.speak:hover { background: var(--paper-2); }
button.ghost.speaking { background: var(--accent); color: #fff; border-color: var(--accent); }

/* raccords TP3 (plan du cours) */
.tp3 { margin-top: 20px; }
.tp3 h3 { font-size: 12px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.tp3-card { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 9px 12px; margin-top: 7px; font-size: 14px; line-height: 1.45; }
.tp3-card b { font-family: var(--read); font-size: 15.5px; }
.tp3-card .small { color: var(--muted); font-size: 12.5px; }

@media (max-width: 1100px) { #coach { right: 12px; left: 12px; } #coach-text { font-size: 15.5px; } }
@media (max-width: 900px) { :root { --panel-w: 360px; } }
body.capture { --coach-h: 0px; }
body.capture #coach, body.capture #ctxmenu { display: none !important; }

/* actions compactes dans le bandeau : options en colonnes */
#coach-action .opts { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin: 4px 0; gap: 5px; }
#coach-action .opt { padding: 6px 10px; font-size: 14px; }
#coach-action .ord { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 5px; margin: 4px 0; }
#coach-action .ord-row { padding: 3px 6px 3px 10px; font-size: 14px; }
#coach-action .q-prompt { font-size: 15.5px !important; }
#coach-action .actions { margin-top: 6px; }
#coach-action .feedback { margin: 6px 0; font-size: 14px; padding: 7px 10px; }
#coach-action .found { margin: 4px 0; }

/* =====================================================================
   Finition V3r2 : zone utile, panneau de figure compact, dock de coupe repliable
   ===================================================================== */
#stage.plate-open { --plate-w: min(42%, 500px); }
#plate { top: var(--gap); right: var(--gap); bottom: auto; max-height: calc(100% - 2 * var(--gap)); width: var(--plate-w); }
#plate .plate-head { padding: 6px 8px; gap: 5px; }
#plate .plate-title { display: inline-block; font-weight: 650; font-size: 13.5px; color: var(--accent-2); padding: 3px 4px; }
#plate .plate-view { flex: 0 1 auto; width: 100%; aspect-ratio: var(--ar, 3 / 2); max-height: var(--plate-room, 60vh); min-height: 120px; container-type: size; display: grid; place-items: center; overflow: hidden; }
#plate .plate-fig { max-width: none; max-height: none; }
#plate .plate-fig img { max-width: 100cqw; max-height: 100cqh; width: auto; height: auto; }
#plate .plate-cap { flex: 0 0 auto; max-height: 38%; overflow-y: auto; padding: 8px 12px 10px; font-size: 13px; line-height: 1.42; color: var(--ink-2); }
#plate .plate-cap p { margin: 0 0 4px; }
#plate .plate-leg { color: var(--ink); font-weight: 600; font-size: 13.5px; }
#plate .plate-teach { color: var(--ink); }
#plate .plate-note { font-size: 11.5px; color: var(--muted); }
#plate .plate-more { margin: 3px 0 0; }
#plate .plate-more summary { cursor: pointer; font-size: 12px; color: var(--warn); }
#plate .plate-more p { color: var(--warn); margin: 4px 0 0; font-size: 12.5px; }

/* image agrandie : l'image entière tient d'abord dans la fenêtre ; zoom par boutons ou par clic ; défilement dans l'image zoomée */
#dlg-zoom { width: min(1180px, 96vw); height: min(92vh, 900px); padding: 0; border: 0; border-radius: 14px; overflow: hidden; background: var(--paper); }
#dlg-zoom[open] { display: flex; }
#zoom-body { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; width: 100%; height: 100%; max-width: none; max-height: none; overflow: hidden; }
#zoom-body .zoom-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: none; }
#zoom-body .zoom-sp { flex: 1; }
#zoom-body .zoom-level { font-size: 12.5px; color: var(--muted); min-width: 84px; text-align: center; }
#zoom-body .plate-tool { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 4px 10px; font-size: 13px; }
#zoom-body .zoom-stage { flex: 1 1 auto; min-height: 0; container-type: size; display: grid; place-items: center; overflow: auto; background: #1b1f24; border-radius: 8px; }
#zoom-body .zoom-stage.zoomed { display: block; }
#zoom-body .zoom-stage img { display: block; width: auto; height: auto; max-width: 100cqw; max-height: 100cqh; border-radius: 0; background: #fff; cursor: zoom-in; }
#zoom-body .zoom-stage.zoomed img { cursor: zoom-out; margin: 0 auto; }
#zoom-body .zoom-cap { flex: none; max-height: 24%; overflow-y: auto; font-size: 13.5px; line-height: 1.45; color: var(--ink-2); }
#zoom-body .zoom-cap p { margin: 0 0 4px; }
#zoom-body .plate-more summary { cursor: pointer; font-size: 12.5px; color: var(--warn); }
#zoom-body .plate-more p { color: var(--warn); }

/* rangée de vues et outils plus compacts : moins de scène masquée */
#views { gap: 3px; }
#views button { padding: 4px 8px; font-size: 12px; }
#tools { margin-top: 4px; gap: 5px; }
.tool-switch { padding: 4px 8px; font-size: 12.5px; }
button.mini { padding: 4px 8px; font-size: 12.5px; }
#orient-caption { margin-top: 6px; }

/* dock de commandes de coupe : compact (≈ 262 px de large), repliable, au bord de la zone utile ; il ne recouvre ni la boussole ni le zoom */
#slice-ui { width: 262px; padding: 6px 9px 7px; border-radius: 10px; }
#slice-ui .sd-head { display: flex; align-items: center; gap: 5px; }
#slice-label { flex: 1; min-width: 0; margin: 0; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#slice-ui .sd-btn { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); color: #fff; border-radius: 6px; width: 24px; height: 22px; font-size: 13px; line-height: 1; padding: 0; flex: none; }
#slice-ui .sd-btn:hover { background: rgba(255,255,255,.22); }
#slice-ui .sd-row { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
#slice-ui #slice-planes { margin: 0; display: flex; gap: 4px; }
#slice-ui #slice-planes button { padding: 3px 0; font-size: 11.5px; }
#slice-ui .slice-row { width: 100%; }
#slice-ui .sd-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-top: 5px; }
#slice-ui .real-row { display: flex; align-items: center; gap: 5px; font-size: 12px; white-space: nowrap; }
#slice-ui .real-row input { accent-color: #7cc7d0; margin: 0; }
#slice-ui #slice-hint { margin-top: 4px; font-size: 11px; line-height: 1.35; color: #aab6c3; }
#slice-ui #slice-more { flex: 1; text-align: right; }
#slice-ui #slice-more summary { cursor: pointer; font-size: 11px; color: #aab6c3; line-height: 18px; }
#slice-ui #slice-more[open] { flex-basis: 100%; text-align: left; }
#slice-ui #slice-more[open] summary { text-align: right; }
#slice-ui #slice-more .contrast-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-top: 6px; }
#slice-ui #slice-more .contrast-row input { flex: 1; accent-color: #7cc7d0; }
#slice-ui #slice-help { margin-top: 5px; font-size: 11px; line-height: 1.4; color: #aab6c3; }
#slice-ui.folded { width: auto; max-width: 262px; }
#slice-ui.folded .sd-body { display: none; }

/* nom d'un tissu / message de chargement pendant une coupe : petite pastille en haut de la zone utile, jamais une carte haute posée sur l'image (top et bottom ne s'additionnent plus) */
#stage.has-slice #namecard, #stage.has-slice #toast, #stage.has-slice.plate-open #namecard, #stage.has-slice.plate-open #toast {
  top: calc(var(--safe-top, 150px) + 2px); bottom: auto; left: var(--safe-cx, 50%); transform: translateX(-50%); width: max-content; max-width: min(360px, calc(var(--safe-w, 100%) - 20px)); }
#stage.has-slice #namecard { padding: 6px 12px 8px; }
#stage.has-slice #namecard .nm { font-size: 17px; }
#stage.has-slice #toast { padding: 7px 12px; font-size: 13.5px; }

/* bandeau de consigne plus compact : moins de scène masquée */
#coach { padding: 8px 14px 9px; gap: 5px; }
#coach-text { font-size: 15.5px; line-height: 1.38; }
#coach-action .opts { grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); }
#coach-action .cbtn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 11px; font-size: 13.5px; }
#coach-action .cbtn:hover:not(:disabled) { background: var(--paper-2); }
#coach-action .cbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#coach-controls .cbtn { padding: 4px 10px; }
