:root {
  --primary: #0B4F8A;
  --secondary: #F2C230;
  --on-primary: #ffffff;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

/* Contenedor AR a pantalla completa (MindAR inserta aquí <video> y <canvas>) */
#ar {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

/* El video del holograma solo alimenta la textura WebGL; no debe verse ni ocupar espacio. */
#holo {
  position: fixed;
  width: 2px;
  height: 2px;
  left: 0;
  top: 0;
  opacity: 0;
  pointer-events: none;
}

/* Pantallas superpuestas */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,.16) 0%, transparent 70%),
    linear-gradient(180deg, var(--primary), #050a14);
  background-color: var(--primary);
  text-align: center;
}

.start-inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.logo { height: 48px; width: auto; color: #fff; }

h1, h2 { margin: 0; font-size: clamp(1.6rem, 6vw, 2.1rem); line-height: 1.15; letter-spacing: -0.01em; }
.lead { margin: 0; font-size: 1.125rem; line-height: 1.45; opacity: .92; }
.note { margin: 0; font-size: .875rem; line-height: 1.4; opacity: .75; max-width: 32ch; }

.howto svg { display: block; }
.howto-photo { fill: none; stroke: #fff; stroke-width: 2.5; }
.howto-phone { fill: rgba(255,255,255,.12); stroke: var(--secondary); stroke-width: 3; }
.howto-ray { stroke: var(--secondary); stroke-width: 2.5; stroke-dasharray: 4 4; fill: none; }

/* Botones */
.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  min-height: 56px;
  min-width: 240px;
  padding: 0 28px;
  font: 700 1.125rem/1 var(--font);
  color: #111;
  background: var(--secondary);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  transition: transform .12s ease, opacity .2s ease;
}
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.btn-small { min-width: 0; min-height: 44px; font-size: 1rem; padding: 0 18px; }

.progress { width: 240px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.2); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--secondary); transition: width .2s ease; }

/* HUD sobre la cámara */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud .btn { pointer-events: auto; }

.guide {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity .3s ease;
}
.guide-frame { position: relative; width: min(72vw, 360px); aspect-ratio: 4 / 3; }
.guide-frame span { position: absolute; width: 36px; height: 36px; border: 4px solid #fff; filter: drop-shadow(0 0 4px rgba(0,0,0,.6)); }
.guide-frame span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 12px; }
.guide-frame span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
.guide-frame span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 12px; }
.guide-frame span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 12px; }
@media (prefers-reduced-motion: no-preference) {
  .guide-frame { animation: breathe 2.2s ease-in-out infinite; }
}
@keyframes breathe { 50% { transform: scale(1.04); } }

.guide-text, .toast {
  margin: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0,0,0,.6);
  font-size: 1.05rem;
  font-weight: 600;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.toast { position: absolute; left: 50%; top: calc(20px + var(--safe-top)); transform: translateX(-50%); white-space: nowrap; }

.end {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(32px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}
.end .btn { pointer-events: auto; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn-secondary { background: rgba(0,0,0,.6); color: #fff; box-shadow: inset 0 0 0 2px #fff, 0 6px 20px rgba(0,0,0,.35); }

/* Subtítulos: texto nítido sobre la cámara, sin quemarlo en el video */
.captions {
  position: absolute;
  left: 50%;
  bottom: calc(40px + var(--safe-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(92vw, 560px);
  margin: 0;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: clamp(1rem, 4.4vw, 1.25rem);
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  white-space: pre-line;
  text-wrap: balance;
}
#btn-sound { position: absolute; right: 16px; top: calc(16px + var(--safe-top)); }

.start-group { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; }

/* Enlaces con aspecto de texto */
.link-btn {
  appearance: none; border: 0; background: none; color: #fff;
  font: 600 1rem var(--font); text-decoration: underline; text-underline-offset: 3px;
  padding: 10px 8px; min-height: 44px; cursor: pointer; opacity: .9;
}
.link-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; border-radius: 6px; }

/* Navegador interno */
.steps { margin: 0; padding-left: 1.4em; text-align: left; font-size: 1.05rem; line-height: 1.5; max-width: 34ch; }
.steps li { margin: 6px 0; }
.copy-row { display: flex; gap: 8px; width: 100%; max-width: 360px; }
.url-field {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.4); background: rgba(0,0,0,.25); color: #fff; font: 0.9rem var(--font);
}

/* Modo alternativo */
.fallback {
  position: fixed; inset: 0; z-index: 2;
  background:
    radial-gradient(90% 55% at 50% 100%, rgba(127,231,255,.22) 0%, transparent 70%),
    linear-gradient(180deg, #050a14, var(--primary));
  background-color: var(--primary);
}
.fallback-stage { position: absolute; inset: 0; }
.fallback-stage canvas { display: block; }
.fallback-2d { position: absolute; left: 50%; transform: translateX(-50%); transition: opacity .45s ease; }
.banner {
  position: absolute; z-index: 6; left: 12px; right: 12px; top: calc(12px + var(--safe-top));
  display: flex; gap: 8px; align-items: flex-start;
  padding: 12px 12px 12px 16px; border-radius: 14px;
  background: rgba(0,0,0,.72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: .95rem; line-height: 1.4;
}
.banner p { margin: 0; flex: 1; }
.banner-actions { display: flex; align-items: center; gap: 4px; }
.banner .link-btn { padding: 0 6px; font-size: .95rem; }
.banner-close {
  appearance: none; border: 0; background: rgba(255,255,255,.15); color: #fff;
  width: 36px; height: 36px; border-radius: 50%; font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.icon-btn {
  position: absolute; z-index: 6; right: 16px; bottom: calc(16px + var(--safe-bottom));
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; font-size: 1.1rem; cursor: pointer;
}
.icon-btn:focus-visible, .banner-close:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
body.mode-fallback .captions { bottom: calc(84px + var(--safe-bottom)); }
body.mode-fallback #btn-sound { top: auto; right: 80px; bottom: calc(20px + var(--safe-bottom)); }

/* Aviso de orientación: solo celulares en horizontal */
.rotate {
  display: none; position: fixed; inset: 0; z-index: 50;
  flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: var(--primary); color: #fff; font-size: 1.2rem; font-weight: 700; text-align: center; padding: 24px;
}
.rotate p { margin: 0; }
@media (orientation: landscape) and (max-height: 540px) {
  html.is-mobile .rotate { display: flex; }
}

/* Registro de diagnóstico (?debug=1) */
.diag {
  position: fixed; z-index: 60; left: 8px; right: 8px; top: calc(8px + var(--safe-top));
  max-height: 28vh; overflow: auto; margin: 0; padding: 8px 10px; border-radius: 8px;
  background: rgba(0,0,0,.7); color: #b8f5c8; font: 11px/1.35 ui-monospace, Menlo, monospace;
  white-space: pre-wrap; pointer-events: none;
}

/* Panel de depuración */
#debug {
  position: fixed;
  left: 8px; bottom: calc(8px + var(--safe-bottom));
  z-index: 20;
  width: min(320px, calc(100vw - 16px));
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,.75);
  font: 12px/1.4 ui-monospace, Menlo, monospace;
}
#debug label { display: grid; grid-template-columns: 82px 1fr 44px; align-items: center; gap: 6px; margin-top: 4px; }
#debug input[type=range], #debug select { width: 100%; }
#debug select { font: inherit; padding: 4px; border-radius: 6px; }
#debug button { margin-top: 6px; font: inherit; padding: 6px 10px; border-radius: 6px; border: 0; }
#debug pre { margin: 0; white-space: pre-wrap; }
