:root {
  --bg: #0f1419;
  --panel: #1a2230;
  --panel-2: #222d3d;
  --line: #2c3a4f;
  --text: #e6edf3;
  --muted: #8aa0b6;
  --accent: #00c2a8;
  --accent-2: #ffb020;
  --on: #2ee06a;
  --off: #38465a;
  --red: #ff5a5a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 20px;
}

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 16px; margin-bottom: 16px;
}
.brand h1 { margin: 0; font-size: 24px; font-weight: 700; }
.brand .accent { color: var(--accent); }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.controls { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.btn {
  background: var(--accent); color: #03201c; border: none; border-radius: 8px;
  padding: 10px 16px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn:hover { filter: brightness(1.08); }
.btn-sec { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn-sec:hover { border-color: var(--accent); filter: none; }
.btn-sec:disabled { opacity: .45; cursor: not-allowed; }
.btn-sec.active { border-color: var(--accent-2); color: var(--accent-2); }
.astab-ctrl { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.astab-ctrl input[type=range] { accent-color: var(--accent); }
.sep { width: 1px; height: 24px; background: var(--line); display: inline-block; margin: 0 2px; }

.dropzone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 18px;
  text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 12px;
}
.dropzone.drag { border-color: var(--accent); color: var(--text); background: var(--panel); }
.dropzone code { color: var(--accent-2); }

.status { color: var(--muted); font-size: 13px; margin: 8px 0 16px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 18px;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }

.frame { display: flex; gap: 24px; flex-wrap: wrap; }
.frame-group { display: flex; align-items: center; gap: 10px; }
.frame-label { font-weight: 700; width: 18px; color: var(--accent); }
.frame-bits { display: flex; gap: 4px; flex-wrap: wrap; }
.frame-bit {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  font-size: 10px; border-radius: 4px; background: var(--off); color: var(--muted);
}
.frame-bit.on { background: var(--on); color: #04240f; font-weight: 700; }

.devices { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

.device {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px;
}
.device-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.device-title { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.mod-badge {
  width: 26px; height: 26px; border-radius: 6px; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 800; color: #06121a;
}
.mod-B { background: #6cc4ff; }
.mod-A { background: #ffd166; }
.mod-C { background: #b292ff; }

.conn-led { width: 14px; height: 14px; border-radius: 50%; background: var(--red); box-shadow: 0 0 6px var(--red); }
.conn-led.on { background: var(--on); box-shadow: 0 0 8px var(--on); }

.io-block { margin-top: 12px; }
.io-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.io-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.in-cell {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
  cursor: pointer;
}
.in-cell input { accent-color: var(--accent); }
.in-labels { display: flex; flex-direction: column; line-height: 1.1; }
.in-name { font-weight: 600; }
.in-fn { font-size: 9px; color: var(--muted); }
.in-cell.in-tand { border-color: var(--accent); }
.in-cell.in-tand .in-fn { color: var(--accent); }
.in-cell.in-used { border-color: #3a567a; }

.out-cell {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px;
}
.out-led {
  width: 12px; height: 12px; border-radius: 50%; background: var(--off);
  transition: background .08s, box-shadow .08s;
}
.out-led.on { background: var(--on); box-shadow: 0 0 8px var(--on); }

/* Scenariusze */
.scenarios { display: flex; flex-wrap: wrap; gap: 10px; }
.scn-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 14px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.scn-btn:hover { border-color: var(--accent); }
.scn-trio { border-color: var(--accent-2); color: var(--accent-2); }
.scn-clear { border-color: var(--red); color: var(--red); }

/* Diagnostyka */
.diag { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 12px; }
.diag-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.diag-cell {
  display: flex; align-items: center; gap: 6px; font-size: 11px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px;
}
.diag-led { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.diag-led.on { background: var(--accent); box-shadow: 0 0 7px var(--accent); }
.diag-empty { color: var(--muted); font-size: 11px; }
.diag-counters { margin-top: 8px; font-size: 11px; color: var(--muted); font-family: ui-monospace, monospace; }

/* Edytor pk_cfg */
.editor { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 12px; }
.pk-editor {
  width: 100%; min-height: 150px; resize: vertical; box-sizing: border-box;
  background: #0c1118; color: #cfe3ef; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px; line-height: 1.4;
}
.pk-editor:focus { outline: none; border-color: var(--accent); }
.editor-bar { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.editor-status { font-size: 11px; }
.editor-status.ok { color: var(--on); }
.editor-status.err { color: var(--red); }

/* Podglad pamieci */
.memblock { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 12px; }
.mem-half-label { font-size: 10px; color: var(--muted); margin: 6px 0 4px; }
.mem-grid {
  display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; max-width: 280px;
}
.mem-cell {
  width: 100%; aspect-ratio: 1 / 1; background: var(--off); border-radius: 2px;
  cursor: help; transition: background .05s;
}
.mem-cell.on { background: var(--on); }
.mem-cell.mem-relay { outline: 1px solid var(--accent-2); outline-offset: -1px; }
.mem-cell.mem-relay.on { background: var(--accent-2); }

.foot { margin-top: 20px; color: var(--muted); font-size: 12px; text-align: center; }
.foot-links { display: block; margin-top: 8px; }
.foot-links a { color: var(--accent); text-decoration: none; }
.foot-links a:hover { text-decoration: underline; }
