:root {
  --bg-primary: #0F1E36;
  --bg-surface: #162A4A;
  --bg-panel: #1D355C;
  --text-primary: #F4F7FB;
  --text-muted: #C5D3E8;
  --accent-primary: #F2B705;
  --accent-red: #D92B2B;
  --accent-green: #1E7E53;
  --steel-border: #385582;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: clip;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: clip;
  min-height: 100vh;
}

#factory-bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

h1, h2, h3, h4, .plant-title {
  font-family: 'Chakra Petch', 'Oswald', sans-serif;
  letter-spacing: 0.02em;
  margin-top: 0;
}

/* Cinta transportadora superior y guirnalda */
.conveyor-progress-shell {
  position: sticky;
  top: 0;
  z-index: 60;
  background: #0A1526;
  border-bottom: 2px solid var(--steel-border);
}

.conveyor-track {
  height: 9px;
  width: 100%;
  background: repeating-linear-gradient(
    90deg,
    #162A4A 0px,
    #162A4A 18px,
    #25416E 18px,
    #25416E 36px
  );
  overflow: hidden;
}

.conveyor-fill {
  height: 100%;
  width: 8%;
  background: repeating-linear-gradient(
    -45deg,
    var(--accent-primary),
    var(--accent-primary) 12px,
    var(--accent-red) 12px,
    var(--accent-red) 24px
  );
  transition: width 0.25s ease-out;
}

.garland-strip {
  display: flex;
  justify-content: space-around;
  padding: 3px 1rem 5px;
  background: rgba(15, 30, 54, 0.92);
}

.bulb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  animation: bulbBlink 1.8s infinite alternate;
}
.bulb.b-red { background: var(--accent-red); box-shadow: 0 0 8px var(--accent-red); animation-delay: 0s; }
.bulb.b-gold { background: var(--accent-primary); box-shadow: 0 0 8px var(--accent-primary); animation-delay: 0.5s; }
.bulb.b-green { background: #2ECC71; box-shadow: 0 0 8px var(--accent-green); animation-delay: 1s; }

@keyframes bulbBlink {
  0% { opacity: 0.45; transform: scale(0.88); }
  100% { opacity: 1; transform: scale(1.12); }
}

/* Header estilo consola de planta */
.plant-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 3vw, 2.5rem);
  background: color-mix(in srgb, var(--bg-surface) 92%, #000000);
  border-bottom: 3px solid var(--accent-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.plant-brand {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.plant-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-primary);
  letter-spacing: 0.1em;
}

.plant-title {
  font-size: clamp(1.1rem, 2vw, 1.45rem);
}

.plant-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.nav-switch {
  text-decoration: none;
  color: var(--text-primary);
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.55rem 0.85rem;
  border-radius: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--steel-border);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.2s;
}

.nav-switch:hover,
.nav-switch:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.mobile-only {
  display: none;
}

/* Botones tipo interruptor físico industrial */
.switch-btn {
  appearance: none;
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
  padding: 0.7rem 1.15rem;
  min-height: 46px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  color: var(--text-primary);
  background: var(--bg-panel);
  box-shadow: 0 4px 0 #091322, 0 6px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.16s;
}

.switch-btn:hover {
  transform: translateY(-2px);
}

.switch-btn:active {
  transform: translateY(2px);
}

.switch-btn:focus-visible {
  outline: 3px solid var(--accent-primary);
  outline-offset: 2px;
}

.switch-amber {
  background: var(--accent-primary);
  color: #0F1E36;
  border-color: #FFE07D;
}

.switch-red {
  background: var(--accent-red);
  color: #FFFFFF;
}

.switch-green {
  background: var(--accent-green);
  color: #FFFFFF;
}

.switch-compact {
  padding: 0.5rem 0.9rem;
  font-size: 0.88rem;
}

