:root {
  --bg: #16171a;
  --panel: #1e2024;
  --panel-2: #26292e;
  --line: #33363c;
  --text: #e6e6e6;
  --muted: #8c9099;
  --accent: #ff5a36;
  --accent-ink: #fff;
  --check-a: #ffffff;
  --check-b: #e4e4e4;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

button, select, input { font: inherit; color: inherit; }
select, input[type="number"], input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
}
button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.muted { color: var(--muted); }

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.topbar-group { display: flex; align-items: center; gap: 12px; }
.topbar-group.export { margin-left: auto; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
label.inline select { color: var(--text); }
label.check { cursor: pointer; }

/* layout */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 330px;
  flex: none;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  padding: 24px;
  min-height: 0;
}
.viewport canvas { margin: auto; display: block; box-shadow: 0 0 0 1px var(--line); }
.checker {
  background-color: var(--check-a);
  background-image: conic-gradient(var(--check-b) 25%, transparent 0 50%, var(--check-b) 0 75%, transparent 0);
  background-size: 16px 16px;
}
.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}
#status.busy { color: var(--accent); }
#status.error { color: #ff6b6b; }

/* control sections */
details.section { border-bottom: 1px solid var(--line); }
details.section > summary {
  list-style: none;
  cursor: pointer;
  padding: 9px 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before {
  content: "";
  width: 6px; height: 6px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}
details.section[open] > summary::before { transform: rotate(45deg); }
details.section > summary .dot {
  margin-left: auto;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  visibility: hidden;
}
details.section.active > summary .dot { visibility: visible; }
.section-body { padding: 2px 14px 12px; display: grid; gap: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }

.ctl { display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 8px; }
.ctl > * { min-width: 0; }
.ctl select, .ctl input[type="text"], .ctl input[type="number"] { width: 100%; }
.ctl > label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctl > label[title] { cursor: help; }
.ctl.hidden { display: none; }
.range { display: grid; grid-template-columns: 1fr 58px; gap: 6px; align-items: center; }
.range input[type="number"] { width: 100%; padding: 2px 4px; text-align: right; }
.row { display: flex; gap: 6px; align-items: center; }
.row > * { min-width: 0; }
.row button { flex: none; }
.row input[type="number"], .row input[type="text"] { flex: 1; width: 100%; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }
input[type="color"] {
  width: 42px; height: 24px; padding: 0;
  border: 1px solid var(--line); border-radius: 4px; background: none;
}
.segmented { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; flex: 1; padding: 3px 6px; background: var(--panel-2); color: var(--muted); }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.on { background: var(--accent); color: var(--accent-ink); }

@media (max-width: 760px) {
  .layout { flex-direction: column-reverse; }
  .panel { width: 100%; height: 50vh; border-right: 0; border-top: 1px solid var(--line); }
  .viewport { padding: 12px; }
  .topbar-group.export { margin-left: 0; }
}
