/* Look follows the GaugeGarage plugin UI (Figma): rows with bar sliders,
   JetBrains Mono values, a green accent. One dark surface everywhere; controls are outlined, not filled. */
:root {
  /* The sidebar shares the preview's background. Controls are filled with one light tint and have
     no outline; groups are told apart by a line between them. */
  --bg: #1f1f1f;
  --panel: var(--bg);
  --panel-2: var(--bg);
  --field: rgba(255, 255, 255, 0.08);       /* inputs, tracks, cells: filled like the buttons */
  --field-line: transparent;                /* no outline; the border only keeps sizes */
  --line: rgba(255, 255, 255, 0.045);        /* between groups and panes */
  --btn-fill: rgba(255, 255, 255, 0.08);    /* buttons are filled, not outlined */
  --btn-fill-hover: rgba(255, 255, 255, 0.12);
  --knob-fill: #5c5c5c;
  --knob-line: var(--knob-fill);
  --text: #e2e2e2;
  --label: #b8b8b8;
  --muted: #8a8a8a;
  --value: #a8a8a8;
  --accent: #4fcf68;
  --accent-soft: #7be08f;
  --accent-tint: rgba(79, 207, 104, 0.22);
  --accent-grad: linear-gradient(270deg, #3fbe5a 4%, #5fd876 87%);
  --danger: #ff6b6b;
  --radius: 8px;
  --field-h: 28px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Lucide icons: the SVG is a mask, so the icon takes the text colour. */
.ico { display: inline-block; flex: none; width: 16px; height: 16px; background-color: currentColor; -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; vertical-align: middle; }
/* No focus rings on controls. */
input, select, textarea, button { outline: none; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 500 14px/1.35 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: -0.01em; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }

.app { display: grid; grid-template-columns: 480px 1fr; height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--panel); border-right: 1.5px solid var(--line); overflow-y: auto; }

/* One outline around the whole switch; segments have none, the selected one is filled. */
/* Mode switch: two large words, left-aligned; the current one is light, the other grey. */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 12px 16px; }
.mode-switch { display: flex; gap: 18px; }
/* Looks like the selected segment, in green. */
/* Export: a green icon in the player; its settings show on hover (or while one of them is in use). */
.export-split { position: relative; display: flex; }
.transport .icon-btn.export-btn { color: var(--accent); }
.transport .icon-btn.export-btn:hover { color: var(--accent-soft); background: var(--accent-tint); }
.export-btn:disabled { opacity: .5; cursor: default; }
.export-menu { display: none; }
.export-split:hover .export-menu, .export-menu:focus-within { display: block; }
/* Invisible bridge over the gap, so the pointer can move from the button to the menu. */
.export-menu::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 10px; }
/* Styled like the sidebar (thin lines between rows and around it, no shadow), on a lighter ground so it stands off the page.
   No overflow clipping: the hover bridge below hangs outside it. */
