:root {
  --bg: #14161a;
  --panel: #1c1f26;
  --panel-2: #22262f;
  --line: #333846;
  --text: #e6e8ee;
  --muted: #9aa1b1;
  --accent: #6ea8fe;
  --accent-2: #ff5f9e;
  --danger: #ff6b6b;
  --rail: 132px;
  --inspector: 268px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
}
button:hover { background: #2c313c; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #10131a; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.active { outline: 2px solid var(--accent); outline-offset: -2px; }

input[type=text], input[type=number], select, textarea {
  font: inherit;
  color: var(--text);
  background: #12151b;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 6px;
  width: 100%;
  min-width: 0;
}
input[type=color] {
  width: 100%;
  height: 26px;
  padding: 0;
  background: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); }
label { color: var(--muted); font-size: 11px; }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .3px; margin-right: 6px; color: var(--accent); }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }
.spacer { flex: 1; }
.readout { color: var(--muted); min-width: 46px; text-align: center; }

.menu { position: relative; }
.menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  min-width: 190px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px #0009;
}
.menu-panel.wide { min-width: 260px; }
.menu.open .menu-panel { display: block; }
.menu-panel button { display: block; width: 100%; text-align: left; margin-bottom: 4px; }
.menu-panel button:last-child { margin-bottom: 0; }
.menu-panel h4 { margin: 4px 0 6px; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.menu-panel hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }

/* ---------- layout ---------- */

.app {
  display: grid;
  grid-template-columns: var(--rail) 1fr var(--inspector);
  height: calc(100% - 44px - 26px);
}

.rail, .inspector {
  background: var(--panel);
  overflow-y: auto;
  padding: 10px;
}
.rail { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }

.rail-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin: 6px 0;
}
.rail-note { color: var(--muted); font-size: 11px; margin: 8px 0; }
.rail-row { display: flex; gap: 4px; margin-bottom: 6px; }
.rail-row button { flex: 1; padding: 4px; }

button.swatch { height: 22px; padding: 0; }

.shape-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.shape-picker button {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
}
.shape-picker svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- stage ---------- */

.stage {
  position: relative;
  overflow: hidden;
  background:
    repeating-conic-gradient(#191c22 0% 25%, #1e222a 0% 50%) 50% / 24px 24px;
}
.canvas-stack { position: absolute; inset: 0; }
.canvas-stack canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#overlay { touch-action: none; }

.drop-hint {
  position: absolute;
  inset: 18px;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: #6ea8fe1a;
  font-size: 18px;
  pointer-events: none;
}
.stage.dragover .drop-hint { display: grid; }

/* ---------- inspector ---------- */

.insp-section { border-bottom: 1px solid var(--line); padding: 8px 0; }
.insp-section:last-child { border-bottom: 0; }
.insp-section h3 {
  margin: 0 0 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600;
}
.field { margin-bottom: 8px; }
.field > label { display: block; margin-bottom: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.inline { display: flex; align-items: center; gap: 6px; }
.inline label { margin: 0; }
.empty-state { color: var(--muted); padding: 20px 4px; text-align: center; }
.value-tag { color: var(--muted); font-variant-numeric: tabular-nums; float: right; }

/* ---------- status ---------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 26px;
  padding: 0 10px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

/* ---------- dialogs / toast ---------- */

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  max-width: 560px;
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 10px; font-size: 16px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
dialog form { display: contents; }
#relink-list { max-height: 180px; overflow: auto; padding-left: 18px; color: var(--muted); }

/* ---------- share dialog ---------- */

.dialog-note { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.dialog-note.warn { color: #ffca7a; }
#share-dialog { min-width: min(520px, 90vw); }
#share-url { font: 12px/1.4 ui-monospace, monospace; }
#share-mine { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
#share-mine summary { cursor: pointer; color: var(--muted); font-size: 12px; }
#share-mine[hidden] { display: none; }
#share-list { list-style: none; margin: 10px 0; padding: 0; max-height: 160px; overflow: auto; }
#share-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
#share-list a { color: var(--accent); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#share-list button { font-size: 11px; padding: 3px 8px; }

.help-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 5px 12px;
  font-size: 12px;
}
.help-grid kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  font: 11px ui-monospace, monospace;
  white-space: nowrap;
}
.help-grid span { color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 46px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  box-shadow: 0 10px 30px #0009;
  z-index: 100;
}
.toast.err { border-color: var(--danger); color: #ffd7d7; }
