:root {
  color-scheme: dark;
  --bg: #14110f;
  --panel: #1d1916;
  --panel-2: #26211d;
  --line: #3a322b;
  --text: #efe7da;
  --muted: #a89c8b;
  --accent: #e08a3c;
  --accent-ink: #1c1412;
  --danger: #ff8f7a;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

h1, h2 { margin: 0; font-weight: 600; }
button, select, input, textarea { font: inherit; color: inherit; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand h1 { font: 600 16px/1 var(--mono); letter-spacing: 0.02em; }
.mark { width: 16px; height: 16px; fill: var(--accent); align-self: center; }
.by { color: var(--muted); font-size: 12px; }
.bar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.pro { border-color: var(--accent); color: var(--accent); }
button.small { padding: 4px 8px; font-size: 12px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px 1fr; }
.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 4px 12px 12px;
}
.panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel h2 {
  font: 600 11px/1 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.field { display: block; margin-bottom: 10px; }
.field > span { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: 13px; }
.field output { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.field small, .check small, legend small { color: var(--muted); font-weight: 400; }
select, input[type="text"], input[type="email"], input[type="number"], textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
}
input[type="number"] { width: 4.5em; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
textarea { font-family: var(--mono); resize: vertical; }

.check { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); flex: none; }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.inline select { width: auto; padding: 3px 6px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.error { color: var(--danger); font-size: 12px; min-height: 1.4em; margin: 6px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 4px 10px; font-size: 12px; border-radius: 999px; }
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.swatches { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.swatch { position: relative; width: 26px; height: 26px; border-radius: 4px; border: 1px solid var(--line); overflow: hidden; }
.swatch input[type="color"] { position: absolute; inset: -4px; width: 40px; height: 40px; padding: 0; border: 0; background: none; cursor: pointer; }
.swatch button {
  position: absolute; top: 0; right: 0; width: 12px; height: 12px; padding: 0; border: 0; border-radius: 0 0 0 4px;
  background: rgba(0, 0, 0, 0.7); color: #fff; font-size: 10px; line-height: 12px; display: none;
}
.swatch:hover button, .swatch:focus-within button { display: block; }

.note { padding-top: 12px; color: var(--muted); font-size: 12px; }
.note p { margin: 0 0 6px; }

.stage-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  position: relative;
  background-color: #0e0c0b;
  background-image: linear-gradient(45deg, #171412 25%, transparent 25%, transparent 75%, #171412 75%), linear-gradient(45deg, #171412 25%, transparent 25%, transparent 75%, #171412 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}
#view { image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; box-shadow: 0 0 0 1px var(--line), 0 8px 30px rgba(0, 0, 0, 0.5); }
.stage.dragging { outline: 2px dashed var(--accent); outline-offset: -8px; }
.drop-hint { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 17, 15, 0.8); font: 600 16px var(--mono); pointer-events: none; }
.drop-hint[hidden] { display: none; }

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font: 12px var(--mono);
  color: var(--muted);
  flex-wrap: wrap;
}
.spacer { flex: 1; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
}
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); overflow: hidden; overscroll-behavior: contain; }
dialog h1 { font-size: 17px; margin-bottom: 10px; }
dialog p { margin: 0 0 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 12px; padding: 8px 12px 6px; }
legend { padding: 0 4px; font-size: 13px; font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
code { font-family: var(--mono); }

.toast {
  position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

@media (max-width: 760px) {
  body { height: auto; min-height: 100%; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto; }
  .stage-wrap { order: -1; height: 56vh; }
  .panel { border-right: 0; border-top: 1px solid var(--line); overflow: visible; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
