/* Capturazo — cámara y micrófono en el celular */

:root {
  --bg: #000;
  --surface: #111113;
  --surface-2: #1b1b1e;
  --surface-3: #262629;
  --line: rgba(255, 255, 255, .07);
  --text: #f5f5f7;
  --muted: #8e8e93;
  --accent: #1ec8ff;
  --accent-2: #0a84ff;
  --rec: #ff3b30;
  --ok: #34c759;
  --warn: #ff9f0a;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  pointer-events: none;
}

[hidden] { display: none !important; }
.muted { color: var(--muted); }

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
  background: radial-gradient(520px 320px at 50% 112%, rgba(30, 200, 255, .12), transparent 70%), var(--bg);
}

@keyframes pulse { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------- cabecera */

.top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 56px;
  padding: 0 10px 0 14px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 32px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}
.status .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.app[data-conn="connected"] .status .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 199, 89, .22); }
.app[data-conn="waiting"] .status .dot,
.app[data-conn="connecting"] .status .dot,
.app[data-conn="reconnecting"] .status .dot,
.app[data-conn="offline"] .status .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }

.top-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--muted);
}
.icon-btn:active { background: var(--surface); color: var(--text); }

.rec-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 59, 48, .16);
  color: #ff6961;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.rec-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--rec); animation: pulse 1.2s ease-in-out infinite; }

/* ---------------------------------------------------------- vista previa */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 12px;
  border-radius: 26px;
  overflow: hidden;
  background: #050506;
  box-shadow: 0 0 0 1px var(--line);
}
.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #050506;
}
.stage video.mirror { transform: scaleX(-1); }
.app.fit .stage video { object-fit: contain; }

