:root {
  --bg: #0b0f14;
  --panel: rgba(15, 20, 28, 0.94);
  --panel-2: #151c26;
  --line: #263140;
  --text: #e8eef6;
  --muted: #8b98a9;
  --accent: #ffb020;
  --cyan: #35d0e0;
  --green: #43d17c;
  --orange: #ff8a3d;
  --red: #ff4d5e;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0,0,0,.45);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: transparent; color: var(--text); font-size: 13px; }
body.demo {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(53,208,224,.12), transparent 60%),
    radial-gradient(900px 500px at 95% 110%, rgba(255,176,32,.10), transparent 60%),
    linear-gradient(160deg, #0a0e13, #0d131b 60%, #0a0f16);
}
body.demo::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .35;
  background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 36px 36px;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--cyan); }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 50;
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
  background: rgba(10,14,19,.82); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
}
body.embedded #topbar { display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--orange)); display: grid; place-items: center; color: #1a1205; font-weight: 900; }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; border: 1px solid var(--line); color: var(--muted); }
.badge.live { color: var(--green); border-color: rgba(67,209,124,.4); background: rgba(67,209,124,.08); }
.badge.sim { color: var(--accent); border-color: rgba(255,176,32,.4); background: rgba(255,176,32,.08); }
.badge.warn { color: var(--red); border-color: rgba(255,77,94,.4); background: rgba(255,77,94,.08); }
.spacer { flex: 1; }
.topnote { color: var(--muted); font-size: 12px; }

.window {
  position: fixed; width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; z-index: 10;
  backdrop-filter: blur(10px);
}
.window.wide { width: 430px; }
.window.hidden { display: none; }
.window-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: grab; user-select: none;
  background: linear-gradient(180deg, rgba(255,255,255,.04), transparent); border-bottom: 1px solid var(--line);
}
.window-header:active { cursor: grabbing; }
.window-title { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.window-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.window-controls { margin-left: auto; display: flex; gap: 4px; }
.icon-btn {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid transparent; background: transparent; color: var(--muted);
  display: grid; place-items: center; font-size: 14px; line-height: 1;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.window-body { padding: 12px; max-height: calc(100vh - 120px); overflow: auto; }
.window.minimized .window-body { display: none; }

.metric { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.metric .label { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .8px; }
.metric .value { font-size: 24px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric .unit { font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 3px; }
.metric .sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* Deck */
#deck { top: 76px; left: 20px; }
body.embedded #deck { top: 20px; left: 20px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; }
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 12px 0 8px; }
.section-title:first-child { margin-top: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.btn { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 600; font-size: 12px; }
.btn:hover { border-color: var(--cyan); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--orange)); color: #1a1205; border: none; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 8px; font-size: 11px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
input[type="text"], input[type="number"], select {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0a0e13; outline: none;
}
input:focus, select:focus { border-color: var(--cyan); }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 12px; }
.check input { accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 11px; line-height: 1.45; margin-top: 6px; }
.hint.warn { color: var(--accent); }

.dest-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow: auto; margin-top: 8px; }
.dest-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.dest-item.active { border-color: var(--cyan); background: rgba(53,208,224,.07); }
.dest-item .meta { flex: 1; min-width: 0; }
.dest-item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest-item .coords { color: var(--muted); font-size: 11px; }
.dest-item .actions { display: flex; gap: 4px; }
.macro-step { display: flex; flex-direction: column; gap: 6px; }
.macro-row { cursor: pointer; }
.macro-row:hover { border-color: var(--accent); }
.macro-row .actions { flex-shrink: 0; }
.macro-editor {
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px;
  background: rgba(255,255,255,.02); padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.macro-editor .field { margin-bottom: 0; }
.macro-editor .row { gap: 6px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12px; }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; word-break: break-all; }
.log { background: #0a0e13; border: 1px solid var(--line); border-radius: 8px; padding: 8px; height: 120px; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--muted); }
.log div { padding: 1px 0; }
.sim-controls { display: grid; gap: 8px; }
.sim-readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sim-readout .metric .value { font-size: 18px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; z-index: 100;
  transition: all .2s; pointer-events: none; font-size: 12px; box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
body.embedded.pinned .window { pointer-events: none; }
body.embedded.pinned .window-header { cursor: default; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.modal {
  position: fixed; inset: 0; display: none; place-items: center; z-index: 200;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
}
.modal.show { display: grid; }
.modal-card {
  width: min(420px, calc(100vw - 40px)); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.modal-title { font-size: 16px; font-weight: 800; margin-bottom: 8px; }
.modal-text { color: var(--text); margin-bottom: 14px; line-height: 1.45; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 10px; }

@media (max-width: 860px) {
  #deck { left: 20px; top: 76px; }
  .window.wide { width: min(430px, calc(100vw - 40px)); }
}
