/* ==========================================================================
   IconSetter Studio
   --------------------------------------------------------------------------
   Three themes. The light palette is defined on bare :root, and the dark one
   is redefined twice: once behind prefers-color-scheme for the default
   "system" setting, once behind [data-theme="dark"] so an explicit choice
   wins in both directions. No colour is ever defined only inside a media
   query, so nothing can end up unstyled.
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f4f6fa;
  --panel-3: #e9edf3;
  --panel-hi: #ffffff;
  --line: #e0e5ee;
  --line-soft: #eef1f6;

  --ink: #10141d;
  --ink-2: #394154;
  --muted: #697487;
  --faint: #9aa4b6;

  --accent: #2f6ae0;
  --accent-hover: #2559c9;
  --accent-ink: #ffffff;
  --accent-soft: rgba(47, 106, 224, .10);
  --accent-ring: rgba(47, 106, 224, .22);
  --accent-line: rgba(47, 106, 224, .38);

  --ok: #14875a;
  --ok-soft: rgba(20, 135, 90, .10);
  --warn: #9a6412;
  --warn-soft: rgba(154, 100, 18, .10);
  --err: #c0372b;
  --err-soft: rgba(192, 55, 43, .10);

  --shadow-sm: 0 1px 2px rgba(16, 20, 29, .06), 0 1px 3px rgba(16, 20, 29, .05);
  --shadow-md: 0 4px 12px rgba(16, 20, 29, .08), 0 1px 3px rgba(16, 20, 29, .06);
  --shadow-lg: 0 18px 44px rgba(16, 20, 29, .14), 0 2px 8px rgba(16, 20, 29, .07);
  --scrim: rgba(28, 34, 46, .38);

  --checker-a: #eceff4;
  --checker-b: #f7f9fc;

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --topbar-h: 54px;
  --sidebar-w: 264px;
  --tools-w: 50px;
  --inspector-w: 316px;

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

  --ease: cubic-bezier(.22, .61, .36, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #0a0c11;
    --panel: #11141b;
    --panel-2: #171b23;
    --panel-3: #1e232d;
    --panel-hi: #232935;
    --line: #262c38;
    --line-soft: #1b2029;

    --ink: #e9edf6;
    --ink-2: #c2cad9;
    --muted: #8b94a8;
    --faint: #5d6679;

    --accent: #6aa9ff;
    --accent-hover: #85b9ff;
    --accent-ink: #06111f;
    --accent-soft: rgba(106, 169, 255, .14);
    --accent-ring: rgba(106, 169, 255, .26);
    --accent-line: rgba(106, 169, 255, .42);

    --ok: #4ade80;
    --ok-soft: rgba(74, 222, 128, .13);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, .13);
    --err: #f87171;
    --err-soft: rgba(248, 113, 113, .13);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, .42);
    --shadow-lg: 0 22px 54px rgba(0, 0, 0, .55), 0 2px 10px rgba(0, 0, 0, .4);
    --scrim: rgba(4, 6, 10, .66);

    --checker-a: #0e1117;
    --checker-b: #131822;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0a0c11;
  --panel: #11141b;
  --panel-2: #171b23;
  --panel-3: #1e232d;
  --panel-hi: #232935;
  --line: #262c38;
  --line-soft: #1b2029;

  --ink: #e9edf6;
  --ink-2: #c2cad9;
  --muted: #8b94a8;
  --faint: #5d6679;

  --accent: #6aa9ff;
  --accent-hover: #85b9ff;
  --accent-ink: #06111f;
  --accent-soft: rgba(106, 169, 255, .14);
  --accent-ring: rgba(106, 169, 255, .26);
  --accent-line: rgba(106, 169, 255, .42);

  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, .13);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .13);
  --err: #f87171;
  --err-soft: rgba(248, 113, 113, .13);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, .42);
  --shadow-lg: 0 22px 54px rgba(0, 0, 0, .55), 0 2px 10px rgba(0, 0, 0, .4);
  --scrim: rgba(4, 6, 10, .66);

  --checker-a: #0e1117;
  --checker-b: #131822;
}

:root[data-theme="light"] { color-scheme: light; }

/* ------------------------------------------------------------------ reset */
* { box-sizing: border-box; }

