/* BuilderAR · visor público. Pantalla completa sobre la cámara; botones grandes para el pulgar. */
:root {
  --ink: #ffffff;
  --ink-suave: rgba(255, 255, 255, .78);
  --glass: rgba(17, 16, 24, .62);
  --accent: #7b66ff;
  --sun: #f2b84b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: #111018; color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; -webkit-tap-highlight-color: transparent;
}
/* La cámara de MindAR va con z-index negativo: el fondo oscuro va en html, no en body, para no taparla. */
html { background: #111018; }
body.viewer--ar { background: transparent; }

.ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.ui > * { pointer-events: auto; }
.ui > .hint, .ui > .status, .ui > .toast, .ui > .flash, .ui > .preview-badge { pointer-events: none; }

.preview-badge {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: var(--sun); color: #2b1d00; font-weight: 700; font-size: .8rem; padding: 4px 12px; border-radius: 999px;
}

/* Instrucción inicial con marco de enfoque */
.hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 24px;
}
.hint__frame {
  width: min(64vw, 300px); aspect-ratio: 3 / 4; border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, .85); box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .18);
  animation: pulse 1.8s ease-in-out infinite;
}
.hint p {
  margin: 0; background: var(--glass); padding: 10px 16px; border-radius: 12px; text-align: center; font-weight: 600;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); max-width: 320px;
}
@keyframes pulse { 50% { transform: scale(1.03); opacity: .75; } }

/* Página web pegada al marcador (br-webpage, viewer.js): panel DOM, no una textura 3D del marcador —
   un iframe de otro origen no se puede pintar sobre el lienzo. z-index 5: encima de la cámara (negativo),
   debajo de .ui (10), así los botones de sonido/captura siguen por encima del panel. Sin esquinas redondeadas
   ni sombra a propósito: por defecto debe llenar el rectángulo del marcador sin costura visible, como si la
   imagen impresa misma se animara (el "periódico de Harry Potter"), no una tarjeta flotando encima. */
