:root {
  --bg: #0b1220;
  --surface: rgba(11, 18, 32, 0.78);
  --surface-solid: #131c2e;
  --line: rgba(148, 163, 184, 0.28);
  --text: #e6edf7;
  --muted: #9aa8bd;
  --accent: #22c55e;
  --accent-ink: #052e16;
  --info: #38bdf8;
  --warn: #f59e0b;
  --danger: #f87171;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; overflow: hidden; }

#video, #overlay, .backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#video, .backdrop { object-fit: cover; background: #000; }
#overlay { pointer-events: none; }

[hidden] { display: none !important; }

/* HUD */
.hud { position: absolute; left: 0; right: 0; padding: 12px 16px; display: flex; gap: 8px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud.top { top: 0; padding-top: calc(var(--safe-top) + 12px); flex-direction: column; align-items: flex-start; }
.hud.bottom {
  bottom: 0;
  padding-bottom: calc(var(--safe-bottom) + 12px);
  align-items: flex-end;
  justify-content: space-between;
}

.pill {
  background: var(--surface);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  max-width: 100%;
}
.pill.small { font-size: 12px; font-weight: 500; color: var(--muted); }
.pill[data-kind="ok"] { border-color: rgba(34, 197, 94, 0.6); }
.pill[data-kind="ok"]::before,
.pill[data-kind="warn"]::before,
.pill[data-kind="idle"]::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  background: var(--muted);
}
.pill[data-kind="ok"]::before { background: var(--accent); }
.pill[data-kind="warn"]::before { background: var(--warn); }

.readout {
  flex: 1;
  max-width: 60%;
  background: var(--surface);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 16px;
  min-width: 0;
}
.count { display: flex; align-items: baseline; gap: 8px; }
.count #count { font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.count .unit { color: var(--muted); font-size: 14px; }
.detail { color: var(--muted); font-size: 13px; margin-top: 4px; }

.occupancy { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); color: #fcd34d; font-size: 13px; font-weight: 600; white-space: pre-line; max-height: 28vh; overflow-y: auto; }
dialog .note { display: block; margin: -4px 0 14px; }

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

/* Botones */
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.icon { padding: 0; width: 44px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .link:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

/* Pantalla de inicio */
.start {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  background: radial-gradient(120% 90% at 50% 0%, #17233b 0%, var(--bg) 60%);
  overflow-y: auto;
}
.card { width: min(100%, 420px); margin: auto 0; }
.brand { width: min(100%, 420px); background: #fff; border-radius: 14px; padding: 12px 16px; }
.brand img { display: block; width: 100%; height: auto; max-height: 56px; object-fit: contain; }
.credit { color: var(--muted); font-size: 12px; text-align: center; max-width: 420px; }
.logo { border-radius: 16px; display: block; margin-bottom: 16px; }
h1 { font-size: 28px; line-height: 1.15; margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 16px; }
.steps { margin: 0 0 20px; padding-left: 20px; display: grid; gap: 8px; }
.steps strong { color: var(--accent); white-space: nowrap; }
.error { color: var(--danger); background: rgba(248, 113, 113, 0.1); border: 1px solid rgba(248, 113, 113, 0.4); border-radius: 12px; padding: 10px 12px; margin: 0 0 16px; font-size: 14px; }
.start .btn.primary { width: 100%; min-height: 52px; font-size: 17px; }
.links { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; }
.link {
  appearance: none; background: none; border: 0; padding: 8px 0;
  color: var(--info); font: inherit; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* Ajustes */
dialog {
  width: min(100% - 32px, 440px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface-solid);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog label { display: grid; gap: 6px; margin-bottom: 14px; font-size: 14px; font-weight: 600; }
dialog small { color: var(--muted); font-weight: 400; font-size: 12px; }
dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
input, select {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  font-size: 16px; /* evita el zoom automático en iOS */
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }

@media (max-width: 380px) {
  .count #count { font-size: 32px; }
  .btn { padding: 0 12px; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn { transition: transform 0.08s ease; }
}
