/* Icon Recomposer — editor UI. Dark, calm, tool-like. */
:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #161922;
  --panel-2: #1c2030;
  --line: #2a2f3a;
  --line-2: #353c4a;
  --text: #e6e8ec;
  --muted: #9aa0aa;
  --accent: #5b9dff;
  --accent-weak: #24304a;
  --radius: 10px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- top bar ---- */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  font-size: 14px;
}
.brand-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  vertical-align: middle;
  margin-right: 8px;
}
.brand .version {
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 0;
  color: var(--muted);
}
.doc-name {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  font: inherit;
  border-radius: 8px;
  padding: 0.3rem 0.55rem;
  width: 150px;
}
.doc-name:focus { outline: none; border-color: var(--accent); }
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
}
.spacer { flex: 1; }

.tbtn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.tbtn:hover { border-color: var(--accent); }
.tbtn:active { transform: translateY(1px); }
.tbtn.icon { font-size: 15px; line-height: 1; padding: 0.35rem 0.55rem; }
.tbtn:disabled { opacity: 0.4; cursor: default; }

.privacy-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  padding: 0.35rem 0.5rem;
  white-space: nowrap;
}
.privacy-link:hover { color: var(--accent); }

.dropdown { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 4px;
  min-width: 200px;
  z-index: 30;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 0.5rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
}
.menu button:hover { background: var(--accent-weak); }

/* ---- workspace ---- */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px 1fr 300px;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0; /* grid items default to min-width:auto and would overflow the track */
  padding: 0.75rem;
}
#inspector { border-right: none; border-left: 1px solid var(--line); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0;
}
.hint { color: var(--muted); font-size: 11px; margin: 0.75rem 0 0; }
.link {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font: inherit; padding: 0;
}

/* ---- layer list ---- */
.layer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
}
.layer-item:hover { border-color: var(--line-2); }
.layer-item.selected { border-color: var(--accent); background: var(--accent-weak); }
.layer-item.primary { box-shadow: inset 3px 0 0 var(--accent); }
.layer-item .vis {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 13px; padding: 0; width: 18px; text-align: center;
}
.layer-item .lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item.hidden-layer .lname { color: var(--muted); text-decoration: line-through; }
.layer-item .mini {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 12px; padding: 2px 3px; border-radius: 5px;
}
.layer-item .mini:hover { color: var(--text); background: rgba(255,255,255,0.08); }

/* ---- stage / canvas ---- */
.stage {
  background:
    radial-gradient(120% 120% at 50% 0%, #1a1e29 0%, #0c0e13 100%);
  display: grid;
  place-items: center;
  padding: 2rem;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.canvas-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  max-width: min(100%, 70vh);
  max-height: 100%;
  width: 70vh;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.checker {
  position: absolute; inset: 0;
  background-color: #cfd3da;
  background-image:
    linear-gradient(45deg, #9aa0aa 25%, transparent 25%),
    linear-gradient(-45deg, #9aa0aa 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #9aa0aa 75%),
    linear-gradient(-45deg, transparent 75%, #9aa0aa 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.preview { position: absolute; inset: 0; }
.preview svg { display: block; width: 100%; height: 100%; }

/* selection marquee — drawn over the preview, never part of any export */
.selection-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.selection-overlay[hidden] { display: none; }
/* Invisible filled hit target inside the marquee — drag it to move the layer(s).
   A child can opt back into hit-testing with pointer-events even though the
   overlay root is `none`. Decorative strokes stay inert. */
.selection-overlay .sel-hit { pointer-events: fill; cursor: move; touch-action: none; }
.selection-overlay .sel-halo,
.selection-overlay .sel-line { pointer-events: none; }
.selection-overlay .sel-halo {
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 3.5px;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
}
.selection-overlay .sel-line {
  stroke: #fff;
  stroke-width: 1.75px;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  stroke-dasharray: 5 4;
  animation: marching-ants 0.55s linear infinite;
}
@keyframes marching-ants { to { stroke-dashoffset: -18; } }

/* Overlay is inert — only the handle is interactive, so clicking the canvas
   elsewhere never moves the light. */
.light-overlay { position: absolute; inset: 0; pointer-events: none; }
.light-handle {
  position: absolute;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #fff 0%, #ffe9a8 55%, #ffb74d 100%);
  border: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5), 0 0 18px 6px rgba(255, 220, 140, 0.6);
  cursor: grab;
  touch-action: none;
  pointer-events: auto;
}
.light-handle:active { cursor: grabbing; }

/* ---- inspector controls ---- */
.group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem 0.7rem;
  margin: 0 0 0.75rem;
  min-width: 0; /* <fieldset> defaults to min-width:min-content — would overflow */
}
.group legend {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 0 0.3rem;
}
.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 30px;
  margin: 4px 0;
}
.row > span:first-child {
  flex: 0 0 78px;
  color: var(--muted);
}
.row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
.row output { flex: 0 0 38px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.row input[type="text"], .row input[type="number"], .row select {
  min-width: 0; /* number inputs default to a wide auto min-width — let them shrink */
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 7px;
  padding: 0.3rem 0.45rem;
  font: inherit;
}
.row input[type="text"], .row select { flex: 1; }
/* color swatch button (opens the custom popover) */
.swatch {
  inline-size: 42px; block-size: 26px; padding: 0;
  border: 1px solid var(--line-2); border-radius: 6px; cursor: pointer;
  background: #000;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.swatch:hover { border-color: var(--accent); }
.row .num { flex: 0 0 72px; min-width: 0; }
.times, .unit { color: var(--muted); }
.presets { display: flex; gap: 4px; flex: 1; min-width: 0; }
.chip {
  flex: 1;
  min-width: 0; /* allow shrinking so the row never overflows the panel */
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  border-radius: 6px;
  padding: 3px 2px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip:active { transform: translateY(1px); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-weak); }

/* gradient editor */
.grad-bar {
  flex: 1;
  height: 18px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: #000;
}
#grad-stops { display: flex; flex-direction: column; gap: 4px; margin: 2px 0; }
.grad-stop { gap: 6px; }
.grad-stop .swatch { flex: 0 0 38px; }
.seg { display: flex; gap: 0.75rem; }
.seg label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 50;
  max-width: 80vw;
}
.toast.warn { border-color: #b4791f; }
.toast.error { border-color: #c0463a; }

/* ---- custom color popover ---- */
.cp-popover {
  position: fixed;
  z-index: 60;
  width: 200px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  user-select: none;
}
.cp-sv {
  position: relative;
  width: 100%;
  height: 130px;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
  background-color: #f00;
  background-image:
    linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
    linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
}
.cp-sv-thumb,
.cp-hue-thumb {
  position: absolute;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.cp-hue {
  position: relative;
  width: 100%;
  height: 14px;
  margin-top: 12px;
  border-radius: 7px;
  cursor: ew-resize;
  touch-action: none;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
.cp-hue-thumb { top: 50%; }
.cp-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.cp-preview {
  width: 26px; height: 26px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  flex: 0 0 auto;
}
.cp-hex {
  flex: 1; min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line-2);
  color: var(--text);
  border-radius: 7px;
  padding: 0.3rem 0.45rem;
  font: inherit;
  text-transform: lowercase;
}
.cp-hex:focus { outline: none; border-color: var(--accent); }

@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .canvas-wrap { width: min(90vw, 60vh); }
}
