:root {
  --bg: #1b1c1f; --stage: #232428; --panel: #2a2b30; --panel2: #34353b; --line: #3e3f46;
  --text: #e8e8ea; --dim: #9c9da4; --accent: #4aa3ff; --accent2: #2a6fc0; /* accent2 keeps white text at 5:1 contrast (WCAG AA) */ --warn: #ff9a57;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 13px/1.35 "Segoe UI", system-ui, sans-serif;
  display: grid; grid-template-columns: 1fr 330px; grid-template-rows: 44px 1fr 26px; overflow: hidden;
  user-select: none;
}
button, select, input[type=number], input[type=text] {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 4px;
  padding: 5px 10px; font: inherit;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
button.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
input[type=text], input[type=number] { user-select: text; cursor: text; }
input:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible,
#layerList li:focus-visible, #recentList li:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#layerList li:focus-visible { outline-offset: -2px; }

/* toolbar */
#toolbar { grid-column: 1 / 3; display: flex; align-items: center; gap: 14px; padding: 0 10px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.tgroup { display: flex; align-items: center; gap: 4px; }
.tgroup + .tgroup { padding-left: 14px; border-left: 1px solid var(--line); }
#zoomLabel { min-width: 52px; text-align: center; color: var(--dim); font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }

/* stage */
#stage { position: relative; overflow: auto; background: var(--stage); display: grid; place-items: center; }
#canvasWrap { position: relative; margin: 24px; box-shadow: 0 6px 40px rgba(0,0,0,.55); line-height: 0;
  background: repeating-conic-gradient(#2c2d31 0% 25%, #26272b 0% 50%) 50% / 16px 16px; }
#view { display: block; image-rendering: auto; }
#view.pixelated { image-rendering: pixelated; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#overlay.active { pointer-events: auto; }
#overlay.crop { cursor: crosshair; }
#badge { position: absolute; top: 14px; left: 14px; background: rgba(0,0,0,.65); padding: 3px 9px;
  border-radius: 3px; font-size: 11px; letter-spacing: .6px; }
#busy { position: absolute; bottom: 14px; left: 14px; background: rgba(0,0,0,.7); padding: 5px 12px; border-radius: 4px; }
#cropbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center;
  gap: 8px; background: rgba(30,31,35,.94); border: 1px solid var(--line); padding: 6px 10px; border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,.4); z-index: 5; }
#cropSize { color: var(--dim); min-width: 110px; font-variant-numeric: tabular-nums; }

