:root {
  --bg: #0b1220;
  --panel: #111b2e;
  --panel-alt: #16233b;
  --border: #243554;
  --text: #e6edf7;
  --muted: #8ea4c8;
  --primary: #0ea5e9;
  --primary-hover: #38bdf8;
  --accent: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --mono: "Cascadia Code", "Consolas", "Fira Code", monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: linear-gradient(90deg, #0f1b33 0%, #0d2240 100%);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 38px; height: 38px; border-radius: 8px; object-fit: contain; }
.brand-title { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(14, 165, 233, 0.2);
  color: #7dd3fc;
  border: 1px solid rgba(14, 165, 233, 0.45);
  border-radius: 999px;
}

.top-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ctrl-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
select, input[type="text"], input[type="number"] {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 13px;
}
.proj-input { width: 175px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 18px 0;
  background: #0d1628;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  padding: 8px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--bg);
  color: #7dd3fc;
  border-color: var(--border);
}

.container { padding: 14px 18px 28px; max-width: 1680px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.btn {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.btn:hover { border-color: var(--primary); color: #fff; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #031525; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.accent { background: rgba(16, 185, 129, 0.2); border-color: var(--accent); color: #6ee7b7; }
.btn.accent:hover { background: rgba(16, 185, 129, 0.35); }
.file-btn { display: inline-flex; align-items: center; }

.split-grid, .sim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 980px) {
  .split-grid, .sim-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}
.subhead { border-top: 1px solid var(--border); }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }

#ilEditor {
  width: 100%;
  min-height: 430px;
  resize: vertical;
  background: #09101d;
  color: #dbeafe;
  border: none;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  outline: none;
}

.ladder-canvas {
  min-height: 430px;
  max-height: 540px;
  overflow: auto;
  padding: 10px 12px;
  background: #09101d;
}
.rung-box {
  margin-bottom: 10px;
  border: 1px solid #1e2f4d;
  border-radius: 8px;
  background: #0d1729;
  padding: 6px 10px;
}
.rung-title { font-size: 11px; color: #7dd3fc; margin-bottom: 4px; font-family: var(--mono); }

.console-card { margin-top: 14px; }
.console-body {
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  background: #080e1a;
  color: #cbd5e1;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
}
.issue-err { color: #fca5a5; }
.issue-warn { color: #fcd34d; }
.issue-ok { color: #6ee7b7; }

.status-pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}
.status-pill.ok { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.status-pill.err { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

.io-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
}
.io-bit {
  padding: 10px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0c1526;
  text-align: center;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.io-bit.on {
  background: rgba(16, 185, 129, 0.25);
  border-color: var(--accent);
  color: #a7f3d0;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.35);
}
.reg-row { display: flex; flex-wrap: wrap; gap: 12px; padding: 12px; align-items: center; }
.online-body { padding: 12px 14px; }
.mcp-url-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #09101d;
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 8px;
  margin: 10px 0 16px;
}
.mcp-url-box code { flex: 1; font-family: var(--mono); color: #7dd3fc; font-size: 13px; }
.mcp-list { line-height: 1.75; color: #cbd5e1; }
.mcp-list code { color: #7dd3fc; font-family: var(--mono); }
