:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #5d6573;
  --border: #dde1e7;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #dcf5e3;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bad: #b42318;
  --bad-bg: #fde4e1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #181c22;
    --text: #e6e8eb;
    --muted: #98a1ae;
    --border: #2a3039;
    --accent: #4c8dff;
    --accent-text: #0b0d10;
    --ok: #4ac26b;
    --ok-bg: #12301c;
    --warn: #e3b341;
    --warn-bg: #33290d;
    --bad: #ff7b72;
    --bad-bg: #3b1715;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top { padding: 14px 16px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.top h1 { margin: 0; font-size: 20px; }
.top .sub { color: var(--muted); font-size: 14px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 0 16px 24px;
  max-width: 1500px;
  margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.viewport {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.viewport canvas { display: block; width: 100%; height: 100%; object-fit: contain; }
.viewport canvas.card-mode { touch-action: none; cursor: ew-resize; }
/* O vídeo precisa continuar decodificando (display:none pausa em alguns browsers). */
.viewport video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.overlay-msg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; text-align: center; padding: 16px;
  background: rgba(0, 0, 0, .55);
}
.overlay-msg.hidden { display: none; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.toolbar.hidden { display: none; }
.toolbar .hint { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 14px; }
.card-info { flex-basis: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
.progress { color: var(--muted); font-size: 14px; }

button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
kbd { border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 12px; }

.tips { color: var(--muted); font-size: 14px; padding-left: 18px; margin: 12px 0 0; }

.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.box { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.box h2 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
details.box summary { cursor: pointer; font-weight: 600; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }

.result.empty { color: var(--muted); font-size: 14px; }
.result .big { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.result .big div { text-align: center; }
.result .big b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.result .big span { font-size: 12px; color: var(--muted); }
.result .meta { font-size: 13px; color: var(--muted); }
.result .meta b { color: var(--text); font-weight: 600; }
.result .error { color: var(--bad); }

.live { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 14px; }
.live dt { color: var(--muted); }
.live dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.form { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form input { font: inherit; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.form hr { border: 0; border-top: 1px solid var(--border); width: 100%; margin: 4px 0; }
.note { font-size: 13px; color: var(--muted); margin: 0; }

.hidden { display: none !important; }

.prec { font-size: 13px; color: var(--muted); margin: 8px 0 0; padding-left: 16px; }
.prec li { margin-bottom: 3px; }
.error { color: var(--bad); }

/* Botão de tela cheia sobre o vídeo */
.fs-btn {
  position: absolute; right: 10px; bottom: 10px; z-index: 4;
  background: rgba(0, 0, 0, .6); color: #fff; border-color: rgba(255, 255, 255, .35);
}

/* Modo tela cheia: só o vídeo/estímulo e os botões de captura */
body.fs { overflow: hidden; }
body.fs .stage {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
  padding: 0 0 max(8px, env(safe-area-inset-bottom));
  background: #000;
}
body.fs .viewport { flex: 1 1 auto; min-height: 0; aspect-ratio: auto; border-radius: 0; }
body.fs .tips { display: none; }
body.fs .toolbar { margin: 0; padding: 0 12px; justify-content: center; }
body.fs .toolbar .hint, body.fs .toolbar .card-info, body.fs .progress { color: #d6dae0; }
body.fs .toolbar button { padding: 12px 18px; }

/* Ponto de fixação: topo central, o mais perto possível da câmera frontal.
   O status fica colado nele porque é para onde a pessoa está olhando. */
.gaze-dot {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: min(92%, 520px); pointer-events: none;
  --p: 0; --ring: #3fdc7a;
}
.gaze-dot .ring {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--ring) calc(var(--p) * 1turn), rgba(255, 255, 255, .28) 0);
  -webkit-mask: radial-gradient(circle, #000 0 11px, transparent 11.5px 14px, #000 14.5px);
          mask: radial-gradient(circle, #000 0 11px, transparent 11.5px 14px, #000 14.5px);
}
.gaze-dot .ring span {
  width: 18px; height: 18px; border-radius: 50%;
  background: #ff2a2a;
  animation: gaze-pulse 1.4s ease-in-out infinite;
}
@keyframes gaze-pulse { 50% { transform: scale(.75); } }
.gaze-dot p {
  margin: 0; padding: 6px 12px; border-radius: 8px;
  background: rgba(0, 0, 0, .7); color: #fff;
  font-size: 15px; font-weight: 600; line-height: 1.3; text-align: center;
}
.gaze-dot[data-state="hold"] { --ring: #ffffff; }
.gaze-dot[data-state="hold"] p { color: #3fdc7a; }
.gaze-dot[data-state="collect"] p { color: #ffd23f; font-size: 17px; }
.gaze-dot[data-state="collect"] .ring span { animation-duration: .6s; }
.gaze-dot[data-state="done"] .ring span { background: #3fdc7a; animation: none; }
.gaze-dot[data-state="done"] p { color: #3fdc7a; }
@media (prefers-reduced-motion: reduce) { .gaze-dot .ring span { animation: none !important; } }
.viewport.card .gaze-dot { display: none; }
body.fs .gaze-dot { top: max(6px, env(safe-area-inset-top)); }
.sound-btn { right: auto; left: 10px; }

/* Tabela das coletas */
.runs { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; margin: 8px 0 4px; }
.runs th, .runs td { padding: 4px; text-align: right; border-bottom: 1px solid var(--border); }
.runs th:first-child, .runs td:first-child { text-align: left; }
.runs th { color: var(--muted); font-weight: 600; font-size: 12px; }
.runs tfoot td { font-weight: 700; }
.runs tfoot tr:last-child td { font-weight: 400; color: var(--muted); }

/* Tela de resultado ao terminar as coletas */
.result-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg); overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.rs-card {
  max-width: 560px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 16px;
}
.rs-card h2 { margin: 0 0 14px; font-size: 20px; }
.rs-card .big b { font-size: 32px; }
.rs-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.rs-actions button { flex: 1 1 150px; padding: 12px; }

/* Modo validação (?lab=1) */
.lab { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border); }
.lab h3 { margin: 0 0 10px; font-size: 15px; }
.lab-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.lab-form label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.lab-form input { font: inherit; padding: 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); min-width: 0; }
.lab .meta { margin-top: 10px; }
.lab-hint { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.lab-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
.lab-row label { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.lab-row label.grow { flex: 3; }
.lab-row input { width: 100%; min-width: 0; font: inherit; font-size: 20px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.lab-row #lab-note { font-size: 15px; padding: 11px 10px; }
.lab-row button { padding: 11px 18px; }
.lab-row select { width: 100%; min-width: 0; font: inherit; font-size: 15px; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
