:root {
  --bg: #f4f4f5; --panel: #ffffff; --line: #e4e4e7; --text: #111114; --muted: #6b6b73;
  --accent: #111114; --brand: #E52A1F; --blue: #5E8DEA; --pink: #FF4FA1; --green: #18D24A;
  --fill: #f1f1f3; --radius: 10px; --font: "Helvetica Neue", Helvetica, Inter, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); font-size: 13px; color: var(--text); background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; }
button:hover { border-color: #bbb; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: #333; }
button.ghost { background: transparent; }
button.small { padding: 4px 8px; font-size: 12px; }
h2 { font-size: 12px; font-weight: 600; color: var(--text); margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 11px; }
code { background: #eee; padding: 1px 4px; border-radius: 4px; }

.topbar { height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--pink), var(--green) 45%, var(--brand) 75%, var(--blue)); }
.brand .sub { color: var(--muted); }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
/* One export button; the attached chevron chooses the file type. */
.split { display: flex; align-items: stretch; }
.split > button { border-radius: 8px 0 0 8px; }
.split > select { width: 30px; padding: 0; border-radius: 0 8px 8px 0; border: 1px solid var(--accent); border-left: 1px solid rgba(255,255,255,.3);
  background: var(--accent) no-repeat center / 9px 9px; color: transparent; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke='%23ffffff' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M2 3.8 5 6.8l3-3'/%3E%3C/svg%3E"); }
.split > select:hover { background-color: #333; }
.file-btn { display: inline-block; cursor: pointer; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; background: transparent; }
.file-btn.small { padding: 5px 8px; font-size: 12px; }
.file-btn.block { display: block; text-align: center; }

.layout { flex: 1; display: grid; grid-template-columns: 300px 1fr 320px; min-height: 0; }
.panel { background: var(--panel); overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 18px; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); padding-top: 0; gap: 0; }
/* Design / Motion, the way Figma splits its right-hand panel. */
.panel-tabs { display: flex; gap: 1px; position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); margin: 0 -14px 12px; padding: 8px 14px; }
.panel-tabs button { border: 0; background: transparent; border-radius: 7px; padding: 5px 8px; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.panel-tabs button:hover { background: var(--fill); color: var(--text); }
.panel-tabs button.active { background: var(--fill); color: var(--text); }
#controls { display: flex; flex-direction: column; gap: 18px; }
.panel section { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; justify-content: space-between; }
.row.gap { gap: 6px; justify-content: flex-start; margin-top: 8px; flex-wrap: wrap; }
.row label { display: flex; align-items: center; gap: 4px; }
.row input[type=number] { width: 70px; }
.lbl { color: var(--text); }


.templates { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tpl { border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11px; }
.tpl svg { width: 34px; height: 34px; }
.tpl.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tpl.active svg path, .tpl.active svg line { stroke: #fff; }

.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; width: 40px; height: 40px; padding: 0; border-radius: 8px; border: 1px solid rgba(0,0,0,.12); overflow: hidden; }
.chip .x { position: absolute; top: 0; right: 0; width: 16px; height: 16px; font-size: 10px; line-height: 15px; text-align: center; border-radius: 0 0 0 6px; background: rgba(255,255,255,.85); cursor: pointer; }
/* Colours come from the brand set, so picking one is a row of swatches, not a colour dialogue. */
.swatch-pop { position: fixed; z-index: 60; display: flex; gap: 6px; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.16); }
.swatch-pop button { width: 30px; height: 30px; padding: 0; border-radius: 7px; border: 1px solid rgba(0,0,0,.12); }
.swatch-pop button:hover:not(:disabled) { transform: scale(1.08); }
.swatch-pop button:disabled { opacity: .25; cursor: not-allowed; }
.swatches { display: flex; gap: 6px; margin-top: 6px; }
.sw-btn { width: 34px; height: 34px; padding: 0; border-radius: 8px; border: 1px solid rgba(0,0,0,.12); }
.sw-btn:hover { transform: scale(1.06); }
.sw-btn.active { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; max-width: 100%; }
input[type=number], input[type=text] { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; }
textarea { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; font: inherit; resize: vertical; width: 100%; }

.stage-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage { flex: 1; position: relative; min-height: 0; background: #e9e9ec; background-image: radial-gradient(#d4d4d8 1px, transparent 1px); background-size: 18px 18px; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.stage-info { position: absolute; left: 12px; bottom: 10px; font-size: 11px; color: var(--muted); background: rgba(255,255,255,.8); padding: 3px 8px; border-radius: 6px; pointer-events: none; }
.stagebar { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; }
.stagebar label { display: flex; align-items: center; gap: 6px; }
.stagebar .spacer { flex: 1; }
.toggle input { accent-color: var(--accent); }

/* Controls */
.group { border-top: 1px solid var(--line); padding-top: 12px; }
.group:first-child { border-top: 0; padding-top: 0; }
.group h3 { margin: 0 0 9px; font-size: 12px; font-weight: 600; color: var(--text); display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none; }
.group h3::after { content: ''; width: 7px; height: 7px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg) translate(-2px, -2px); }
.group.collapsed h3::after { transform: rotate(-45deg) translate(-2px, -2px); }
.group.collapsed .ctrls { display: none; }
.ctrls { display: flex; flex-direction: column; gap: 7px; }
.ctrl { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; }
.ctrl.wide { grid-template-columns: 1fr; }
.ctrl label { color: var(--text); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Sliders read as a filled gauge with the number inside, so the whole row is the target. */
.range { position: relative; height: 30px; min-width: 0; border-radius: 7px; background: var(--fill); overflow: hidden; }
.range .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: #d7d7dd; pointer-events: none; }
.range input[type=range] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; background: transparent; appearance: none; -webkit-appearance: none; cursor: ew-resize; }
.range input[type=range]::-webkit-slider-runnable-track { height: 30px; background: transparent; }
.range input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 3px; height: 30px; border-radius: 2px; background: var(--accent); }
.range input[type=range]::-moz-range-track { height: 30px; background: transparent; }
.range input[type=range]::-moz-range-thumb { width: 3px; height: 30px; border: 0; border-radius: 2px; background: var(--accent); }
.range input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.range .val { position: absolute; right: 0; top: 0; height: 30px; width: 62px; font-size: 11px; text-align: right; padding: 0 8px 0 0;
  border: 0; border-radius: 0; background: transparent; font-variant-numeric: tabular-nums; pointer-events: none; }
.range .val:focus { pointer-events: auto; outline: 0; }
.range:hover .val { pointer-events: auto; }
.row-toggle { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-width: 0; }
.seg button { flex: 1; border: 0; border-radius: 0; padding: 5px 4px; font-size: 11px; background: transparent; min-width: 0; }
.seg button.active { background: var(--accent); color: #fff; }

/* Figma-style compact controls: filled, borderless, captioned above rather than beside.
   The icon at the left of a field scrubs the value on horizontal drag. */
.fieldrow { display: grid; gap: 6px; min-width: 0; align-items: end; }
.fcell { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.flabel { color: var(--muted); font-size: 11px; }
.flabel.solo { display: block; margin: 5px 0 -2px; }
.field { display: flex; align-items: center; border: 1px solid transparent; border-radius: 7px; background: var(--fill); min-width: 0; height: 30px; padding-right: 4px; }
.field:hover { border-color: var(--line); }
.field:focus-within { background: #fff; border-color: var(--accent); }
.field .ico { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin: 0 1px 0 3px; flex: none; color: var(--muted); cursor: ew-resize; border-radius: 5px; touch-action: none; user-select: none; }
.field .ico.glyph { font-size: 11px; }
.field .ico:hover { background: rgba(0,0,0,.06); color: var(--text); }
.field.scrubbing .ico { background: var(--accent); color: #fff; }
.field .ico svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.field .num { flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; padding: 0; font-size: 12px; font-variant-numeric: tabular-nums; }
.field > .num:first-child { padding-left: 8px; }
.field .num:focus { outline: 0; }
.fcell > input[type=color] { width: 100%; height: 30px; border: 1px solid transparent; border-radius: 7px; background: var(--fill); padding: 3px; }
select.compact { height: 30px; padding: 0 6px; font-size: 12px; min-width: 0; width: 100%; border-color: transparent; background: var(--fill); }
select.compact:hover { border-color: var(--line); }
/* The bare chevron next to the size field: a preset list with no visible value. */
select.chev { height: 30px; width: 100%; padding: 0; border-color: transparent; color: transparent; appearance: none; -webkit-appearance: none;
  background: var(--fill) no-repeat center / 9px 9px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' fill='none' stroke='%236b6b73' stroke-width='1.4' stroke-linecap='round'%3E%3Cpath d='M2 3.8 5 6.8l3-3'/%3E%3C/svg%3E"); }
select.chev:hover { border-color: var(--line); }
/* Icon segments sit in a filled track; the chosen one lifts out in white. */
.seg.icons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; border: 0; background: var(--fill); border-radius: 7px; padding: 2px; }
.seg.icons button { display: flex; align-items: center; justify-content: center; height: 24px; padding: 0; border-radius: 5px; color: var(--muted); }
.seg.icons button:hover { color: var(--text); }
.seg.icons button.active { background: #fff; color: var(--text); box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0,0,0,.06); }
.seg.icons svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; }

.toast { position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%); background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 80vw; }
.progress { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #fff; z-index: 60; }
.progress .bar { width: 320px; height: 8px; background: rgba(255,255,255,.25); border-radius: 4px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--green), var(--blue)); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 260px 1fr 280px; }
}
