@layer components {
  /* ---------- buttons ---------- */
  .btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--line); background: var(--bg-3); border-radius: var(--r-md); transition: background .12s, border-color .12s; white-space: nowrap; }
  .btn:hover:not(:disabled) { background: var(--bg-4); }
  .btn:disabled { opacity: .4; }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
  .btn.primary:hover:not(:disabled) { background: var(--accent-2); }
  .btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
  .btn.ghost:hover:not(:disabled) { background: var(--bg-3); color: var(--text); }
  .btn.icon { width: 30px; padding: 0; justify-content: center; }
  .btn.small { height: 24px; padding: 0 8px; font-size: 12px; }
  .btn.big { height: 44px; padding: 0 20px; font-size: 14px; }
  .btn.danger:hover:not(:disabled) { color: var(--danger); }
  .ico { display: block; flex: none; }

  /* ---------- menus ---------- */
  .menubar { display: flex; gap: 2px; }
  .menu { position: relative; }
  .menu-btn { height: 30px; padding: 0 10px; background: transparent; border: 0; border-radius: var(--r-md); color: var(--text); }
  .menu-btn:hover, .menu.open .menu-btn { background: var(--bg-4); }
  .dropdown { width: max-content; position: absolute; top: calc(100% + 4px); left: 0; min-width: 240px; margin: 0; padding: 4px; list-style: none; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow); z-index: 60; }
  .dropdown li { position: relative; }
  .dropdown hr { margin: 4px 0; }
  .mi { white-space: nowrap; display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); width: 100%; height: 28px; padding: 0 10px; background: transparent; border: 0; border-radius: var(--r-sm); text-align: left; }
  .mi:hover:not(:disabled) { background: var(--accent); color: var(--accent-text); }
  .mi:hover:not(:disabled) kbd { color: inherit; background: transparent; border-color: currentColor; }
  .mi:disabled { color: var(--text-dim); opacity: .55; }
  .subwrap > .subdrop { display: none; top: -5px; left: calc(100% - 2px); }
  .subwrap:hover > .subdrop, .subwrap:focus-within > .subdrop { display: block; }
  .chev { display: inline-flex; opacity: .7; }

  /* ---------- toolbar ---------- */
  .tool { width: 38px; height: 36px; display: grid; place-items: center; background: transparent; border: 1px solid transparent; border-radius: var(--r-md); color: var(--text-dim); }
  .tool:hover { background: var(--bg-3); color: var(--text); }
  .tool.active { background: color-mix(in srgb, var(--accent) 22%, transparent); border-color: var(--accent); color: var(--text); }
  .colors { position: relative; width: 40px; height: 52px; margin-top: var(--s-3); flex: none; }
  .swatch { position: absolute; display: block; width: 26px; height: 26px; border-radius: var(--r-sm); border: 2px solid var(--bg-2); outline: 1px solid var(--line); cursor: pointer; overflow: hidden; }
  .swatch input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }
  .fgsw { left: 0; top: 0; z-index: 2; } .bgsw { left: 12px; top: 14px; }
  .swap { position: absolute; right: -4px; top: -4px; width: 18px; height: 18px; display: grid; place-items: center; background: var(--bg-3); border: 1px solid var(--line); border-radius: 50%; padding: 0; color: var(--text-dim); z-index: 3; }
  .swatch.sm { position: static; width: 18px; height: 18px; flex: none; }

  /* ---------- tool options container ---------- */
  .tool-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .opts { display: grid; gap: 8px; min-width: 0; }
  .opt { display: grid; grid-template-columns: 84px minmax(0, 1fr); align-items: center; gap: 8px; }
  .opt.t-note, .opt.t-checkbox, .opt.t-textarea { grid-template-columns: 1fr; }
  .opts textarea { width: 100%; min-height: 70px; resize: vertical; }
  .opt-label { color: var(--text-dim); font-size: 12px; }
  .note { color: var(--text-dim); font-size: 12px; }
  .rangebox { display: inline-flex; align-items: center; gap: 6px; }
  .rangebox output { min-width: 30px; text-align: right; font: 12px var(--mono); color: var(--text-dim); }
  .opts input[type=range] { flex: 1; min-width: 0; width: 100%; }
  .opts .rangebox { display: flex; width: 100%; }
  .opts input.num, .opts select { width: 100%; }
  .check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

  /* ---------- form controls ---------- */
  input[type=text], input[type=number], select, textarea { background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 4px 8px; min-height: 28px; }
  input[type=text]:focus, input[type=number]:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
  input.num { width: 64px; } input.num.wide { width: 120px; }
  textarea { width: 100%; resize: vertical; font-family: var(--font); }
  input[type=color] { width: 44px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--bg-3); cursor: pointer; }
  input[type=range] { accent-color: var(--accent); height: 20px; margin: 0; }
  input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
  select { max-width: 220px; }
  .opts select { max-width: none; }

  /* ---------- tabs ---------- */
  .tab { display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px; max-width: 220px; background: var(--bg-3); border: 1px solid var(--line); border-bottom: 0; border-radius: var(--r-md) var(--r-md) 0 0; color: var(--text-dim); cursor: pointer; }
  .tab.active { background: var(--stage); color: var(--text); }
  .tname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
  .tx { display: grid; place-items: center; width: 20px; height: 20px; border: 0; background: transparent; border-radius: 50%; color: inherit; padding: 0; }
  .tx:hover { background: var(--bg-4); }
  .tab-new { width: 28px; height: 28px; border: 0; background: transparent; color: var(--text-dim); border-radius: var(--r-md); display: grid; place-items: center; padding: 0; margin-bottom: 2px; }
  .tab-new:hover { background: var(--bg-3); color: var(--text); }

  /* ---------- panels ---------- */
  .panel { border-bottom: 1px solid var(--line); }
  .panel > header { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 var(--s-3); font-weight: 600; cursor: pointer; user-select: none; color: var(--text-dim); }
  .panel > header:hover { color: var(--text); }
  .panel-body { padding: var(--s-2) var(--s-3) var(--s-3); }
  .hsl { display: grid; gap: 4px; }
  .hsl label { display: grid; grid-template-columns: 14px auto minmax(0, 1fr) auto; align-items: center; gap: 6px; color: var(--text-dim); }
  .hsl input[type=range] { width: 100%; }
  input.hue { background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); border-radius: 10px; -webkit-appearance: none; appearance: none; height: 8px; }
  input.hue::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid #333; }
  input.hue::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid #333; }
  .hexrow { display: flex; align-items: center; gap: 6px; margin: var(--s-2) 0; }
  .hex { width: 76px; font-family: var(--mono); }
  .swatches { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 6px; align-items: center; }
  .sw { width: 18px; height: 18px; border: 1px solid var(--line); border-radius: 3px; padding: 0; }
  .sw:hover { transform: scale(1.2); }

  .layer-props { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s-2); }
  .layer-props select { max-width: none; width: 100%; }
  .layer-props .rangebox input { flex: 1; }
  .layers { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 80px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
  .layer { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
  .layer:hover { background: var(--bg-3); }
  .layer.active { background: color-mix(in srgb, var(--accent) 24%, transparent); }
  .layer.hidden .lname, .layer.hidden .thumb { opacity: .45; }
  .layer.drop-here { box-shadow: inset 0 2px 0 var(--accent); }
  .eye, .lock { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; background: transparent; color: var(--text-dim); border-radius: var(--r-sm); }
  .eye:hover, .lock:hover { color: var(--text); background: var(--bg-4); }
  .lock { opacity: .35; } .lock.on { opacity: 1; color: var(--accent); }
  .thumb { width: 34px; height: 28px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 3px; background: repeating-conic-gradient(#fff 0 25%, #cfd3da 0 50%) 0 0 / 8px 8px; overflow: hidden; }
  .thumb img { max-width: 100%; max-height: 100%; display: block; }
  .thumb.mask { background: var(--bg-3); color: var(--text-dim); }
  .thumb.mask.editing { outline: 2px solid var(--accent); color: var(--accent); }
  .lname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lname input { width: 100%; min-height: 24px; }
  .layer-actions { display: flex; gap: 4px; margin-top: var(--s-2); flex-wrap: wrap; }

  .history { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg); }
  .history li { padding: 3px 10px; cursor: pointer; color: var(--text-dim); border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
  .history li:hover { background: var(--bg-3); }
  .history li.current { background: color-mix(in srgb, var(--accent) 24%, transparent); color: var(--text); }
  .histogram { width: 100%; height: 64px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); }
  .histogram polyline { fill: none; stroke-width: 1; vector-effect: non-scaling-stroke; mix-blend-mode: screen; }
  .hr { stroke: #ff5a5a; } .hg { stroke: #4cd08f; } .hb { stroke: #5b8cff; }

  /* ---------- status ---------- */
  .chip { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); display: inline-block; }
  .zoomctl input[type=range] { width: 110px; }
  .zoomctl .btn.icon { width: 24px; height: 24px; }

  /* ---------- welcome / overlays ---------- */
  .welcome { position: absolute; inset: 0; display: grid; place-items: center; padding: var(--s-4); overflow: auto; }
  .welcome-card { width: min(650px, 100%); padding: var(--s-5); background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); display: grid; gap: var(--s-3); text-align: center; }
  .welcome-card h1 { font-size: 30px; color: var(--accent); }
  .welcome-card .row { display: flex; gap: var(--s-3); justify-content: center; flex-wrap: wrap; }
  .welcome-card .row .btn { width: 140px; justify-content: center; }   /* New image and Open… the same width */
  .restore { text-align: left; border-top: 1px solid var(--line); padding-top: var(--s-3); display: grid; gap: var(--s-2); }
  .restore h2 { font-size: 14px; }
  /* one row per image: thumbnail | name and details | Restore | Discard (the buttons line up in columns, side by side) */
  .restore-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) 84px 84px; align-items: center; gap: var(--s-3); padding: 4px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg-3); }
  .restore .btn { width: 84px; height: 32px; min-height: 32px; padding: 0 8px; font-size: 13px; justify-content: center; }   /* every button here: same size */
  .restore-info { min-width: 0; }
  .restore-info .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .restore-info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .restore-thumb { width: 72px; height: 54px; display: grid; place-items: center; overflow: hidden; border-radius: var(--r-sm); background: repeating-conic-gradient(#d6d9df 0 25%, #fff 0 50%) 0 0 / 10px 10px; }
  .restore-thumb img { max-width: 100%; max-height: 100%; display: block; }
  .dropzone, .busy { position: absolute; inset: 12px; display: grid; place-items: center; border: 3px dashed var(--accent); border-radius: var(--r-lg); background: color-mix(in srgb, var(--accent) 14%, transparent); font-size: 18px; font-weight: 600; pointer-events: none; }
  .busy { inset: auto 12px 12px auto; padding: 8px 14px; border: 0; background: var(--bg-2); box-shadow: var(--shadow); border-radius: var(--r-md); font-size: 13px; }

  .overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: var(--s-4); background: rgba(5, 8, 14, .18); }
  .overlay.top { place-items: start center; padding-top: 12vh; }
  .dialog { width: max-content; max-width: 100%; max-height: 90vh; overflow: auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: var(--s-4) var(--s-5) var(--s-4); display: grid; gap: var(--s-3); }
  .dialog h2 { font-size: 16px; }
  .dialog .msg:not(.pre) { max-width: 56ch; }
  .field label, .field > span { overflow-wrap: normal; }
  .field select { text-overflow: clip; }
  .dialog h2.dlg-handle { cursor: move; user-select: none; touch-action: none; }
  .msg { color: var(--text-dim); white-space: pre-line; }
  .msg.pre { font: 12px/1.5 var(--mono); white-space: pre; overflow: auto; max-height: 55vh; color: var(--text); background: var(--bg); padding: var(--s-3); border-radius: var(--r-md); }
  .fields { display: grid; gap: var(--s-3); }
  .field { display: grid; grid-template-columns: 150px 1fr; gap: var(--s-3); align-items: center; }
  .field.ft-checkbox, .field.ft-textarea { grid-template-columns: 1fr; }
  .field .rangebox { width: 100%; } .field .rangebox input[type=range] { flex: 1; }
  .field select, .field input[type=text] { width: 100%; max-width: none; }
  .info { font-size: 12px; color: var(--accent); }
  .dlg-buttons { display: flex; gap: var(--s-2); padding-top: var(--s-2); }
  .anchor { display: grid; grid-template-columns: repeat(3, 26px); gap: 3px; }
  .anchor button { width: 26px; height: 26px; border: 1px solid var(--line); background: var(--bg-3); border-radius: 4px; padding: 0; }
  .anchor button.on { background: var(--accent); border-color: var(--accent); }
  .matrix { display: grid; gap: 3px; } .matrix input { width: 100%; min-width: 0; padding: 2px 4px; text-align: center; }
  @media (max-width: 520px) { .field { grid-template-columns: 1fr; gap: 4px; } }

  .palette { width: min(560px, 100%); background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
  .palette input { width: 100%; height: 46px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: 0 var(--s-4); font-size: 15px; }
  .palette ul { list-style: none; margin: 0; padding: 4px; max-height: 50vh; overflow-y: auto; }
  .palette li { display: flex; justify-content: space-between; gap: var(--s-3); padding: 8px 12px; border-radius: var(--r-sm); cursor: pointer; }
  .palette li.sel { background: var(--accent); color: var(--accent-text); }
  .palette li.sel kbd { color: inherit; border-color: currentColor; background: transparent; }
  .palette li.off { opacity: .45; }

  .toasts { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); display: grid; gap: 6px; z-index: 100; pointer-events: none; }
  .toast { background: var(--bg-2); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: var(--r-md); padding: 8px 16px; animation: toast-in .18s ease; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
}

  .autosave-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text-dim); user-select: none; }
  .autosave-toggle:hover { color: var(--text); }

  /* width:0 + min-width:100% keeps the canvas (whose pixel size changes as it is drawn) out of the dialog's content-based width */
  .dlg-pane { display: grid; gap: 4px; width: 0; min-width: 100%; }
  .pane-canvas { width: 100%; max-width: 100%; height: 210px; display: block; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--stage); cursor: grab; touch-action: none; }
  .pane-canvas:active { cursor: grabbing; }
  .pane-bar { display: flex; align-items: center; gap: 6px; }

  /* ◀ ▶ buttons added beside every slider by ui/rangeSteppers.js */
  .step-btn { flex: none; display: inline-grid; place-items: center; width: 18px; height: 20px; padding: 0; border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--text-dim); cursor: pointer; }
  .step-btn:hover { background: var(--bg-4); color: var(--text); border-color: var(--line); }
  .step-btn:active { background: var(--accent); color: var(--accent-text); }
  .step-btn.left svg { transform: scaleX(-1); }
  .step-btn svg { display: block; }

  /* ---------- recent files (welcome screen) ---------- */
  .recent-files { display: grid; gap: var(--s-2); text-align: left; }
  .recent-head { display: flex; align-items: center; justify-content: space-between; }
  .recent-head h2 { font-size: 14px; }
  .recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--s-2); max-height: 280px; overflow: auto; padding: 2px; }
  .recent-card { position: relative; }
  .recent-open { display: grid; gap: 2px; justify-items: center; width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--bg-3); text-align: center; cursor: pointer; }
  .recent-open:hover { background: var(--bg-4); border-color: var(--accent); }
  .recent-thumb { width: 96px; height: 72px; object-fit: contain; background: repeating-conic-gradient(#d6d9df 0 25%, #fff 0 50%) 0 0 / 10px 10px; border-radius: var(--r-sm); }
  .recent-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }
  .recent-x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px; padding: 0; border: 0; border-radius: 50%; background: var(--bg-2); color: var(--text-dim); cursor: pointer; opacity: 0; }
  .recent-card:hover .recent-x, .recent-x:focus { opacity: 1; }
  .recent-x:hover { background: var(--danger, #c0392b); color: #fff; }

  .colour-readout { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; padding: 0 4px; border-radius: var(--r-sm); min-width: 17em; }
  .colour-readout:hover { background: var(--bg-3); }
  .colour-readout .fmt { font-size: 10px; font-weight: 700; padding: 1px 4px; border-radius: 3px; background: var(--bg-4); color: var(--text-dim); }

  /* ---------- tool help cards ---------- */
  .tool-help-btn { width: 24px; height: 24px; font-weight: 700; margin-right: var(--s-2); }
  .tool-help { position: fixed; z-index: 70; width: 300px; max-width: calc(100vw - 80px); padding: var(--s-3) var(--s-4); background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); display: grid; gap: 6px; pointer-events: none; font-size: 13px; }
  .tool-help.pinned { pointer-events: auto; }
  .tool-help h3 { font-size: 14px; display: flex; align-items: center; gap: 8px; }
  .tool-help p { color: var(--text); line-height: 1.4; margin: 0; }
  .tool-help ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
  .tool-help li { display: grid; grid-template-columns: minmax(70px, auto) 1fr; gap: 8px; align-items: baseline; color: var(--text-dim); font-size: 12px; }
  .tool-help kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg-3); color: var(--text); white-space: normal; }
  .tool-help-x { position: absolute; top: 4px; right: 6px; border: 0; background: transparent; color: var(--text-dim); font-size: 18px; cursor: pointer; }

  /* ---------- MDI windows (windowed images): narrow border, slim title bar ---------- */
  .mdi { position: absolute; inset: 0; overflow: hidden; isolation: isolate; z-index: 0; background: var(--stage); }
  .mdi[hidden] { display: none; }
  .mdi-win { position: absolute; display: flex; flex-direction: column; background: var(--stage); border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0, 0, 0, .25); min-width: 0; min-height: 0; }
  .mdi-win.active { border-color: var(--accent); }
  .mdi-title { flex: none; height: 20px; display: flex; align-items: center; gap: 4px; padding: 0 2px 0 6px; background: var(--bg-3); color: var(--text-dim); font-size: 11px; user-select: none; touch-action: none; cursor: default; }
  .mdi-win.active .mdi-title { background: var(--accent); color: var(--accent-text); }
  .mdi-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mdi-win { container-type: inline-size; }
  .mdi-keys { flex: none; margin-right: 6px; font-size: 10px; opacity: .75; white-space: nowrap; }
  .mdi-win.minimised .mdi-keys { display: none; }
  @container (max-width: 640px) { .mdi-keys { display: none; } }
  .mdi-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
  .mdi-btns { display: flex; gap: 1px; flex: none; }
  .mdi-b { width: 18px; height: 16px; padding: 0; border: 0; border-radius: 2px; background: transparent; color: inherit; font-size: 12px; line-height: 14px; cursor: pointer; }
  .mdi-b:hover { background: rgba(255, 255, 255, .25); }
  .mdi-b.close:hover { background: #d33; color: #fff; }
  .mdi-body { position: relative; flex: 1; min-height: 0; }
  .mdi-body canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
  .mdi-win.minimised .mdi-body, .mdi-win.minimised .mdi-rz { display: none; }
  .mdi-win.maximised .mdi-rz { display: none; }
  .mdi-rz { position: absolute; z-index: 5; }
  .mdi-rz.n { top: -3px; left: 8px; right: 8px; height: 6px; cursor: ns-resize; } .mdi-rz.s { bottom: -3px; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
  .mdi-rz.e { right: -3px; top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; } .mdi-rz.w { left: -3px; top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
  .mdi-rz.ne { top: -3px; right: -3px; width: 10px; height: 10px; cursor: nesw-resize; } .mdi-rz.sw { bottom: -3px; left: -3px; width: 10px; height: 10px; cursor: nesw-resize; }
  .mdi-rz.nw { top: -3px; left: -3px; width: 10px; height: 10px; cursor: nwse-resize; } .mdi-rz.se { bottom: -3px; right: -3px; width: 10px; height: 10px; cursor: nwse-resize; }

  /* MDI window: rounded corners (the resize handles sit just outside the border, so the clipping is done per child) */
  .mdi-win { border-radius: 7px; }
  .mdi-title { border-radius: 6px 6px 0 0; }
  .mdi-win.minimised .mdi-title { border-radius: 6px; }
  .mdi-body { border-radius: 0 0 6px 6px; overflow: hidden; }
  /* narrow overlay scrollbars, shown only when part of the picture is outside the window */
  .sb { position: absolute; z-index: 4; background: rgba(0, 0, 0, .06); }
  .sb[hidden] { display: none; }
  .sb-x { left: 0; right: 0; bottom: 0; height: 8px; } .sb-y { top: 0; bottom: 0; right: 0; width: 8px; }
  .sb-thumb { position: absolute; background: rgba(110, 120, 140, .55); border-radius: 4px; cursor: default; }
  .sb-x .sb-thumb { top: 1px; bottom: 1px; } .sb-y .sb-thumb { left: 1px; right: 1px; }
  .sb-thumb:hover, .sb-thumb.on { background: rgba(110, 120, 140, .85); }

  /* reorderable side panels */
  .panel > header { cursor: grab; }
  .panel > header:active { cursor: grabbing; }
  .panel > header .grip { color: var(--text-dim); opacity: .55; letter-spacing: -2px; font-size: 12px; margin-right: 2px; user-select: none; }
  .panel > header:hover .grip { opacity: 1; }
  .panel.drop-before { box-shadow: 0 -3px 0 0 var(--accent); }
  .panel.drop-after { box-shadow: 0 3px 0 0 var(--accent); }

  /* ---------- Combine images dialog ---------- */
  .combine-host[hidden] { display: none; }
  .cb-host { display: grid; gap: 6px; }
  .cb-bar { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
  .cb-spacer { flex: 1; }
  .cb-area { position: relative; height: 340px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--stage); touch-action: none; user-select: none;
    background-image: radial-gradient(circle, rgba(128, 128, 128, .35) 1px, transparent 1.5px); background-size: 16px 16px; }
  .cb-item { position: absolute; box-sizing: border-box; border: 1px solid var(--accent); background: #fff; cursor: grab; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
  .cb-item.drag { cursor: grabbing; box-shadow: 0 5px 16px rgba(0, 0, 0, .45); }
  .cb-thumb { width: 100%; height: 100%; display: block; pointer-events: none; }
  .cb-label { position: absolute; left: 0; right: 0; bottom: 0; padding: 1px 5px; font-size: 10px; background: rgba(0, 0, 0, .55); color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
  .cb-x { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; line-height: 17px; cursor: pointer; }
  .cb-item.off { opacity: .35; filter: grayscale(1); }
  .cb-frame { position: absolute; z-index: 5000; border: 2px dashed var(--accent); pointer-events: none; box-sizing: border-box; }
  .cb-frame[hidden] { display: none; }
  .cb-frame-label { position: absolute; top: -19px; left: -2px; padding: 0 6px; border-radius: 3px; background: var(--accent); color: var(--accent-text); font-size: 11px; white-space: nowrap; }

  /* floating tool options: sits against the left edge of the side panels (follows their width) until the user drags it */
  .tool-options { position: fixed; z-index: 40; width: 300px; max-width: calc(100vw - 16px); max-height: calc(100vh - var(--bar-h) - 48px); overflow-y: auto; display: grid; gap: var(--s-2); padding: 0 var(--s-3) var(--s-3);
    background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); right: calc(var(--dock-w) + 14px); top: calc(var(--bar-h) + 8px); }
  .tool-options[hidden] { display: none; }
  .to-head { display: flex; align-items: center; gap: 6px; margin: 0 calc(-1 * var(--s-3)); padding: 6px var(--s-3); border-bottom: 1px solid var(--line); border-radius: var(--r-lg) var(--r-lg) 0 0; background: var(--bg-3); cursor: move; user-select: none; touch-action: none; position: sticky; top: 0; z-index: 1; }
  .to-grip { color: var(--text-dim); opacity: .6; letter-spacing: -2px; font-size: 12px; }
  .to-apply { width: 100%; justify-content: center; }
  @media (max-width: 920px) { .tool-options { right: 8px; } }

  .to-close { width: 24px; height: 24px; font-size: 16px; line-height: 1; }

  .restore-head { display: flex; align-items: center; gap: var(--s-3); padding-right: 4px; }
