:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --border: #dde2e8;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0e9f6e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(14, 159, 110, .12);
  --warn: #b45309;
  --warn-soft: rgba(217, 119, 6, .12);
  --danger: #dc2626;
  --stage: #0b0f14;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1c2430;
    --border: #2a3441;
    --text: #e6edf3;
    --muted: #8b98a8;
    --accent: #22c55e;
    --accent-ink: #052e16;
    --accent-soft: rgba(34, 197, 94, .14);
    --warn: #f59e0b;
    --warn-soft: rgba(245, 158, 11, .14);
    --danger: #f87171;
    --stage: #05080b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #151b23; --surface-2: #1c2430; --border: #2a3441;
  --text: #e6edf3; --muted: #8b98a8; --accent: #22c55e; --accent-ink: #052e16;
  --accent-soft: rgba(34, 197, 94, .14); --warn: #f59e0b; --warn-soft: rgba(245, 158, 11, .14);
  --danger: #f87171; --stage: #05080b; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Pretendard", system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; letter-spacing: -.01em; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .92em; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.brand-mark { width: 26px; height: 26px; fill: var(--text); }
.brand-mark .lens { fill: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill-ok .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pill-warn .dot { background: var(--warn); }
.pill-wait .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.update-banner {
  font-size: 12.5px; padding: 5px 12px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn); font-weight: 500;
}
.update-banner a { color: inherit; font-weight: 700; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600;
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn {
  appearance: none; background: none; border: 1px solid transparent; border-radius: 7px;
  width: 30px; height: 30px; display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- setup views ---------- */
.setup { flex: 1; overflow: auto; padding: 32px 16px; display: flex; justify-content: center; }
.lead { color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.steps { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 14px; }
.steps li { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--bg); }
.steps p { margin: 6px 0 12px; }
.step-head { display: flex; align-items: center; gap: 10px; }
.step-head h2 { font-size: 15.5px; }
.step-no {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; flex: none;
}
.hint { margin-top: 10px; font-size: 13px; }
.hint summary { cursor: pointer; color: var(--muted); }
.hint p { margin: 6px 0 0; }
.waiting { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite;
}

/* ---------- workspace ---------- */
.workspace {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 260px minmax(0, 1fr) 300px;
}
.panel { background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 8px; flex: none;
}
.panel-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.empty { padding: 8px 16px; }
.empty p { margin: 0 0 8px; }

.camera-list { list-style: none; margin: 0; padding: 4px 8px 12px; overflow: auto; }
.camera {
  border: 1px solid transparent; border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; margin-bottom: 4px;
}
.camera:hover { background: var(--surface-2); }
.camera.is-open { border-color: var(--accent); background: var(--accent-soft); }
.camera.is-busy { opacity: .55; }
.camera-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; }
.camera-sub { color: var(--muted); font-size: 12px; margin-top: 2px; font-family: ui-monospace, Consolas, monospace; }
.badge {
  font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 5px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); flex: none;
}
.camera-actions { margin-top: 8px; display: flex; gap: 6px; }

.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tool-group { display: flex; gap: 6px; flex-wrap: wrap; }
.stage { position: relative; flex: 1; min-height: 240px; background: var(--stage); overflow: hidden; }
.stage.fit canvas { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; }
.stage.one { overflow: auto; }
.stage.one canvas { display: block; }
.stage canvas { image-rendering: pixelated; }
.stage-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #6b7785; gap: 10px; text-align: center; padding: 16px; pointer-events: none;
}
.stage-empty svg { width: 48px; height: 48px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.stage-empty p { margin: 0; }
.hud {
  position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none;
}
.hud span, .pixel {
  background: rgba(0, 0, 0, .62); color: #e6edf3; font: 12px/1 ui-monospace, Consolas, monospace;
  padding: 5px 8px; border-radius: 6px; backdrop-filter: blur(4px);
}
.pixel { position: absolute; right: 10px; bottom: 10px; pointer-events: none; }

/* ---------- params ---------- */
.params { overflow: auto; padding: 0 14px 20px; }
.group { border-top: 1px solid var(--border); padding: 12px 0 6px; }
.group:first-child { border-top: 0; padding-top: 4px; }
.group h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; }
.field { margin-bottom: 12px; }
.field-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; font-size: 12.5px; }
.field-label .name { font-weight: 600; }
.field-label .node { color: var(--muted); font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
.field-row { display: flex; gap: 8px; align-items: center; }
.field input[type="range"] { flex: 1; accent-color: var(--accent); min-width: 0; }
.field input[type="number"], .field select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px;
}
.field input[type="number"] { width: 92px; text-align: right; font-family: ui-monospace, Consolas, monospace; }
.field select { width: 100%; }
.field .range-hint { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace; }
.field.is-readonly { opacity: .6; }
.readout { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
.switch input:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- overlay & toasts ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5, 8, 11, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.overlay-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; max-width: 420px; box-shadow: var(--shadow); }
.overlay-card h2 { font-size: 17px; margin-bottom: 6px; }
.overlay-card p { color: var(--muted); margin: 0 0 18px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 30; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 9px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 13px;
  animation: toast-in .18s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 260px; }
}
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-auto-rows: auto; overflow: auto; }
  .panel-left, .panel-right { border: 0; border-bottom: 1px solid var(--border); }
  .stage { min-height: 56vw; }
  .camera-list { max-height: 220px; }
  .setup-card { padding: 22px 18px; }
}