.export-menu { --menu-line: rgba(255, 255, 255, 0.04); position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 10; width: 320px; border-radius: var(--radius); background: #363636; border: 1.5px solid var(--menu-line); }
.export-opts { display: grid; }
.export-opts label { display: grid; grid-template-columns: 1fr 180px; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px; border-bottom: 1.5px solid var(--menu-line); color: var(--label); font-size: 14px; }
.export-opts label[hidden] { display: none; }
.export-opts .size { padding: 12px; color: var(--muted); font: 500 12.5px var(--mono); }
/* A line under the switch, across the sidebar, like the ones between groups. */
.side-head + #panels { border-top: 1.5px solid var(--line); }
/* Project menu: a + at the right of the mode switch, its list dropping below it. */
.project-menu { position: relative; }
/* Sized to the 22 px mode words, with a heavier stroke to match their weight. */
.project-menu .icon-btn { width: 34px; height: 34px; color: var(--label); }
.project-menu .ico { width: 24px; height: 24px; }
/* Same look as the export settings: rows split by quiet lines, the list framed by one. */
.menu { --menu-line: rgba(255, 255, 255, 0.04); position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 200px; display: grid; border-radius: var(--radius); background: #363636; border: 1.5px solid var(--menu-line); overflow: hidden; }
.menu button { min-height: 38px; padding: 0 12px; border: 0; border-bottom: 1.5px solid var(--menu-line); background: none; color: var(--label); font-size: 14px; text-align: left; cursor: pointer; }
.menu button:last-child { border-bottom: 0; }
.menu button { display: flex; align-items: center; gap: 10px; }
.menu button .ico { width: 17px; height: 17px; color: var(--muted); }
.menu button.danger .ico { color: inherit; }
.menu button:hover .ico { color: inherit; }
/* Hover in the lines' own tint, so a highlighted row merges with the lines around it. */
.menu button:hover { background: var(--menu-line); color: var(--text); }
.menu button.danger { color: var(--danger); }
.mode-switch button { border: 0; background: none; padding: 0; cursor: pointer; font-size: 22px; font-weight: 500; letter-spacing: -0.02em; color: #6b6b6b; transition: color .15s; }
.mode-switch button:hover { color: var(--label); }
.mode-switch button.active { color: var(--text); cursor: default; }

.hotbar { position: relative; display: grid; grid-template-columns: repeat(9, 1fr); gap: 8px; }
.hotbar .slot { position: relative; aspect-ratio: 1; border-radius: var(--radius); background: var(--field); display: grid; place-items: center; cursor: pointer; overflow: hidden; }
.hotbar .slot:hover { background: var(--btn-fill-hover); }
/* The selected slot gets a green outline. */
.hotbar .slot { transition: box-shadow .15s; }
.hotbar .slot.active { box-shadow: inset 0 0 0 2px var(--accent); }
.hotbar .slot canvas { width: 78%; height: 78%; }
/* Swap tab in the slot's bottom-right corner: a light square flush with the edges (the slot clips it to its own
   corner), only its inner corner rounded, with two light dots. */
.hotbar .swap { position: absolute; right: 0; bottom: 0; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; gap: 2.5px; padding: 0; border: 0; border-radius: 6px 0 0 0; background: #6e6e6e; cursor: pointer; opacity: 0; transition: opacity .12s; }
.hotbar .swap i { width: 3px; height: 3px; border-radius: 50%; background: #f0f0f0; }
.hotbar .swap:hover { background: #7e7e7e; }
/* On the selected slot the tab takes the outline's green, its dots the page colour. */
.hotbar .slot.active .swap { background: var(--accent); }
.hotbar .slot.active .swap:hover { background: var(--accent-soft); }
.hotbar .slot.active .swap i { background: var(--bg); }
.hotbar .slot:hover .swap { opacity: 1; }

.app.building #preview { cursor: crosshair; }

/* ---------- groups and rows ---------- */

details.section { border-bottom: 1.5px solid var(--line); }
details.section > summary { height: 44px; cursor: pointer; list-style: none; padding: 0 10px; display: flex; align-items: center; gap: 8px; user-select: none; background: var(--panel); }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before { content: ""; width: 14px; height: 14px; flex: none; background: url(ui/chevron-closed.svg) center / 14px no-repeat; }
details.section[open] > summary { background: var(--panel-2); }
/* A group switched off by its header toggle: settings shown greyed out and not clickable. */
details.section.off > .section-body { opacity: .35; filter: grayscale(1); pointer-events: none; user-select: none; }
details.section[open] > summary::before { background-image: url(ui/chevron-open.svg); }
details.section > summary:hover .sec-title { color: var(--text); }
.sec-title { color: var(--label); font-size: 14px; letter-spacing: -0.14px; }
.sec-switch { margin-left: auto; display: flex; }

/* The line under an open group's header sits exactly where a closed group's bottom line is, so it doesn't jump. */
.section-body { background: var(--panel-2); display: grid; border-top: 1.5px solid var(--line); }
/* Every line of a group is a row of its own, indented under the arrow. */
.section-body > *, .section-body > .pair > .row { padding: 8px 12px 8px 32px; }
.section-body > .row, .section-body > .check, .section-body > .pair > .row { min-height: 44px; padding-top: 6px; padding-bottom: 6px; }
.hotbar-wrap { padding: 12px; background: var(--panel); border-top: 0; border-bottom: 1.5px solid var(--line); }
.hotbar-wrap > .hotbar { padding: 0; border: 0; }
/* A label over the rows that follow; not a group of its own, so no arrow and no fill. */
.subhead { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; padding-top: 16px !important; padding-bottom: 6px !important; }

.row { display: grid; grid-template-columns: minmax(0, 1fr) 240px; align-items: center; gap: 10px; }
.row > span { color: var(--label); }
.row.hidden, .check.hidden, .section-body > .hidden { display: none !important; }
.row:has(textarea) { grid-template-columns: 1fr; gap: 6px; }
.row > span:empty { display: none; }
.section-body > .pair { display: contents; }

/* ---------- fields ---------- */
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; min-width: 0; height: var(--field-h); background: var(--field); border: 1.5px solid var(--field-line); border-radius: var(--radius); padding: 0 8px;
}
input[type=number] { font: 500 13.5px var(--mono); color: var(--value); text-align: center; padding: 0 4px; font-feature-settings: "zero" 1; -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=text], input[type=search] { color: var(--text); font-size: 14px; }
select { appearance: none; -webkit-appearance: none; color: var(--text); font-size: 14px; padding-right: 24px; cursor: pointer; background: var(--field) url(ui/chevron-open.svg) right 6px center / 14px no-repeat; }
textarea { height: auto; min-height: 52px; padding: 7px 9px; resize: vertical; line-height: 1.35; font-size: 14px; color: var(--text); }

/* Colour: swatch + hex in a pill, the native picker invisible on top. */
.picker { position: relative; justify-self: end; display: inline-flex; align-items: center; gap: 7px; height: var(--field-h); padding: 0 10px 0 5px; background: var(--field); border: 1.5px solid var(--field-line); border-radius: var(--radius); cursor: pointer; }
.picker .swatch { width: 16px; height: 16px; border-radius: 2px; }
.picker .hex { font: 500 13.5px var(--mono); color: var(--value); font-feature-settings: "zero" 1; }
.picker input[type=color] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
input[type=color] { width: 100%; height: 24px; padding: 2px; background: var(--field); border: 1.5px solid var(--field-line); border-radius: var(--radius); }

/* Slider: a bar filled up to the value, like the player's timeline but thicker; no knob.
   --bar is the bar's thickness, --h the height of the grab area around it (the native range, transparent on top). */
/* Registered so the thickness can animate. */
@property --bar { syntax: "<length>"; inherits: true; initial-value: 8px; }
.slider { --bar: 8px; --bar-active: 12px; --h: var(--field-h); position: relative; display: block; height: var(--h); transition: --bar .15s ease-out; }
/* Hover, drag and keyboard focus: the bar grows, centred on itself. */
.slider:hover, .slider:has(input:active), .slider:has(input:focus-visible) { --bar: var(--bar-active); }
.slider::before { content: ""; position: absolute; left: 0; right: 0; top: calc((var(--h) - var(--bar)) / 2); height: var(--bar); border-radius: calc(var(--bar) / 2); background: var(--field); }
.slider-fill { position: absolute; left: 0; top: calc((var(--h) - var(--bar)) / 2); height: var(--bar); width: calc(var(--p, 0) * 100%); border-radius: calc(var(--bar) / 2); background: #a8a8a8; pointer-events: none; }
.slider input[type=range] { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: var(--h); margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 100%; background: transparent; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 2px; height: 100%; border: 0; background: transparent; }
input[type=range]::-moz-range-track { background: transparent; }
input[type=range]::-moz-range-thumb { width: 2px; height: 100%; border: 0; border-radius: 0; background: transparent; }
.range-num { display: grid; grid-template-columns: 1fr 52px; gap: 16px; align-items: center; }

/* On/off in group headers. */
/* Pill knob inside the track with an even 3 px inset; no border anywhere. */
.switch { -webkit-appearance: none; appearance: none; position: relative; width: 46px; height: 22px; margin: 0; border: 0; border-radius: 11px; background: var(--btn-fill); cursor: pointer; transition: background .15s; }
.switch::before { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 16px; border-radius: 8px; background: #8c8c8c; transition: left .15s, background .15s; }
.switch:checked { background: var(--accent-grad); }
.switch:checked::before { left: 21px; background: #fff; }

/* Checkbox rows: label on the left, a square box on the right. */
.check { display: flex; flex-direction: row-reverse; justify-content: space-between; align-items: center; gap: 10px; color: var(--label); cursor: pointer; }
.check input { -webkit-appearance: none; appearance: none; flex: none; width: var(--field-h); height: var(--field-h); margin: 0; border-radius: var(--radius); background: var(--field) center / 10px 10px no-repeat; border: 1.5px solid var(--field-line); cursor: pointer; }
.check input:checked { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10'%3E%3Crect width='10' height='10' rx='1' fill='%23f4f4f4'/%3E%3C/svg%3E"); }

/* ---------- buttons ---------- */
.btn { height: 30px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--btn-fill); border: 0; border-radius: var(--radius); padding: 0 10px; cursor: pointer; white-space: nowrap;
  color: var(--label); font-size: 13px; }
.btn:hover { color: var(--text); background: var(--btn-fill-hover); }
.btn.primary { background: var(--accent-tint); color: var(--accent-soft); }
.btn.primary:hover { background: rgba(79,207,104,.32); color: #a3f0b2; }
.btn.small { height: 28px; padding: 0 9px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
/* Buttons sharing a row's full width equally. */
.btn-row.stretch { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding-top: 10px; padding-bottom: 14px; }
.icon-btn { background: none; border: 0; padding: 0; border-radius: 6px; width: 28px; height: 28px; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--btn-fill); color: var(--text); }

/* ---------- placement picker ---------- */
.anchor-row { align-items: start; }
.anchor-row > span { padding-top: 4px; }
/* No border, so the pad's own box is the coordinate frame the marker is placed in. */
.anchor-pad { position: relative; justify-self: end; border-radius: var(--radius); background: var(--field); display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.anchor-spot { position: relative; border: 0; background: none; padding: 0; cursor: pointer; display: grid; place-items: center; border-radius: 6px; }
/* Edge dots 22 px in from the pad's edges (20 px padding + half of a 4 px dot); main.js uses the same inset. */
.anchor-spot:nth-child(3n + 1 of .anchor-spot) { justify-items: start; padding-left: 20px; }
.anchor-spot:nth-child(3n of .anchor-spot) { justify-items: end; padding-right: 20px; }
.anchor-spot:nth-child(-n + 3 of .anchor-spot) { align-items: start; padding-top: 20px; }
.anchor-spot:nth-last-child(-n + 3 of .anchor-spot) { align-items: end; padding-bottom: 20px; }
.anchor-spot i { width: 4px; height: 4px; border-radius: 50%; background: #6a6a6a; transition: transform .12s, background .12s; }
.anchor-spot:hover i { background: #9a9a9a; transform: scale(1.5); }
.anchor-spot.active i { opacity: 0; }
.anchor-marker { position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); pointer-events: none; transition: transform .2s cubic-bezier(.3, .7, .3, 1); }

/* ---------- items ---------- */
/* Items: a flat list like the other rows; the tools show on hover. */
.section-body > .items, .section-body > .items-head, .section-body > .items-actions { padding-left: 12px; padding-right: 12px; }
/* The grip hangs in the list's left gutter, so rows keep their alignment. */
.section-body > .items { padding-left: 22px; }
.items { display: grid; gap: 2px; padding-top: 6px !important; padding-bottom: 6px !important; }
.item, .items-head { display: grid; grid-template-columns: 36px minmax(0, 1fr) 52px 14px 52px; gap: 8px; align-items: center; }
.item.no-change { grid-template-columns: 36px minmax(0, 1fr) 52px; }
.item { position: relative; min-height: 44px; padding: 4px 4px; border-radius: var(--radius); background: var(--bg); }
.grip { position: absolute; left: -18px; top: 50%; transform: translateY(-50%); width: 16px; height: 28px; display: grid; place-items: center; color: var(--muted); cursor: grab; opacity: 0; transition: opacity .12s; touch-action: none; }
.grip .ico { width: 16px; height: 16px; }
.item:hover .grip, .item.dragging .grip { opacity: 1; }
.grip:hover { color: var(--text); }
/* While sorting, the other rows slide out of the way; the dragged one follows the pointer, lifted. */
.items.sorting .item:not(.dragging) { transition: transform .18s cubic-bezier(.2, .7, .3, 1); }
.item.dragging { z-index: 2; background: #363636; }
.items.sorting, .items.sorting * { cursor: grabbing !important; }
/* No outline on the row itself: it would run right beside the count fields' outlines. Hover shows the tools. */
.name-cell { position: relative; min-width: 0; }
.item .thumb, .brush .thumb { width: 36px; height: 36px; border-radius: 6px; border: 0; background: var(--field); cursor: pointer; padding: 0; display: grid; place-items: center; }
.item .thumb canvas, .brush .thumb canvas { width: 30px; height: 30px; }
.item .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; color: var(--label); }
.item .arrow { color: var(--muted); text-align: center; font-size: 12px; }
.item .tools { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: flex; opacity: 0; pointer-events: none; transition: opacity .12s; }
/* On hover the name ends (with an ellipsis) before the four tool buttons instead of running under them. */
.item:hover .name, .item:focus-within .name { padding-right: 116px; }
.item:hover .tools, .item:focus-within .tools { opacity: 1; pointer-events: auto; }
.item .tools .icon-btn { width: 28px; height: 28px; }
.item .tools .ico { width: 18px; height: 18px; }
.items-head { padding-top: 12px !important; padding-bottom: 0 !important; padding-left: 26px !important; padding-right: 16px !important; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.items-head span { text-align: center; }
.section-body > .items-actions { padding-top: 4px; padding-bottom: 12px; padding-left: 22px; display: grid; grid-template-columns: 1fr 1fr; }

/* ---------- stage ---------- */
.stage { display: grid; grid-template-rows: 1fr auto auto; min-width: 0; min-height: 0; background: var(--bg); }
.viewport { position: relative; min-height: 0; display: grid; place-items: center; padding: 20px; overflow: hidden; }
.canvas-wrap { position: relative; }
.canvas-wrap.checker {
  background-color: #b9b9b9;
  background-image: linear-gradient(45deg, #8f8f8f 25%, transparent 25%), linear-gradient(-45deg, #8f8f8f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #8f8f8f 75%), linear-gradient(-45deg, transparent 75%, #8f8f8f 75%);
  background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
/* Preview without a background: a quiet line shows where the frame ends. */
.canvas-wrap.bare { box-shadow: 0 0 0 1.5px var(--line); }
#preview { display: block; image-rendering: auto; }
#preview.over-text { cursor: text !important; }
/* Typing over text on the preview: the field is invisible (it only takes the keys), a white caret blinks in the text. */
.text-editor { position: absolute; left: 0; top: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; resize: none; pointer-events: none; }
.text-caret { position: absolute; z-index: 5; width: 4px; margin-left: 2px; background: #fff; pointer-events: none; animation: caret-blink 1s steps(1) infinite; }
@keyframes caret-blink { 50% { opacity: 0; } }
.drop-hint { position: absolute; inset: 12px; border: 1.5px dashed var(--accent); border-radius: 12px; display: none; place-items: center; background: rgba(23,23,23,.8); font-size: 15px; color: var(--accent-soft); }
.viewport.dragging .drop-hint { display: grid; }

/* Player row: 20 px from the window's edge, export at its right end. */
.transport { display: flex; align-items: center; gap: 14px; height: 36px; box-sizing: content-box; padding: 0 20px 20px; }
/* Timeline scrubber: a thin bar filled up to the playhead, no knob; the input stays tall for easy grabbing. */
/* The player's timeline: the same bar, thinner. */
.transport .slider.scrub { flex: 1; margin: 0 10px; --bar: 6px; --bar-active: 10px; --h: 20px; }
.transport .slider.scrub:hover, .transport .slider.scrub:has(input:active), .transport .slider.scrub:has(input:focus-visible) { --bar: var(--bar-active); }
/* Loop: a Lucide icon in a chip; dim when off. */
.loop-btn { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border: 0; padding: 0; border-radius: var(--radius); background: none; cursor: pointer; }
.loop-btn:hover { background: var(--btn-fill); }
.loop-btn { color: #5c5c5c; }
.btn .ico { width: 15px; height: 15px; }
/* Player: bigger buttons, bigger icons drawn with a heavier stroke (ui/lucide/bold). */
.transport .icon-btn { width: 36px; height: 36px; color: var(--muted); }
.transport .icon-btn:hover { color: var(--text); }
.transport .ico { width: 22px; height: 22px; }
.loop-btn.on { color: var(--muted); }
.loop-btn:hover { color: var(--text); }
/* Large running time; tabular figures so it doesn't jitter, leading zeros dimmed. */
.time { flex: none; font-size: 24px; font-weight: 400; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--label); }
.time .dim { color: #555; }

.export-bar { display: flex; align-items: center; padding: 0 20px 20px; }
/* Only there while an export runs (or just finished). */
.export-bar:has(> .progress[hidden]) { display: none; }
.progress { flex-basis: 100%; display: flex; align-items: center; gap: 12px; }
.progress .bar { flex: 1; height: 6px; border-radius: 4px; background: var(--field); border: 1.5px solid var(--field-line); overflow: hidden; }
.progress .bar div { height: 100%; width: 0; background: var(--accent-grad); transition: width .1s; }
.progress span { color: var(--muted); font: 500 11px var(--mono); min-width: 150px; }

/* ---------- dialogs ---------- */
.dlg { background: var(--bg); color: var(--text); border: 1.5px solid var(--line); border-radius: 12px; padding: 0; width: min(860px, 94vw); max-height: 86vh; outline: none; }
.dlg.narrow { width: min(460px, 94vw); }
.dlg::backdrop { background: rgba(0, 0, 0, .5); }
.dlg-head { display: flex; align-items: center; gap: 12px; padding: 12px; position: sticky; top: 0; z-index: 1; background: var(--bg); border-bottom: 1.5px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 14px; font-weight: 500; white-space: nowrap; }
.dlg-head .icon-btn { margin-left: auto; }
/* Search field with its icon inside. */
.search { position: relative; flex: 1; display: flex; align-items: center; }
.search .ico { position: absolute; left: 9px; width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 30px; }
.search input::-webkit-search-cancel-button { display: none; }

/* Block picker: light tiles, a fill on hover, the current block outlined in green. */
#pickerDlg { width: min(780px, 94vw); }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 4px; padding: 4px 12px 16px; overflow-y: auto; max-height: calc(86vh - 60px); }
.picker-sep { grid-column: 1 / -1; padding: 14px 4px 6px; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.pick { position: relative; display: grid; justify-items: center; align-content: start; gap: 6px; padding: 10px 6px 8px; border-radius: var(--radius); cursor: pointer; text-align: center; color: var(--label); transition: background .12s, box-shadow .12s; }
.pick:hover { background: var(--field); color: var(--text); }
.pick.current { box-shadow: inset 0 0 0 2px var(--accent); color: var(--text); }
.pick canvas { width: 56px; height: 56px; }
.pick-name { font-size: 12px; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pick.upload { place-content: center; justify-items: center; min-height: 100px; color: var(--muted); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .12); }
.pick.upload .ico { width: 20px; height: 20px; color: var(--accent); }
.pick .del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; opacity: 0; transition: opacity .12s; }
/* How the block turns when placed: shown on hover, and always when it turns at all. */
.pick .place { position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; opacity: 0; transition: opacity .12s; }
.pick .place .ico { width: 14px; height: 14px; }
.pick .place.on { color: var(--accent); opacity: .8; }
.pick:hover .place { opacity: 1; }
.pick .del .ico { width: 14px; height: 14px; }
.pick:hover .del { opacity: 1; }

.custom-body { padding: 14px; display: grid; gap: 10px; }
.model-row { grid-template-columns: 132px auto 1fr auto; }
.model-info { color: var(--muted); font-size: 12px; }
.face-inputs { display: grid; gap: 8px; }
.face-input { display: grid; grid-template-columns: 132px 40px 1fr auto; gap: 8px; align-items: center; }
.face-input span { color: var(--label); }
.face-input .sw { width: 40px; height: 40px; border-radius: 6px; border: 1.5px solid var(--field-line); background: var(--field); image-rendering: pixelated; object-fit: cover; }
.custom-preview { display: grid; place-items: center; background: #424242; border-radius: 8px; padding: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.custom-body .row { grid-template-columns: 132px 1fr; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  .sidebar { max-height: none; border-right: 0; }
  .stage { order: -1; position: sticky; top: 0; z-index: 5; background: var(--bg); }
  .viewport { height: 46vh; padding: 10px; }
  .model-row { grid-template-columns: 110px auto 1fr auto; }
}

