:root {
  --bg: #10141a;
  --bg-2: #0c1016;
  --panel: #171d27;
  --panel-2: #212938;
  --line: #313c4e;
  --text: #e8eef6;
  --muted: #93a0b3;
  --accent: #2fd3c5;
  --accent-ink: #062421;
  --amber: #f0a202;
  --danger: #f07178;
  --ok: #8fd98a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(47, 211, 197, 0.09), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(240, 162, 2, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", "Noto Sans", "PT Sans", sans-serif;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 20, 26, 0.92);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 8px;
  background:
    linear-gradient(160deg, rgba(47, 211, 197, 0.2), transparent 60%),
    var(--panel-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

.mark span {
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent);
  border-radius: 2px;
  box-shadow: 6px 6px 0 -4px var(--amber);
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.top-meta {
  color: var(--muted);
  font-size: 12px;
  font-family: ui-monospace, "Cascadia Code", monospace;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 520px;
  min-height: 0;
}

.stage-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 0;
  flex-wrap: wrap;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 420px;
  margin: 10px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
}

.stage.is-drag {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 211, 197, 0.2);
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
  text-align: center;
  padding: 24px;
}

.empty strong { font-size: 18px; font-weight: 650; }

.empty span { color: var(--muted); max-width: 360px; }

.hidden { display: none !important; }

.hint {
  margin: 0 14px 12px;
  color: var(--muted);
  font-size: 12px;
}

.side {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: rgba(12, 16, 22, 0.45);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row.wrap { flex-wrap: wrap; }

.grow { flex: 1; min-width: 0; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 7px 12px;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover { border-color: #4c5d74; }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 700;
}

.btn.primary:hover { filter: brightness(1.05); }

.btn.ghost { background: transparent; }

.btn.danger { color: var(--danger); }

.seg {
  display: flex;
  padding: 3px;
  border-radius: 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 6px 8px;
  color: var(--muted);
}

.seg button.is-on {
  background: var(--panel-2);
  color: var(--text);
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  outline: none;
}

input[type="number"] {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, monospace;
}

input:focus, select:focus { border-color: var(--accent); }

input[type="color"] {
  width: 42px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 7px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.slider {
  display: grid;
  grid-template-columns: 108px 1fr 42px;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
  font-size: 13px;
}

.slider output {
  text-align: right;
  font-family: ui-monospace, monospace;
  color: var(--accent);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  max-height: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 1080px;
}

th, td {
  padding: 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #1c2431;
  color: var(--muted);
  font-weight: 600;
  z-index: 1;
}

tr.is-selected { background: rgba(47, 211, 197, 0.1); }

td input[type="number"] { width: 64px; padding: 4px 6px; }
td input[type="text"] { width: 120px; padding: 4px 6px; }
td select { width: 230px; padding: 4px 6px; }

.id-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, monospace;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}

.icon-btn:hover { color: var(--danger); border-color: var(--line); }

.preview-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 7px;
  padding: 4px 8px;
  white-space: nowrap;
}

.preview-btn:hover { border-color: var(--accent); color: var(--accent); }

.preview {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.preview::backdrop { background: rgba(6, 8, 12, 0.72); }

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-stage {
  margin-top: 12px;
  max-height: 70vh;
  overflow: auto;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #2a3140 25%, transparent 25%),
    linear-gradient(-45deg, #2a3140 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a3140 75%),
    linear-gradient(-45deg, transparent 75%, #2a3140 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-color: #1a2030;
  padding: 12px;
}

.preview-stage canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: none;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
  padding: 16px;
}

.status {
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
}

.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

.grid-fields { display: none; gap: 8px; margin-top: 10px; }
.grid-fields.is-on { display: flex; flex-wrap: wrap; align-items: flex-end; }
.grid-span { flex: 1 0 100%; }

.card.is-dim { opacity: 0.55; }

kbd {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  color: var(--text);
}

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .side {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: none;
  }
  .top-meta { display: none; }
  .stage { min-height: 52vh; }
}
