:root {
  --bg: #f5f3ef;
  --panel: #ffffff;
  --text: #1c1c1c;
  --muted: #777;
  --line: #e4e1db;
  --accent: #1d3fbf;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
aside {
  width: 320px;
  flex: none;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
header { padding: 16px 16px 8px; }
h1 { font-size: 17px; margin: 0; }
header p { margin: 2px 0 0; color: var(--muted); }
section { padding: 8px 16px 12px; border-top: 1px solid var(--line); }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 6px 0 8px; }
.row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 8px; margin: 6px 0; }
.row[hidden] { display: none; }
.row .name { color: #444; }
.row select, .row input[type=file], .row .palette, .row .seed { grid-column: 2 / 4; }
.row input[type=range] { width: 100%; accent-color: var(--accent); }
.row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
select, input[type=number] { width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font: inherit; }
.palette { display: flex; gap: 6px; }
.palette input { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
.palette input[hidden] { display: none; }
.seed { display: flex; gap: 6px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
button, .btn {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font: inherit;
  cursor: pointer;
  color: var(--text);
}
button:hover, .btn:hover { border-color: #bbb; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
main { flex: 1; position: relative; display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.tabs button.active { background: var(--text); color: #fff; border-color: var(--text); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
#view { flex: 1; min-height: 0; }
#view canvas { width: 100%; height: 100%; display: block; }
#map { position: absolute; inset: 53px 0 0 0; background: #fff; padding: 16px; overflow: auto; }
#map[hidden] { display: none; }
#map svg { max-width: 100%; max-height: 100%; }
#stats {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.9); box-shadow: 0 1px 6px rgba(0,0,0,0.12);
  max-width: calc(100% - 24px);
}
.swatches { display: flex; gap: 8px; }
.swatches span { display: flex; align-items: center; gap: 4px; }
.swatches i { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.2); display: inline-block; }
.warn { color: #a55a00; }
.muted { color: var(--muted); }
#busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(245,243,239,0.8); font-size: 15px; }
#busy[hidden] { display: none; }
@media (max-width: 760px) {
  body { flex-direction: column; }
  aside { width: 100%; height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  main { height: 55vh; }
}
.row { grid-template-columns: 104px 1fr 58px; }
.row input.num { width: 100%; padding: 3px 4px; border: 1px solid var(--line); border-radius: 6px; font: inherit; text-align: right; font-variant-numeric: tabular-nums; }
.row.wide { grid-template-columns: 1fr; }
.row.wide .name { display: none; }
.shape-editor svg { width: 100%; max-width: 220px; aspect-ratio: 1; display: block; margin: 0 auto; background: #faf9f7; border: 1px solid var(--line); border-radius: 8px; touch-action: none; cursor: crosshair; }
.shape-editor .limit { fill: none; stroke: #ccc; stroke-width: 0.012; stroke-dasharray: 0.04 0.03; }
.shape-editor .axis { stroke: #999; stroke-width: 0.015; }
.shape-editor .axis-head { fill: #999; }
.shape-editor .shape { fill: rgba(29, 63, 191, 0.18); stroke: var(--accent); stroke-width: 0.02; stroke-linejoin: round; }
.shape-editor .shape.bad { fill: rgba(200, 40, 40, 0.15); stroke: #c62828; }
.shape-editor .final { fill: none; stroke: #888; stroke-width: 0.012; stroke-dasharray: 0.03 0.02; }
.shape-editor .handle { fill: #fff; stroke: var(--accent); stroke-width: 0.02; cursor: grab; }
.shape-editor .hint { color: var(--muted); font-size: 11px; margin: 6px 0; }
.shape-editor textarea { width: 100%; font: 11px/1.3 ui-monospace, Consolas, monospace; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; resize: vertical; }
.shape-editor .btns { display: flex; gap: 6px; margin-top: 6px; }
.palettes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.palettes > button { display: flex; align-items: center; gap: 0; padding: 4px; flex-wrap: wrap; text-align: left; }
.palettes > button i { width: 14px; height: 14px; display: inline-block; }
.palettes > button i:first-child { border-radius: 3px 0 0 3px; }
.palettes > button i:nth-child(6) { border-radius: 0 3px 3px 0; }
.palettes > button span { width: 100%; font-size: 11px; color: #555; margin-top: 3px; }
.palette-tools { grid-column: 1 / -1; display: flex; gap: 6px; }
.single-color { width: 40px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.presets.user { margin-top: 6px; }
.presets.user:empty { display: none; }
.user-preset { display: inline-flex; }
.user-preset > button:first-child { border-radius: 7px 0 0 7px; background: #eef1fb; border-color: #c9d2f0; }
.user-preset > .del { border-radius: 0 7px 7px 0; border-left: 0; padding: 6px 8px; color: #888; background: #eef1fb; border-color: #c9d2f0; }
.user-preset > .del:hover { color: #c62828; }
.preset-save { display: flex; gap: 6px; margin-top: 8px; }
.preset-save input { flex: 1; min-width: 0; padding: 5px 7px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.preset-msg { font-size: 11px; color: var(--muted); margin-top: 4px; min-height: 14px; }
.preset-msg.warn { color: #a55a00; }
.actions button.active { background: #8a5a2b; border-color: #8a5a2b; color: #fff; }
