:root {
  --bg: #0d0f17; --panel: #151927; --panel2: #1c2133; --line: #2a3048;
  --text: #e8ebf5; --muted: #8b93ad; --accent: #7c5cff; --accent2: #22d3ee;
  --ok: #34d399; --warn: #fbbf24; --err: #f87171;
  --radius: 12px; --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: #0f1220; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.ver { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 3px 10px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.chip.armed { color: #111; background: var(--warn); border-color: var(--warn); font-weight: 600; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; padding: 16px; align-items: start; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

.stage-wrap { position: sticky; top: 66px; }
.stage { position: relative; background: #05060a; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; max-height: calc(100vh - 140px); width: 100%; }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage.mirror video, .stage.mirror canvas { transform: scaleX(-1); }
.placeholder { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; gap: 4px; }
.placeholder .big { font-size: 56px; }
.placeholder p { margin: 0; }
.stage-help { margin-top: 10px; color: var(--muted); font-size: 12.5px; }

.hud-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; justify-content: center; pointer-events: none; }
.kame { background: rgba(10, 12, 20, .75); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; display: flex; gap: 10px; align-items: center; font-weight: 600; }
.kame .bar { width: 160px; height: 8px; border-radius: 99px; background: #23283c; overflow: hidden; }
.kame i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #38bdf8, #a5f3fc); box-shadow: 0 0 12px #38bdf8; }
.kame.charged i { background: #e0f2fe; }

.hud-bottom { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.cand { background: rgba(10, 12, 20, .78); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; min-width: 120px; }
.cand .name { font-size: 12.5px; font-weight: 600; }
.cand .bar { height: 5px; background: #23283c; border-radius: 99px; margin-top: 5px; overflow: hidden; }
.cand .bar i { display: block; height: 100%; background: var(--accent); }
.cand.done .bar i { background: var(--ok); }

.toast { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(10, 12, 20, .85);
  border: 1px solid var(--accent); border-radius: 16px; padding: 14px 22px; font-size: 22px; font-weight: 700; text-align: center;
  box-shadow: 0 0 40px rgba(124, 92, 255, .45); pointer-events: none; animation: pop .25s ease-out; }
.toast small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 4px; }
.toast.blocked { border-color: var(--warn); box-shadow: 0 0 40px rgba(251, 191, 36, .35); }
.toast.error { border-color: var(--err); }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.85); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.side { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.card[open] { padding-bottom: 14px; }
.card summary { cursor: pointer; padding: 12px 0; font-weight: 600; letter-spacing: .2px; list-style: none; }
.card summary::-webkit-details-marker { display: none; }
.card summary::after { content: '▾'; float: right; color: var(--muted); }
.card:not([open]) summary::after { content: '▸'; }
.card label { display: block; margin: 8px 0; color: var(--muted); font-size: 12.5px; }
.card label input:not([type=checkbox]):not([type=file]), .card select { display: block; width: 100%; margin-top: 4px; }
.card label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-size: 13px; }
.card p { margin: 8px 0 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.row select { flex: 1; min-width: 0; }

input[type=text], input:not([type]), input[type=password], select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; outline: none; }
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible, .file:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; margin-top: 1px; }

button { border: 1px solid var(--line); background: var(--panel2); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; }
button.small, .small button { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.file { position: relative; display: inline-block; border: 1px dashed var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; color: var(--text) !important; margin: 0 !important; font-size: 14px !important; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.maps { display: flex; flex-direction: column; gap: 8px; }
.map { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.map.off { opacity: .6; }
.map.flash { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok); }
.map .head { display: flex; align-items: center; gap: 8px; }
.map .head .ico { font-size: 18px; width: 24px; text-align: center; }
.map .head .lbl { flex: 1; font-weight: 600; font-size: 13px; }
.map .head .lbl small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; }
.map .fields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 7px; }
.map .fields input { width: 100%; padding: 5px 8px; font-size: 12.5px; }
.map .tools { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.map .tools label { margin: 0; display: flex; align-items: center; gap: 5px; color: var(--text); font-size: 12px; }
.map .tools button { margin-left: auto; }
.switch { position: relative; width: 34px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: #2b3149; transition: background .15s; pointer-events: none; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent2); outline-offset: 2px; }

.log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; font-size: 12.5px; }
.log li { padding: 5px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.log li time { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; flex: none; padding-top: 1px; }
.log li.ok { color: var(--ok); } .log li.warn { color: var(--warn); } .log li.err { color: var(--err); }
.log li:empty::after { content: '—'; }

/* urządzenia */
.devs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.dev { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dev .ico { font-size: 17px; width: 22px; text-align: center; }
.dev .lbl { flex: 1; min-width: 140px; font-weight: 600; font-size: 13px; }
.dev .lbl small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.dev .acts { display: flex; gap: 4px; flex-wrap: wrap; }
.dev.flash { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok); }
.devform { background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px; padding: 4px 10px; margin: 8px 0; }
.devform p { margin: 2px 0 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.err-text { color: var(--err); }
details.sub { border-top: 1px solid var(--line); margin-top: 10px; }
details.sub summary { cursor: pointer; padding: 8px 0 0; font-weight: 600; font-size: 13px; }
details.sub summary span { font-weight: 400; margin-left: 6px; }
.map .fields select { width: 100%; padding: 5px 8px; font-size: 12.5px; }
.map .fields .full { grid-column: 1 / -1; }
.devs:empty::after { content: 'Brak urządzeń — dodaj pierwsze.'; color: var(--muted); font-size: 12.5px; }
.note { background: color-mix(in srgb, var(--warn) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: var(--radius); padding: 10px 14px; font-size: 12.5px; }