/* Contenedor principal y paneles metálicos con remaches */
.plant-main {
  max-width: 1260px;
  margin: 0 auto;
  padding: clamp(1.2rem, 3vw, 2.5rem) clamp(1rem, 2.5vw, 2rem) 4rem;
  display: flex;
  flex-direction: column;
  gap: 2.2rem;
}

.rivet-panel {
  position: relative;
  background: linear-gradient(160deg, rgba(22, 42, 74, 0.95), rgba(15, 30, 54, 0.96));
  border: 2px solid var(--steel-border);
  border-radius: 14px;
  padding: clamp(1.25rem, 3vw, 2.2rem);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.rivet {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #A7BBD9, #2E476E);
  border: 1px solid #091322;
}
.r-tl { top: 10px; left: 10px; }
.r-tr { top: 10px; right: 10px; }
.r-bl { bottom: 10px; left: 10px; }
.r-br { bottom: 10px; right: 10px; }

/* Animación de entrada y scroll reveal */
[data-reveal] {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 0.65s cubic-bezier(0.22, 1, 0.36, 1), transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0);
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.95fr;
  gap: 1.8rem;
  align-items: center;
}

.hazard-tag {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  background: rgba(242, 183, 5, 0.16);
  border-left: 4px solid var(--accent-primary);
  color: var(--accent-primary);
  font-family: 'Oswald', sans-serif;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

.hero-heading {
  font-size: clamp(1.85rem, 3.8vw, 2.9rem);
  line-height: 1.15;
  margin-bottom: 0.85rem;
}

.hero-lead {
  color: var(--text-muted);
  font-size: clamp(1rem, 1.4vw, 1.12rem);
  margin-bottom: 1.2rem;
}

.telemetry-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.35rem;
}

.telemetry-box {
  background: rgba(10, 21, 38, 0.82);
  border: 1px solid var(--steel-border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
}

.tel-label {
  display: block;
  font-size: 0.72rem;
  color: var(--accent-primary);
  letter-spacing: 0.08em;
}

.tel-val {
  font-family: 'Chakra Petch', sans-serif;
  font-size: 1.05rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.blueprint-frame {
  margin: 0;
  background: #0A1526;
  border: 2px solid var(--accent-primary);
  border-radius: 12px;
  overflow: hidden;
}

.blueprint-frame img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.blueprint-frame figcaption {
  padding: 0.65rem 0.9rem;
  font-size: 0.86rem;
  color: var(--text-muted);
}

/* Teoría exacta */
.section-header-bar {
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--steel-border);
  padding-bottom: 0.75rem;
}

.step-pill {
  display: inline-block;
  background: var(--accent-red);
  color: #FFFFFF;
  font-family: 'Oswald', sans-serif;
  font-size: 0.78rem;
  padding: 0.2rem 0.65rem;
  border-radius: 4px;
  letter-spacing: 0.07em;
  margin-bottom: 0.4rem;
}

.theory-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.4rem;
}

.exact-question {
  color: var(--accent-primary);
  font-size: clamp(1.25rem, 2.2vw, 1.6rem);
  margin-bottom: 0.6rem;
}

.exact-paragraph {
  background: rgba(10, 21, 38, 0.68);
  padding: 1rem 1.2rem;
  border-left: 4px solid var(--accent-primary);
  border-radius: 8px;
  margin-bottom: 1.1rem;
}

.theory-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 1.1rem;
}

.metal-subcard {
  background: rgba(10, 21, 38, 0.78);
  border: 1px solid var(--steel-border);
  border-radius: 10px;
  padding: 1.1rem;
}

.metal-subcard h4 {
  color: var(--accent-primary);
  margin-bottom: 0.65rem;
}

.exact-list,
.exact-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.exact-list li,
.exact-steps li {
  background: rgba(29, 53, 92, 0.45);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
}

.theory-diagram-box img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
  margin-bottom: 0.9rem;
}