/* Class-level display rules out-specify the UA's [hidden] - force it. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13.5px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.011em; }
button, input, select, textarea { font: inherit; color: inherit; }
p { margin: 0; }
.muted { color: var(--muted); }
code { font-family: var(--mono); font-size: .92em; }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent-ring);
  border-radius: var(--radius-xs);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2);
  cursor: pointer; white-space: nowrap; font-weight: 500;
  transition: background .13s var(--ease), border-color .13s var(--ease),
              color .13s var(--ease), transform .08s var(--ease);
}
.btn:hover { background: var(--panel-3); color: var(--ink); }
/* An svg is a flex item like any other and a tight button will squash it. */
.btn svg, .tool svg, .layer-ic svg, .seg svg, .popup svg, .num-grip svg,
.align-grid svg, .empty-state svg { flex: none; }
.btn:active { transform: translateY(.5px); }
.btn.primary {
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
  font-weight: 600; box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--line); }
.btn.icon { padding: 0; width: 30px; height: 30px; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn.icon.sm { width: 25px; height: 25px; }
.btn.lg { padding: 11px 20px; font-size: 14.5px; }
.btn.wide { width: 100%; }
.btn.danger {
  color: var(--err); border-color: var(--line);
}
.btn.danger:hover { background: var(--err-soft); border-color: var(--err); }
.btn.danger.primary { background: var(--err); border-color: transparent; color: #fff; }
.btn.danger.primary:hover { filter: brightness(1.08); }
.btn[disabled] { opacity: .42; pointer-events: none; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--panel-3); border: 1px solid var(--line);
  color: var(--muted); font-size: 11.5px; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.chip.accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }

/* ----------------------------------------------------------------- inputs */
.input,
input[type="text"], input[type="search"], textarea, select {
  width: 100%; padding: 6px 9px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  transition: border-color .13s var(--ease), box-shadow .13s var(--ease);
}
.input:hover, input[type="text"]:hover, select:hover, textarea:hover { border-color: var(--faint); }
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea {
  resize: vertical; min-height: 58px;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
}
select { cursor: pointer; appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* --- checkbox as a switch ------------------------------------------------ */
.switch {
  appearance: none; margin: 0; cursor: pointer; flex: none;
  width: 34px; height: 20px; border-radius: 999px;
  background: var(--panel-3); border: 1px solid var(--line);
  position: relative; transition: background .16s var(--ease), border-color .16s var(--ease);
}
.switch::after {
  content: ""; position: absolute; inset: 2px auto 2px 2px;
  width: 14px; border-radius: 50%; background: var(--faint);
  transition: transform .16s var(--ease), background .16s var(--ease);
}
.switch:checked { background: var(--accent); border-color: transparent; }
.switch:checked::after { transform: translateX(14px); background: var(--accent-ink); }

/* --- number scrubber ---------------------------------------------------- */
.num {
  display: flex; align-items: stretch; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); overflow: hidden;
  transition: border-color .13s var(--ease), box-shadow .13s var(--ease);
}
.num:hover { border-color: var(--faint); }
.num:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.num-grip {
  flex: none; width: 22px; display: grid; place-items: center;
  cursor: ew-resize; color: var(--faint); background: var(--panel-2);
  border-right: 1px solid var(--line); user-select: none;
  transition: color .13s var(--ease), background .13s var(--ease);
}
.num-grip:hover { color: var(--accent); background: var(--accent-soft); }
.num-grip svg { display: block; }
.num input {
  flex: 1; min-width: 0; width: 100%;
  border: 0; background: transparent; padding: 6px 4px 6px 8px;
  font-variant-numeric: tabular-nums;
}
.num input:focus { outline: none; box-shadow: none; }
.num-suffix {
  flex: none; display: grid; place-items: center; padding: 0 7px 0 2px;
  color: var(--faint); font-size: 11.5px; pointer-events: none;
}
.num-steps {
  flex: none; display: flex; flex-direction: column;
  border-left: 1px solid var(--line); opacity: 0;
  transition: opacity .13s var(--ease);
}
.num:hover .num-steps, .num:focus-within .num-steps { opacity: 1; }
.num-steps button {
  flex: 1; width: 18px; border: 0; padding: 0; cursor: pointer;
  background: var(--panel-2); color: var(--muted); font-size: 8px; line-height: 1;
}
.num-steps button:hover { background: var(--accent-soft); color: var(--accent); }
.num-steps button:first-child { border-bottom: 1px solid var(--line); }
.num.scrubbing { border-color: var(--accent); }

/* --- colour field ------------------------------------------------------- */
.color-field { display: flex; gap: 6px; align-items: center; min-width: 0; }
.swatch {
  flex: none; width: 28px; height: 28px; padding: 0; cursor: pointer;
  border-radius: var(--radius-xs); border: 1px solid var(--line);
  position: relative; overflow: hidden;
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}
.swatch i { position: absolute; inset: 0; display: block; }
.swatch input { position: absolute; inset: -8px; opacity: 0; cursor: pointer; }
.color-field input[type="text"] { font-family: var(--mono); font-size: 11.5px; }

/* --- slider ------------------------------------------------------------- */
.slider { display: flex; align-items: center; gap: 9px; min-width: 0; }
.slider input[type="range"] {
  flex: 1; min-width: 0; height: 18px; appearance: none; background: transparent;
  cursor: pointer; margin: 0;
}
.slider input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px; background: var(--panel-3);
}
.slider input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 13px; height: 13px; margin-top: -4.5px;
  border-radius: 50%; background: var(--accent);
  border: 2px solid var(--panel); box-shadow: var(--shadow-sm);
}
.slider input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 999px; background: var(--panel-3);
}
.slider input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--panel); box-shadow: var(--shadow-sm);
}
.slider .chip { flex: none; min-width: 42px; justify-content: center; }

