:root {
  --qc-bg: #080a09;
  --qc-ink: #f1f2e8;
  --qc-muted: #b9c0b1;
  --qc-dim: rgba(241, 242, 232, 0.66);
  --qc-line: rgba(241, 242, 232, 0.18);
  --qc-cyan: #6de6dc;
  --qc-gold: #d8aa3f;
  --qc-rose: #e66c84;
  --qc-green: #9fcf92;
  --prob-a: 60%;
  --prob-b: 40%;
  --coherence: 47%;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--qc-bg);
  color: var(--qc-ink);
  font-family: var(--sans), "Source Sans 3", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

/* Nav según protocolo del Lab (réplica de /assets/minilab-nav.css para que
   el minilab también se vea correcto en desarrollo local; en producción
   ambas hojas coinciden). Valores canónicos de tokens.css con fallback. */
.quantum-nav {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 10000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans, "Source Sans 3"), Inter, system-ui, sans-serif;
  font-size: 13px;
  line-height: 1;
}

.quantum-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 8px 12px;
  border: 1px solid var(--green-edge, rgba(74, 103, 65, 0.26));
  border-radius: 999px;
  background: rgba(249, 251, 249, 0.92);
  color: var(--text, #101812);
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.quantum-nav a:hover {
  background: var(--border, #dde5dd);
  border-color: rgba(74, 103, 65, 0.42);
  color: var(--text, #101812);
}

.quantum-nav a:last-child {
  background: var(--gold, #8b6914);
  border-color: var(--gold, #8b6914);
  color: var(--bg, #f9fbf9);
}

.quantum-nav a:last-child:hover {
  background: #c9a44a;
  border-color: #c9a44a;
  color: var(--text, #101812);
}

.quantum-nav a:focus-visible {
  outline: 2px solid var(--qc-gold);
  outline-offset: 2px;
}

/* El escenario ocupa una pantalla; debajo, el footer estándar del Lab. */
.quantum-shell {
  position: relative;
  height: 100svh;
  isolation: isolate;
  overflow: hidden;
}

#quantum-field,
.fallback-field {
  position: absolute;
  inset: 0;
  z-index: -3;
  width: 100%;
  height: 100%;
  background: var(--qc-bg);
}

.fallback-field {
  display: none;
}

/* ── Acto 1: portada ──────────────────────────────────────────────────────── */

.hero-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  padding: 0 18px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.kicker {
  margin: 0 0 12px;
  color: var(--qc-gold);
  font-family: var(--mono), "Courier New", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1 {
  margin: 0 auto 16px;
  max-width: 14ch;
  font-family: var(--serif), "Playfair Display", Georgia, serif;
  font-size: clamp(2.4rem, 6.5vw, 5.4rem);
  line-height: 1.0;
  text-wrap: balance;
}

.subtitle {
  margin: 0 auto;
  max-width: 44ch;
  color: var(--qc-muted);
  font-size: clamp(1rem, 1.6vw, 1.18rem);
  line-height: 1.5;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
}

/* Tras el primer disparo, el título se recoge a una esquina discreta. */
body.started .hero-panel {
  inset: auto;
  top: 62px;
  left: 20px;
  display: block;
  text-align: left;
  animation: hero-in 0.5s ease;
}

body.started h1 {
  margin: 0;
  max-width: none;
  font-size: 1.12rem;
  line-height: 1.2;
}

body.started .kicker,
body.started .subtitle {
  display: none;
}

@keyframes hero-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ── Lecturas: una sola línea discreta ────────────────────────────────────── */

.readout-strip {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 10;
  display: flex;
  gap: 14px;
  padding: 8px 14px;
  border: 1px solid var(--qc-line);
  border-radius: 999px;
  background: rgba(8, 10, 9, 0.55);
  backdrop-filter: blur(16px);
  color: var(--qc-dim);
  font-family: var(--mono), "Courier New", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

body.started .readout-strip {
  opacity: 1;
}

.readout-strip strong {
  color: var(--qc-ink);
  font-weight: 600;
}

.readout-strip span:nth-child(1) strong {
  color: var(--qc-cyan);
}

.readout-strip span:nth-child(2) strong {
  color: var(--qc-gold);
}

.readout-strip span:nth-child(3) strong {
  color: var(--qc-green);
}

.readout-strip em {
  font-style: normal;
  color: var(--qc-dim);
}

/* ── Pie de escenario: narración, relatos, acciones ───────────────────────── */

.stage-foot {
  position: absolute;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(940px, calc(100vw - 24px));
}

.narration {
  min-height: 1.5em;
  margin: 0;
  text-align: center;
  color: var(--qc-ink);
  font-size: clamp(0.98rem, 1.5vw, 1.12rem);
  line-height: 1.4;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.85), 0 0 30px rgba(0, 0, 0, 0.6);
  text-wrap: balance;
}

.mode-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

body.has-measured .mode-row {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.mode-row label {
  position: relative;
  cursor: pointer;
}

.mode-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-row span {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid rgba(241, 242, 232, 0.18);
  border-radius: 999px;
  color: var(--qc-muted);
  background: rgba(8, 10, 9, 0.55);
  backdrop-filter: blur(12px);
  font-size: 0.88rem;
  transition: border-color 0.18s ease, color 0.18s ease, background-color 0.18s ease;
}

.mode-row input:checked + span {
  border-color: rgba(109, 230, 220, 0.70);
  color: var(--qc-ink);
  background: rgba(109, 230, 220, 0.14);
}

.mode-row input:focus-visible + span {
  outline: 2px solid var(--qc-gold);
  outline-offset: 2px;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.action-row button {
  min-height: 46px;
  padding: 10px 20px;
  border: 1px solid rgba(241, 242, 232, 0.20);
  border-radius: 8px;
  color: var(--qc-ink);
  background: rgba(8, 10, 9, 0.6);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.3s ease;
}

.action-row button:hover {
  transform: translateY(-1px);
  border-color: rgba(241, 242, 232, 0.38);
}

.action-row button:focus-visible {
  outline: 2px solid var(--qc-gold);
  outline-offset: 2px;
}

#fire-button {
  min-width: 190px;
  border-color: rgba(109, 230, 220, 0.62);
  background: rgba(109, 230, 220, 0.16);
  font-size: 1.04rem;
  font-weight: 600;
}

body.stage-intro #fire-button {
  animation: fire-pulse 2.6s ease-in-out infinite;
}

body.stage-intro #settings-button {
  display: none;
}

@keyframes fire-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(109, 230, 220, 0);
  }
  50% {
    box-shadow: 0 0 26px rgba(109, 230, 220, 0.38);
  }
}

/* ── Cajón de ajustes ─────────────────────────────────────────────────────── */

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(340px, 92vw);
  height: 100%;
  padding: 76px 22px 22px;
  overflow-y: auto;
  border-left: 1px solid var(--qc-line);
  background: rgba(8, 10, 9, 0.88);
  backdrop-filter: blur(22px);
  transform: translateX(105%);
  transition: transform 0.35s ease;
}

.settings-drawer.open {
  transform: translateX(0);
}

.settings-drawer h2 {
  margin: 0 0 10px;
  font-family: var(--serif), Georgia, serif;
  font-size: 1.3rem;
}

.drawer-note {
  margin: 0 0 18px;
  color: rgba(241, 242, 232, 0.55);
  font-size: 0.78rem;
  line-height: 1.45;
}

.range-control {
  display: block;
  margin-bottom: 18px;
}

.range-control > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: rgba(241, 242, 232, 0.72);
  font-size: 0.86rem;
}

.range-control output {
  color: var(--qc-ink);
  font-family: var(--mono), "Courier New", monospace;
  font-size: 0.78rem;
}

.range-control small {
  display: block;
  margin-top: 4px;
  color: rgba(241, 242, 232, 0.48);
  font-size: 0.74rem;
  line-height: 1.35;
}

.range-control input[type="range"] {
  width: 100%;
  min-height: 30px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  accent-color: var(--qc-cyan);
}

.range-control input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(241, 242, 232, 0.18);
}

.range-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border: 2px solid rgba(8, 10, 9, 0.95);
  border-radius: 999px;
  background: var(--qc-cyan);
}

.range-control input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(241, 242, 232, 0.18);
}

