:root {
  --bg: #14161a;
  --panel: #1c1f25;
  --panel-2: #23272f;
  --border: #2f343e;
  --text: #dfe3ea;
  --muted: #8b93a1;
  --accent: #4aa3ff;
  --accent-bg: #16324d;
  --ok: #3fb950;
  --warn: #e3a008;
  --fail: #f85149;
  --thick: #58a6ff;
  --radius: 6px;
  --gap: 10px;
  --bar-h: 48px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
}
h1 { font-size: 15px; margin: 0 8px 0 0; letter-spacing: .04em; white-space: nowrap; }
h2 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* controls */
button, select, input[type=text], input[type=number], textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 8px;
}
input[type=text], input[type=number], textarea, select { width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 3.2em; font-family: ui-monospace, monospace; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent-bg); border-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
input[type=range] { accent-color: var(--accent); }

/* header */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  min-height: var(--bar-h); padding: 6px 12px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.style-pick { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.style-pick select { width: auto; }
.chk { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.path { margin-left: auto; color: var(--muted); font-family: ui-monospace, monospace; font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; direction: rtl; text-align: left; }

.banner { background: #4a1d1d; color: #ffd7d5; border-bottom: 1px solid var(--fail); padding: 6px 12px; white-space: pre-wrap; }
.banner[hidden], .toast[hidden] { display: none; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 10; background: var(--panel-2);
  border: 1px solid var(--accent); border-radius: var(--radius); padding: 8px 12px; max-width: 70vw; }

/* layout */
.layout {
  flex: 1; min-height: 0; display: grid; gap: var(--gap); padding: var(--gap);
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) minmax(300px, 380px);
}
.sidebar, .panels { overflow-y: auto; min-height: 0; }
.preview { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); }
  .panels { grid-column: 1 / -1; overflow: visible; }
}
@media (max-width: 720px) {
  body { display: block; height: auto; }
  .layout { display: flex; flex-direction: column; }
  .sidebar, .panels { overflow: visible; }
  .stage { height: 70vh; }
  .path { margin-left: 0; max-width: 100%; }
}

/* form */
.group { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; }
.group > summary { cursor: pointer; padding: 6px 10px; font-weight: 600; list-style: none; user-select: none; }
.group > summary::before { content: "\25B8"; display: inline-block; width: 1em; color: var(--muted); }
.group[open] > summary::before { content: "\25BE"; }
.group-body { padding: 4px 10px 10px; display: grid; gap: 8px; }
.subhead { margin: 6px 0 -2px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field { display: grid; gap: 3px; }
.field > label { color: var(--muted); font-size: 12px; }
.field.bool { grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; }
.field.bool > label { color: var(--text); }
.help { color: var(--muted); font-size: 11px; grid-column: 1 / -1; }
.row { display: flex; gap: 6px; align-items: center; }
.row > input[type=number] { width: 5.5em; flex: none; }
.row > select { width: 9em; flex: none; }
.row > input[type=text] { flex: 1; }
.icon-btn { padding: 2px 8px; flex: none; line-height: 1.2; }
.thumb { max-width: 96px; max-height: 96px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.rows { display: grid; gap: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--border); }
.chip.on { background: var(--accent-bg); border-color: var(--accent); }
.chip.on span { margin-left: 6px; color: var(--muted); }
.chip-pool { max-height: 130px; overflow-y: auto; padding: 4px; border: 1px solid var(--border); border-radius: var(--radius); }

/* preview */
.toolbar { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; }
.toolbar input[type=range] { flex: 0 1 200px; }
.busy { margin-left: auto; color: var(--accent); }
.spinner { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.stage {
  flex: 1; min-height: 240px; overflow: auto; padding: 16px; text-align: center;
  background: repeating-conic-gradient(#2a2e36 0 25%, #252930 0 50%) 0 0 / 20px 20px;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.stage.stale { opacity: .6; }
.stage svg { display: inline-block; background: #fff; box-shadow: 0 2px 12px #0008; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.s-OK { color: var(--ok); } .s-WARN { color: var(--warn); } .s-FAIL { color: var(--fail); } .s-THICKENED { color: var(--thick); }
/* status at a glance: filled pills, tinted rows, one big verdict */
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: .02em; line-height: 16px; color: #0b0d10; background: var(--muted); }
.pill.s-OK { background: var(--ok); } .pill.s-WARN { background: var(--warn); } .pill.s-FAIL { background: var(--fail); color: #fff; } .pill.s-THICKENED { background: var(--thick); }
.pill.s-none { background: var(--panel-2); color: var(--muted); }
#safety-badge { margin-left: 4px; }
#safety-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 8px; }
.verdict { font-size: 14px; font-weight: 800; padding: 2px 10px; border-radius: 6px; color: #0b0d10; background: var(--muted); }
.verdict.s-OK { background: var(--ok); } .verdict.s-WARN { background: var(--warn); } .verdict.s-FAIL { background: var(--fail); color: #fff; } .verdict.s-THICKENED { background: var(--thick); }
.counts { display: inline-flex; gap: 4px; margin-left: auto; }
tr.row-FAIL td { background: rgba(248, 81, 73, .12); } tr.row-WARN td { background: rgba(227, 160, 8, .10); }
td.label { max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
#safety-table { font-size: 11px; } #safety-table th, #safety-table td { padding: 2px 4px; }
.warnings, .files { margin: 8px 0 0; padding-left: 18px; }
.warnings li { color: var(--warn); }
.files a { color: var(--accent); }
.report { margin: 8px 0 0; padding: 8px; background: var(--bg); border-radius: var(--radius); overflow-x: auto; font-size: 11px; }
.report[hidden] { display: none; }

/* items: drag handles in the preview, positions group */
.stage svg [data-item] { cursor: move; }
.stage svg [data-item]:hover { filter: drop-shadow(0 0 2px #2d8cf0) drop-shadow(0 0 1px #2d8cf0); }
.stage svg [data-item].selected { filter: drop-shadow(0 0 3px #2d8cf0) drop-shadow(0 0 2px #2d8cf0); }
.stage:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.toolbar button.on { background: var(--accent); color: #0b0d10; border-color: var(--accent); }
#drag-info { font-size: 11px; margin-left: auto; }
.pos-row { display: grid; grid-template-columns: 1fr 64px 64px 28px; gap: 4px; align-items: center; padding: 2px 4px; border-radius: 4px; }
.pos-row.selected { background: var(--panel-2); }
.pos-row input { width: 100%; padding: 2px 4px; font-size: 12px; }
.pos-name { font-size: 12px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { padding: 0 6px; line-height: 20px; }
.toolbar select#grid-step { flex: 0 0 auto; width: auto; }
#btn-undo, #btn-redo { font-size: 16px; line-height: 1; padding: 2px 8px; }
button:disabled { opacity: .45; cursor: default; }
.stage svg image[data-portrait] { cursor: grab; }