/* --- segmented ---------------------------------------------------------- */
.seg {
  display: flex; gap: 2px; padding: 2px; min-width: 0;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.seg button {
  flex: 1; min-width: 0; padding: 4px 7px; border: 0; cursor: pointer;
  border-radius: var(--radius-xs); background: transparent; color: var(--muted);
  font-size: 11.5px; font-weight: 500; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
  transition: background .13s var(--ease), color .13s var(--ease);
}
.seg button:hover { color: var(--ink); }
.seg button.on {
  background: var(--panel-hi); color: var(--ink);
  box-shadow: var(--shadow-sm); font-weight: 600;
}
.seg.icons button { flex: none; width: 28px; display: grid; place-items: center; }

/* ------------------------------------------------------------------- gate */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1000px 560px at 18% -12%, var(--accent-soft), transparent 62%),
    radial-gradient(760px 460px at 105% 112%, var(--accent-soft), transparent 60%),
    var(--bg);
  z-index: 60;
}
.gate-card {
  width: min(432px, 100%); text-align: center; padding: 42px 36px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
}
.gate-mark { margin-bottom: 20px; }
.gate-card h1 { font-size: 22px; margin-bottom: 9px; }
.gate-card h1 span { color: var(--muted); font-weight: 500; }
.gate-card > p { color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.gate-note { margin-top: 16px !important; font-size: 12px; color: var(--muted); }
.gate-note.error { color: var(--err); }
.gate-theme { position: fixed; top: 16px; right: 16px; }

/* -------------------------------------------------------------- app shell */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 14px;
  padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 14px; flex: none; }