.range-control input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(8, 10, 9, 0.95);
  border-radius: 999px;
  background: var(--qc-cyan);
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: 4px 0 18px;
}

.toggle-row label {
  position: relative;
  cursor: pointer;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-row span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 12px;
  border: 1px solid rgba(241, 242, 232, 0.16);
  border-radius: 999px;
  color: var(--qc-muted);
  background: rgba(241, 242, 232, 0.045);
  font-size: 0.82rem;
}

.toggle-row input:checked + span {
  border-color: rgba(216, 170, 63, 0.62);
  color: var(--qc-ink);
  background: rgba(216, 170, 63, 0.12);
}

.toggle-row input:focus-visible + span {
  outline: 2px solid var(--qc-gold);
  outline-offset: 2px;
}

.rho-block {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 12px;
  border: 1px solid rgba(241, 242, 232, 0.12);
  border-radius: 8px;
}

.rho-grid {
  display: grid;
  flex-shrink: 0;
  grid-template-columns: repeat(2, 14px);
  gap: 4px;
}

.rho-grid i {
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--qc-green);
  opacity: 0.4;
  transition: opacity 0.2s linear;
}

.rho-grid i:nth-child(2),
.rho-grid i:nth-child(3) {
  background: var(--qc-cyan);
}

.rho-block small {
  color: rgba(241, 242, 232, 0.55);
  font-size: 0.74rem;
  line-height: 1.4;
}

#reset-button {
  min-height: 40px;
  padding: 8px 15px;
  border: 1px solid rgba(241, 242, 232, 0.18);
  border-radius: 6px;
  color: var(--qc-ink);
  background: rgba(241, 242, 232, 0.06);
  cursor: pointer;
}

