:root {
  --bg: #1b1b1c; --panel: #2a2a2c; --panel2: #232325; --line: #3a3a3d; --text: #d8d8da; --dim: #8e8e93;
  --accent: #3b82f6; --hover: #3a3a3e; --canvasbg: #3b3b3e;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 12px/1.3 system-ui, "Segoe UI", sans-serif; overflow: hidden; user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select { font: inherit; color: inherit; background: var(--panel2); border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px; }
input[type=number] { width: 52px; }
button:disabled { opacity: .4; cursor: default; }

#app { display: flex; flex-direction: column; height: 100%; }

/* Menus */
#menubar { display: flex; align-items: center; height: 28px; background: var(--panel); border-bottom: 1px solid var(--line); padding: 0 6px; }
.brand { display: flex; align-items: center; gap: 8px; margin: 0 14px 0 4px; font-size: 14px; font-weight: 700; letter-spacing: .2px; color: #fff; user-select: none; }
.brand svg { width: 20px; height: 20px; }
.brand small { font-size: 10px; font-weight: 500; color: var(--dim); letter-spacing: 0; }
.menu { position: relative; }
.menu-btn { padding: 5px 10px; border-radius: 3px; }
.menu-btn:hover, .menu.open .menu-btn { background: var(--hover); }
.dropdown { display: none; position: absolute; top: 100%; left: 0; z-index: 50; min-width: 270px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 4px; box-shadow: 0 8px 24px #0008; }
.menu.open .dropdown { display: block; }
.item { display: flex; width: 100%; justify-content: space-between; gap: 24px; padding: 5px 10px; border-radius: 3px; text-align: left; align-items: center; }
.item:hover:not(:disabled) { background: var(--accent); color: #fff; }
.item kbd { font: inherit; color: var(--dim); }
.item:hover:not(:disabled) kbd { color: #dbe8ff; }
.sep { height: 1px; background: var(--line); margin: 4px 2px; }

/* Barre d'options */
#optionsbar { display: flex; align-items: center; gap: 12px; height: 36px; padding: 0 10px; background: var(--panel2); border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; }
.toolname { font-weight: 600; min-width: 130px; }
.opt { display: flex; align-items: center; gap: 6px; }
.opt span { color: var(--dim); }
.opt input[type=range] { width: 80px; accent-color: var(--accent); }
.opt small { color: var(--dim); }
.opt.check { gap: 5px; }
.opt.check span { color: var(--text); }
.hint { color: var(--dim); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg button { padding: 4px 9px; background: var(--panel); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.seg button:not(.on):hover { background: var(--hover); }

#main { flex: 1; display: flex; min-height: 0; }

/* Outils */
#toolbar { width: 46px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; }
.tool { position: relative; width: 36px; height: 34px; border-radius: 4px; color: var(--text); display: grid; place-items: center; }
.tool svg { width: 22px; height: 22px; }
.tool:hover { background: var(--hover); }
.tool.active { background: var(--accent); color: #fff; }
.tool .corner { position: absolute; right: 3px; bottom: 3px; border: 3px solid transparent; border-right-color: currentColor; border-bottom-color: currentColor; opacity: .7; }
.flyout { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 4px; min-width: 210px; box-shadow: 0 8px 24px #0008; }
.flyout .item { justify-content: flex-start; gap: 10px; }
.flyout svg { width: 18px; height: 18px; }
.flyout kbd { margin-left: auto; }
.fgbg { position: relative; width: 36px; height: 44px; margin-top: auto; }
.fgbg .fgc, .fgbg .bgc { position: absolute; width: 22px; height: 22px; border: 2px solid #fff; outline: 1px solid #000; cursor: pointer; }
.fgbg .fgc { left: 2px; top: 2px; z-index: 2; }
.fgbg .bgc { left: 12px; top: 12px; }
.fgbg .target { outline: 2px solid var(--accent); }
.fgbg button { position: absolute; font-size: 13px; color: var(--dim); }
.fgbg .swap { right: -2px; top: -2px; }
.fgbg .reset { left: 0; bottom: -2px; }
.fgbg button:hover { color: var(--text); }

/* Espace de travail */
#workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#docTab { height: 26px; line-height: 26px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); color: var(--dim); }
#viewport { position: relative; flex: 1; overflow: hidden; background: var(--canvasbg); touch-action: none; }
#viewport.grabbing { cursor: grabbing !important; }
#paper { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 0 0 1px #000a, 0 6px 30px #0009;
  background: repeating-conic-gradient(#c8c8c8 0% 25%, #fff 0% 50%); background-size: 16px 16px; }
#paper canvas { display: block; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#statusbar { display: flex; gap: 18px; align-items: center; height: 24px; padding: 0 12px; background: var(--panel); border-top: 1px solid var(--line); color: var(--dim); }
#statusbar .spacer { flex: 1; }

/* Panneaux */
#panels { width: 264px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; overflow-y: auto; }
.panel { border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1; display: flex; flex-direction: column; min-height: 260px; border-bottom: 0; }
.panel h4::before { content: ''; width: 0; height: 0; border: 4px solid transparent; border-top: 5px solid currentColor; border-bottom: 0; flex: none; }
.panel.collapsed h4::before { border: 4px solid transparent; border-left: 5px solid currentColor; border-right: 0; }
.panel.collapsed > :not(h4) { display: none; }
.panel.grow.collapsed { flex: none; min-height: 0; }
.panel h4 { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; margin: 0; padding: 6px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); background: var(--panel2); }
.cpick, #colorBody { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.cpick .sv { width: 100%; height: auto; aspect-ratio: 220/130; border-radius: 3px; cursor: crosshair; touch-action: none; }
.cpick .hue { width: 100%; height: 12px; appearance: none; border-radius: 6px; padding: 0; border: 0;
  background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.cpick .hue::-webkit-slider-thumb { appearance: none; width: 8px; height: 16px; border-radius: 3px; background: #fff; border: 1px solid #000; }
.hexrow { display: flex; gap: 4px; align-items: center; }
.hexrow span { color: var(--dim); }
.hexrow input { min-width: 0; }
.cpick .hex { width: 62px; }
.hexrow input[type=number] { width: 44px; padding: 2px; }
.palbar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.palbar select { flex: 1 1 100%; min-width: 0; }
.palbar button { padding: 2px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel2); }
.palbar button:hover { background: var(--hover); }
.palgrid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; }
.palempty { grid-column: 1 / -1; color: var(--dim); }
.swatch { aspect-ratio: 1; border-radius: 2px; border: 1px solid #0006; }
.swatch:hover { outline: 1px solid #fff; }
#historyBody { max-height: 130px; overflow-y: auto; }
.hrow { display: block; width: 100%; text-align: left; padding: 3px 10px; }
.hrow:hover { background: var(--hover); }
.hrow.current { background: #3b82f633; color: #fff; }
.hrow.undone { color: var(--dim); font-style: italic; }

/* Calques */
.lctl { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--line); }
.lctl select { width: 100%; padding: 3px; }
.lctl label { display: flex; align-items: center; gap: 6px; color: var(--dim); }
.lctl label input[type=range] { flex: 1; accent-color: var(--accent); }
.lctl label input[type=number] { width: 46px; margin-left: auto; }
.lctl small { color: var(--dim); }
.locks { display: flex; gap: 6px; align-items: center; color: var(--dim); }
.locks button { width: 32px; height: 26px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; color: var(--text); }
.locks button svg { width: 18px; height: 18px; }
.locks button.on { background: var(--accent); color: #fff; }
#layerList { flex: 1; overflow-y: auto; min-height: 120px; background: var(--panel2); }
.lrow { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-bottom: 1px solid #0003; cursor: pointer; }
.lrow:hover { background: var(--hover); }
.lrow.active { background: #3b82f64d; }
.lrow.dragover { box-shadow: inset 0 2px 0 var(--accent); }
.lrow .eye { width: 20px; height: 20px; padding: 0; color: var(--dim); opacity: .55; display: grid; place-items: center; }
.lrow .eye svg { width: 17px; height: 17px; }
.lrow .eye.on { color: var(--text); opacity: 1; }
.thumb { width: 48px; height: 36px; flex: none; border: 1px solid #000; background: repeating-conic-gradient(#999 0% 25%, #ccc 0% 50%) 0 0/10px 10px; }
.lrow.group { background: #ffffff08; font-weight: 600; }
.lrow .arrow { width: 14px; color: var(--dim); }
.lrow .folder { width: 30px; text-align: center; font-size: 18px; }
.lrow.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.lrow.drop-below { box-shadow: inset 0 -2px 0 var(--accent); }
.lrow.drop-into { outline: 2px solid var(--accent); outline-offset: -2px; }
.obtn { padding: 4px 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); }
.obtn:hover { background: var(--hover); }
.obtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.fxdlg { width: 760px; max-width: 96vw; }
.fxbody { display: flex; gap: 14px; height: 470px; }
.fxlist { width: 220px; overflow-y: auto; border-right: 1px solid var(--line); padding-right: 8px; }
.fxhead { margin: 10px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); }
.fxitem { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; cursor: pointer; width: 100%; text-align: left; }
.fxitem:hover { background: var(--hover); }
.fxitem.sel { background: #3b82f64d; }
.fxitem.off { opacity: .4; cursor: default; }
.fxpane { flex: 1; overflow-y: auto; padding-right: 4px; }
.fxsec { border: 1px solid var(--line); border-radius: 4px; margin: 0 0 12px; padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.fxsec legend { padding: 0 6px; color: var(--dim); }
.fxrow { display: flex; align-items: center; gap: 10px; }
.fxrow > span { width: 120px; color: var(--dim); flex: none; }
.fxrow input[type=range] { flex: 1; accent-color: var(--accent); width: auto; }
.fxrow input[type=number] { width: 56px; }
.fxrow select { flex: 1; width: auto; }
.fxrow input[type=color] { width: 48px; height: 26px; padding: 0; border: 1px solid var(--line); background: none; }
.fxrow small { width: 18px; color: var(--dim); }
.fxcheck { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; }
.fxcheck input { width: auto; }
.fxhint { color: var(--dim); font-size: 11px; }
.bitracks { display: flex; flex-direction: column; gap: 4px; }
.bilabel { color: var(--dim); margin-top: 4px; }
.bitrack { position: relative; height: 40px; margin: 0 8px; }
.bibar { position: absolute; left: 0; right: 0; top: 4px; height: 14px; border: 1px solid #000; background: linear-gradient(90deg, #000, #fff); }
.bih { position: absolute; top: 19px; width: 0; height: 0; margin-left: -6px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid #aaa; cursor: ew-resize; touch-action: none; }
.bih.blk { border-bottom-color: #000; filter: drop-shadow(0 0 1px #fff); }
.bih.wht { border-bottom-color: #fff; filter: drop-shadow(0 0 1px #000); }
.biread { position: absolute; right: 0; top: 30px; color: var(--dim); font-size: 11px; }
.gedit { display: flex; flex-direction: column; gap: 8px; }
.gpresets { display: flex; flex-wrap: wrap; gap: 4px; }
.gpreset { width: 44px; height: 20px; border: 1px solid #000; border-radius: 2px; }
.gpreset:hover { outline: 2px solid var(--accent); }
.gwrap { position: relative; margin: 0 8px; }
.gbar { height: 28px; border: 1px solid #000; }
.gmarkers { position: relative; height: 18px; cursor: copy; }
.gmark { position: absolute; width: 12px; height: 14px; margin-left: -6px; border: 1px solid #000; background: var(--c, #fff); cursor: ew-resize; touch-action: none; }
.gmarkers.bottom .gmark { top: 2px; border-radius: 0 0 2px 2px; clip-path: polygon(50% 0, 100% 30%, 100% 100%, 0 100%, 0 30%); border: 0; filter: drop-shadow(0 0 1px #000); }
.gmarkers.top .gmark { bottom: 2px; clip-path: polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%); border: 0; filter: drop-shadow(0 0 1px #000); }
.gmark.sel { outline: 2px solid var(--accent); }
.gdetail { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--dim); }
.gdetail input[type=number] { width: 56px; }
.gdetail input[type=color] { width: 44px; height: 24px; padding: 0; border: 1px solid var(--line); }
.pixelmode { margin-left: auto; display: flex; align-items: center; gap: 6px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.pixelmode:hover { background: var(--hover); }
.pixelmode input { accent-color: var(--accent); }
.opt.locked { opacity: .35; pointer-events: none; }
.texteditor { position: absolute; z-index: 5; display: none; margin: 0; padding: 0; border: 0; outline: none; resize: none; overflow: hidden;
  background: transparent; color: transparent; -webkit-text-fill-color: transparent; box-shadow: 0 0 0 1px rgba(90,160,255,.9); }
.ppicker { display: flex; flex-direction: column; gap: 8px; }
.pgrid { display: flex; flex-wrap: wrap; gap: 6px; }
.pbtn { padding: 0; border: 2px solid transparent; border-radius: 3px; line-height: 0; }
.pbtn.sel { border-color: var(--accent); }
.pbtn:hover { border-color: var(--hover); }
.pthumb { width: 40px; height: 40px; background: #888; display: block; }
.resizedlg { width: 520px; max-width: 96vw; }
.resizedlg .fields { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.resizedlg .fxrow > span { width: 130px; }
.resizedlg input[type=number] { width: 110px; }
.resizedlg select { flex: 1; width: auto; }
.resizedlg .fxcheck { justify-content: flex-start; }
.resizedlg input[type=checkbox] { width: 15px; }
.rsinfo b { font-weight: 600; }
.rsresult { margin-top: 12px; min-height: 16px; }
.anchorgrid { display: grid; grid-template-columns: repeat(3, 30px); gap: 3px; }
.anc { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 3px; color: var(--dim); background: var(--panel2); }
.anc.sel { background: var(--accent); color: #fff; border-color: var(--accent); }
.animstage { display: flex; justify-content: center; padding: 10px; background: var(--panel2); }
.animcv { image-rendering: pixelated; border: 1px solid #000; cursor: pointer; max-width: 100%; }
.animctl { display: flex; justify-content: center; gap: 4px; padding: 6px 8px 0; }
.animctl button { min-width: 32px; height: 26px; border: 1px solid var(--line); border-radius: 3px; background: var(--panel2); }
.animctl button:hover { background: var(--hover); }
.animctl button.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 44px; }
.aninfo { text-align: center; color: var(--dim); font-size: 11px; padding: 6px 8px 2px; }
.animfields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; padding: 8px 10px 10px; align-items: center; }
.animfields label { display: flex; align-items: center; gap: 6px; color: var(--dim); min-width: 0; }
.animfields label input[type=number], .animfields label select { flex: 1; min-width: 0; width: 100%; }
.animfields label.chk { grid-column: 1 / -1; color: var(--text); }
.animfields label.chk input { width: auto; flex: none; accent-color: var(--accent); }
.animfields small { color: var(--dim); }
.animfields details { grid-column: 1 / -1; color: var(--dim); }
.animfields details summary { cursor: pointer; padding: 2px 0; }
.animfields.sub { padding: 6px 0 0; }
.lrow .folder.adj { font-size: 20px; color: var(--accent); }
.adjdlg { width: 480px; max-width: 96vw; }
.adjbody { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; max-height: 70vh; overflow-y: auto; }
.adjdlg .fxrow > span { width: 130px; flex: none; }
.adjdlg input[type=checkbox] { width: 15px; }
.curvecv { width: 256px; height: 256px; border: 1px solid #000; cursor: crosshair; align-self: center; touch-action: none; }
.gradbtn { width: 150px; height: 22px; border: 1px solid #000; border-radius: 3px; cursor: pointer; }
.gradpop { width: 300px; }
.menus { display: flex; }

.lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rename { flex: 1; min-width: 0; }
.badges { color: var(--dim); font-size: 11px; }
.badges i { font-style: normal; border: 1px solid var(--dim); border-radius: 2px; padding: 0 3px; margin-left: 3px; }
.lbtns { display: flex; justify-content: space-between; gap: 4px; padding: 8px; border-top: 1px solid var(--line); }
.lbtns button { flex: 1; height: 34px; display: grid; place-items: center; border-radius: 5px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); }
.lbtns button svg { width: 20px; height: 20px; }
.lbtns button:hover { background: var(--hover); }
.lbtns #lyDel:hover { color: #f87171; }

/* Modales & toast */
.modal-back { position: fixed; inset: 0; background: #0009; display: grid; place-items: center; z-index: 100; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 16px 18px; min-width: 340px; box-shadow: 0 20px 60px #000a; }
.modal h3 { margin: 0 0 12px; font-size: 14px; }
.modal .fields { display: flex; flex-direction: column; gap: 8px; }
.modal label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal input, .modal select { width: 170px; }
.modal .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal .btns button { padding: 6px 14px; border: 1px solid var(--line); border-radius: 4px; }
.modal .btns .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
#toast { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%) translateY(10px); background: #000c; padding: 8px 16px; border-radius: 6px; opacity: 0; transition: .2s; pointer-events: none; z-index: 200; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* Boîte « Options de fusion » : neutralise les règles génériques des modales */
.fxdlg label { justify-content: flex-start; }
.fxdlg input, .fxdlg select { width: auto; }
.fxdlg input[type=checkbox] { width: 15px; height: 15px; flex: none; margin: 0; }
.fxdlg .fxrow input[type=range] { flex: 1; min-width: 0; }
.fxdlg .fxrow input[type=number] { width: 56px; flex: none; }
.fxdlg .fxrow select { flex: 1; min-width: 0; }
.fxdlg .fxrow input[type=color] { width: 48px; flex: none; }
.fxitem > span { flex: 1; text-align: left; }
.fxpane { overflow-x: hidden; }

[hidden] { display: none !important; }
.toolsbox { display: flex; flex-direction: column; align-items: center; gap: 3px; }
#paletteBody { padding: 8px 10px 10px; }
.colorpop { position: fixed; left: 54px; bottom: 36px; z-index: 70; width: 252px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 10px 30px #000a; padding-bottom: 10px; }
.colorpop .cphead { padding: 8px 10px 0; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.colorpop .palette { padding: 0 10px; }
.prefsdlg { width: 560px; max-width: 96vw; }
.prefsbody { max-height: 66vh; overflow-y: auto; padding-right: 4px; }
.prefrow { display: flex; align-items: center; gap: 8px; padding: 3px 2px; justify-content: flex-start; cursor: pointer; }
.prefrow input { width: 15px; height: 15px; flex: none; accent-color: var(--accent); }
.prefrow small { color: var(--dim); }
.ticon { display: inline-block; width: 18px; height: 18px; margin-right: 8px; vertical-align: middle; color: var(--dim); }
.ticon svg { width: 18px; height: 18px; }
.toolchecks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.prefsdlg .prefrow { justify-content: flex-start; }
.prefsdlg input[type=checkbox] { width: 15px; }