.brand b { font-weight: 700; }
.topbar-mid { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.name-input {
  max-width: 300px; font-weight: 600; font-size: 14px;
  background: transparent; border-color: transparent;
}
.name-input:hover { background: var(--panel-2); border-color: var(--line); }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.dot-dirty {
  width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none;
  box-shadow: 0 0 0 3px var(--warn-soft);
}

.workspace {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: var(--sidebar-w) var(--tools-w) 1fr var(--inspector-w);
}

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.side-head, .panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px 8px;
}
.side-head h2, .panel-head h2 {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint);
  font-weight: 600;
}
.side-search { padding: 0 11px 9px; }
.tpl-list {
  flex: 1; overflow-y: auto; padding: 0 9px 10px;
  display: flex; flex-direction: column; gap: 4px;
}

.tpl-card {
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px;
  padding: 8px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid transparent; background: transparent; text-align: left;
  transition: background .13s var(--ease), border-color .13s var(--ease);
}
.tpl-card:hover { background: var(--panel-2); }
.tpl-card.active { background: var(--accent-soft); border-color: var(--accent-line); }
.tpl-card canvas {
  width: 44px; height: 44px; border-radius: var(--radius-xs);
  background: var(--panel-2); border: 1px solid var(--line-soft);
}
.tpl-meta { min-width: 0; }
.tpl-meta strong {
  display: block; font-size: 12.5px; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tpl-meta span { font-size: 11px; color: var(--muted); }
.tpl-card.inactive .tpl-meta strong { color: var(--faint); }
.tpl-card.inactive canvas { opacity: .42; }
.tpl-menu { opacity: 0; transition: opacity .13s var(--ease); }
.tpl-card:hover .tpl-menu, .tpl-card.active .tpl-menu, .tpl-menu:focus-visible { opacity: 1; }

.side-foot {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 11px; border-top: 1px solid var(--line);
}
.account { display: flex; align-items: center; gap: 8px; min-width: 0; }
.account img {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--panel-3); flex: none; object-fit: cover;
}
.account-meta { min-width: 0; line-height: 1.32; }
.account-meta strong { display: block; font-size: 12px; font-weight: 550; }
.account-meta span {
  display: block; font-size: 10.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 128px;
}

/* ------------------------------------------------------------------ tools */
.tools {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.tool {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer;
  transition: background .13s var(--ease), color .13s var(--ease);
}
.tool:hover { background: var(--panel-2); color: var(--ink); }
.tool.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.tool svg { display: block; }
.tool-sep { width: 20px; height: 1px; background: var(--line); margin: 5px 0; }

/* ------------------------------------------------------------------ stage */
.stage { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.stage-scroll {
  flex: 1; min-height: 0; display: grid; place-items: center; overflow: auto; padding: 26px;
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-a) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-a) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-a) 75%);
  background-color: var(--checker-b);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.stage-inner { position: relative; line-height: 0; box-shadow: var(--shadow-lg); }
.stage-inner canvas { display: block; }
#overlay { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
.stage-inner.move-tool #overlay { cursor: default; }
.stage-inner.panning #overlay { cursor: grabbing; }

.stage-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; padding: 8px 12px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.zoom { display: flex; align-items: center; gap: 5px; }
.preview-data { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.preview-data label {
  display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted);
}
.preview-data .input { width: 230px; }
.preview-data .num { width: 84px; }
.file-label { cursor: pointer; }