#reset-button:hover {
  border-color: rgba(241, 242, 232, 0.34);
}

/* ── Modo director: durante el vuelo, todo se aparta del escenario ────────── */

.hero-panel,
.readout-strip,
.mode-row,
.settings-drawer {
  will-change: opacity;
}

body.is-running .hero-panel,
body.is-running .readout-strip {
  opacity: 0.15;
}

body.is-running.has-measured .mode-row {
  opacity: 0.25;
}

body.is-running .readout-strip:hover,
body.is-running.has-measured .mode-row:hover {
  opacity: 1;
}

/* Texto mínimo y discreto sobre lo que representa la animación. */
.stage-caption {
  position: absolute;
  left: 16px;
  bottom: 34px;
  z-index: 4;
  margin: 0;
  max-width: 280px;
  color: rgba(241, 242, 232, 0.50);
  font-size: 0.72rem;
  line-height: 1.45;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
  transition: opacity 0.35s ease;
}

body.is-running .stage-caption {
  opacity: 0.15;
}

.render-note {
  position: absolute;
  left: 16px;
  bottom: 14px;
  z-index: 4;
  margin: 0;
  color: rgba(241, 242, 232, 0.42);
  font-family: var(--mono), "Courier New", monospace;
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.no-webgl #quantum-field {
  display: none;
}

.no-webgl .fallback-field {
  display: block;
}

/* ── Móvil: misma escena, mismo flujo ─────────────────────────────────────── */

@media (max-width: 720px) {
  h1 {
    font-size: clamp(2rem, 10vw, 2.8rem);
  }

  .subtitle {
    max-width: 30ch;
    font-size: 0.95rem;
  }

  body.started .hero-panel {
    top: 58px;
    left: 14px;
  }

  /* En móvil el pie está ocupado: la explicación vive en el cajón de ajustes. */
  .stage-caption {
    display: none;
  }

  body.started h1 {
    font-size: 0.98rem;
  }

  .readout-strip {
    top: auto;
    right: 10px;
    left: 10px;
    bottom: calc(176px + env(safe-area-inset-bottom));
    justify-content: space-between;
    gap: 8px;
    padding: 7px 12px;
    font-size: 0.6rem;
  }

  .stage-foot {
    gap: 10px;
  }

  .mode-row {
    max-width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 3px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .mode-row::-webkit-scrollbar {
    display: none;
  }

  .mode-row label {
    flex: 0 0 auto;
  }

  .mode-row span {
    min-height: 44px;
    white-space: nowrap;
  }

  .action-row {
    width: 100%;
  }

  #fire-button {
    flex: 1;
    min-width: 0;
  }

  .settings-drawer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: auto;
    max-height: 72svh;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    border-left: 0;
    border-top: 1px solid var(--qc-line);
    border-radius: 14px 14px 0 0;
    transform: translateY(105%);
  }

  .settings-drawer.open {
    transform: translateY(0);
  }

  .range-control input[type="range"] {
    min-height: 44px;
  }

  .range-control input[type="range"]::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
    margin-top: -11px;
  }

  .range-control input[type="range"]::-moz-range-thumb {
    width: 28px;
    height: 28px;
  }
}

/* ── Footer estándar del Lab (réplica local de /assets/minilab-nav.css) ──── */

.nc-minilab-footer {
  width: 100%;
  box-sizing: border-box;
  padding: 56px 16px 48px;
  background: var(--footer-bg, #1a1a1a);
  color: var(--footer-text, #dde5dd);
  text-align: center;
  font-family: var(--sans, "Source Sans 3"), Inter, system-ui, sans-serif;
}

.nc-minilab-footer-inner {
  max-width: 1120px;
  margin: 0 auto;
}

.nc-minilab-footer-logo {
  display: inline-block;
  margin-bottom: 20px;
}

.nc-minilab-footer-logo img {
  display: block;
  height: 112px;
  width: auto;
  max-width: min(72vw, 160px);
  object-fit: contain;
  opacity: 0.96;
}

.nc-minilab-footer-links ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
}

.nc-minilab-footer-links li {
  display: inline;
  margin: 0;
}

.nc-minilab-footer-links li + li::before {
  content: " · ";
  margin: 0 8px;
  opacity: 0.55;
}

.nc-minilab-footer-links a {
  color: var(--footer-text, #dde5dd);
  text-decoration: none;
  transition: color 0.2s ease;
}

.nc-minilab-footer-links a:hover {
  color: var(--sage, #dde5dd);
}

.nc-minilab-copy {
  margin: 14px 0 0;
  color: var(--footer-text, #dde5dd);
  opacity: 0.55;
  font-size: 0.9rem;
}

.nc-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 600px) {
  .quantum-nav {
    top: 10px;
    left: 10px;
    right: 10px;
    font-size: 12px;
  }

  .quantum-nav a {
    min-height: 30px;
    padding: 7px 10px;
  }

  .nc-minilab-footer {
    padding: 44px 14px 38px;
  }

  .nc-minilab-footer-logo img {
    height: 96px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