.br-webpage-pin {
  position: fixed; left: 0; top: 0; z-index: 5; transform-origin: center center;
  overflow: hidden; opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.br-webpage-pin--on { opacity: 1; pointer-events: auto; }
.br-webpage-pin iframe { width: 100%; height: 100%; border: 0; display: block; }

/* Indicador de estado */
.status {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 14px;
  background: var(--glass); padding: 6px 12px 6px 26px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.status::before {
  content: ""; position: absolute; left: 11px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%;
  background: var(--sun);
}
.status--live::before { background: #46d68c; box-shadow: 0 0 0 4px rgba(70, 214, 140, .25); }

.toast {
  position: absolute; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--glass); padding: 8px 14px; border-radius: 10px; font-size: .9rem; white-space: nowrap;
}

/* Botones flotantes: sonido y captura */
.fabs {
  position: absolute; right: 16px; bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.fab {
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--glass); color: #fff; display: grid; place-items: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
}
.fab svg { width: 28px; height: 28px; fill: currentColor; }
.fab:active { transform: scale(.94); }
.fab--on { background: var(--accent); }
#br-sound .ico-on { display: none; }
#br-sound.fab--on .ico-on { display: inline; }
#br-sound.fab--on .ico-off { display: none; }

/* Flash de la captura */
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
.flash--go { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

/* Capas: iniciar, cargando, error */
.overlay {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
  background: radial-gradient(circle at 50% 30%, #2a2350 0%, #111018 70%);
}
.overlay__card { max-width: 380px; }
.overlay h1 { font-size: 1.45rem; margin: 0 0 8px; }
.overlay p { margin: 0 0 18px; color: var(--ink-suave); }
.overlay .small { font-size: .85rem; margin-top: 14px; }
.overlay__actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.cta {
  font: inherit; font-weight: 700; font-size: 1.05rem; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; padding: 14px 28px; border-radius: 999px; box-shadow: 0 6px 24px rgba(123, 102, 255, .45);
}
.cta:active { transform: scale(.97); }
.spinner {
  width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .2); border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Aviso sin AR (no disponible, sin licencia, sin preparar) */
.notice { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 30%, #3a1414 0%, #1A1A1A 70%); }
.notice__card { max-width: 400px; text-align: center; padding: 28px 24px; border-radius: 16px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); }
.notice__card img { border-radius: 12px; }
.notice__card h1 { font-size: 1.35rem; margin: 14px 0 8px; }
.notice__card p { color: var(--ink-suave); margin: 0; }

@media (prefers-reduced-motion: reduce) {
  .hint__frame, .spinner { animation: none; }
}

/* Etapa 2: marca en las pantallas propias, créditos, cara y vista previa 3D */
.brand { display: block; margin: 0 auto 10px; border-radius: 14px; }
.brand--pulse { animation: pulse 1.8s ease-in-out infinite; }
.brand-line { position: absolute; bottom: calc(18px + env(safe-area-inset-bottom)); left: 0; right: 0; margin: 0; font-size: .78rem; color: var(--ink-suave); }
.overlay p.brand-line { margin: 0; }

.credits-btn {
  position: absolute; left: 14px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 25;
  font: inherit; font-size: .8rem; font-weight: 600; color: #fff; border: 0; cursor: pointer;
  background: var(--glass); padding: 7px 12px; border-radius: 999px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.overlay--credits { z-index: 30; background: rgba(17, 16, 24, .92); }
.credits { list-style: none; margin: 0 0 18px; padding: 0; text-align: left; font-size: .9rem; color: var(--ink-suave); max-height: 55vh; overflow: auto; }
.credits li { padding: 8px 0; border-bottom: 1px solid rgba(255, 255, 255, .12); }
.credits strong { color: #fff; }
.credits a { color: #c9bfff; }

/* Cara: marco ovalado para la instrucción */
.hint--face .hint__frame { width: min(58vw, 250px); aspect-ratio: 3 / 4; border-radius: 50%; }

/* Vista previa 3D sin cámara (se ve dentro del panel) */
body.viewer--previa { background: #1b1830; }
body.viewer--previa .status { pointer-events: none; }

/* Espacio (sin marcador): three.js de fondo, barra de AR y mensajes. En WebXR, #br-ui es la capa DOM encima de la
   cámara: todo lo que no sea un botón debe quedar transparente (si no, tapa la cámara). */
.viewer--space .br-canvas { position: fixed; inset: 0; display: block; touch-action: none; }
.viewer--space .ui { z-index: 10; }
.en-ar, .en-ar body { background: transparent !important; }
#br-ui:xr-overlay, :xr-overlay { background: transparent !important; }
:xr-overlay::backdrop { background: transparent !important; }
.br-touch { position: absolute; inset: 0; pointer-events: auto; touch-action: none; }
.pill {
  position: absolute; left: 50%; top: calc(18px + env(safe-area-inset-top)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: var(--glass); padding: 9px 16px; border-radius: 999px; font-weight: 600;
  font-size: .92rem; text-align: center; pointer-events: none;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ar-bar {
  position: absolute; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 10px; z-index: 12;
}
.ar-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 68px; padding: 8px 12px;
  font: inherit; font-size: .75rem; font-weight: 600; color: #fff; border: 0; border-radius: 16px; cursor: pointer;
  background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ar-btn svg { width: 24px; height: 24px; fill: currentColor; }
.ar-btn--off { opacity: .55; }
/* Mira del centro mientras busca piso o pared, y el botón Reiniciar (visor de espacio) */
.aim { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; z-index: 11; pointer-events: none; }
.aim::before, .aim::after { content: ""; position: absolute; background: rgba(255, 255, 255, .9); border-radius: 2px; box-shadow: 0 0 6px rgba(0, 0, 0, .5); }
.aim::before { left: 50%; top: 4px; bottom: 4px; width: 2px; margin-left: -1px; }
.aim::after { top: 50%; left: 4px; right: 4px; height: 2px; margin-top: -1px; }
.aim span { position: absolute; inset: 10px; border: 2px solid rgba(255, 255, 255, .55); border-radius: 50%; animation: aim-pulse 1.4s ease-in-out infinite; }
.aim--found span { border-color: #7b66ff; }
@keyframes aim-pulse { 50% { transform: scale(1.25); opacity: .4; } }
.ar-reset { position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 14px; z-index: 12; display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border: 0; border-radius: 999px; color: #fff; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
  background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.ar-reset svg { width: 18px; height: 18px; fill: currentColor; }
.gal-nav {
  position: absolute; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; z-index: 12; max-width: calc(100% - 32px);
}
.viewer--previa .gal-nav, .gal-nav--3d { bottom: calc(22px + env(safe-area-inset-bottom)); }
.gal-nav__btn {
  display: grid; place-items: center; width: 48px; height: 48px; border: 0; border-radius: 50%; cursor: pointer; color: #fff;
  background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.gal-nav__btn svg { width: 28px; height: 28px; fill: currentColor; }
.gal-nav__label {
  padding: 8px 14px; border-radius: 999px; color: #fff; font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; background: var(--glass); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.cta--ghost { background: rgba(255, 255, 255, .12); box-shadow: none; }
.cta--float { position: absolute; right: 16px; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 12; padding: 12px 20px; font-size: .95rem; }
.br-mv { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.viewer--space .status { max-width: calc(100% - 28px); }

/* Panel de «más información» de las interacciones (br-capas.js) */
.br-info { position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; padding: 16px; background: rgba(8, 7, 14, .35); }
.br-info[hidden] { display: none; }
.br-info__card { position: relative; width: min(440px, 100%); max-height: 70vh; overflow: auto; background: rgba(24, 22, 36, .96); color: #fff;
  border-radius: 18px; padding: 20px 20px 18px; box-shadow: 0 18px 50px rgba(0, 0, 0, .45); animation: br-info-in .22s ease-out;
  margin-bottom: env(safe-area-inset-bottom); }
.br-info__card h2 { margin: 0 32px 8px 0; font-size: 1.15rem; }
.br-info__card p { margin: 0 0 14px; line-height: 1.45; white-space: pre-line; opacity: .9; }
.br-info__x { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .12); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }
.br-info__btn { display: inline-block; background: #7b66ff; color: #fff; text-decoration: none; font-weight: 700; padding: 10px 18px; border-radius: 999px; }
.br-info__btn[hidden] { display: none; }
@keyframes br-info-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