.stage-off {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #0b0b0c;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}
.stage-off svg { width: 40px; height: 40px; stroke-width: 1.5; }

.stage-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 70%;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip span { overflow: hidden; text-overflow: ellipsis; }
.chip i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.on i { background: var(--accent); box-shadow: 0 0 0 3px rgba(30, 200, 255, .25); animation: pulse 1.6s ease-in-out infinite; }
.chip.ghost { font-weight: 500; color: rgba(255, 255, 255, .8); font-variant-numeric: tabular-nums; }

.use-btn {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--text);
  color: #000;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

.torch {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.torch.on { background: #ffd60a; color: #000; }

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.go { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

/* ---------------------------------------------------------- controles */

.panel {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px calc(14px + var(--safe-b));
}

.cams {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -12px;
  padding: 0 12px;
}
.cams::-webkit-scrollbar { display: none; }
.cams:empty { display: none; }
.cams button {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 550;
  white-space: nowrap;
}
.cams button svg { width: 17px; height: 17px; }
.cams button[aria-checked="true"] { background: var(--text); color: #000; }

.mic-row { display: flex; align-items: center; gap: 12px; }

.seg {
  flex: 1;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border-radius: 14px;
  background: var(--surface-2);
}
.seg button {
  height: 36px;
  padding: 0 8px;
  border-radius: 11px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 550;
  white-space: nowrap;
}
.seg button[aria-checked="true"] { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.seg button[data-mode="nr"][aria-checked="true"] { background: linear-gradient(180deg, #24b8ff, var(--accent-2)); color: #fff; }
.seg.small button { height: 32px; font-size: 13px; }
.seg:disabled, .seg.disabled { opacity: .45; pointer-events: none; }

.meter {
  flex: none;
  display: flex;
  align-items: center;
  gap: 3px;
  height: 36px;
  --level: 0;
}
.meter i {
  width: 4px;
  height: 22px;
  border-radius: 2px;
  background: var(--surface-3);
  transition: background .08s linear;
}
.meter i.lit { background: var(--accent); }
.meter i.lit.hot { background: var(--warn); }

.controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.ctl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 0;
  color: var(--text);
}
.ctl-ico {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-2);
  transition: background .15s ease, transform .1s ease;
}
.ctl:active .ctl-ico { transform: scale(.92); }
.ctl-ico svg { width: 24px; height: 24px; }
.ctl-label { font-size: 11.5px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.ctl .off { display: none; }
.ctl[aria-pressed="false"] .on { display: none; }
.ctl[aria-pressed="false"] .off { display: block; }
.ctl:not(.rec)[aria-pressed="false"] .ctl-ico { background: #3a1513; color: #ff6961; }
.ctl:disabled { opacity: .4; pointer-events: none; }
.rec-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--rec); transition: border-radius .2s ease, width .2s ease, height .2s ease; }
.ctl.rec[aria-pressed="true"] .ctl-ico { background: rgba(255, 59, 48, .18); }
.ctl.rec[aria-pressed="true"] .rec-dot { width: 18px; height: 18px; border-radius: 5px; }

/* Horizontal: la vista previa a la izquierda y los controles a la derecha. */
@media (orientation: landscape) and (max-height: 560px) {
  .app { flex-direction: row; flex-wrap: wrap; padding-bottom: var(--safe-b); }
  .top { position: absolute; top: var(--safe-t); right: var(--safe-r); left: auto; width: 46%; z-index: 2; }
  .stage { flex: 1 1 54%; margin: 10px 0 10px 10px; }
  .panel { flex: 0 0 46%; justify-content: flex-end; padding-top: 64px; }
  .ctl-ico { width: 48px; height: 48px; }
}

/* ---------------------------------------------------------- inicio (permiso) */

.start {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) 28px calc(24px + var(--safe-b));
  background: radial-gradient(420px 300px at 50% 115%, rgba(30, 200, 255, .18), transparent 70%), rgba(0, 0, 0, .94);
  text-align: center;
}
.start-inner { display: flex; flex-direction: column; align-items: center; max-width: 330px; }
.start-logo { margin-bottom: 20px; }
.start h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.025em; }
.start p { margin: 8px 0 0; font-size: 15px; line-height: 1.5; color: var(--muted); }
.start .btn { min-width: 200px; }
.start-err { color: #ff8a80 !important; font-size: 14px !important; }

/* ---------------------------------------------------------- pantalla de conexión */

.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) 32px calc(24px + var(--safe-b));
  background: radial-gradient(420px 300px at 50% 115%, rgba(30, 200, 255, .16), transparent 70%), var(--bg);
  text-align: center;
  transition: opacity .3s ease, visibility .3s;
}
.app.ready .gate { opacity: 0; visibility: hidden; pointer-events: none; }
.app.instant .gate { transition: none; }
.gate-inner { display: flex; flex-direction: column; align-items: center; max-width: 320px; }
.gate-logo { margin-bottom: 22px; }
.gate h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.025em; }
.gate p { margin: 8px 0 0; font-size: 15px; line-height: 1.5; color: var(--muted); }
.gate-credit { position: absolute; bottom: calc(18px + var(--safe-b)); font-size: 12px; color: #48484a; }

.spinner {
  width: 26px;
  height: 26px;
  margin-top: 26px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .12);
  border-top-color: var(--text);
  animation: spin .8s linear infinite;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  margin-top: 24px;
  padding: 0 26px;
  border-radius: 16px;
  background: var(--surface-2);
  font-size: 16px;
  font-weight: 600;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--text); color: #000; }
.btn.danger { color: var(--rec); }

/* ---------------------------------------------------------- hoja de ajustes */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  margin: auto auto 0;
  padding: 8px 20px calc(18px + var(--safe-b));
  border: 0;
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  color: var(--text);
}
.sheet[open] { animation: rise .28s cubic-bezier(.2, .8, .2, 1); }
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet form { display: flex; flex-direction: column; }
.sheet-handle { flex: none; width: 38px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: var(--surface-3); }
.sheet h2 { margin: 0 0 8px; font-size: 20px; font-weight: 650; letter-spacing: -.02em; }
.field { display: flex; flex-direction: column; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.field-row { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field-label { font-size: 13px; color: var(--muted); }
.field select {
  max-width: 60%;
  height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text);
  font: 14px var(--font);
}
.sheet .btn { flex: none; width: 100%; margin-top: 12px; }
.sheet .btn.danger { margin-top: 18px; background: var(--surface-2); }
.credit { margin: 16px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.credit a { color: inherit; }

.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background .2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
  transition: transform .22s cubic-bezier(.3, .7, .4, 1);
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

/* ---------------------------------------------------------- aviso */

.toast {
  position: fixed;
  top: calc(64px + var(--safe-t));
  left: 50%;
  z-index: 30;
  max-width: calc(100% - 40px);
  padding: 10px 16px;
  border-radius: 18px;
  background: rgba(38, 38, 41, .97);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: rgba(80, 24, 22, .97); }

/* tablets: centrado */
@media (min-width: 700px) and (min-height: 600px) {
  .app { inset: 0 max(0px, calc((100% - 640px) / 2)); }
}