.theory-confirm-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(30, 126, 83, 0.2);
  border: 1px solid var(--accent-green);
  padding: 0.85rem 1.1rem;
  border-radius: 10px;
}

/* Juegos */
.station-selector {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.3rem;
}

.station-tab.active {
  background: var(--accent-primary);
  color: #0F1E36;
  border-color: #FFFFFF;
}

.game-stage {
  background: rgba(10, 21, 38, 0.85);
  border: 1px solid var(--steel-border);
  border-radius: 12px;
  padding: clamp(1rem, 2.2vw, 1.5rem);
}

.game-top-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.game-controls-mini {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.hud-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.6rem;
  background: var(--bg-surface);
  border: 1px solid var(--steel-border);
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.94rem;
}

.hud-metrics strong {
  color: var(--accent-primary);
  font-family: 'Chakra Petch', sans-serif;
}

.sim-canvas {
  width: 100%;
  height: auto;
  background: #08111F;
  border: 2px solid var(--steel-border);
  border-radius: 10px;
  display: block;
  margin-bottom: 1rem;
}

.interactive-canvas {
  cursor: crosshair;
  touch-action: manipulation;
}

.physical-switches-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
}

/* Juego 3 Balanceo */
.balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.95rem;
}

.balance-card {
  background: var(--bg-surface);
  border: 2px solid var(--steel-border);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.balance-card.bottleneck {
  border-color: var(--accent-red);
}

.balance-card.balanced {
  border-color: #2ECC71;
}

.pile-bar-wrap {
  height: 12px;
  background: #091322;
  border-radius: 6px;
  overflow: hidden;
}

.pile-bar-fill {
  height: 100%;
  background: var(--accent-primary);
  transition: width 0.25s;
}

.balance-btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

/* Cámara en vivo adaptable PC horizontal / Móvil vertical sin deformación */
.camera-intro {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.camera-controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.camera-stage-wrap {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  background: #070F1C;
  border: 3px solid var(--accent-primary);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}

.camera-stage-wrap.is-portrait-mode {
  max-width: 430px;
  aspect-ratio: 3 / 4;
}

.camera-live-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Felicitación y resumen */
.congrats-panel {
  border-color: var(--accent-primary);
}

.congrats-badge {
  display: inline-block;
  background: rgba(242, 183, 5, 0.2);
  color: var(--accent-primary);
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  font-family: 'Chakra Petch', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}

.badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0 1.3rem;
}

.unit-badge {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: rgba(10, 21, 38, 0.85);
  border: 1px solid var(--steel-border);
  font-size: 0.86rem;
  font-family: 'Chakra Petch', sans-serif;
}

.unit-badge.done {
  background: var(--accent-green);
  border-color: #6CE5A6;
  color: #FFFFFF;
}

.learned-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.3rem;
}

.learned-item {
  background: rgba(10, 21, 38, 0.72);
  border: 1px solid var(--steel-border);
  border-radius: 10px;
  padding: 0.95rem;
}

.learned-item strong {
  color: var(--accent-primary);
  display: block;
  margin-bottom: 0.35rem;
}

.plant-footer {
  text-align: center;
  padding: 1.6rem 1rem 2.4rem;
  background: #08111F;
  border-top: 2px solid var(--steel-border);
  color: var(--text-muted);
  font-size: 0.92rem;
}

.industrial-dialog {
  max-width: 620px;
  width: calc(100% - 2rem);
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 2px solid var(--accent-primary);
  border-radius: 14px;
  padding: 1.5rem;
}

.industrial-dialog::backdrop {
  background: rgba(5, 10, 20, 0.78);
}

.dialog-list {
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.2rem;
}

/* Responsive Tablet y Celular */
@media (max-width: 920px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .mobile-only {
    display: inline-flex;
  }
  .plant-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .plant-nav.open {
    display: flex;
  }
  .camera-stage-wrap {
    max-width: 420px;
    aspect-ratio: 3 / 4;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
  }
}