/* --- real-size preview strip -------------------------------------------- */
.sizes {
  flex: none; display: flex; align-items: flex-end; gap: 16px;
  padding: 11px 14px; overflow-x: auto;
  background: var(--panel-2); border-top: 1px solid var(--line);
}
.btn.sm.on, .btn.on {
  background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent);
}
.sizes-label {
  flex: none; align-self: center; max-width: 96px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--faint); font-weight: 600; line-height: 1.35;
}
.size-cell { flex: none; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.size-cell canvas { image-rendering: auto; }
.size-cell span { font-size: 10px; color: var(--faint); font-variant-numeric: tabular-nums; }
.sizes-swap { flex: none; align-self: center; margin-left: auto; }
.sizes.on-dark { background: #14161c; }
.sizes.on-dark .sizes-label, .sizes.on-dark .size-cell span { color: #7d8798; }
.sizes.on-light { background: #eef1f6; }
.sizes.on-light .sizes-label, .sizes.on-light .size-cell span { color: #7b8496; }

/* -------------------------------------------------------------- inspector */
.inspector {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line);
}
.layers { display: flex; flex-direction: column; min-height: 132px; max-height: 40%; }
.panel-actions { display: flex; gap: 3px; }
.layer-list { flex: 1; overflow-y: auto; padding: 0 7px 9px; }

.layer-row {
  display: grid; grid-template-columns: 20px 20px 1fr; align-items: center; gap: 5px;
  padding: 5px 7px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid transparent;
}
.layer-row:hover { background: var(--panel-2); }
.layer-row.active { background: var(--accent-soft); border-color: var(--accent-line); }
.layer-row.dragging { opacity: .38; }
.layer-row.drop-above { box-shadow: inset 0 2px 0 var(--accent); }
.layer-row.drop-below { box-shadow: inset 0 -2px 0 var(--accent); }
.layer-ic {
  display: grid; place-items: center; width: 19px; height: 19px;
  border-radius: var(--radius-xs); color: var(--faint);
  background: transparent; border: 0; cursor: pointer; padding: 0;
}
.layer-ic:hover { background: var(--panel-3); color: var(--ink); }
.layer-ic.on { color: var(--accent); }
.layer-ic svg { display: block; }
.layer-name {
  min-width: 0; font-size: 12px; display: flex; align-items: baseline; gap: 6px;
}
.layer-name b {
  font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.layer-name em { color: var(--faint); font-style: normal; font-size: 10.5px; flex: none; }
.layer-row.hidden-layer .layer-name b { color: var(--faint); }
.layer-name input {
  width: 100%; padding: 1px 4px; font-size: 12px; border-radius: var(--radius-xs);
}

.props { flex: 1; display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); }
.prop-panel { flex: 1; overflow-y: auto; padding: 0 13px 22px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 30px 16px; text-align: center; color: var(--faint);
}
.empty-state svg { opacity: .5; }
.empty-state p { font-size: 12px; line-height: 1.5; }
.empty-state strong { color: var(--muted); font-size: 12.5px; font-weight: 550; }

.group { border-top: 1px solid var(--line-soft); padding: 10px 0 3px; }
.group:first-child { border-top: 0; }
.group > h3 {
  font-size: 10px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--faint); margin-bottom: 8px; display: flex; align-items: center; gap: 7px;
  font-weight: 600;
}
.field {
  display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px;
  margin-bottom: 6px;
}
.field > label { font-size: 11.5px; color: var(--muted); }
.field.wide { grid-template-columns: 1fr; gap: 4px; }
.field.inline { grid-template-columns: 1fr auto; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; min-width: 0; }
.hint { font-size: 11px; color: var(--faint); margin: 1px 0 8px; line-height: 1.45; }
.hint.warn { color: var(--warn); }
.checks { display: flex; gap: 14px; align-items: center; }
.checks label {
  display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted);
  cursor: pointer;
}

.field.inactive > label { color: var(--faint); }
.field.inactive input, .field.inactive select,
.field.inactive textarea, .field.inactive button { opacity: .4; cursor: not-allowed; }
.field.inactive .seg, .field.inactive .num, .field.inactive .swatch { opacity: .4; }
.inactive-note {
  display: block; margin-top: 3px; font-size: 10.5px; line-height: 1.4;
  color: var(--faint); font-style: italic;
}

.asset-preview {
  width: 100%; height: 78px; border-radius: var(--radius-sm);
  border: 1px dashed var(--line); margin-bottom: 6px;
  background: var(--panel-2) center/contain no-repeat;
}
.align-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.align-grid button {
  height: 26px; display: grid; place-items: center; padding: 0;
  border-radius: var(--radius-xs); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); cursor: pointer;
}
.align-grid button:hover { background: var(--accent-soft); color: var(--accent); }

/* ----------------------------------------------------------------- modals */
.scrim {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 22px;
  background: var(--scrim); backdrop-filter: blur(3px);
  animation: fade .16s var(--ease);
}
.modal {
  width: min(520px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pop .18s var(--ease);
}
.modal.wide { width: min(780px, 100%); }
.modal.narrow { width: min(412px, 100%); }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 15px; }
.modal-head p { font-size: 12px; color: var(--muted); margin-top: 3px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-body > .field:last-child { margin-bottom: 0; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 13px 18px; border-top: 1px solid var(--line);
}
.modal-foot .spacer { margin-right: auto; font-size: 11.5px; color: var(--muted); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; }
.settings-grid .group { border-top: 0; padding-top: 0; }

.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.help-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.help-table caption {
  text-align: left; padding: 0 0 7px; color: var(--faint); font-weight: 600;
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
}
.help-table td { padding: 5px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.help-table td:first-child { width: 48%; }
.help-table code {
  background: var(--panel-2); padding: 1px 5px; border-radius: 5px;
  border: 1px solid var(--line); color: var(--accent); white-space: nowrap;
}
.help-table td:last-child { color: var(--muted); }
.keys { display: grid; gap: 5px; }
.keys div { display: flex; align-items: baseline; gap: 10px; font-size: 12px; }
.keys kbd {
  flex: none; min-width: 22px; text-align: center;
  padding: 2px 6px; border-radius: 5px; font-family: var(--font); font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-width: 2px; color: var(--ink-2);
}
.keys span { color: var(--muted); }

/* ------------------------------------------------------------- popup menu */
.popup {
  position: fixed; z-index: 55; min-width: 196px; padding: 5px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: pop .13s var(--ease);
}
.popup button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border: 0; border-radius: var(--radius-xs);
  background: transparent; color: var(--ink-2); cursor: pointer;
  font-size: 12.5px; text-align: left;
}
.popup button:hover { background: var(--panel-2); color: var(--ink); }
.popup button.danger { color: var(--err); }
.popup button.danger:hover { background: var(--err-soft); }
.popup button .k { margin-left: auto; color: var(--faint); font-size: 11px; }
.popup hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

/* ------------------------------------------------------------ toast, busy */
.toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 70; display: flex; flex-direction: column; gap: 7px; align-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 15px; border-radius: 999px; font-size: 12.5px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow-lg); color: var(--ink);
  animation: rise .2s var(--ease);
}
.toast.ok { border-color: var(--ok); color: var(--ok); }
.toast.err { border-color: var(--err); color: var(--err); }
.toast .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.busy {
  position: fixed; inset: 0; z-index: 65; display: flex; gap: 13px;
  align-items: center; justify-content: center; flex-direction: column;
  background: var(--scrim); backdrop-filter: blur(2px);
  color: var(--muted); font-size: 12.5px;
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--panel-3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--panel-3); border-radius: 6px; border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: padding-box; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1240px) {
  :root { --sidebar-w: 224px; --inspector-w: 292px; }
  .preview-data .input { width: 168px; }
}
@media (max-width: 1020px) {
  .workspace { grid-template-columns: var(--tools-w) 1fr; grid-template-rows: 1fr auto; }
  .sidebar { display: none; }
  .inspector {
    grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line);
    max-height: 44vh; flex-direction: row;
  }
  .layers, .props { flex: 1; max-height: none; }
  .props { border-top: 0; border-left: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; height: auto; padding: 9px 11px; gap: 9px; }
  .settings-grid, .help-cols { grid-template-columns: 1fr; }
  .sizes { display: none; }
}
@media (max-width: 680px) {
  .topbar-actions .btn.ghost { display: none; }
  .inspector { flex-direction: column; }
  .props { border-left: 0; border-top: 1px solid var(--line); }
}
