/* Cuerdas de luz · estilos */

:root {
  --glass: rgba(18, 18, 24, .5);
  --glass-hover: rgba(42, 42, 54, .68);
  --line: rgba(255, 255, 255, .14);
  --line-strong: rgba(255, 255, 255, .3);
  --text: rgba(255, 255, 255, .93);
  --muted: rgba(255, 255, 255, .58);
  --rec: #ff3b4e;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #000; color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none; /* arrastrar no selecciona texto */
  overscroll-behavior: none;   /* sin "tirar para recargar" en el celu */
  touch-action: manipulation;  /* sin zoom por doble toque */
}

#stage {
  position: fixed; inset: 0; display: block;
  width: 100vw; height: 100vh; height: 100dvh;
  touch-action: none; /* evita scroll/zoom mientras dibujás con el dedo */
  cursor: crosshair;
}
/* La cámara se dibuja en el lienzo. El <video> queda invisible pero no con display:none,
   porque Safari en iPhone puede dejar de actualizar los cuadros de un video oculto así. */
#video { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid #9ff; outline-offset: 2px; }

kbd {
  font: 500 11px var(--mono);
  padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
}

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
}

/* ───────── Botones ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 15px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
}
.btn:hover { background: var(--glass-hover); border-color: var(--line-strong); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.icon { width: 38px; padding: 0; }
.btn.on { background: rgba(255, 255, 255, .92); color: #000; border-color: transparent; }
.btn.primary { background: #fff; color: #000; border-color: transparent; }
.btn.primary:hover { background: rgba(255, 255, 255, .82); }
.btn.ghost { background: transparent; }

.link {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px; border: 0; background: none; cursor: pointer;
  font-size: 13px; color: var(--muted);
}
.link:hover { color: var(--text); }

/* Textos distintos para pantalla táctil (celu, tablet) y para mouse */
@media (pointer: coarse) { .only-fine, .link kbd { display: none !important; } }
@media not all and (pointer: coarse) { .only-coarse { display: none !important; } }

/* ───────── Inicio ───────── */
.intro {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: calc(20px + var(--safe-t)) 20px calc(20px + var(--safe-b));
  transition: opacity .6s ease, visibility 0s linear 0s;
}
.intro.hide { opacity: 0; visibility: hidden; transition: opacity .6s ease, visibility 0s linear .6s; }

.card {
  width: min(400px, 100%);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 34px 30px 24px; border-radius: 28px; text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .4);
}
.eyebrow { margin: 0; font-size: 12px; font-weight: 500; letter-spacing: .32em; text-transform: uppercase; color: var(--muted); }

.ring { position: relative; width: 132px; height: 132px; display: grid; place-items: center; }
.ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 2; }
.ring .track { stroke: rgba(255, 255, 255, .12); }
.ring .prog { stroke: #fff; stroke-linecap: round; stroke-dasharray: 389.56; stroke-dashoffset: 389.56; transition: stroke-dashoffset .08s linear; }
.thumb { font-size: 56px; line-height: 1; filter: grayscale(.25); transition: transform .25s ease, filter .25s ease; }
.ring.seen .thumb { transform: scale(1.1); filter: none; }

.msg { margin: 0; font-size: 20px; font-weight: 500; line-height: 1.35; letter-spacing: -.01em; }
.msg span { color: var(--muted); font-weight: 400; }
.status { margin: 0; min-height: 1.45em; max-width: 34ch; font-size: 13px; line-height: 1.45; color: var(--muted); }
.status.error { color: #ffb8b8; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.fine { margin: 4px 0 0; max-width: 34ch; font-size: 11.5px; line-height: 1.5; color: var(--muted); }
.credit { margin: 0; font-size: 11.5px; color: var(--muted); }
.credit a { text-decoration: none; border-bottom: 1px solid var(--line-strong); }
.credit a:hover { color: var(--text); border-color: var(--text); }

/* ───────── Controles ───────── */
.controls {
  position: fixed; z-index: 5;
  top: calc(16px + var(--safe-t)); right: calc(16px + var(--safe-r)); left: calc(16px + var(--safe-l));
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
  pointer-events: none; /* el contenedor no tapa el lienzo; solo los botones */
  opacity: 0; transform: translateY(-6px);
  transition: opacity .5s ease .2s, transform .5s ease .2s;
}
body.live .controls { opacity: 1; transform: none; }
body.live .controls .btn { pointer-events: auto; }

.rec .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--rec); box-shadow: 0 0 0 3px rgba(255, 59, 78, .22); }
.rec .label { font-variant-numeric: tabular-nums; }
.rec.arming .dot { background: #ffb020; box-shadow: 0 0 0 3px rgba(255, 176, 32, .25); }
.rec.recording { background: rgba(70, 8, 16, .66); border-color: rgba(255, 59, 78, .6); }
.rec.recording .dot { animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }

.snd-off { display: none; }
.btn.off .snd-on { display: none; }
.btn.off .snd-off { display: block; }
.btn.off { color: var(--muted); }

.rec-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 7;
  background: var(--rec); box-shadow: 0 0 12px rgba(255, 59, 78, .8);
  transform: scaleX(0); transform-origin: left center;
  opacity: 0; transition: opacity .3s;
  pointer-events: none;
}
.rec-bar.on { opacity: 1; }

