/* The editor's own chrome is dark on purpose: the drawing it frames is a neon-on-black manual
   page, and a light frame around it would make the default style hard to judge. */
:root {
  color-scheme: dark;
  --ground: #0c0f12;
  --panel: #13181d;
  --raised: #1a2128;
  --line: #27313a;
  --text: #e4ecf0;
  --muted: #8796a2;
  --accent: #8fefe2;
  --accent-ink: #062321;
  --danger: #ff7a7a;
  --radius: 6px;
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Bahnschrift, "DIN Alternate", "Roboto Condensed", "Arial Narrow", var(--font-ui);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 14px/1.45 var(--font-ui);
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand-mark { color: var(--accent); display: inline-flex; }

.topbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.field-inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }

select, input[type="text"] {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  min-width: 0;
}

.field-inline select { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); }

.btn {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.icon { padding: 6px 10px; font-size: 16px; line-height: 1; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.storage-warning {
  padding: 8px 16px;
  background: #3a2a10;
  color: #ffd79a;
  border-bottom: 1px solid #5a4118;
}

/* ---------- workspace ---------- */

.work {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}

.stage-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}

.stage svg { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; }
.stage svg:focus { outline: none; }
.stage.is-linking { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.stage.is-linking svg [data-key] { cursor: crosshair; }

.inline-edit {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0 4px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 4px;
}

.example-note { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- side panel ---------- */

.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; overflow-y: auto; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.muted { color: var(--muted); margin: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: var(--sw);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
  padding: 0;
}

.swatch.is-theme { background: conic-gradient(var(--sw) 0 50%, transparent 0) , var(--raised); }
.swatch.is-on { box-shadow: 0 0 0 2px var(--accent); }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 10px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.chip button {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 999px;
}

.chip button:hover { color: var(--danger); }

.export-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.look-row { display: flex; gap: 12px; align-items: flex-end; }
.look-row .grow { flex: 1; min-width: 0; }

input[type="color"] {
  width: 52px;
  height: 32px;
  padding: 2px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

input[type="range"] { width: 100%; margin: 0; height: 32px; accent-color: var(--accent); }

output { color: var(--text); font-variant-numeric: tabular-nums; }

.help ol { margin: 0; padding-left: 18px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

/* ---------- toast & dialog ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  background: var(--raised);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

.toast.is-error { border-color: var(--danger); }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  max-width: min(420px, calc(100% - 32px));
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog p { margin: 0 0 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  .work { grid-template-columns: minmax(0, 1fr); }
  .stage { max-height: none; }
  .panel { overflow: visible; }
}
