:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c232c;
  --line: #2a323d;
  --text: #e6edf3;
  --dim: #8b949e;
  --accent: #2563eb;
  --ok: #2ea043;
  --warn: #d29922;
  --bad: #da3633;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  padding: 18px 16px 10px;
}

h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.sub {
  margin: 4px 0 0;
  color: var(--dim);
  font-size: 13px;
}

main {
  padding: 0 16px 32px;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- video ---------- */

.stage {
  position: relative;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
}

video {
  width: 100%;
  height: 100%;
  /* contain, never cover: the guide box must match the pixels we analyse */
  object-fit: contain;
  display: block;
}

video.mirror { transform: scaleX(-1); }

.roi {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 30%;   /* matches the 0.84 x 0.30 crop in grabFrame */
  transform: translateY(-50%);
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.badge {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13px;
  text-align: center;
}

.badge.ok { background: rgba(46, 160, 67, 0.9); }
.badge.bad { background: rgba(218, 54, 51, 0.9); }

.cam-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}

.chip {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13px;
  cursor: pointer;
}

.chip.on { background: var(--warn); color: #000; border-color: var(--warn); }

.cam-name {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11.5px;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- motores ---------- */

.engines {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.engine {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 11px;
  padding: 11px 12px;
  cursor: pointer;
}

.engine:disabled { opacity: 0.4; cursor: not-allowed; }
.engine.active { border-color: var(--accent); background: #16233b; }
.engine .name { font-weight: 600; font-size: 14px; }
.engine .desc { color: var(--dim); font-size: 12px; }

/* ---------- métricas ---------- */

.live {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  min-width: 0;
}

.metric .k {
  display: block;
  color: var(--dim);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric .v {
  display: block;
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* ---------- ajustes ---------- */

.settings {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 13px;
  margin-bottom: 14px;
}

summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.hint { color: var(--dim); font-weight: 400; font-size: 12px; }

.settings .grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--dim);
}

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  width: 100%;
}

/* ---------- resultados ---------- */

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

h2 { font-size: 15px; margin: 0; }

.count {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 12px;
  color: var(--dim);
  font-weight: 400;
}

.actions { display: flex; gap: 6px; }

.actions button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}

.actions .ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.actions .danger { color: #f0837f; }

.privacy {
  color: var(--dim);
  font-size: 11.5px;
  margin: 8px 0 10px;
  line-height: 1.45;
}

.log { display: flex; flex-direction: column; gap: 6px; }
.empty { color: var(--dim); font-size: 13px; margin: 4px 0; }

.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 13px;
}

.row.hit { border-left-color: var(--ok); }
.row.miss { border-left-color: var(--bad); }
.row .eng { font-weight: 600; }
.row .info { color: var(--dim); font-size: 12px; min-width: 0; overflow-wrap: anywhere; }
.row .ttr { font-variant-numeric: tabular-nums; font-weight: 650; }

@media (max-width: 420px) {
  .live { grid-template-columns: repeat(2, 1fr); }
  .settings .grid { grid-template-columns: 1fr; }
}

/* Live thumbnail of the exact frame handed to the decoder. */
.peek {
  position: absolute;
  left: 10px;
  top: 46px;
  width: 124px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  background: #000;
  image-rendering: pixelated;
}