.countdown {
  position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; pointer-events: none;
  font-size: min(34vw, 240px); font-weight: 200; color: rgba(255, 255, 255, .92);
  text-shadow: 0 0 40px rgba(255, 255, 255, .35);
  font-variant-numeric: tabular-nums;
}
.countdown:empty { display: none; }
.countdown span { animation: pop .95s ease-out both; }
@keyframes pop { from { transform: scale(1.35); opacity: 0; } 20% { opacity: 1; } to { transform: scale(.9); opacity: .15; } }

/* ───────── Ayuda ───────── */
.help {
  position: fixed; z-index: 5;
  left: calc(16px + var(--safe-l)); bottom: calc(16px + var(--safe-b));
  width: min(370px, calc(100vw - 32px));
  padding: 16px 18px 14px; border-radius: 18px;
  font-size: 13px; line-height: 1.5;
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity .35s ease, transform .35s ease;
}
.help.show { opacity: 1; transform: none; pointer-events: auto; }
.help h2 { margin: 0 0 10px; font-size: 11px; font-weight: 500; letter-spacing: .24em; text-transform: uppercase; color: var(--muted); }
.help ul { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 9px; }
.help li { display: grid; grid-template-columns: 40px 1fr; gap: 6px; align-items: start; }
.help .g { font-size: 16px; line-height: 1.3; }
.help b { font-weight: 600; }
.help .keys { margin: 0 0 10px; line-height: 2.1; color: var(--muted); }

/* ───────── Avisos ───────── */
.toast {
  position: fixed; z-index: 9; left: 50%; bottom: calc(20px + var(--safe-b));
  display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: calc(100vw - 32px); padding: 10px 12px 10px 16px; border-radius: 16px;
  font-size: 13px; line-height: 1.4;
  opacity: 0; transform: translate(-50%, 10px); pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.toast:empty { display: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-action {
  flex: none; padding: 5px 12px; border: 0; border-radius: 999px; cursor: pointer;
  background: #fff; color: #000; font-size: 12px; font-weight: 600;
}

/* ───────── Clip ───────── */
.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 20px;
  background: rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.modal-card {
  width: min(680px, 100%); max-height: calc(100dvh - 40px); overflow: auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px; border-radius: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0 0 0 4px; font-size: 17px; font-weight: 600; }
.modal video { width: 100%; max-height: 58dvh; border-radius: 14px; background: #000; }
.modal-note { margin: 0 4px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; padding: 24px; text-align: center; }

/* ───────── Pantallas chicas ───────── */
@media (max-width: 760px) {
  .controls { gap: 6px; left: calc(12px + var(--safe-l)); right: calc(12px + var(--safe-r)); }
  .controls .label { display: none; }
  .controls .btn { width: 40px; height: 40px; padding: 0; }
  .controls .btn.rec { width: auto; padding: 0 12px; }
  .controls .btn.rec .label { display: inline; }
  /* los avisos van arriba, debajo de los botones, para no tapar la ayuda ni las manos */
  .toast { top: calc(66px + var(--safe-t)); bottom: auto; transform: translate(-50%, -10px); }
  .toast.show { transform: translate(-50%, 0); }
  .card { padding: 28px 22px 20px; gap: 14px; }
}

/* En teléfonos angostos, "Grabar" es solo el punto rojo; al grabar muestra el tiempo y esconde la vista 3D */
@media (max-width: 420px) {
  .controls .btn.rec:not(.recording):not(.arming) { width: 40px; padding: 0; }
  .controls .btn.rec:not(.recording):not(.arming) .label { display: none; }
  .controls:has(.rec.recording) #viewBtn, .controls:has(.rec.arming) #viewBtn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
