:root {
  --bg: #0b0d10;
  --surface: #12151a;
  --surface-2: #181c22;
  --line: #242a33;
  --text: #e6e9ee;
  --muted: #8a93a1;
  --ok: #3ddc97;
  --warn: #f5b041;
  --bad: #ff5d5d;
  --accent: #6ea8ff;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  --sans: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
}

.app {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: 100%;
}

/* ---------- camera ---------- */
.stage {
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 10px;
  min-width: 0;
}

.feed {
  position: relative;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #050607;
}

.feed video, .feed canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: scaleX(-1);
}

.boot {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}
.boot[hidden] { display: none; }

.flash {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 93, 93, 0.22);
  color: var(--text);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.02em;
  animation: flash 1.6s ease-out forwards;
}
.flash[hidden] { display: none; }
@keyframes flash {
  0%, 60% { opacity: 1; }
  100% { opacity: 0; }
}

.note {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12.5px;
}
.note[hidden] { display: none; }

.meter {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: var(--warn);
  transition: width 0.1s linear;
}

/* ---------- side panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.dot {
  width: 12px;
  height: 12px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}
.status[data-state="ok"] .dot { background: var(--ok); box-shadow: 0 0 12px var(--ok); }
.status[data-state="away"] .dot { background: var(--warn); box-shadow: 0 0 12px var(--warn); }
.status[data-state="fired"] .dot { background: var(--bad); box-shadow: 0 0 12px var(--bad); }
.status[data-state="off"] .dot { background: var(--muted); }
.status-label { font-weight: 600; font-size: 16px; }
.status-sub { color: var(--muted); font-size: 12.5px; }

.readouts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0;
}
.readouts div {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.readouts dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.readouts dd {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 14px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }

.range, .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.range span, .field span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12.5px;
}
.range output { color: var(--text); font-family: var(--mono); }
.range input { accent-color: var(--accent); }

.field input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 13px var(--mono);
}
.field input:focus-visible, button:focus-visible, .switch input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

.log h2 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.log ol {
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--mono);
  font-size: 12px;
}
.log li {
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.log li time { color: var(--text); margin-right: 8px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .stage { height: 60vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  .meter-fill { transition: none; }
  .flash { animation: none; }
}
