/* Magma — app styles. Tokens first (light + dark), then shell, canvas, panels, controls, overlays. */

:root {
  --left: 248px;
  --right: 264px;
  --top: 44px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --bg: #FFFFFF;
  --bg-2: #F4F4F6;
  --bg-3: #E9E9EC;
  --field: #F4F4F6;
  --border: #E5E5E9;
  --border-2: #D6D6DC;
  --text: #1D1D22;
  --text-2: #62626C;
  --text-3: #9C9CA5;
  --accent: #2F6FEB;
  --accent-weak: #E8F0FE;
  --accent-text: #1F5AD1;
  --brand: #FF5A1F;
  --brand-2: #E8480F;
  --comp: #8B4DF0;
  --comp-weak: #F2EAFE;
  --danger: #D93A3F;
  --ok: #1E9E5A;
  --menu: #1E1E23;
  --menu-text: #F2F2F4;
  --menu-hover: #2F6FEB;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 8px 24px rgb(0 0 0 / .12);
  --shadow-lg: 0 2px 6px rgb(0 0 0 / .08), 0 24px 60px rgb(0 0 0 / .22);
  --checker: repeating-conic-gradient(#D9D9DE 0 25%, #FFFFFF 0 50%) 0 0 / 10px 10px;

  /* canvas overlay colors are theme independent */
  --sel: #0D99FF;
  --sel-comp: #9747FF;
  --guide: #FF2E63;

  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #1E1E22;
  --bg-2: #28282D;
  --bg-3: #323238;
  --field: #28282D;
  --border: #2E2E34;
  --border-2: #3C3C44;
  --text: #EDEDF0;
  --text-2: #A5A5AF;
  --text-3: #6F6F79;
  --accent: #4C8DF6;
  --accent-weak: #22324F;
  --accent-text: #8DB6FF;
  --comp: #B08BFF;
  --comp-weak: #332A4A;
  --menu: #111114;
  --checker: repeating-conic-gradient(#3A3A40 0 25%, #2A2A2F 0 50%) 0 0 / 10px 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .45);
  --shadow-lg: 0 2px 6px rgb(0 0 0 / .3), 0 24px 60px rgb(0 0 0 / .6);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1E1E22;
    --bg-2: #28282D;
    --bg-3: #323238;
    --field: #28282D;
    --border: #2E2E34;
    --border-2: #3C3C44;
    --text: #EDEDF0;
    --text-2: #A5A5AF;
    --text-3: #6F6F79;
    --accent: #4C8DF6;
    --accent-weak: #22324F;
    --accent-text: #8DB6FF;
    --comp: #B08BFF;
    --comp-weak: #332A4A;
    --menu: #111114;
    --checker: repeating-conic-gradient(#3A3A40 0 25%, #2A2A2F 0 50%) 0 0 / 10px 10px;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .45);
    --shadow-lg: 0 2px 6px rgb(0 0 0 / .3), 0 24px 60px rgb(0 0 0 / .6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
  grid-template-rows: var(--top) minmax(0, 1fr);
  grid-template-areas: "top top top" "left canvas right";
  overflow: hidden;
  font: 12px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
}
body:not(.ready) .viewport { opacity: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
.ico { display: block; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
kbd {
  display: inline-block; min-width: 18px; padding: 1px 5px; border-radius: 4px;
  font: 11px/1.4 var(--font); background: var(--bg-2); border: 1px solid var(--border); color: var(--text-2); text-align: center;
}
.muted { color: var(--text-3); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 20;
  min-width: 0;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tb-right { justify-content: flex-end; }
.logo-btn {
  display: flex; align-items: center; gap: 2px; height: 32px; padding: 0 6px 0 4px; border: 0; border-radius: 8px; background: none; color: var(--text-2);
}
.logo-btn:hover { background: var(--bg-2); }
.logo {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; color: #fff;
  background: linear-gradient(135deg, #FFB347, #FF5A1F 55%, #B3175A);
}
.logo.big { width: 52px; height: 52px; border-radius: 14px; margin-bottom: 8px; }
.tools { display: flex; align-items: center; gap: 2px; margin-left: 6px; }
.tool-group { display: flex; gap: 1px; padding-right: 4px; margin-right: 2px; border-right: 1px solid var(--border); }
.tool-group:last-child { border-right: 0; }
.tool {
  display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 7px; background: none; color: var(--text);
}
.tool:hover { background: var(--bg-2); }
.tool.on { background: var(--accent); color: #fff; }
.doc-center { display: flex; align-items: center; gap: 4px; min-width: 0; }
.doc-name {
  width: clamp(120px, 22vw, 260px); height: 28px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px; background: none;
  font-weight: 600; text-align: center; text-overflow: ellipsis;
}
.doc-name:hover { border-color: var(--border); }
.doc-name:focus { border-color: var(--accent); outline: none; background: var(--bg); }
.save-status { font-size: 11px; color: var(--text-3); white-space: nowrap; min-width: 48px; }
.save-status.error { color: var(--danger); font-weight: 600; }
.zoom-btn {
  height: 28px; min-width: 52px; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--text-2); font-variant-numeric: tabular-nums;
}
.zoom-btn:hover { background: var(--bg-2); color: var(--text); }
.export-btn { margin-left: 4px; }

/* ---------- panels ---------- */
.panel {
  display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
  background: var(--bg); z-index: 10;
}
.panel.left { grid-area: left; border-right: 1px solid var(--border); }
.panel.right { grid-area: right; border-left: 1px solid var(--border); }
body.no-left .panel.left, body.no-right .panel.right { display: none; }
body.no-left .resizer.left, body.no-right .resizer.right { display: none; }
.resizer { position: fixed; top: var(--top); bottom: 0; width: 6px; z-index: 30; cursor: col-resize; }
.resizer.left { left: calc(var(--left) - 3px); }
.resizer.right { right: calc(var(--right) - 3px); }
.resizer:hover { background: linear-gradient(90deg, transparent 2px, var(--accent) 2px 4px, transparent 4px); }
.panel-tabs { display: flex; gap: 2px; height: 40px; flex: none; align-items: center; padding: 0 8px; border-bottom: 1px solid var(--border); }
.tab { height: 28px; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--text-3); font-weight: 600; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); background: var(--bg-2); }

/* pages */
.pages { flex: none; border-bottom: 1px solid var(--border); padding: 4px 0; max-height: 34%; overflow: auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 4px; height: 30px; }
.sh-toggle { display: flex; align-items: center; gap: 4px; border: 0; background: none; font-weight: 600; color: var(--text); padding: 4px; border-radius: 5px; }
.sh-toggle:hover { background: var(--bg-2); }
.page-row { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px 0 8px; cursor: default; border-radius: 6px; margin: 0 6px; }
.page-row:hover { background: var(--bg-2); }
.page-row.on { font-weight: 600; }
.page-row .check { width: 14px; color: var(--text-2); }
.page-row .name, .layer .name, .asset .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

/* layer tree */
.tree { flex: 1; min-height: 0; overflow: auto; position: relative; outline: none; }
.tree-inner { position: relative; margin-bottom: 24px; }
.layer {
  display: flex; align-items: center; gap: 4px; height: 28px; padding-right: 6px; cursor: default; position: absolute; left: 0; right: 0;
  border-radius: 0; user-select: none;
}
.layer:hover, .layer.hov { background: var(--bg-2); box-shadow: inset 0 0 0 1px var(--border-2); }
.layer.anc { background: color-mix(in srgb, var(--accent-weak) 45%, transparent); }
.layer.sel { background: var(--accent-weak); }
.layer.sel:hover { box-shadow: none; }
.layer.hidden .name, .layer.hidden .ticon { opacity: .45; }
.layer.comp .ticon, .layer.comp .name { color: var(--comp); }
.layer .chev { width: 16px; height: 20px; display: grid; place-items: center; border: 0; background: none; color: var(--text-3); padding: 0; flex: none; }
.layer .chev.none { visibility: hidden; }
.layer .ticon { color: var(--text-2); flex: none; width: 16px; display: grid; place-items: center; }
.layer .acts { display: flex; gap: 0; opacity: 0; flex: none; }
.layer:hover .acts, .layer .acts:has(.on) { opacity: 1; }
.layer .acts .act:not(.on) { opacity: .0; }
.layer:hover .acts .act { opacity: 1; }
.act { display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: 4px; background: none; color: var(--text-2); padding: 0; }
.act:hover { background: var(--bg-3); color: var(--text); }
.rename {
  flex: 1; min-width: 0; height: 22px; padding: 0 4px; border: 1px solid var(--accent); border-radius: 4px; background: var(--bg); outline: none;
}
.tree.dragging .layer:hover { box-shadow: none; }
.drop-line { position: absolute; right: 6px; height: 2px; background: var(--accent); border-radius: 1px; pointer-events: none; }
.drop-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 6px; height: 6px; border: 2px solid var(--accent); border-radius: 50%; background: var(--bg); }
.layer.drop-inside { box-shadow: inset 0 0 0 2px var(--accent) !important; }
.empty { padding: 20px 16px; color: var(--text-2); text-align: center; }
.empty p { margin: 0 0 6px; }
.empty.pad { padding: 32px 20px; }

/* assets */
.assets { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.asset-search { padding: 8px; }
.asset-list { flex: 1; overflow: auto; padding-bottom: 24px; }
.asset-page { padding: 10px 12px 4px; font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.asset { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px 0 12px; cursor: grab; color: var(--comp); }
.asset:hover { background: var(--bg-2); }
.asset .name { color: var(--text); }
.asset .count { color: var(--text-3); font-size: 11px; }
.asset .act { opacity: 0; }
.asset:hover .act { opacity: 1; }

/* ---------- properties ---------- */
.props-body { flex: 1; min-height: 0; overflow: auto; padding-bottom: 40px; }
.sec { padding: 8px 12px 12px; border-bottom: 1px solid var(--border); }
.sec.collapsed { padding-bottom: 6px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; height: 28px; }
.sec-title { font-weight: 600; font-size: 12px; }
.sec-actions { display: flex; gap: 2px; }
.sec-body { display: flex; flex-direction: column; gap: 8px; }
.sec.collapsed .sec-body:empty { display: none; }
.sec.comp .sec-title { color: var(--comp); }
.prow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: center; min-width: 0; }
.prow.wh { grid-template-columns: 1fr 1fr 28px; }
.plabel { color: var(--text-2); }
.hint { margin: 0; color: var(--text-2); font-size: 11.5px; line-height: 1.45; }
.hint.warn { color: var(--danger); }
.tips { margin: 0; padding-left: 16px; color: var(--text-2); line-height: 2; }
.align-bar { display: flex; justify-content: space-between; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.align-bar .icon-btn { width: 26px; }
.preset-bar { padding: 8px 12px 0; }
.preset-btn { width: 100%; justify-content: space-between; }
.comp-row { display: flex; align-items: center; gap: 6px; color: var(--comp); min-width: 0; }
.comp-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.check-row { display: flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; user-select: none; }
.check-row input { margin: 0; accent-color: var(--accent); }
.code {
  margin: 0; padding: 10px; border-radius: 6px; background: var(--field); font: 11px/1.55 var(--mono); color: var(--text);
  white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; user-select: text;
}
.pad { padding: 12px; }

/* number field */
.nf {
  display: flex; align-items: center; height: 28px; min-width: 0; border-radius: 6px; background: var(--field);
  border: 1px solid transparent; transition: border-color .1s;
}
.nf:hover { border-color: var(--border-2); }
.nf:focus-within { border-color: var(--accent); background: var(--bg); }
.nf-label {
  flex: none; display: grid; place-items: center; min-width: 26px; height: 100%; padding: 0 2px 0 4px; color: var(--text-3);
  cursor: ew-resize; user-select: none; font-size: 11px;
}
.nf.labeled .nf-label { min-width: 34px; }
.nf-input { flex: 1; min-width: 0; width: 100%; height: 100%; border: 0; background: none; padding: 0 6px 0 2px; outline: none; font-variant-numeric: tabular-nums; }
.nf-input::placeholder { color: var(--text-3); }
.nf-suffix { padding-right: 8px; color: var(--text-3); }
.nf.disabled { opacity: .5; }
.nf.disabled .nf-label { cursor: default; }
body.scrubbing, body.scrubbing * { cursor: ew-resize !important; user-select: none; }
.nf.op { width: 64px; flex: none; }
.nf.op .nf-label { display: none; }
.nf.op .nf-input { padding-left: 8px; }

/* inputs, selects, segmented, buttons */
.input {
  height: 28px; width: 100%; padding: 0 8px; border: 1px solid transparent; border-radius: 6px; background: var(--field); outline: none; min-width: 0;
}
.input:hover { border-color: var(--border-2); }
.input:focus { border-color: var(--accent); background: var(--bg); }
.select {
  appearance: none; -webkit-appearance: none; height: 28px; width: 100%; min-width: 0; padding: 0 22px 0 8px; border: 1px solid transparent; border-radius: 6px;
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 16 16' fill='none' stroke='%238a8a94' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3.5 6 8 10.5 12.5 6'/%3E%3C/svg%3E") no-repeat right 8px center;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden; text-align: left;
}
.select:hover { border-color: var(--border-2); }
.select:focus { border-color: var(--accent); outline: none; }
.select:disabled { opacity: .5; }
.font-btn { font-size: 13px; cursor: pointer; }
.seg { display: inline-flex; gap: 1px; padding: 2px; border-radius: 7px; background: var(--field); min-width: 0; justify-self: start; }
.seg-btn { display: grid; place-items: center; min-width: 26px; height: 24px; padding: 0 6px; border: 0; border-radius: 5px; background: none; color: var(--text-2); }
.seg-btn:hover { color: var(--text); }
.seg-btn.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.seg-btn.it { font-style: italic; font-family: Georgia, serif; font-size: 13px; }
.picker-tabs { width: 100%; }
.picker-tabs .seg-btn { flex: 1; font-size: 11px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 7px;
  border: 1px solid var(--border-2); background: var(--bg); color: var(--text); font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--bg-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { height: 24px; padding: 0 8px; font-size: 11px; }
.btn.wide { width: 100%; }
.icon-btn {
  display: grid; place-items: center; width: 28px; height: 28px; flex: none; border: 0; border-radius: 6px; background: none; color: var(--text-2); padding: 0;
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn.on { background: var(--accent-weak); color: var(--accent-text); }
.icon-btn:disabled { opacity: .35; background: none; }
.icon-btn.small { width: 24px; height: 24px; }

/* paints */
.paint-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.paint-row.off > :not(.icon-btn) { opacity: .45; }
.paint-row.no-eye > .icon-btn { display: none; }
.swatch-btn {
  flex: none; width: 22px; height: 22px; border-radius: 5px; border: 0; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .14); padding: 0; cursor: pointer;
}
.hexin { flex: 1; font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; }
.paint-label { flex: 1; min-width: 0; padding-left: 4px; color: var(--text); }
.fx-row { display: grid; grid-template-columns: 28px 1fr 28px 28px; gap: 4px; align-items: center; }
.fx-row.off .select { opacity: .45; }
.fx-detail { display: flex; flex-direction: column; gap: 8px; padding: 8px; margin-top: -4px; border-radius: 8px; background: var(--bg-2); }
.fx-detail .nf, .fx-detail .input { background: var(--bg); }

/* auto layout */
.al-wrap { display: grid; grid-template-columns: 76px 1fr; gap: 8px; }
.al-grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); height: 64px; padding: 4px; border-radius: 6px; background: var(--field); }
.al-cell { border: 0; background: none; position: relative; border-radius: 3px; }
.al-cell::after { content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 1px; background: var(--text-3); opacity: .6; }
.al-cell:hover { background: var(--bg-3); }
.al-cell.on::after { width: 12px; height: 4px; margin: -2px -6px; background: var(--accent); opacity: 1; box-shadow: 0 5px 0 var(--accent); height: 3px; margin-top: -4px; }
.al-grid.col .al-cell.on::after { width: 3px; height: 12px; margin: -6px -4px; box-shadow: 5px 0 0 var(--accent); }
.al-side { display: flex; flex-direction: column; gap: 8px; }

/* ---------- canvas ---------- */
.viewport {
  grid-area: canvas; position: relative; overflow: hidden; background: #EDEDEF; outline: none;
  contain: strict; user-select: none; -webkit-user-select: none; touch-action: none;
}
.viewport.drop { box-shadow: inset 0 0 0 3px var(--sel); }
.viewport:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.world {
  position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0;
  font-size: 16px; line-height: normal; color: #000; letter-spacing: normal; text-align: left; font-family: system-ui, sans-serif;
}
.world .n { position: absolute; box-sizing: border-box; margin: 0; }
.world .n[data-type="group"], .world .n[data-type="path"] { pointer-events: none; }
.world .n[data-type="text"] { cursor: default; }
.world .n > svg.pv { position: absolute; left: 0; top: 0; display: block; overflow: visible; pointer-events: none; }
.world .n > svg.pv * { pointer-events: none; }
.world .n > svg.pv .hit { pointer-events: visiblePainted; }
.world .n.editing { cursor: text; user-select: text; -webkit-user-select: text; outline: none; caret-color: var(--sel); }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.flabel {
  position: absolute; display: flex; align-items: center; gap: 3px; padding-bottom: 5px; font-size: 11px; line-height: 13px;
  color: #7A7A84; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transform-origin: 0 0;
}
.flabel span { overflow: hidden; text-overflow: ellipsis; }
.flabel.hov { color: #3A3A42; }
.flabel.sel { color: var(--sel); }
.flabel.comp { color: var(--sel-comp); }
:root[data-theme="dark"] .flabel { color: #9A9AA4; }
.o-sel { fill: none; stroke: var(--sel); stroke-width: 1.5; }
.o-sel-item { fill: none; stroke: var(--sel); stroke-width: 1; }
.o-hover { fill: none; stroke: var(--sel); stroke-width: 2; }
.o-sel.comp, .o-sel-item.comp, .o-hover.comp { stroke: var(--sel-comp); }
.o-handle { fill: #fff; stroke: var(--sel); stroke-width: 1.2; }
.o-handle.comp { stroke: var(--sel-comp); }
.o-badge rect { fill: var(--sel); }
.o-badge.comp rect { fill: var(--sel-comp); }
.o-badge text, .o-mlabel text { fill: #fff; font: 600 10.5px/1 var(--font); font-variant-numeric: tabular-nums; }
.o-guide { stroke: var(--guide); stroke-width: 1; }
.o-guide-x { stroke: var(--guide); stroke-width: 1; fill: none; }
.o-measure { stroke: var(--guide); stroke-width: 1; }
.o-mlabel rect { fill: var(--guide); }
.o-mbox { fill: none; stroke: var(--guide); stroke-width: 1; stroke-dasharray: 3 2; }
.o-marquee { fill: rgb(13 153 255 / .08); stroke: var(--sel); stroke-width: 1; }
.o-drop { fill: rgb(13 153 255 / .06); stroke: var(--sel); stroke-width: 2; }
.o-insert { stroke: var(--sel); stroke-width: 3; stroke-linecap: round; }
.o-path { fill: none; stroke: var(--sel); stroke-width: 1.5; }
.o-path.ghost { stroke-dasharray: 4 3; opacity: .7; }
.o-anchor { fill: #fff; stroke: var(--sel); stroke-width: 1.3; }
.o-anchor.sel { fill: var(--sel); }
.o-hline { stroke: var(--sel); stroke-width: 1; opacity: .8; }
.o-hdot { fill: #fff; stroke: var(--sel); stroke-width: 1.2; }
.inline-rename { position: fixed; z-index: 60; height: 20px; font-size: 11px; padding: 0 4px; border: 1px solid var(--sel); border-radius: 3px; background: var(--bg); outline: none; }

/* ---------- menus & popovers ---------- */
.menu {
  position: fixed; z-index: 1000; min-width: 230px; max-height: calc(100vh - 16px); overflow: auto; padding: 6px; border-radius: 10px;
  background: var(--menu); color: var(--menu-text); box-shadow: var(--shadow-lg); outline: none;
}
.menu-item {
  display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 6px; width: 100%; height: 28px; padding: 0 10px 0 6px;
  border: 0; border-radius: 6px; background: none; color: inherit; text-align: left; white-space: nowrap;
}
.menu-item:hover:not(.disabled), .menu-item:focus-visible { background: var(--menu-hover); outline: none; }
.menu-item.disabled { opacity: .38; }
.mi-key { color: rgb(255 255 255 / .5); font-size: 11px; padding-left: 16px; }
.mi-sub { opacity: .6; }
.menu-sep { height: 1px; margin: 5px 4px; background: rgb(255 255 255 / .1); }
.menu-header { padding: 8px 10px 4px; font-size: 11px; color: rgb(255 255 255 / .5); font-weight: 600; }
.popover {
  position: fixed; z-index: 900; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.picker { width: 252px; }
.picker-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 10px; border-bottom: 1px solid var(--border); }
.picker-head .seg { flex: 1; }
.picker-title { flex: 1; font-weight: 600; }
.picker-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.color-ui { display: flex; flex-direction: column; gap: 10px; }
.sv { position: relative; height: 176px; border-radius: 6px; cursor: crosshair; touch-action: none; }
.hue, .alpha { position: relative; height: 12px; border-radius: 6px; cursor: pointer; touch-action: none; }
.hue { background: linear-gradient(to right, #f00, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00); }
.alpha { background: var(--checker); }
.alpha-fill { position: absolute; inset: 0; border-radius: 6px; }
.knob { position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; top: 50%; border-radius: 50%; border: 2.5px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .25), 0 1px 3px rgb(0 0 0 / .3); pointer-events: none; }
.sv .knob { top: 0; }
.color-row { display: flex; align-items: center; gap: 6px; }
.color-row .hash { color: var(--text-3); margin-right: -4px; }
.color-row .hex { flex: 1; font-family: var(--mono); text-transform: uppercase; }
.color-row .pct { width: 58px; flex: none; }
.picker-sub { font-size: 11px; color: var(--text-3); font-weight: 600; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch { aspect-ratio: 1; border: 0; border-radius: 5px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .14); padding: 0; }
.stops { display: flex; flex-direction: column; gap: 10px; }
.stops-bar { position: relative; height: 16px; border-radius: 4px; margin: 4px 7px; cursor: copy; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .1); }
.stop { position: absolute; top: 50%; width: 14px; height: 22px; margin: -11px 0 0 -7px; border-radius: 4px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .3), 0 1px 3px rgb(0 0 0 / .3); cursor: ew-resize; touch-action: none; }
.stop.on { box-shadow: 0 0 0 2px var(--sel), 0 1px 3px rgb(0 0 0 / .3); }
.stops-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.img-preview { height: 140px; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--border); }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.gap .select { flex: 1; }
.font-picker { width: 260px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.font-list { max-height: 320px; overflow: auto; display: flex; flex-direction: column; }
.font-item { display: flex; justify-content: space-between; align-items: center; height: 30px; padding: 0 8px; border: 0; border-radius: 6px; background: none; text-align: left; }
.font-item:hover, .font-item.on { background: var(--bg-2); }
.font-item .muted { font-size: 11px; }

/* ---------- dialogs ---------- */
.backdrop { position: fixed; inset: 0; z-index: 800; display: grid; place-items: center; padding: 16px; background: rgb(10 10 14 / .45); animation: fade .12s ease-out; }
.dialog { width: min(440px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--bg); border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .14s ease-out; }
.dialog.wide { width: min(760px, 100%); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 20px; }
.dialog-head h2 { margin: 0; font-size: 15px; }
.dialog-body { padding: 8px 20px 16px; overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
.dialog-text { margin: 0; color: var(--text-2); font-size: 13px; line-height: 1.5; }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field > span { color: var(--text-2); font-weight: 500; }
.field-row { display: flex; gap: 12px; }
.file-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 14px; }
.file-card { position: relative; border-radius: 10px; border: 1px solid var(--border); overflow: hidden; cursor: pointer; background: var(--bg); }
.file-card:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.file-card.current { border-color: var(--accent); }
.file-card .thumb { aspect-ratio: 16 / 10; background: var(--bg-2) center / contain no-repeat; display: grid; place-items: center; color: var(--text-3); }
.file-card .meta { display: flex; flex-direction: column; padding: 8px 10px 10px; gap: 2px; }
.file-card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 22px; }
.file-card .more { position: absolute; right: 4px; bottom: 16px; }
.palette-dialog { width: min(560px, 100%); align-self: start; margin-top: 12vh; }
.palette-dialog .dialog-head { display: none; }
.palette-dialog .dialog-body { padding: 10px; }
.palette-input { height: 38px; font-size: 14px; }
.palette-list { display: flex; flex-direction: column; margin-top: 8px; max-height: 50vh; overflow: auto; }
.pal-item { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; height: 34px; padding: 0 10px; border: 0; border-radius: 7px; background: none; text-align: left; }
.pal-item.on { background: var(--accent-weak); }
.pal-item .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-item .muted { font-size: 11px; }
.shortcuts { columns: 2 280px; column-gap: 28px; }
.sc-group { break-inside: avoid; margin-bottom: 16px; }
.sc-group h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin: 0 0 6px; }
.sc-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.about { text-align: center; padding: 8px 8px 0; }
.about .logo { margin: 0 auto 12px; }
.about p { font-size: 13px; line-height: 1.5; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 2000; max-width: min(520px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 10px;
  background: var(--menu); color: var(--menu-text); box-shadow: var(--shadow-lg); font-size: 12.5px;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: transform .18s ease, opacity .18s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: var(--danger); color: #fff; }
.toast.success::before { content: "✓  "; color: #6EE7A8; }

/* ---------- presentation ---------- */
.present { position: fixed; inset: 0; z-index: 1500; background: #0E0E11; overflow: hidden; outline: none; cursor: pointer; }
.present-slot { position: absolute; inset: 0 0 40px; }
.present-slot > .n { box-shadow: 0 20px 80px rgb(0 0 0 / .5); }
.present-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 40px; display: grid; place-items: center; color: #8B8B96; font-size: 12px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- small screens: keep the canvas usable ---------- */
@media (max-width: 1100px) {
  .save-status { display: none; }
  .tools .tool-group:nth-child(3) .tool:nth-child(n+3) { display: none; }
}
@media (max-width: 820px) {
  :root { --left: 0px !important; --right: 0px !important; }
  .panel.left, .panel.right, .resizer { display: none; }
  .topbar { grid-template-columns: auto 1fr auto; }
  .doc-name { width: 100%; }
  .tb-right .icon-btn:not(.theme-btn), .zoom-btn { display: none; }
  .export-btn span:last-child { display: none; }
}
.noscript { padding: 40px; font-size: 14px; }
.sec.presets .sec-body { gap: 0; }
.preset-row { display: flex; justify-content: space-between; align-items: center; height: 30px; padding: 0 8px; margin: 0 -8px; border: 0; border-radius: 6px; background: none; text-align: left; }
.preset-row:hover { background: var(--bg-2); }
.version-list { display: flex; flex-direction: column; margin-bottom: 12px; max-height: 50vh; overflow: auto; }
.version-row { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.v-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); justify-self: center; }
.v-dot.auto { background: var(--text-3); }
.v-meta { display: flex; flex-direction: column; min-width: 0; }
.v-meta .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* color styles */
.style-chip {
  flex: 1; min-width: 0; height: 28px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px; background: var(--field);
  text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500;
}
.style-chip:hover { border-color: var(--border-2); }
.style-picker { width: 260px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.sp-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 0; }
.style-list { max-height: 300px; overflow: auto; display: flex; flex-direction: column; }
.style-item { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; height: 32px; padding: 0 6px; border: 0; border-radius: 6px; background: none; text-align: left; }
.style-item:hover, .style-item.on { background: var(--bg-2); }
.style-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.style-item .muted { font-size: 11px; font-family: var(--mono); }
.style-row { display: grid; grid-template-columns: 22px 1fr auto 28px; gap: 8px; align-items: center; min-height: 30px; }
.style-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; }
.style-row .muted { font-size: 11px; }
.swatch.on { box-shadow: 0 0 0 2px var(--sel); }
.pad-s { padding: 8px 4px; }
/* text styles */
.ts-row { display: flex; align-items: center; gap: 4px; }
.ts-row .style-chip { display: flex; align-items: center; gap: 8px; }
.ts-btn { flex: 1; justify-content: flex-start; }
.ts-preview { display: inline-block; width: 26px; text-align: center; line-height: 1; color: var(--text); flex: none; }
.style-item.ts { grid-template-columns: 30px 1fr auto; }
.ts-editor { width: 260px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.ts-srow { grid-template-columns: 30px 1fr auto 28px; }
.ts-name { display: flex; flex-direction: column; min-width: 0; cursor: pointer; }
.ts-name .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* variants */
.var-row { display: grid; grid-template-columns: 1fr 1fr 28px; gap: 6px; align-items: center; }
.var-key { color: var(--text-2); }
.var-prop .plabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.o-set { fill: none; stroke: var(--sel-comp); stroke-width: 1; stroke-dasharray: 5 4; opacity: .8; }
.asset .name .muted { font-size: 11px; }
/* paint rows: keep the hex field readable next to style / visibility / remove buttons */
.paint-row { gap: 4px; }
.paint-row > .icon-btn { width: 24px; }
.paint-row .nf.op { width: 58px; }
.paint-row .nf.op .nf-input { padding: 0 2px 0 6px; }
.paint-row .nf.op .nf-suffix { padding-right: 5px; }
.paint-row .hexin { min-width: 62px; padding: 0 6px; }
.o-textsel { fill: rgb(13 153 255 / .28); }
