:root {
  --bg: #14161b; --panel: #1c1f26; --panel2: #242830; --line: #333946; --text: #e6e9ef; --dim: #98a1b3;
  --accent: #ff8a3d; --accent2: #3fb6c9; --danger: #e5534b; --ok: #4cc38a; --r: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
[hidden] { display: none !important; }
.grow { flex: 1; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=number], input:not([type]), select, textarea {
  background: #0f1115; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; }
input[type=color] { width: 44px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px; cursor: pointer; white-space: nowrap; font-weight: 600; }
.btn:hover { background: #2e333d; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1206; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary.alt { background: var(--accent2); border-color: var(--accent2); color: #04181c; }
.btn.ghost { background: none; border-color: transparent; color: var(--dim); }
.btn.ghost:hover { color: var(--text); background: var(--panel2); }
.btn.danger { color: #ff9a94; }
.btn.danger:hover { background: #4a2020; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn.big { padding: 12px 26px; font-size: 17px; }
.btn.play { background: var(--ok); border-color: var(--ok); color: #05210f; }
.btn.play.stop { background: var(--danger); border-color: var(--danger); color: #fff; }
.pill { display: inline-block; background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 12.5px; color: var(--dim); margin: 0; }
.badge { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 4px; background: #555; letter-spacing: .05em; }
.badge.m2d { background: var(--accent); color: #1a1206; } .badge.m3d { background: var(--accent2); color: #04181c; }
.help { color: var(--dim); font-size: 12.5px; margin: 10px 0 0; }
.error { color: #ff9a94; margin: 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b3140; border: 1px solid var(--line); padding: 10px 18px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 30px #0008; }
.toast.bad { border-color: var(--danger); }
.center-msg { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 16px; }

/* ---- navigation ---- */
.nav { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.nav > a:not(.btn):not(.logo) { color: var(--dim); font-weight: 600; }
.nav > a:not(.btn):hover { color: var(--text); }
.logo { font-weight: 800; font-size: 19px; display: inline-flex; align-items: center; gap: 7px; letter-spacing: -.01em; }
.logo-mark { color: var(--accent); font-size: 20px; }
.who { color: var(--dim); font-weight: 600; }

/* ---- accueil ---- */
.hero { padding: 64px 16px 48px; text-align: center; background: radial-gradient(900px 300px at 50% 0, #ff8a3d22, transparent), radial-gradient(700px 300px at 70% 20%, #3fb6c922, transparent); }
.hero h1 { font-size: clamp(28px, 5vw, 46px); letter-spacing: -.02em; max-width: 760px; margin: 0 auto; text-wrap: balance; }
.hero p { color: var(--dim); max-width: 620px; margin: 16px auto 26px; font-size: 17px; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 16px 60px; }
.wrap h2 { margin-bottom: 16px; font-size: 21px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #0d0f13; display: grid; place-items: center; font-size: 44px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge { position: absolute; top: 8px; left: 8px; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.card-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { color: var(--dim); font-size: 13px; margin: 0; }
.card-actions { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.empty { color: var(--dim); grid-column: 1 / -1; padding: 30px 0; }

/* ---- connexion ---- */
.auth { display: grid; place-items: center; padding: 48px 16px; }
.auth-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.auth-box label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 14px; }
.auth-box input { padding: 9px 10px; }
.tabs { display: flex; background: #0f1115; border-radius: 8px; padding: 3px; }
.tabs button { flex: 1; background: none; border: 0; padding: 8px; border-radius: 6px; cursor: pointer; font-weight: 700; color: var(--dim); }
.tabs button.on { background: var(--panel2); color: var(--text); }

/* ---- scène de jeu ---- */
.stage-wrap { position: relative; background: #000; display: grid; place-items: center; }
.stage { position: relative; width: 100%; max-height: 100%; background: #000; overflow: hidden; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-wrap:fullscreen { width: 100vw; height: 100vh; }
.stage-wrap:fullscreen .stage { width: auto; height: 100%; max-width: 100%; }
.start-overlay { position: absolute; inset: 0; background: #0009; border: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-size: 20px; font-weight: 800; color: #fff; }
.start-overlay span { width: 84px; height: 84px; border-radius: 50%; background: var(--accent); color: #1a1206; display: grid; place-items: center; font-size: 34px; padding-left: 6px; }
.start-overlay:hover span { transform: scale(1.06); }

/* ---- page projet ---- */
.play-page { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 22px; align-items: start; }
.play-main { min-width: 0; }
.play-page .stage-wrap { border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); }
.play-bar { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.play-info h1 { font-size: 24px; margin-bottom: 4px; overflow-wrap: anywhere; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; color: #c9cfdb; }
.share-link { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--dim); margin-top: 16px; }
@media (max-width: 860px) { .play-page { grid-template-columns: 1fr; } }

/* ---- éditeur ---- */
.editor-page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.title-in { width: 240px !important; font-weight: 700; background: transparent !important; border-color: transparent !important; }
.title-in:hover:not(:disabled), .title-in:focus { border-color: var(--line) !important; background: #0f1115 !important; }
#editor { flex: 1; min-height: 0; display: grid; grid-template-columns: 340px minmax(0, 1fr) 270px; gap: 1px; background: var(--line); }
#editor.big-stage { grid-template-columns: minmax(340px, 55%) minmax(0, 1fr) 270px; }
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--panel2); border-bottom: 1px solid var(--line); font-weight: 700; font-size: 13px; min-height: 36px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.panel-head .hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#left .stage:not(.playing) { cursor: grab; }
.console { height: 62px; overflow: auto; font: 12px/1.45 ui-monospace, Consolas, monospace; padding: 4px 8px; background: #0d0f13; color: #b7c0d0; border-bottom: 1px solid var(--line); flex: none; }
.console:empty::before { content: "Console — les messages et erreurs du jeu s’affichent ici."; color: #5c6577; }
.console .err { color: #ff8a84; }
.objects { overflow: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.obj { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; cursor: pointer; text-align: left; }
.obj:hover { background: var(--panel2); }
.obj.on { background: #2f3542; border-color: var(--accent); }
.obj-ic { width: 20px; text-align: center; flex: none; }
.obj-bp { margin-left: auto; color: var(--accent2); }
.add-wrap { position: relative; }
.popmenu { position: absolute; right: 0; top: 100%; margin-top: 4px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px; z-index: 20; min-width: 170px; box-shadow: 0 10px 30px #0009; text-transform: none; letter-spacing: 0; }
.popmenu button { display: flex; gap: 8px; width: 100%; background: none; border: 0; padding: 7px 9px; border-radius: 5px; cursor: pointer; text-align: left; }
.popmenu button:hover { background: #363c49; }
.inspector { padding: 10px 12px 20px; overflow: auto; }
.inspector h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--dim); margin: 14px 0 8px; }
.inspector h4:first-child { margin-top: 2px; }
.f { display: grid; grid-template-columns: 84px minmax(0, 1fr); align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.f > span { color: #c2c9d6; }
.f-in { display: flex; gap: 4px; min-width: 0; align-items: center; }
.f-in input[type=number], .f-in input[type=text], .f-in select { padding: 4px 6px; }
.f-in input[type=file] { font-size: 12px; width: 100%; }
.f-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
#center { position: relative; }
.no-graph { flex: 1; display: grid; place-items: center; color: var(--dim); padding: 20px; text-align: center; }
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(480px, calc(100vw - 32px)); }
.dlg::backdrop { background: #000a; }
.dlg h3 { margin-bottom: 14px; }
.dlg label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--dim); margin-top: 12px; }
.dlg .check { flex-direction: row; gap: 10px; align-items: flex-start; color: var(--text); font-size: 15px; background: #0f1115; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.dlg .check input { margin-top: 3px; flex: none; }
.dlg .check small { display: block; color: var(--dim); }
.dlg .check:has(input:disabled) { opacity: .5; cursor: default; }
.dlg .pill { margin-top: 12px; }
.copy-row { display: flex; gap: 6px; }
.dlg-foot { display: flex; justify-content: flex-end; margin-top: 16px; }
@media (max-width: 900px) {
  .editor-page { height: auto; overflow: auto; }
  #editor, #editor.big-stage { grid-template-columns: 1fr; }
  #center { height: 70vh; }
}

/* ---- éditeur de graphes (Blueprint) ---- */
.ge { position: relative; flex: 1; min-height: 0; overflow: hidden; outline: none; cursor: default; user-select: none; touch-action: none;
  background-color: #22252b;
  background-image: linear-gradient(#2c3038 1px, transparent 1px), linear-gradient(90deg, #2c3038 1px, transparent 1px), linear-gradient(#15171b 1px, transparent 1px), linear-gradient(90deg, #15171b 1px, transparent 1px); }
.ge.panning { cursor: grabbing; }
.ge-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.ge-wires { position: absolute; left: -20000px; top: -20000px; width: 40000px; height: 40000px; pointer-events: none; }
.wire { fill: none; stroke-width: 2.5; pointer-events: stroke; cursor: pointer; }
.wire.exec { stroke-width: 3.5; }
.wire:hover { stroke-width: 5; filter: brightness(1.3); }
.wire.temp { pointer-events: none; stroke-dasharray: 6 5; }
.ge.wiring .wire { pointer-events: none; }
.ge-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #6c7588; pointer-events: none; font-size: 16px; }
.ge-box { position: absolute; border: 1px dashed var(--accent2); background: #3fb6c91a; pointer-events: none; }
.node { position: absolute; min-width: 150px; background: #101216e8; border: 1.5px solid #05060899; border-radius: 9px; box-shadow: 0 4px 14px #0007; font-size: 12.5px; }
.node.sel { border-color: #ffb400; box-shadow: 0 0 0 1.5px #ffb400, 0 4px 14px #0007; }
.node-head { padding: 5px 10px; border-radius: 7px 7px 0 0; font-weight: 700; white-space: nowrap; cursor: grab; text-shadow: 0 1px 2px #0008; }
.node.k-pure .node-head { font-weight: 600; }
.node-body { display: flex; justify-content: space-between; gap: 18px; padding: 7px 0 8px; }
.node-col { display: flex; flex-direction: column; gap: 5px; }
.node-col.out { align-items: flex-end; }
.pin-row { display: flex; align-items: center; gap: 6px; padding: 0 9px; min-height: 22px; white-space: nowrap; }
.node-col.out .pin-row { flex-direction: row-reverse; }
.pin-label { color: #cdd3de; }
.pin { --c: #aaa; width: 13px; height: 13px; flex: none; cursor: crosshair; position: relative; }
.pin::after { content: ""; position: absolute; inset: -6px; } /* zone de clic élargie */
.pin.data { border-radius: 50%; border: 2.5px solid var(--c); }
.pin.data.on { background: var(--c); }
.pin.exec { clip-path: polygon(0 0, 55% 0, 100% 50%, 55% 100%, 0 100%); background: #fff; }
.pin.exec:not(.on) { background: linear-gradient(#fff, #fff) padding-box; -webkit-mask: none; opacity: .45; }
.pin:hover { filter: brightness(1.4) drop-shadow(0 0 3px var(--c)); opacity: 1 !important; }
.pin-w { width: 92px !important; padding: 2px 5px !important; font-size: 12px; border-radius: 4px !important; background: #1b1e25 !important; }
input.pin-w.num { width: 58px !important; }
select.pin-w { width: 128px !important; }
input[type=checkbox].pin-w { width: 15px !important; height: 15px; padding: 0 !important; }
input[type=color].pin-w { width: 40px !important; height: 22px; padding: 0 !important; }
.ge-menu { position: absolute; width: 290px; max-height: 380px; display: flex; flex-direction: column; background: #1a1d23; border: 1px solid #444b5a; border-radius: 8px; box-shadow: 0 14px 40px #000b; z-index: 30; overflow: hidden; cursor: default; }
.ge-menu-title { padding: 7px 10px 2px; font-size: 12px; color: var(--dim); }
.ge-menu input { margin: 6px 8px; width: auto; }
.ge-menu-list { overflow: auto; overscroll-behavior: contain; padding: 0 4px 6px; }
.ge-menu-cat { --c: #555; width: 100%; background: none; border: 0; cursor: pointer; text-align: left; font-size: 12.5px; font-weight: 700; color: #d5dae4; padding: 6px 6px; border-radius: 4px; display: flex; align-items: center; gap: 7px; }
.ge-menu-cat:hover { background: #262b35; }
.ge-menu-arrow { width: 10px; color: var(--dim); transition: transform .1s; }
.ge-menu-cat.open .ge-menu-arrow { transform: rotate(90deg); }
.ge-menu-sw { width: 9px; height: 9px; border-radius: 2px; background: var(--c); flex: none; }
.ge-menu-catname { flex: 1; }
.ge-menu-count { color: var(--dim); font-weight: 400; font-size: 11.5px; }
.ge-menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 5px 10px 5px 32px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.ge-menu-item:hover, .ge-menu-item.first { background: #2f3644; }
.ge-menu-empty { padding: 14px; color: var(--dim); text-align: center; }
