:root {
  --bg: #07090f; --bg2: #0d111b; --panel: #111727; --line: #1f2940; --text: #dfe7ff; --muted: #7c89a8;
  --cyan: #00e5ff; --pink: #ff4fa3; --lime: #b6ff3b; --amber: #ffc24b; --red: #ff5a5a;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace; --sans: 'Space Grotesk', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
button { font: inherit; color: inherit; }
.top { display: flex; align-items: center; gap: 24px; height: 58px; padding: 0 18px; border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #0b1020, #0a0d16); }
.logo { font: 800 18px var(--mono); letter-spacing: .18em; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.logo .glyph { color: var(--cyan); text-shadow: 0 0 12px var(--cyan); }
.logo em { font: 400 11px var(--mono); letter-spacing: .05em; color: var(--muted); font-style: normal; }
.level-title { flex: 1; margin: 0; font: 600 18px var(--sans); }
.level-title small { display: block; font: 400 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.progress { display: flex; align-items: center; gap: 10px; font: 600 12px var(--mono); color: var(--muted); }
.progress .bar { width: 140px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); }

.shell { display: grid; grid-template-columns: 250px 1fr; height: calc(100% - 58px); }
.sidebar { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; background: var(--bg2); display: flex; flex-direction: column; gap: 10px; }
.chapter h4 { margin: 8px 0 0; font: 600 12px var(--mono); color: var(--cyan); letter-spacing: .06em; }
.chapter p { margin: 2px 0 6px; font-size: 11px; color: var(--muted); }
.chapter ul { list-style: none; margin: 0; padding: 0; }
.chapter button { width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: none; border: 1px solid transparent;
  border-radius: 6px; cursor: pointer; text-align: left; font-size: 13px; }
.chapter button:hover:not(:disabled) { background: #151d30; }
.chapter button.active { border-color: var(--cyan); background: #0d1b2a; }
.chapter button.locked { opacity: .35; cursor: not-allowed; }
.chapter button.done .mark { color: var(--lime); }
.chapter .num { font: 600 11px var(--mono); color: var(--muted); }
.chapter .mark { margin-left: auto; font-size: 11px; }

.stage { overflow: hidden; }
.editor, .lab { display: grid; grid-template-columns: 1fr 360px; height: 100%; }
.panel { border-left: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.panel h3 { margin: 4px 0 6px; font: 600 12px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; justify-content: space-between; }
.story { margin: 0; color: #b9c4e0; }
.goal { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--cyan); border-radius: 8px; background: #071a22; }
.goal span { display: block; font: 600 10px var(--mono); color: var(--cyan); text-transform: uppercase; letter-spacing: .1em; }
.goal strong { font: 600 15px var(--mono); }
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.palette em, .muted { color: var(--muted); font-size: 12px; }
.palette-doc { margin: 6px 0 0; font-size: 12px; color: var(--muted); min-height: 2.6em; }
.chip { display: flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 6px; background: #18213a; border: 1px solid var(--line); cursor: pointer; font-size: 12px; }
.chip:hover { border-color: var(--cyan); }
.chip b { font-family: var(--mono); color: var(--cyan); }

.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #1a2440; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: var(--cyan); }
.btn.primary { background: linear-gradient(90deg, #00b8d4, #d63d8f); border: none; color: #fff; }
.btn.primary:disabled { background: #232c44; color: var(--muted); cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; align-self: flex-start; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .primary { margin-left: auto; }
.hint { margin: 0; padding: 8px 10px; border-left: 3px solid var(--amber); background: #221b0b; color: var(--amber); font-family: var(--mono); font-size: 12px; }
.help { margin: 0; font-size: 11px; color: var(--muted); }

.tests { max-height: 240px; overflow: auto; }
.tests table { width: 100%; border-collapse: collapse; font: 12px var(--mono); }
.tests th { color: var(--muted); font-weight: 400; text-align: right; padding: 3px 5px; position: sticky; top: 0; background: var(--panel); }
.tests td { text-align: right; padding: 3px 5px; border-top: 1px solid var(--line); }
.tests th.o, .tests td.o { color: var(--cyan); }
.tests tr[data-row] { cursor: pointer; }
.tests tr.ok td:last-child { color: var(--lime); }
.tests tr.ko td:last-child { color: var(--red); }
.tests tr.sel td { background: #13203a; }
.score { color: var(--text); text-transform: none; letter-spacing: 0; }
.err { color: var(--red); font-size: 12px; margin: 6px 0 0; }

.board-wrap { overflow: auto; position: relative;
  background: radial-gradient(circle, #1a2236 1px, transparent 1.2px) 0 0 / 24px 24px, var(--bg); }
.board { position: relative; width: 1100px; height: 780px; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.wire { fill: none; stroke-width: var(--w, 2); cursor: pointer; transition: stroke .15s; }
.wire.pos { stroke: var(--cyan); filter: drop-shadow(0 0 3px rgba(0,229,255,.6)); }
.wire.neg { stroke: var(--pink); filter: drop-shadow(0 0 3px rgba(255,79,163,.6)); }
.wire.zero { stroke: #44506d; }
.wire:hover { stroke: var(--red); }
.wire.temp { stroke: var(--amber); stroke-dasharray: 6 4; pointer-events: none; }
.nodes { position: absolute; inset: 0; pointer-events: none; }
.node { position: absolute; min-width: 120px; background: #121a2d; border: 1px solid #2a3758; border-radius: 10px; pointer-events: auto;
  box-shadow: 0 6px 20px rgba(0,0,0,.45); user-select: none; touch-action: none; }
.node.error { border-color: var(--red); }
.node-head { padding: 5px 10px; font: 600 12px var(--mono); border-bottom: 1px solid #2a3758; cursor: grab; display: flex; gap: 6px; align-items: center; }
.node-head .sym { color: var(--cyan); }
.node.t-input { border-color: var(--cyan); }
.node.t-input .node-head { background: #062631; border-radius: 9px 9px 0 0; }
.node.t-output { border-color: var(--pink); }
.node.t-output .node-head { background: #2a0d1e; border-radius: 9px 9px 0 0; justify-content: flex-end; }
.node.t-neuron { border-color: var(--lime); }
.node.t-neuron .sym { color: var(--lime); }
.node-body { display: flex; align-items: center; gap: 6px; padding: 6px 0; }
.ins, .outs { display: flex; flex-direction: column; gap: 4px; }
.mid { flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 0 4px; }
.port { display: flex; align-items: center; gap: 5px; font: 11px var(--mono); color: var(--muted); cursor: crosshair; }
.port .dot { width: 12px; height: 12px; border-radius: 50%; background: #0a0f1c; border: 2px solid #5d6c92; flex: none; }
.port.in .dot { margin-left: -7px; }
.port.out .dot { margin-right: -7px; }
.port:hover .dot { border-color: var(--amber); background: var(--amber); }
.port .val { color: var(--text); font-weight: 600; }
.param { display: flex; align-items: center; gap: 4px; font: 11px var(--mono); color: var(--muted); }
.param input { width: 62px; background: #0a0f1c; border: 1px solid #2a3758; border-radius: 4px; color: var(--amber); font: 600 12px var(--mono); padding: 2px 4px; }
.readout { font: 700 15px var(--mono); text-align: center; padding: 0 8px; }
.readout small { display: block; font-size: 10px; color: var(--muted); font-weight: 400; }
.readout.ok { color: var(--lime); }
.readout.ko { color: var(--red); }

.lab-stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--bg); }
.plot { width: min(68vh, 92%); aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; image-rendering: pixelated; }
.legend { font-size: 12px; color: var(--muted); }
.legend .c0 { color: var(--cyan); } .legend .c1 { color: var(--pink); }
.netviz { width: 100%; background: #0a0f1c; border-radius: 8px; border: 1px solid var(--line); }
.netviz line.pos { stroke: var(--cyan); opacity: .7; } .netviz line.neg { stroke: var(--pink); opacity: .7; }
.netviz circle { fill: #1a2440; stroke: var(--text); stroke-width: 1.2; }
.layer-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.layer-row b { font-family: var(--mono); min-width: 20px; text-align: center; color: var(--amber); }
.mini { width: 24px; height: 24px; border-radius: 5px; border: 1px solid var(--line); background: #18213a; cursor: pointer; }
.mini.del { margin-left: auto; color: var(--red); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 12px; }
select { background: #0a0f1c; color: var(--text); border: 1px solid var(--line); border-radius: 5px; padding: 4px; font: 12px var(--mono); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stats div { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.stats span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stats b { font: 700 15px var(--mono); }
.stats .good b { color: var(--lime); } .stats .bad b { color: var(--red); }

.modal { position: fixed; inset: 0; background: rgba(3,5,10,.75); display: grid; place-items: center; backdrop-filter: blur(4px); z-index: 10; }
.modal[hidden] { display: none; }
.modal .card { width: min(520px, 92vw); background: var(--panel); border: 1px solid var(--cyan); border-radius: 14px; padding: 24px;
  box-shadow: 0 0 40px rgba(0,229,255,.18); }
.modal h2 { margin: 0 0 10px; font: 700 20px var(--sans); }
.modal .unlock { padding: 10px; border-radius: 8px; background: #172409; color: var(--lime); }
.modal .record { color: var(--amber); font-weight: 600; }

/* ---- Mobile / tablette ---- */
.menu-btn, .scrim { display: none; }
@media (max-width: 860px) {
  html, body { height: 100dvh; font-size: 15px; overscroll-behavior: none; }
  .top { height: 52px; gap: 10px; padding: 0 12px; padding-top: env(safe-area-inset-top); }
  .menu-btn { display: block; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #1a2440; font-size: 20px; flex: none; }
  .logo { font-size: 0; gap: 0; } .logo .glyph { font-size: 20px; } .logo em { display: none; }
  .level-title { font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .level-title small { font-size: 9px; overflow: hidden; text-overflow: ellipsis; }
  .progress .bar { width: 48px; }
  .shell { display: block; height: calc(100dvh - 52px - env(safe-area-inset-top)); position: relative; }
  .sidebar { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(82vw, 320px); transform: translateX(-102%); transition: transform .2s;
    padding-top: calc(12px + env(safe-area-inset-top)); box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .scrim { position: fixed; inset: 0; z-index: 19; background: rgba(3,5,10,.6); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; }
  .chapter button { padding: 10px 8px; font-size: 15px; }
  .stage { height: 100%; overflow: hidden; }
  .editor, .lab { grid-template-columns: 1fr; grid-template-rows: minmax(0, 46%) minmax(0, 1fr); }
  .panel { border-left: none; border-top: 1px solid var(--line); padding: 12px; }
  .board-wrap { -webkit-overflow-scrolling: touch; }
  .lab-stage { padding: 8px; }
  .plot { width: min(100%, 38vh); }
  .btn { padding: 11px 16px; min-height: 44px; }
  .btn.small { min-height: 36px; }
  .chip { padding: 9px 12px; font-size: 14px; }
  .port { min-height: 26px; padding: 2px 0; font-size: 12px; }
  .port .dot { width: 20px; height: 20px; }
  .port.in .dot { margin-left: -11px; } .port.out .dot { margin-right: -11px; }
  .node-head { padding: 8px 12px; font-size: 13px; }
  .param input, select, .mini { font-size: 16px; }
  .param input { width: 72px; padding: 5px 6px; }
  .mini { width: 36px; height: 36px; }
  .wire { stroke-width: max(var(--w, 2), 3px); }
  .tests { max-height: 200px; }
  .modal .card { padding: 18px; max-height: 90dvh; overflow-y: auto; }
  .actions .primary { margin-left: 0; }
}

.sync-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 17px; flex: none; }
.sync-btn:hover { border-color: var(--cyan); }
.sync-code { font: 800 30px var(--mono); letter-spacing: .25em; text-align: center; color: var(--cyan); margin: 14px 0; }
.sync-input { width: 100%; padding: 12px; margin: 8px 0; border-radius: 8px; border: 1px solid var(--line); background: #0a0f1c; color: var(--text); font: 600 18px var(--mono); letter-spacing: .15em; text-transform: uppercase; }

/* ==== THEME PASTEL (jeux iPhone minimalistes) ==== */
:root {
  --bg: #f5f0e8; --bg2: #f5f0e8; --panel: #fffdf9; --line: #e6dfd2; --text: #2d2b3a; --muted: #8e8a99;
  --cyan: #5bbfa6; --pink: #f27f8e; --lime: #5bbfa6; --amber: #e9a23b; --red: #e4574f; --lav: #8f84e8; --sun: #ffd37a;
  --mono: ui-rounded, 'SF Pro Rounded', 'Space Grotesk', system-ui, sans-serif; --sans: ui-rounded, 'SF Pro Rounded', 'Space Grotesk', system-ui, sans-serif;
}
html, body { font: 15px/1.5 var(--sans); background: var(--bg); color: var(--text); }
.top { background: var(--bg); border-bottom: none; height: 60px; }
.logo { font: 800 15px var(--sans); letter-spacing: .22em; color: var(--text); }
.logo .glyph { color: var(--pink); text-shadow: none; }
.level-title { font: 700 17px var(--sans); }
.level-title small { font: 600 10px var(--sans); letter-spacing: .12em; color: var(--muted); }
.progress { color: var(--muted); font: 700 12px var(--sans); }
.progress .bar { height: 8px; border-radius: 99px; background: #e9e2d4; width: 90px; }
.progress .bar i { background: var(--lav); border-radius: 99px; }
.sidebar { background: var(--panel); border-right: none; box-shadow: 2px 0 24px rgba(60,50,30,.06); }
.chapter h4 { font: 800 11px var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--lav); }
.chapter p { display: none; }
.chapter button { border-radius: 14px; color: var(--text); font-weight: 600; }
.chapter button:hover:not(:disabled) { background: #f3ede1; }
.chapter button.active { background: #ece8ff; border-color: transparent; }
.chapter .num { color: var(--muted); }
.chapter button.done .mark { color: var(--cyan); }
.shell { gap: 0; }
.panel { background: var(--panel); border-left: none; box-shadow: -2px 0 24px rgba(60,50,30,.06); }
.panel h3 { font: 800 11px var(--sans); letter-spacing: .12em; color: var(--muted); }
.story { color: #55526a; }
.goal { background: #ece8ff; border: none; border-radius: 16px; padding: 12px 14px; }
.goal span { color: var(--lav); font-family: var(--sans); font-weight: 800; }
.goal strong { font: 700 17px var(--sans); color: var(--text); }
.chip { background: #fff; border: 2px solid var(--line); border-radius: 99px; font-weight: 700; }
.chip:hover { border-color: var(--lav); background: #fff; }
.chip b { color: var(--lav); font-family: var(--sans); }
.btn { background: #fff; border: 2px solid var(--line); border-radius: 99px; font-weight: 700; color: var(--text); }
.btn:hover:not(:disabled) { border-color: var(--lav); }
.btn.primary { background: var(--lav); color: #fff; border: none; box-shadow: 0 6px 16px rgba(143,132,232,.4); }
.btn.primary:disabled { background: #e6e1d6; color: var(--muted); box-shadow: none; }
.hint { background: #fff6e3; border-left: none; border-radius: 12px; color: #9a6a12; font-family: var(--sans); }
.help, .muted, .palette em, .palette-doc { color: var(--muted); }
.board-wrap { background: radial-gradient(circle, #d9d1c0 1.4px, transparent 1.6px) 0 0 / 30px 30px, var(--bg); }
.node { background: #fff; border: none; border-radius: 18px; box-shadow: 0 8px 24px rgba(60,50,30,.12); }
.node-head { border-bottom: none; font: 800 12px var(--sans); color: var(--text); padding: 7px 12px; }
.node.t-input .node-head { background: #dff4ee; border-radius: 18px 18px 0 0; color: #2f8e78; }
.node.t-output .node-head { background: #fde3e7; border-radius: 18px 18px 0 0; color: #c24d5f; }
.node.t-neuron .node-head { background: #ece8ff; border-radius: 18px 18px 0 0; }
.node.t-input, .node.t-output, .node.t-neuron { border: none; }
.node.error { outline: 3px solid var(--red); }
.node-head .sym, .node.t-neuron .sym { color: var(--lav); }
.port { color: var(--muted); font-family: var(--sans); font-weight: 600; }
.port .dot { background: #fff; border: 3px solid #cfc7b6; }
.port:hover .dot { background: var(--sun); border-color: var(--amber); }
.port .val { color: var(--text); }
.wire { stroke-width: 3.5px; stroke-linecap: round; }
.wire.pos { stroke: var(--cyan); filter: none; } .wire.neg { stroke: var(--pink); filter: none; } .wire.zero { stroke: #cfc7b6; }
.wire.temp { stroke: var(--lav); }
.param { font-family: var(--sans); }
.param input { background: #f5f0e8; border: none; border-radius: 8px; color: var(--text); font-family: var(--sans); font-weight: 700; }
.readout { font-family: var(--sans); } .readout.ok { color: var(--cyan); } .readout.ko { color: var(--red); }
.tests table { font-family: var(--sans); } .tests th { background: var(--panel); } .tests td { border-top: 1px solid var(--line); }
.tests th.o, .tests td.o { color: var(--lav); font-weight: 700; }
.tests tr.sel td { background: #ece8ff; } .tests tr.ok td:last-child { color: var(--cyan); }
.lab-stage { background: var(--bg); }
.plot { border: none; border-radius: 24px; box-shadow: 0 10px 30px rgba(60,50,30,.12); background: #fff; }
.netviz { background: #fff; border: none; border-radius: 16px; }
.netviz circle { fill: #fff; stroke: var(--lav); }
.netviz line.pos { stroke: var(--cyan); } .netviz line.neg { stroke: var(--pink); }
.legend .c0 { color: var(--cyan); } .legend .c1 { color: var(--pink); }
.mini { background: #fff; border: 2px solid var(--line); border-radius: 10px; }
select { background: #fff; color: var(--text); border: 2px solid var(--line); border-radius: 10px; font-family: var(--sans); }
.stats div { border: none; background: #f5f0e8; border-radius: 14px; }
.stats b { font-family: var(--sans); }
.stats .good b { color: var(--cyan); }
.modal { background: rgba(45,43,58,.35); backdrop-filter: blur(8px); }
.modal .card { background: #fffdf9; border: none; border-radius: 28px; box-shadow: 0 24px 60px rgba(45,43,58,.25); }
.modal h2 { font: 800 22px var(--sans); }
.modal .unlock { background: #e3f6f0; color: #2f8e78; border-radius: 14px; }
.modal .record { color: var(--amber); }
.menu-btn, .sync-btn { background: #fff; border: 2px solid var(--line); border-radius: 14px; color: var(--text); font-size: 0; }
.menu-btn::before { content: "☰"; font-size: 18px; } .sync-btn::before { content: "⟳"; font-size: 18px; color: var(--lav); }
.sync-code { color: var(--lav); font-family: var(--sans); font-weight: 800; }
.sync-input { background: #f5f0e8; border: 2px solid var(--line); border-radius: 14px; color: var(--text); font-family: var(--sans); }
.scrim { background: rgba(45,43,58,.35); }
@media (max-width: 860px) {
  .top { height: 56px; }
  .menu-btn { display: block; }
  .panel { border-radius: 28px 28px 0 0; margin-top: -20px; position: relative; box-shadow: 0 -10px 30px rgba(60,50,30,.1); padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .btn { min-height: 48px; padding: 12px 20px; }
  .chip { padding: 11px 16px; }
  .node { border-radius: 16px; }
  .logo { font-size: 0; letter-spacing: 0; } .logo .glyph { font-size: 22px; }
  .top { gap: 8px; padding: 0 12px; }
  .progress .bar { display: none; }
  .level-title { font-size: 15px; }
  .plot { width: min(100%, 34vh); border-radius: 20px; }
  .lab-stage { padding: 6px 12px 22px; gap: 6px; }
  .legend { font-size: 11px; }
}

/* ==== FORMES (style Mini Metro : formes simples, traits epais) ==== */
.node { background: none; box-shadow: none; border: none; min-width: 0; width: 72px; display: flex; flex-direction: column; align-items: center; outline: none; }
.node.error .shape { box-shadow: 0 0 0 4px var(--red); }
.shape { position: relative; width: 64px; height: max(64px, calc(var(--n) * 34px)); border-radius: 50%; background: #fff; border: 6px solid var(--lav);
  display: grid; place-items: center; cursor: grab; box-shadow: 0 6px 16px rgba(60,50,30,.10); }
.shape .sym { font: 800 20px var(--sans); color: var(--text); }
.node.t-input .shape { background: var(--cyan); border-color: var(--cyan); } .node.t-input .sym { color: #fff; }
.node.t-output .shape { border-radius: 14px; background: #fff; border-color: var(--pink); }
.node.t-const .shape { border-radius: 14px; border-color: var(--sun); background: #fff; }
.node.t-neuron .shape { background: var(--lav); border-color: var(--lav); } .node.t-neuron .sym { color: #fff; }
.node:not(.t-input):not(.t-output):not(.t-const):not(.t-neuron) .shape[style*="--n:3"], .node:not(.t-input):not(.t-output):not(.t-const):not(.t-neuron) .shape[style*="--n:4"] { border-radius: 32px; }
.ins, .outs { position: absolute; top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: space-evenly; pointer-events: none; }
.ins { left: -13px; } .outs { right: -13px; }
.port { pointer-events: auto; padding: 4px; margin: -4px; display: flex; }
.port .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--text); border: 4px solid var(--bg); margin: 0; box-sizing: content-box; }
.port.in .dot, .port.out .dot { margin: 0; }
.port:hover .dot { background: var(--amber); }
.cap { margin-top: 8px; min-height: 18px; text-align: center; font: 700 12px var(--sans); color: var(--muted); white-space: nowrap; }
.cap small { display: block; font-weight: 600; font-size: 10px; } .cap .ok { color: var(--cyan); } .cap .ko { color: var(--red); }
.mid { display: flex; flex-direction: column; gap: 4px; align-items: center; margin-top: 2px; }
.param { font: 700 10px var(--sans); color: var(--muted); display: flex; gap: 4px; align-items: center; }
.param input { width: 56px; text-align: center; background: #fff; border: 2px solid var(--line); border-radius: 99px; padding: 3px 4px; font-size: 13px; }
.wire { stroke-width: 6px !important; stroke-linecap: round; opacity: .95; }
.wire.zero { stroke: #cfc7b6; } .wire.pos { stroke: var(--cyan); } .wire.neg { stroke: var(--pink); }
.wire:hover { stroke: var(--red); }
@media (max-width: 860px) {
  .shape { width: 58px; height: max(58px, calc(var(--n) * 34px)); }
  .port .dot { width: 20px; height: 20px; }
  .ins { left: -15px; } .outs { right: -15px; }
  .node { width: 66px; }
}

.port .dot { width: 12px; height: 12px; background: var(--text); border: 3px solid var(--bg); }
.port.in .dot { background: #fff; border: 3px solid var(--text); }
@media (max-width: 860px) { .port .dot { width: 14px; height: 14px; } .port { padding: 8px; margin: -8px; } }

/* ==== METRO (Mini Metro : formes geometriques, lignes epaisses, paysage) ==== */
:root { --bg: #f4f2ee; --panel: #fbfaf7; --text: #2b2a2e; --line: #e2ded6; --muted: #8b8790; }
html, body { background: var(--bg); color: var(--text); }
.node { width: 72px; }
.shape { background: none !important; border: none !important; border-radius: 0 !important; box-shadow: none !important; width: 64px; }
.shape .st { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.shape .st * { fill: var(--bg); stroke: var(--text); stroke-width: 7px; vector-effect: non-scaling-stroke; }
.node.t-input .shape .st *, .node.t-output .shape .st * { fill: var(--text); }
.node.t-input .sym, .node.t-output .sym { color: var(--bg) !important; }
.node.error .shape .st * { stroke: #eb5757; }
.shape .sym { position: relative; z-index: 1; font: 800 18px var(--sans); color: var(--text); }
.shape.k-tri .sym { margin-top: 12px; }
.wire { stroke-width: 9px !important; stroke-linejoin: round; stroke-linecap: round; fill: none; }
.wire.zero { opacity: .35; } .wire.live { opacity: 1; }
.wire.temp { stroke: var(--muted) !important; stroke-dasharray: 2 12; opacity: 1; }
.wire:hover { filter: brightness(.8); }
.board-wrap { background: var(--bg); }
.port .dot { background: var(--bg); border: 4px solid var(--text); width: 10px; height: 10px; }
.port.in .dot { background: var(--text); border-color: var(--bg); }
.ins { left: -12px; } .outs { right: -12px; }
@media (max-width: 860px) { .port { padding: 10px; margin: -10px; } .shape { width: 58px; } }

/* paysage (iPhone couche) : jeu plein ecran a gauche, panneau a droite */
@media (orientation: landscape) and (max-height: 520px) {
  .top { height: 44px; padding-top: 0; } .logo { display: none; }
  .level-title small { display: none; } .level-title { font-size: 14px; }
  .shell { height: calc(100dvh - 44px); }
  .stage { height: 100%; }
  .editor, .lab { grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: minmax(0, 1fr); }
  .panel { border-radius: 0; margin-top: 0; box-shadow: -2px 0 20px rgba(0,0,0,.08); padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); gap: 8px; }
  .story { font-size: 13px; line-height: 1.35; }
  .tests { max-height: 90px; }
  .btn { min-height: 40px; padding: 8px 14px; }
  .plot { width: min(100%, 82vh); }
  .lab-stage { padding: 6px; }
  .modal .card { max-height: 92dvh; }
}
.shape { height: max(64px, calc(var(--n) * 30px)); }
@media (max-width: 860px) { .shape { height: max(58px, calc(var(--n) * 30px)); } }

/* ==== DA METRO PAYSAGE (direction A validee : carte plein ecran, HUD flottant, paysage uniquement) ==== */
:root { --bg: #f4f2ee; --panel: #fbfaf7; --text: #2b2a2e; --line: #e2ded6; --muted: #8b8790; --lav: #8f84e8; }
.top { position: fixed; z-index: 12; left: 0; right: 0; top: 0; height: auto; background: none !important; border: none; padding: 18px 44px 0; gap: 10px; pointer-events: none; align-items: flex-start; }
.top > * { pointer-events: auto; }
.top .logo, .top .progress { display: none; }
.level-title { flex: 1; font: 800 22px var(--sans); letter-spacing: -.01em; white-space: nowrap; }
.level-title small { font: 800 10px var(--sans); letter-spacing: .18em; color: var(--lav); margin-bottom: 3px; }
.menu-btn, .sync-btn, .info-btn { display: grid !important; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #fff; border: 2px solid var(--line); color: var(--text); font: 800 15px var(--sans); cursor: pointer; flex: none; }
.info-btn { font-size: 16px; } .menu-btn { order: -1; }
.menu-btn::before, .sync-btn::before { font-size: 16px; }
.shell { display: block; position: fixed; inset: 0; height: auto; }
.stage { position: absolute; inset: 0; height: auto; overflow: hidden; }
.sidebar { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(46vw, 320px); transform: translateX(-102%); transition: transform .2s; padding-top: 18px; }
body.menu-open .sidebar { transform: none; } body.menu-open .scrim { display: block; }
.scrim { position: fixed; inset: 0; z-index: 19; }
.editor, .lab { display: block; position: relative; height: 100%; }
.board-wrap { position: absolute; inset: 0; background: var(--bg); }
.board { margin: 78px 0 96px 24px; }
.editor .panel { position: fixed; z-index: 15; top: 0; bottom: 0; right: 0; width: min(46vw, 340px); border-radius: 28px 0 0 28px; margin: 0; transform: translateX(105%); transition: transform .22s;
  padding: 70px 20px 20px; box-shadow: -10px 0 40px rgba(60,50,30,.14); }
body.info-open .editor .panel { transform: none; }
.hud-goal { position: absolute; z-index: 5; left: 50%; top: 18px; transform: translateX(-50%); }
.hud-goal .goal { display: flex; align-items: center; gap: 10px; margin: 0; padding: 9px 18px; background: #fff; border-radius: 99px; box-shadow: 0 6px 24px rgba(60,50,30,.12); white-space: nowrap; }
.hud-goal .goal span { font: 800 10px var(--sans); letter-spacing: .16em; color: var(--lav); }
.hud-goal .goal strong { font: 800 14px var(--sans); }
.hud-dock { position: absolute; z-index: 5; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 8px; background: #fff; border-radius: 99px; box-shadow: 0 6px 24px rgba(60,50,30,.12); max-width: calc(100% - 40px); }
.hud-dock .palette { flex-wrap: nowrap; overflow-x: auto; gap: 8px; }
.hud-dock .chip { padding: 0 16px; height: 40px; white-space: nowrap; border-width: 2px; }
.hud-dock .actions { flex-wrap: nowrap; gap: 8px; } .hud-dock .actions .primary { margin-left: 0; }
.hud-dock .btn { min-height: 40px; height: 40px; padding: 0 18px; white-space: nowrap; }
.lab .panel { position: absolute; top: 0; bottom: 0; right: 0; width: 320px; border-radius: 28px 0 0 28px; padding-top: 70px; }
.lab { display: grid; grid-template-columns: 1fr 320px; } .lab-stage { padding: 70px 12px 12px; }
.plot { width: min(100%, 62vh); }
.modal .card { max-height: 90dvh; overflow-y: auto; }
/* Paysage sur telephone classique : en portrait, on invite a tourner l'appareil.
   Un appareil pliable (iPhone Duo) se joue dans les quatre sens : pas d'invitation. */
.rotate { display: none; }
@media (orientation: portrait) and (max-width: 599px) {
  html:not(.foldable) body > *:not(.rotate) { display: none !important; }
  html:not(.foldable) .rotate { display: grid; place-items: center; position: fixed; inset: 0; z-index: 99; background: var(--bg); color: var(--text); text-align: center; padding: 30px; }
  .rotate b { display: block; font: 800 22px var(--sans); margin: 18px 0 6px; } .rotate span { color: var(--muted); font-size: 14px; }
  .rotate i { display: block; width: 70px; height: 40px; border: 5px solid var(--text); border-radius: 10px; margin: 0 auto; animation: tourne 2.2s ease-in-out infinite; }
}
@keyframes tourne { 0%,20% { transform: rotate(90deg); } 60%,100% { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) { .rotate i { animation: none; } }

html, body { overflow: hidden; height: 100%; }
.menu-btn::before, .menu-btn::after, .sync-btn::before, .sync-btn::after { content: none !important; }
.menu-btn, .sync-btn { font-size: 17px; line-height: 1; }
.board-wrap { overflow: auto; } .board-wrap::-webkit-scrollbar { display: none; }
.node.error .shape .st * { stroke: var(--text); }
.node.t-output.error .shape { box-shadow: none; }

/* responsive : Safari paysage = ecran bas (~340px) */
.level-title { font-size: 18px; max-width: 36vw; overflow: hidden; text-overflow: ellipsis; }
.hud-goal { left: 44px; top: 64px; transform: none; max-width: 52vw; }
.hud-goal .goal { padding: 6px 14px; box-shadow: 0 3px 12px rgba(60,50,30,.10); white-space: normal; }
.hud-goal .goal span { display: none; }
.hud-goal .goal strong { font-size: 13px; }
.hud-dock .palette > :not(.chip) { display: none; }
.hud-dock .palette:empty { display: none; }
.node.error, .node.error:focus { outline: none !important; border: none !important; box-shadow: none !important; background: none !important; }
.board { margin: 116px 0 84px 44px; }
@media (max-height: 420px) {
  .top { padding: 10px 28px 0; } .menu-btn, .sync-btn, .info-btn { width: 34px; height: 34px; }
  .level-title small { display: none; } .level-title { font-size: 17px; padding-top: 5px; }
  .hud-goal { top: 50px; left: 28px; }
  .board { margin: 96px 0 70px 28px; }
  .hud-dock { bottom: 8px; padding: 5px; } .hud-dock .chip, .hud-dock .btn { height: 34px; min-height: 34px; }
  .shape { transform: scale(.9); }
}

/* ==== Camera, rail d'outils, lisibilite et ecrans pliables (2026-11-21) ==== */
/* Lisibilite : la DA validee est claire (Mini Metro). Le theme clair est impose, meme si l'appareil
   est en mode sombre (un ancien bloc sombre melangeait fonds sombres et textes sombres).
   Violet et gris assombris : contraste >= 4,5:1 sur le fond clair. */
:root { color-scheme: light; }
:root { --lav: #5a4fcf; --muted: #6b6770; }
.param input { background: #fff; color: var(--text); -webkit-text-fill-color: var(--text); border: 2px solid var(--line); opacity: 1; -webkit-appearance: none; appearance: none; }

/* Plateau : la camera (translate + scale) remplace le defilement et les marges fixes. */
.board-wrap { overflow: hidden !important; touch-action: none; }
.board { margin: 0 !important; position: absolute; left: 0; top: 0; transform-origin: 0 0; }

/* En-tete : boutons ronds de 44 pt minimum (zone tactile Apple). */
.menu-btn, .sync-btn, .info-btn, .fit-btn { width: 44px !important; height: 44px !important; }
.fit-btn { display: grid; place-items: center; border-radius: 50%; background: #fff; border: 2px solid var(--line); color: var(--text); cursor: pointer; flex: none; padding: 0; }

/* Outils : rail vertical a gauche, une pastille ronde par composant. */
.hud-tools { position: absolute; z-index: 5; left: 16px; top: 116px; bottom: 16px; display: flex; flex-direction: column; justify-content: center; pointer-events: none; }
.hud-tools .palette { pointer-events: auto; display: flex; flex-direction: column; flex-wrap: nowrap; gap: 10px; padding: 8px; max-height: 100%; overflow-y: auto; scrollbar-width: none;
  background: #fff; border-radius: 32px; box-shadow: 0 6px 24px rgba(60,50,30,.12);
  -webkit-mask-image: linear-gradient(transparent, #000 14px, #000 calc(100% - 14px), transparent); mask-image: linear-gradient(transparent, #000 14px, #000 calc(100% - 14px), transparent); }
.hud-tools .palette::-webkit-scrollbar { display: none; }
.hud-tools .palette:empty, .hud-tools .palette:has(> em) { display: none; }
.hud-tools .chip { flex: none; width: 48px; height: 48px; padding: 0; justify-content: center; border-radius: 50%; border: 2px solid var(--line); background: #fff; color: var(--text); }
.hud-tools .chip b { font-size: 20px; line-height: 1; color: var(--lav); }
.hud-tools .chip .lbl { display: none; }
/* Grand ecran : le nom du composant s'affiche a cote de son symbole. */
@media (min-width: 900px) and (min-height: 600px) {
  .hud-tools .chip { width: auto; height: 44px; border-radius: 99px; padding: 0 16px 0 14px; justify-content: flex-start; gap: 8px; font: 700 14px var(--sans); }
  .hud-tools .chip .lbl { display: inline; }
}
@media (max-height: 420px) { .hud-tools { top: 100px; left: 12px; bottom: 12px; } }

/* Actions : en bas a droite, jamais coupees. */
.hud-dock { left: auto !important; right: 16px; bottom: 16px; transform: none !important; max-width: calc(100% - 100px); padding: 6px; }
.hud-dock .actions { flex-wrap: nowrap; gap: 8px; }
.hud-dock .btn { min-height: 44px !important; height: 44px !important; padding: 0 18px; }
@media (max-height: 420px) { .hud-dock { right: 12px; bottom: 10px; } .hud-dock .btn { padding: 0 14px; } }

/* iPhone Duo a moitie plie, pose livre (pli vertical) : plateau sur la page de gauche,
   explications sur la page de droite. Rien ne traverse le pli. */
html[data-fold="vertical"] .editor .panel { transform: none; left: var(--fold-end); right: 0; width: auto; border-radius: 0; box-shadow: none; border-left: 1px solid var(--line); padding-top: 76px; }
html[data-fold="vertical"] .hud-dock { right: calc(100% - var(--fold-start) + 16px); max-width: calc(var(--fold-start) - 100px); }
html[data-fold="vertical"] .hud-goal { max-width: calc(var(--fold-start) - 60px); }
html[data-fold="vertical"] .level-title { max-width: calc(var(--fold-start) - 140px); }
html[data-fold="vertical"] .modal .card { justify-self: start; margin-left: 16px; width: min(520px, calc(var(--fold-start) - 32px)); }
html[data-fold="vertical"] .lab { grid-template-columns: var(--fold-start) 1fr; }
html[data-fold="vertical"] .lab .panel { left: var(--fold-end); width: auto; border-radius: 0; }

/* Pose portable (pli horizontal, appareil pose) : on regarde en haut, on touche en bas. */
html[data-fold="horizontal"] .hud-tools { bottom: calc(100% - var(--fold-start) + 12px); top: 100px; }
html[data-fold="horizontal"] .editor .panel { transform: none; top: var(--fold-end); bottom: 0; left: 0; right: 0; width: auto; border-radius: 0; box-shadow: none; border-top: 1px solid var(--line); padding: 16px 20px 84px; }
html[data-fold="horizontal"] .hud-dock { z-index: 16; }
html[data-fold="horizontal"] .modal .card { align-self: start; margin-top: 16px; max-height: calc(var(--fold-start) - 32px); }
html[data-fold="horizontal"] .lab { display: block; }
html[data-fold="horizontal"] .lab-stage { height: var(--fold-start); }
html[data-fold="horizontal"] .lab .panel { top: var(--fold-end); left: 0; width: auto; border-radius: 0; }
/* Legendes des composants lisibles meme plateau reduit. */
.cap { font-size: 15px; color: var(--text); opacity: .78; }
.cap small { font-size: 13px; }
.palette-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.palette-legend li { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; line-height: 1.4; color: var(--text); }
.palette-legend b { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line); color: var(--lav); font-size: 16px; }
.palette-legend strong { display: block; }
/* Pose livre : les boutons de l'en-tete passent sur la page de droite, loin du pli. */
html[data-fold="vertical"] .fit-btn { margin-left: auto; }
html[data-fold="vertical"] .top { padding-right: 20px; }

/* ==== Capsule de la camera facon Dynamic Island + commandes placees autour de l'appareil ==== */
/* Les positions viennent de src/ui/hud-layout.js (variables --hud-*, --rail-*, --dock-*). */
.top { padding: var(--hud-header-top, 18px) var(--hud-header-right, 20px) 0 var(--hud-header-left, 24px); }
.fit-btn { margin-left: auto; }
.hud-goal { left: var(--hud-header-left, 24px); }
.hud-tools { left: var(--rail-left, 16px); top: var(--rail-top, 168px); bottom: var(--rail-bottom, 16px); }
.hud-dock { right: var(--dock-right, 16px); bottom: var(--dock-bottom, 16px); }
@media (max-height: 420px) {
  .top { padding: var(--hud-header-top, 10px) var(--hud-header-right, 20px) 0 var(--hud-header-left, 24px); }
  .hud-goal { left: var(--hud-header-left, 24px); }
  .hud-tools { left: var(--rail-left, 12px); top: var(--rail-top, 156px); bottom: var(--rail-bottom, 12px); }
  .hud-dock { right: var(--dock-right, 12px); bottom: var(--dock-bottom, 10px); }
}
.editor .panel { padding-right: calc(20px + var(--safe-right, 0px)); padding-bottom: calc(20px + var(--safe-bottom, 0px)); }
.sidebar { padding-left: calc(12px + var(--safe-left, 0px)); padding-bottom: calc(12px + var(--safe-bottom, 0px)); }
.modal { padding: 0 var(--safe-right, 0px) var(--safe-bottom, 0px) var(--safe-left, 0px); }

.island { position: fixed; z-index: 25; background: #111012; border-radius: 30px; box-shadow: 0 6px 20px rgba(17,16,18,.22);
  transition: left .25s, top .25s, width .25s, height .25s; }
.island .menu-btn { position: absolute; width: 44px !important; height: 44px !important; margin: 0; border: none; background: transparent; color: #fff; font-size: 19px; }
.island .menu-btn:active { background: rgba(255,255,255,.14); }
html.has-island .top .menu-btn { display: none !important; }

/* ==== Relier en visant, menu d'appui long, pages du niveau (2026-11-22) ==== */
/* Le composant et le port vises s'allument pendant qu'on tire un fil. */
.node.snap .shape .st * { stroke: var(--lav); }
.port.snap .dot { background: var(--lav) !important; border-color: #fff !important; transform: scale(1.5); transition: transform .12s; }
.wire.temp { stroke: var(--lav); stroke-dasharray: none; }

/* Menu contextuel (appui long, clic droit). */
.ctx-scrim { position: fixed; inset: 0; z-index: 60; }
.ctx-menu { position: fixed; min-width: 190px; padding: 6px; background: #fff; border-radius: 18px; box-shadow: 0 14px 40px rgba(40,30,20,.22); display: flex; flex-direction: column; animation: ctx-in .14s ease-out; }
.ctx-menu .ctx-title { margin: 6px 12px 4px; font: 800 11px var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.ctx-menu button { min-height: 44px; padding: 0 14px; border: none; border-radius: 12px; background: none; text-align: left; font: 700 16px var(--sans); color: var(--text); cursor: pointer; }
.ctx-menu button:hover, .ctx-menu button:focus-visible { background: #f4f2ee; outline: none; }
.ctx-menu button.danger { color: #c0392b; }
@keyframes ctx-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .ctx-menu { animation: none; } }

/* Pages 1 · 2 · 3 sous l'objectif. */
.hud-goal { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.page-bar { display: flex; gap: 4px; padding: 4px; background: #fff; border-radius: 99px; box-shadow: 0 3px 12px rgba(60,50,30,.10); }
.page-bar .page { width: 36px; height: 36px; border-radius: 50%; border: 2px solid transparent; background: none; font: 800 15px var(--sans); color: var(--text); cursor: pointer; display: grid; place-items: center; padding: 0; position: relative; }
.page-bar .page::after { content: ''; position: absolute; inset: -4px; } /* zone tactile de 44 pt */
.page-bar .page.on { background: var(--text); color: #fff; }
.page-bar .page.empty { color: var(--muted); border-color: var(--line); border-style: dashed; }
.page-bar .page.dup { color: var(--lav); }

/* ==== Aide : bouton Fermer, et feuille du bas sur un ecran etroit (Duo ferme tenu droit) ==== */
.editor .panel { position: fixed; }
.panel-close { position: absolute; top: 14px; right: calc(14px + var(--safe-right, 0px)); width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: #fff; color: var(--text); font: 700 24px/1 var(--sans); cursor: pointer; display: grid; place-items: center; padding: 0; z-index: 1; }
html[data-fold="vertical"] .panel-close, html[data-fold="horizontal"] .panel-close { display: none; } /* l'aide y est toujours ouverte */
@media (max-width: 600px) {
  .editor .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: min(72dvh, 620px);
    border-radius: 28px 28px 0 0; transform: translateY(105%); padding: 64px 20px calc(24px + var(--safe-bottom, 0px)); box-shadow: 0 -12px 40px rgba(60,50,30,.16); }
  .editor .panel .panel-close { right: 14px; }
  body.info-open .editor .panel { transform: none; }
  .tests table { width: 100%; }
}
/* Jeu tactile : pas de selection de texte ni de loupe iOS sur un appui long (sauf dans les champs). */
html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea, .sync-input { -webkit-user-select: text; user-select: text; }
/* Objectif en francais simple ; l'exemple et la formule dans l'aide. */
.brief .example { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: #fff6e3; color: #6b4a0d; font: 600 15px/1.4 var(--sans); }
.brief .math { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.brief .math code { font: 700 13px var(--sans); color: var(--text); }
.hud-goal .goal strong { font-size: 15px; line-height: 1.3; max-width: min(60vw, 420px); }

/* ==== Tutoriel guide (niveaux 1 a 5) ==== */
html.tutoring .page-bar { display: none; }
.tuto-bubble { display: flex; flex-direction: column; gap: 2px; max-width: min(64vw, 440px); padding: 10px 16px; border-radius: 18px;
  background: var(--text); color: #fff; box-shadow: 0 8px 24px rgba(40,30,20,.22); animation: tuto-pop .25s ease-out; }
.tuto-bubble .tuto-count { font: 800 10px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: #c9c3ff; }
.tuto-bubble .tuto-say { font: 700 16px/1.3 var(--sans); }
.tuto-bubble.done { background: #27ae60; }
.tuto-bubble.done .tuto-count { color: #d7f5e2; }
.tuto-hand { position: fixed; left: 0; top: 0; z-index: 40; width: 44px; height: 44px; pointer-events: none; transform-origin: 14.7px 3.7px; filter: drop-shadow(0 3px 5px rgba(0,0,0,.28)); }
.tuto-hand svg { display: block; }
.tuto-ring { position: fixed; z-index: 39; border-radius: 50%; border: 3px solid var(--lav); pointer-events: none; animation: tuto-ring 1.4s ease-out infinite; }
html.touching .tuto-hand, html.touching .tuto-ring { opacity: 0 !important; }
.tuto-confetti { position: fixed; z-index: 41; width: 9px; height: 9px; border-radius: 2px; pointer-events: none; }
@keyframes tuto-pop { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tuto-ring { 0% { transform: scale(.8); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tuto-ring, .tuto-bubble { animation: none; } }
/* Menu des niveaux ouvert : au-dessus de l'en-tete (sinon le titre se superpose a la liste),
   sous la capsule de la camera qui sert a le refermer. */
body.menu-open .shell { z-index: 24; }
/* Niveau deja reussi : bandeau, et pas de tutoriel tant qu'on ne recommence pas. */
.replay-banner { display: inline-flex; align-items: center; gap: 8px; padding: 4px 4px 4px 6px; border-radius: 99px; background: #fff; white-space: nowrap; box-shadow: 0 3px 12px rgba(60,50,30,.10); }
.replay-banner[hidden] { display: none; }
.replay-banner .ok { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #27ae60; color: #fff; font: 800 15px/1 var(--sans); }
.replay-banner b { font: 800 14px var(--sans); color: #1d6b3d; }
.replay-banner button { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; margin-left: 4px; padding: 0 14px; border: 2px solid var(--line); border-radius: 99px; background: #fff; color: var(--text); font: 700 14px var(--sans); cursor: pointer; }
html.replaying .tuto-bubble, html.replaying .tuto-hand, html.replaying .tuto-ring { display: none !important; }
html.replaying .page-bar { display: flex; }

/* ==== Annuler / Refaire : en bas a gauche ==== */
.hud-undo { position: absolute; z-index: 5; left: var(--rail-left, 16px); bottom: var(--dock-bottom, 16px); display: flex; gap: 4px; padding: 4px; background: #fff; border-radius: 99px; box-shadow: 0 6px 24px rgba(60,50,30,.12); }
.hud-undo button { width: 44px; height: 44px; border-radius: 50%; border: none; background: none; color: var(--text); display: grid; place-items: center; cursor: pointer; padding: 0; }
.hud-undo button:disabled { color: #c9c4bc; cursor: default; }
.hud-undo button:not(:disabled):active { background: #f4f2ee; }
@media (max-height: 420px) { .hud-undo { left: var(--rail-left, 12px); bottom: var(--dock-bottom, 10px); } }
html[data-fold="horizontal"] .hud-undo { z-index: 16; }
html[data-fold="vertical"] .hud-undo { left: 16px; }
.hud-tools { bottom: calc(var(--rail-bottom, 16px) + 60px); }
@media (max-height: 420px) { .hud-tools { bottom: calc(var(--rail-bottom, 12px) + 56px); } }

/* ==== Signal qui circule + curseur d'une entree ==== */
.wires .flow { fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 0.01 18; opacity: .9; pointer-events: none; animation: flow-beads .9s linear infinite; }
@keyframes flow-beads { to { stroke-dashoffset: -18; } }
@media (prefers-reduced-motion: reduce) { .wires .flow { animation: none; } }
.node.t-input .shape { cursor: pointer; }
.dial { min-width: 240px; padding: 8px 14px 10px; }
.dial .dial-value { margin: 2px 2px 6px; font: 800 26px var(--sans); color: var(--text); }
.dial .dial-value .n { color: var(--lav); }
.dial input[type="range"] { width: 100%; height: 44px; accent-color: var(--text); }
.dial .dial-ends { display: flex; justify-content: space-between; margin: -6px 2px 6px; font: 600 12px var(--sans); color: var(--muted); }
.dial .dial-reset { text-align: center; color: var(--lav); border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; }

/* ==== Situations concretes : etiquette d'objet sous les entrees et sorties ==== */
.tag { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; padding: 4px 10px 4px 8px; border-radius: 99px; background: #fff; border: 1.5px solid var(--line); color: var(--text); font: 700 14px var(--sans); white-space: nowrap; box-shadow: 0 2px 8px rgba(60,50,30,.08); }
.tag .ico { flex: none; }
.tag.lit { background: #fff4c8; border-color: #f2c94c; box-shadow: 0 0 0 4px rgba(242,201,76,.25), 0 2px 10px rgba(242,201,76,.45); }
.tag + .cap { margin-top: 4px; }

/* ==== Objectif en carte (2026-11-22) : sur un ecran etroit (Duo ferme tenu droit) la pilule
   etroite cassait le texte sur 4 lignes. La carte s'etend jusqu'a la capsule, angles doux. ==== */
.hud-goal { max-width: none; right: var(--hud-header-right, 20px); }
.hud-goal .goal { border-radius: 16px; padding: 9px 14px; max-width: 440px; }
.hud-goal .goal strong { font: 600 15px/1.38 var(--sans); max-width: none; letter-spacing: 0; }
html[data-fold="vertical"] .hud-goal { right: calc(100% - var(--fold-start) + 16px); }

/* ---- Creer une brique (chapitre VI) */
.brick-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.brick-head h2 { margin: 0; }
.brick-head p { margin: 2px 0 0; }
.brick-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: #2b2a2e; color: #fff; flex: none; }
.brick-name { display: flex; flex-direction: column; gap: 6px; font: 700 13px var(--sans); }
.brick-name input { height: 46px; padding: 0 14px; border-radius: 14px; border: 2px solid #e2ded6; font: 700 16px var(--sans); color: #2b2a2e; background: #fff; user-select: text; -webkit-user-select: text; }
.brick-name input:focus { outline: none; border-color: #5a4fcf; }
.chip[class*="t-brick:"] b { color: #5a4fcf; }
.k-brick .st { stroke: #5a4fcf; }
.k-brick .sym { color: #5a4fcf; }
.brick-tag { color: #5a4fcf; }

/* ==== Fenetres centrees dans la zone utile (hors capsule de la camera, hors pli) + fenetre de reussite (2026-11-22) ==== */
/* Avant : largeur en vw, plus large que la zone utile quand la capsule reserve une colonne ; la fenetre debordait et se collait a gauche. */
.modal { grid-template-columns: minmax(0, 1fr);
  padding: max(16px, var(--safe-top, 0px)) max(16px, var(--safe-right, 0px)) max(16px, var(--safe-bottom, 0px)) max(16px, var(--safe-left, 0px)); }
.modal .card { width: min(480px, 100%); max-height: 100%; overflow-y: auto; }
html[data-fold="vertical"] .modal .card { --w: min(480px, calc(var(--fold-start) - 32px)); width: var(--w); justify-self: start;
  margin-left: max(0px, calc((var(--fold-start) - var(--w)) / 2 - max(16px, var(--safe-left, 0px)))); }
html[data-fold="horizontal"] .modal .card { margin-top: 0; max-height: calc(var(--fold-start) - max(16px, var(--safe-top, 0px)) - 16px); }

.win-card { padding: 30px 24px 18px; text-align: center; animation: win-in .4s cubic-bezier(.2, .9, .3, 1.15) both; }
.win { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 20px; }
.win-badge { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 10px; border-radius: 50%; background: #5a4fcf; color: #fff;
  box-shadow: 0 0 0 9px rgba(90, 79, 207, .13), 0 10px 24px rgba(90, 79, 207, .35); animation: win-pop .5s .12s cubic-bezier(.2, .9, .3, 1.4) both; }
.win-badge .ico { stroke-width: 3; }
.win-eyebrow { margin: 0; font: 800 11px var(--sans); letter-spacing: .18em; text-transform: uppercase; color: #5a4fcf; }
.win h2 { margin: 0; font: 800 30px/1.1 var(--sans); letter-spacing: -.02em; text-wrap: balance; }
.win-stats { display: flex; gap: 10px; margin-bottom: 14px; }
.win-stat { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 6px; border-radius: 18px; background: #f4f2ee; }
.win-stat span { font: 800 10px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.win-stat b { font: 800 30px/1.1 var(--sans); font-variant-numeric: tabular-nums; color: var(--text); }
.win-stat small { font-size: 12px; color: var(--muted); }
.win-note { display: flex; align-items: center; justify-content: center; gap: 8px; width: fit-content; margin: 0 auto 8px; padding: 8px 14px; border-radius: 99px;
  background: #f4f2ee; font-weight: 700; font-size: 14px; color: var(--text); }
.win-note.good { background: #ebe9fb; color: #5a4fcf; }
.win-card .unlock { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 4px 0 8px; font-weight: 700; }
.win-card .actions { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; }
.win-card .actions .btn { width: 100%; margin: 0; }
.win-card .actions .primary { order: -1; min-height: 52px; border-radius: 99px; font-size: 17px; }
.win-card .actions .ghost { min-height: 44px; border: none; background: transparent; box-shadow: none; color: var(--muted); font-size: 15px; }
@keyframes win-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes win-pop { from { transform: scale(.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .win-card, .win-badge { animation: none; } }
