:root {
  --bg: #0b0f17;
  --panel: #151b26;
  --panel-2: #1e2633;
  --text: #e8edf5;
  --muted: #8b97a8;
  --gris: #5b6577;
  --azul: #3b82f6;
  --amarillo: #f5b400;
  --verde: #22c55e;
  --rojo: #ef4444;
  --naranja: #f97316;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- Inicio ---------- */
.inicio { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.inicio-caja { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.inicio h1 { margin: 0; font-size: 1.6rem; }
.inicio p { margin: 0; color: var(--muted); line-height: 1.4; }
.inicio input { padding: 14px; font-size: 1.3rem; text-align: center; letter-spacing: .2em; border-radius: 12px; border: 1px solid var(--panel-2); background: var(--panel); color: var(--text); }
.inicio input.campo { letter-spacing: normal; text-align: left; font-size: 1.05rem; }
.primario { background: var(--azul); color: white; padding: 14px; border-radius: 12px; font-weight: 600; }
.secundario { background: var(--panel-2); color: var(--muted); padding: 12px; border-radius: 12px; }
.primario:disabled { opacity: .6; }
.error { color: var(--rojo) !important; min-height: 1.2em; }

/* ---------- App ---------- */
#app { height: 100dvh; display: flex; flex-direction: column; }
.barra { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--panel); }
.pill { padding: 6px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; }
.pill.gris { background: var(--gris); }
.pill.verde { background: var(--verde); color: #06260f; }
.pill.amarillo { background: var(--amarillo); color: #2b2000; }
.pill.rojo { background: var(--rojo); }
.fps { margin-left: auto; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.icono { background: var(--panel-2); width: 40px; height: 40px; border-radius: 10px; font-size: 1.2rem; }

.visor { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.visor video, .visor canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.estado { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); padding: 8px 16px; border-radius: 999px; font-weight: 700; white-space: nowrap; box-shadow: 0 4px 16px rgba(0,0,0,.4); transition: background .15s; }
.estado.gris { background: rgba(91,101,119,.9); }
.estado.azul { background: rgba(59,130,246,.95); }
.estado.amarillo { background: var(--amarillo); color: #2b2000; }
.estado.verde { background: var(--verde); color: #06260f; }
.estado.rojo { background: var(--rojo); }

.flash { position: absolute; inset: 0; display: grid; place-items: center; font-size: 4rem; font-weight: 800; pointer-events: none; opacity: 0; text-shadow: 0 4px 24px rgba(0,0,0,.6); }
.flash.on { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: 1; transform: scale(.8); } 30% { opacity: 1; transform: scale(1.05); } 100% { opacity: 0; transform: scale(1.15); } }

.toast { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); padding: 8px 14px; border-radius: 10px; background: rgba(21,27,38,.95); font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap; }
.toast.on { opacity: 1; }
.toast.error { background: var(--rojo); }

.controles { display: grid; gap: 8px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--panel); }
.toggle { padding: 14px; border-radius: 12px; font-weight: 700; font-size: 1rem; }
.toggle.off { background: var(--panel-2); color: var(--muted); }
.toggle.on { background: var(--verde); color: #06260f; }
.fila { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.nav { padding: 18px 8px; border-radius: 12px; background: var(--azul); color: white; font-size: 1.1rem; font-weight: 700; }
.nav:active, .efectos button:active { filter: brightness(1.3); transform: scale(.97); }
.efectos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.efectos button { padding: 10px 4px; border-radius: 10px; background: var(--panel-2); font-size: .8rem; }

/* En horizontal: controles a la derecha */
@media (orientation: landscape) and (max-height: 600px) {
  #app { display: grid; grid-template-columns: 1fr 300px; grid-template-rows: auto 1fr; }
  .barra { grid-column: 1 / -1; }
  .visor { grid-column: 1; }
  .controles { grid-column: 2; overflow-y: auto; align-content: start; }
  .efectos { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Calibración ---------- */
dialog { width: min(480px, calc(100% - 24px)); max-height: calc(100dvh - 24px); border: 0; border-radius: 16px; background: var(--panel); color: var(--text); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 6px; font-size: 1.2rem; }
.ayuda { color: var(--muted); font-size: .85rem; margin: 0 0 14px; line-height: 1.4; }
.slider { display: grid; gap: 4px; margin-bottom: 14px; }
.slider-top { display: flex; justify-content: space-between; font-size: .9rem; }
.slider-top b { font-variant-numeric: tabular-nums; color: var(--amarillo); }
.slider small { color: var(--muted); font-size: .75rem; }
.slider input { width: 100%; accent-color: var(--azul); }
.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; margin: 4px 0 16px; }
.dialog-botones { display: flex; gap: 8px; flex-wrap: wrap; }
.dialog-botones button { flex: 1; padding: 12px; border-radius: 10px; background: var(--panel-2); }
.dialog-botones .primario { background: var(--azul); }
