* { box-sizing: border-box; }

:root {
  --ink-void: #08090e;
  --panel: rgba(20, 22, 34, 0.78);
  --panel-solid: #12141f;
  --line: rgba(190, 200, 255, 0.14);
  --ink: rgba(240, 243, 255, 0.94);
  --ink-dim: rgba(240, 243, 255, 0.44);
  --lime: #2fff1e;
  --coral: #ff2d55;
  --peri: #3769ff;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  background:
    radial-gradient(ellipse 70% 45% at 12% -8%, rgba(47, 255, 30, 0.12), transparent 60%),
    radial-gradient(ellipse 60% 50% at 92% 8%, rgba(55, 105, 255, 0.14), transparent 62%),
    radial-gradient(circle at 78% 96%, rgba(255, 45, 85, 0.09), transparent 45%),
    var(--ink-void);
  overflow-x: hidden;
}

main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: clamp(20px, 3.4vw, 46px);
  max-width: 1320px;
  margin: 0 auto;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.eyebrow {
  font-family: var(--mono);
  color: rgba(47, 255, 30, 0.72);
  font-size: 11px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

h1 {
  margin: 10px 0 0;
  font-size: clamp(38px, 7vw, 82px);
  font-weight: 800;
  line-height: 0.94;
  letter-spacing: -0.035em;
}

h1 em {
  font-style: normal;
  color: var(--lime);
  -webkit-text-stroke: 0;
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn {
  border: 1px solid var(--line);
  background: rgba(190, 200, 255, 0.07);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover { border-color: rgba(190, 200, 255, 0.34); }
.btn:disabled { opacity: 0.5; cursor: progress; }

.btn.primary {
  border-color: rgba(47, 255, 30, 0.5);
  background: rgba(47, 255, 30, 0.14);
  color: var(--lime);
}

.btn.primary[data-on] {
  background: var(--lime);
  color: #06210a;
  border-color: var(--lime);
}

.btn.ghost { background: transparent; color: var(--ink-dim); }
.btn.ghost:hover { color: var(--ink); }

/* ── Stage ───────────────────────────────────────────────────────────────── */

.stage {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 18px;
  align-items: stretch;
}

.viewport {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--panel-solid);
  overflow: hidden;
  min-height: 340px;
  aspect-ratio: 4 / 3;
}

#feed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Mirror so moving left on screen matches moving left in the room. */
  transform: scaleX(-1);
  opacity: 0;
  transition: opacity 0.4s ease;
}

body[data-live] #feed { opacity: 1; }
body[data-live] .idle { opacity: 0; pointer-events: none; }

.idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.3s ease;
}

.idle p {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.idle-mark { display: flex; gap: 14px; }

.idle-mark span {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--line);
  animation: breathe 2.6s ease-in-out infinite;
}

.idle-mark span:nth-child(1) { background: rgba(47, 255, 30, 0.16); }
.idle-mark span:nth-child(2) { background: rgba(255, 45, 85, 0.16); animation-delay: 0.35s; }
.idle-mark span:nth-child(3) { background: rgba(55, 105, 255, 0.16); animation-delay: 0.7s; }

@keyframes breathe {
  0%, 100% { transform: translateY(0); opacity: 0.55; }
  50% { transform: translateY(-6px); opacity: 1; }
}

.readout {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  padding: 16px 20px;
  border-radius: 18px;
  background: rgba(8, 9, 14, 0.72);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "label label" "verdict val" "meter meter";
  gap: 6px 12px;
}

.label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.readout .label { grid-area: label; }

.verdict {
  grid-area: verdict;
  font-size: clamp(24px, 3.4vw, 40px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.meter {
  grid-area: meter;
  height: 4px;
  border-radius: 999px;
  background: rgba(190, 200, 255, 0.14);
  overflow: hidden;
  margin-top: 6px;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--ink-dim);
  transition: width 0.12s linear;
}

.meter-val {
  grid-area: val;
  align-self: end;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
}

/* ── Side column ─────────────────────────────────────────────────────────── */

.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.lamp-panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "label label" "lamp sign";
  align-items: center;
  gap: 4px 16px;
}

.lamp-panel .label { grid-area: label; margin-bottom: 6px; }

.lamp {
  grid-area: lamp;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(190, 200, 255, 0.06);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.lamp[data-lit] {
  background: var(--glow);
  box-shadow: 0 0 34px var(--glow), inset 0 0 12px rgba(255, 255, 255, 0.45);
  border-color: transparent;
}

.lamp-sign {
  grid-area: sign;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
}

/* ── Sign cards ──────────────────────────────────────────────────────────── */

.cards { display: flex; flex-direction: column; gap: 10px; }

.card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  padding: 13px 16px;
  transition: border-color 0.2s, background 0.2s;
}

.card[data-active] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

.card header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
  flex: none;
  opacity: 0.45;
}

.card[data-taught] .swatch { opacity: 1; }

.card .label {
  /* Overrides the shared .label styling for the editable name field. */
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  color: var(--ink);
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: -0.01em;
  text-transform: none;
  padding: 2px 0;
}

.card .label:hover { border-bottom-color: var(--line); }
.card .label:focus { outline: none; border-bottom-color: var(--accent); }

.count {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
  flex: none;
}

.card[data-taught] .count { color: var(--accent); }

.card-actions { display: flex; gap: 8px; }

.card-actions .btn { padding: 7px 12px; font-size: 10px; }

.card-actions .teach {
  flex: 1;
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  user-select: none;
  touch-action: none;
}

.card-actions .teach[data-on] {
  background: var(--accent);
  color: #08090e;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

.foot {
  display: grid;
  grid-template-columns: 1fr 1.05fr;
  gap: 20px;
  align-items: start;
}

.status {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
}

.status[data-tone="ok"] { color: var(--lime); }
.status[data-tone="warn"] { color: #ffc247; }
.status[data-tone="error"] { color: var(--coral); }

.hint {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.75;
  color: var(--ink-dim);
}

.hint strong { color: var(--ink); font-weight: 500; }
.hint code { color: rgba(47, 255, 30, 0.78); }

@media (max-width: 900px) {
  .stage, .foot { grid-template-columns: 1fr; }
  .viewport { aspect-ratio: 3 / 2; }
}