/* welcome */
#welcome { text-align: center; max-width: 520px; padding: 24px; }
#welcome #logo { display: block; margin: 0 auto 10px; opacity: .95; }
#welcome h1 { font-size: 22px; font-weight: 300; margin: 0 0 6px; letter-spacing: 8px; padding-left: 8px; }
.dialog.wide { width: min(860px, 94vw); }
.printgrid { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
#pPrev { background: #17181a; border-radius: 6px; width: 380px; height: 400px; display: block; }
.printgrid .field { grid-template-columns: 96px 1fr !important; }
#pInfo { margin-top: 10px; line-height: 1.5; }
#welcome .sub { color: var(--dim); margin: 0 0 26px; }
#welcome .hint { color: var(--dim); font-size: 12px; }
button.big { padding: 10px 22px; font-size: 14px; }
#recentWrap { margin-top: 30px; text-align: left; }
#recentWrap h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); font-weight: 600; }
#recentList { list-style: none; padding: 0; margin: 0; }
#recentList li { padding: 6px 10px; border-radius: 4px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#recentList li:hover { background: var(--panel2); }
#recentList li small { color: var(--dim); margin-left: 8px; }
body.dragging #stage { outline: 2px dashed var(--accent); outline-offset: -10px; }

/* panel */
#panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
details { border-bottom: 1px solid var(--line); }
summary { padding: 9px 12px; cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 6px; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸"; color: var(--dim); width: 10px; }
details[open] > summary::before { content: "▾"; }
summary .reset { margin-left: auto; font-size: 11px; padding: 1px 7px; font-weight: 400; }
details.flash > summary { background: var(--panel2); }
.body { padding: 0 12px 12px; }
.row { display: grid; grid-template-columns: 86px 1fr 50px; align-items: center; gap: 8px; margin: 5px 0; }
.row label { color: var(--dim); }
.row label[title]:hover { color: var(--text); }
.row output { text-align: right; font-variant-numeric: tabular-nums; }
.row input[type=number] { width: 100%; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.btns, .seg, .chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.btns button, .seg button { flex: 1; }
.chips button { padding: 3px 9px; font-size: 12px; }
.chips .user { display: inline-flex; gap: 0; }
.chips .user button:first-child { border-radius: 4px 0 0 4px; }
.chips .user button:last-child { border-radius: 0 4px 4px 0; border-left: 0; padding: 3px 6px; color: var(--dim); }
#hist { width: 100%; height: 80px; background: #17181a; border-radius: 3px; display: block; }
.ramp { height: 7px; border-radius: 2px; background: linear-gradient(90deg, #000, #fff); margin: 3px 0 8px; }
#zones { display: grid; grid-template-columns: repeat(11, 1fr); gap: 2px; height: 34px; align-items: end; }
#zones div { background: var(--accent); opacity: .75; border-radius: 1px; min-height: 1px; position: relative; }
#zones div span { position: absolute; bottom: -15px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--dim); }
#statLine { margin-top: 20px; }
.note { color: var(--dim); font-size: 11.5px; margin: 4px 0; }
.warn { color: var(--warn); }

/* status */
#status { grid-column: 1 / 3; display: flex; gap: 18px; align-items: center; padding: 0 12px;
  background: var(--panel); border-top: 1px solid var(--line); color: var(--dim); font-size: 11.5px; white-space: nowrap; }

/* modal + toast */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 20; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px;
  width: min(560px, 92vw); box-shadow: 0 10px 50px rgba(0,0,0,.6); }
.dialog h3 { margin: 0 0 12px; font-size: 15px; }
#mBody { color: var(--text); }
#mBody p { margin: 0 0 10px; }
#mBody input[type=text] { width: 100%; }
#mBody .field { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; margin: 8px 0; }
#mBody .field > span.v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); }
#mBody .pick { display: flex; gap: 6px; align-items: center; min-width: 0; }
#mBody .pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); }
#mBody kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; font: 11px Consolas, monospace; }
#mBody table { width: 100%; border-collapse: collapse; }
#mBody td { padding: 3px 4px; }
progress { width: 100%; height: 10px; accent-color: var(--accent); }
#batchLog { max-height: 140px; overflow-y: auto; font: 11.5px Consolas, monospace; color: var(--dim); margin-top: 8px; user-select: text; }
#mButtons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toast { position: fixed; right: 16px; bottom: 40px; background: #111214; border: 1px solid var(--line);
  border-radius: 6px; padding: 9px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 30; display: flex; gap: 12px; align-items: center; }
#toast button { padding: 2px 8px; font-size: 12px; }

/* icons (inline SVG, stroke = text color) */
.ico { display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.ico svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.scope { margin-left: 2px; font-size: 10px; font-weight: 400; color: var(--dim); text-transform: uppercase; letter-spacing: .5px;
  border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; }
.count { font-size: 11px; font-weight: 400; color: var(--dim); }

/* canvas: layer drop hint */
body.has-doc.dragging #stage::after { content: "Drop to add as a new layer"; position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  background: var(--accent2); color: #fff; padding: 6px 14px; border-radius: 14px; pointer-events: none; z-index: 6; }

/* layers panel */
.lprops { display: grid; grid-template-columns: 1fr auto 90px 34px; gap: 6px; align-items: center; margin: 2px 0 8px; }
.lprops label { color: var(--dim); }
.lprops select { padding: 4px 6px; min-width: 0; }
.lprops output { text-align: right; font-variant-numeric: tabular-nums; }
#layerList { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: #222327;
  max-height: 248px; overflow-y: auto; }
#layerList li { position: relative; display: grid; grid-template-columns: 28px 46px 1fr 28px; align-items: center; gap: 6px;
  padding: 4px 6px 4px 4px; border-bottom: 1px solid #2f3035; cursor: pointer; min-height: 44px; }
#layerList li:last-child { border-bottom: 0; }
#layerList li:hover { background: #2b2c31; }
#layerList li.sel { background: rgba(74,163,255,.20); box-shadow: inset 3px 0 0 var(--accent); }
#layerList li.sel .lname { color: #fff; font-weight: 600; }
#layerList li.off .thumb, #layerList li.off .lname { opacity: .45; }
#layerList li.dragging { opacity: .55; }
#layerList li.drop-above::before, #layerList li.drop-below::after { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); }
#layerList li.drop-above::before { top: -1px; } #layerList li.drop-below::after { bottom: -1px; }
#layerList .thumb { width: 46px; height: 34px; border-radius: 2px; border: 1px solid #44454c;
  background: repeating-conic-gradient(#3a3b40 0% 25%, #2c2d31 0% 50%) 50% / 8px 8px; }
#layerList li.sel .thumb { border-color: var(--accent); }
#layerList .lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#layerList .lname small { display: block; color: var(--dim); font-size: 10.5px; font-weight: 400; }
#layerList .lname input { width: 100%; padding: 2px 4px; }
#layerList li button { background: none; border: 1px solid transparent; padding: 3px; color: var(--dim); display: grid; place-items: center; }
#layerList li button:hover { border-color: var(--line); color: var(--text); }
#layerList li button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#layerList li button.eye { color: var(--text); }
#layerList li.off button.eye { color: var(--dim); }
#layerList li button.lock.on { color: var(--warn); }
#layerList li button.lock:not(.on) { opacity: .35; }
#layerList li:hover button.lock:not(.on) { opacity: 1; }
#layerHint { margin: 6px 2px 0; }
.lbar { display: flex; gap: 4px; margin-top: 8px; align-items: center; }
.lbar button { padding: 5px 7px; }
.lbar button span { font-size: 12px; }
.lbar button.danger:hover:not(:disabled) { border-color: var(--warn); color: var(--warn); }

/* "adjustments apply to" bar: stays visible while scrolling the adjustment panels */
#target { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 10px; padding: 7px 12px;
  background: #23344a; border-bottom: 1px solid var(--accent2); box-shadow: inset 3px 0 0 var(--accent); }
#target canvas { width: 32px; height: 24px; border-radius: 2px; border: 1px solid var(--accent);
  background: repeating-conic-gradient(#3a3b40 0% 25%, #2c2d31 0% 50%) 50% / 8px 8px; }
#target div { display: flex; flex-direction: column; min-width: 0; }
#target small { color: #a9c8ec; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; }
#target b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
#target.flash { background: #2f5785; transition: background .1s; }

/* transform panel */
.txgrid { display: grid; grid-template-columns: 42px 1fr 20px 1fr; gap: 6px 8px; align-items: center; margin: 4px 0 6px; }
.txgrid label { color: var(--dim); }
.txgrid input { width: 100%; padding: 4px 6px; }
.txgrid label[for=tR] { grid-column: 1; }
.txgrid #tR { grid-column: 2; }
.txgrid #tLink { grid-column: 4; justify-self: start; padding: 3px 6px; }
.txgrid #tLink:not(.on) { opacity: .5; }
#panel input:disabled, #panel select:disabled { opacity: .45; }

/* ---------- web build: in-page menu bar (the desktop app uses the native menu) ---------- */
body.web { grid-template-rows: 28px 44px 1fr 26px; }
#menubar { grid-column: 1 / 3; display: flex; align-items: stretch; gap: 0; padding: 0 6px; background: var(--bg);
  border-bottom: 1px solid var(--line); }
#menubar button.top { background: none; border: 0; border-radius: 3px; padding: 0 10px; margin: 3px 0; color: var(--text); }
#menubar button.top:hover, #menubar button.top.open { background: var(--panel2); }
#menubar .ver { margin-left: auto; align-self: center; color: var(--dim); font-size: 11px; padding-right: 6px; }
ul.menu { position: fixed; z-index: 40; list-style: none; margin: 0; padding: 4px; min-width: 240px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 30px rgba(0,0,0,.55); }
ul.menu li { position: relative; }
ul.menu li.sep { height: 1px; margin: 4px 6px; background: var(--line); }
ul.menu button { width: 100%; display: flex; justify-content: space-between; gap: 24px; background: none; border: 0; border-radius: 4px;
  padding: 5px 10px; text-align: left; color: var(--text); white-space: nowrap; }
ul.menu button:hover:not(:disabled), ul.menu button:focus-visible { background: var(--accent2); color: #fff; outline: none; }
ul.menu button .k { color: var(--dim); font-size: 12px; }
ul.menu button:hover .k, ul.menu button:focus-visible .k { color: #e6efff; }
ul.menu ul.sub { display: none; position: absolute; left: 100%; top: -5px; max-width: 420px; }
ul.menu ul.sub button .l { overflow: hidden; text-overflow: ellipsis; }
ul.menu li.has-sub:hover > ul.sub, ul.menu li.has-sub.show > ul.sub { display: block; }
#welcome .privacy { color: var(--dim); font-size: 12px; margin: 26px auto 6px; max-width: 440px; line-height: 1.5; }
#welcome .weblinks { font-size: 12px; margin: 0; }
a { color: var(--accent); }
#mBody .links { margin: 4px 0 10px; }
