:root {
  --bg: #0d1a3a;
  --white: #ffffff;
  --dynamic: #bb81f9;
  --curious: #f48b32;
  --collaborative: #82c24a;
  --tenacious: #07baef;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #050b18;
  font-family: Inter, system-ui, sans-serif;
  font-weight: 700;
  color: var(--white);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.viewport {
  height: 100%;
  width: 100%;
  display: grid;
  place-items: center;
  background: #050b18;
}

/* Fixed 1920×1080 TV canvas, scaled to fit */
.stage {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg);
  container-type: inline-size;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  z-index: 0;
  opacity: 0.92;
}

/* ——— Glass pipes (connected segments, no overlap) ——— */

.pipes {
  /* Centers match traveler path: left 6.25%, top 8.75%, bottom 92.9%, outlet 91% */
  --rail-l: 3.9%;
  --rail-t: 4.45%;
  --rail-b: 88.6%;
  --th-h: 8.6%; /* horizontal tube thickness (% of stage height) */
  --th-w: 4.7%; /* vertical tube thickness (% of stage width) */
  --outlet-x: 88.65%;
  --right-end: 100%;
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.pipe {
  position: absolute;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  box-shadow:
    inset 1px 2px 16px 10px rgba(255, 255, 255, 0.25),
    0 8px 18px rgba(0, 0, 0, 0.25);
}

/* Shared metallic fills */
.pipe-run.pipe-top,
.pipe-run.pipe-bottom,
.pipe-elbow-tl,
.pipe-elbow-bl,
.pipe-elbow-br {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.34) 0%,
    rgba(109, 109, 109, 0.92) 42%,
    rgba(90, 90, 90, 0.95) 100%
  );
}

.pipe-run.pipe-left,
.pipe-run.pipe-outlet,
.spout {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.34) 0%,
    rgba(109, 109, 109, 0.92) 42%,
    rgba(90, 90, 90, 0.95) 100%
  );
}

/* Top-left elbow */
.pipe-elbow-tl {
  left: var(--rail-l);
  top: var(--rail-t);
  width: var(--th-w);
  height: var(--th-h);
  border-radius: 20px 0 0 0;
  border-right: 0;
  border-bottom: 0;
  box-shadow: inset 2px 2px 14px 8px rgba(255, 255, 255, 0.28);
}

/* Top rail — butts against TL elbow, open left */
.pipe-top {
  left: calc(var(--rail-l) + var(--th-w));
  top: var(--rail-t);
  width: calc(var(--right-end) - var(--rail-l) - var(--th-w));
  height: var(--th-h);
  border-radius: 0 20px 20px 0;
  border-left: 0;
}

/* Left riser — between TL and BL elbows */
.pipe-left {
  left: var(--rail-l);
  top: calc(var(--rail-t) + var(--th-h));
  width: var(--th-w);
  height: calc(var(--rail-b) - var(--rail-t) - var(--th-h));
  border-radius: 0;
  border-top: 0;
  border-bottom: 0;
}

/* Bottom-left elbow */
.pipe-elbow-bl {
  left: var(--rail-l);
  top: var(--rail-b);
  width: var(--th-w);
  height: var(--th-h);
  border-radius: 0 0 0 20px;
  border-right: 0;
  border-top: 0;
  box-shadow: inset 2px -2px 14px 8px rgba(255, 255, 255, 0.22);
}

/* Bottom rail — between BL elbow and BR elbow */
.pipe-bottom {
  left: calc(var(--rail-l) + var(--th-w));
  top: var(--rail-b);
  width: calc(var(--outlet-x) - var(--rail-l) - var(--th-w));
  height: var(--th-h);
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}

/* Bottom-right elbow (turns down into outlet) */
.pipe-elbow-br {
  left: var(--outlet-x);
  top: var(--rail-b);
  width: var(--th-w);
  height: var(--th-h);
  border-radius: 0;
  border-left: 0;
  border-bottom: 0;
  /* Match horizontal fill on the elbow body */
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.34) 0%,
    rgba(109, 109, 109, 0.92) 42%,
    rgba(90, 90, 90, 0.95) 100%
  );
}

/* Outlet drops from BR elbow to bottom edge */
.pipe-outlet {
  left: var(--outlet-x);
  top: calc(var(--rail-b) + var(--th-h));
  width: var(--th-w);
  height: calc(100% - var(--rail-b) - var(--th-h));
  border-radius: 0 0 20px 20px;
  border-top: 0;
}

/* Spouts hang flush from underside of top rail */
.spout {
  position: absolute;
  top: calc(var(--rail-t) + var(--th-h));
  width: var(--th-w);
  height: 8.2%;
  border-radius: 0 0 20px 20px;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  border-top: 0;
  box-shadow: inset 1px 2px 14px 8px rgba(255, 255, 255, 0.22);
  z-index: 4;
}

/* Centers align with traveler spout x: 19.92 / 40.05 / 60.13 / 80.29 */
.spout-0 {
  left: calc(19.92% - var(--th-w) / 2);
}
.spout-1 {
  left: calc(40.05% - var(--th-w) / 2);
}
.spout-2 {
  left: calc(60.13% - var(--th-w) / 2);
}
.spout-3 {
  left: calc(80.29% - var(--th-w) / 2);
}

/* ——— Glass vats ——— */

.vats {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.vat {
  position: absolute;
  width: 13.91%;
  display: flex;
  flex-direction: column;
}

.vat[data-index="0"] {
  left: 12.97%;
  top: 16.39%;
  height: 72%;
}
.vat[data-index="1"] {
  left: 33.07%;
  top: 15.83%;
  height: 72.5%;
}
.vat[data-index="2"] {
  left: 53.18%;
  top: 15.28%;
  height: 73%;
}
.vat[data-index="3"] {
  left: 73.28%;
  top: 14.72%;
  height: 73.5%;
}

.vat-tank {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-radius: 10px;
  background:
    linear-gradient(
      160deg,
      rgba(255, 255, 255, 0.22) 0%,
      rgba(210, 225, 245, 0.06) 40%,
      rgba(160, 185, 220, 0.1) 100%
    );
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    inset 0 -30px 50px rgba(15, 30, 60, 0.08),
    inset 18px 0 36px rgba(255, 255, 255, 0.12),
    0 18px 44px rgba(0, 0, 0, 0.32),
    0 0 0 1px rgba(120, 150, 190, 0.2);
  backdrop-filter: blur(12px) saturate(1.25);
  -webkit-backdrop-filter: blur(12px) saturate(1.25);
}

.vat-glass {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(
      100deg,
      rgba(255, 255, 255, 0.55) 0%,
      rgba(255, 255, 255, 0.18) 12%,
      rgba(255, 255, 255, 0.04) 28%,
      transparent 48%
    ),
    linear-gradient(
      255deg,
      transparent 60%,
      rgba(255, 255, 255, 0.08) 82%,
      rgba(255, 255, 255, 0.2) 100%
    );
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.vat-rim {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 4%;
  height: 14%;
  z-index: 4;
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.7) 0%,
    rgba(255, 255, 255, 0.15) 55%,
    rgba(255, 255, 255, 0) 100%
  );
  pointer-events: none;
  opacity: 0.9;
}

.vat-liquid {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  z-index: 1;
  transition: height 0.85s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow:
    inset 0 12px 28px rgba(255, 255, 255, 0.4),
    0 -6px 20px rgba(0, 0, 0, 0.1);
  opacity: 0.82;
  mix-blend-mode: normal;
}

.vat[data-type="dynamic"] .vat-liquid {
  background: linear-gradient(
    180deg,
    rgba(210, 168, 255, 0.95) 0%,
    rgba(187, 129, 249, 0.9) 55%,
    rgba(151, 71, 255, 0.92) 100%
  );
}
.vat[data-type="curious"] .vat-liquid {
  background: linear-gradient(
    180deg,
    rgba(255, 179, 109, 0.95) 0%,
    rgba(244, 139, 50, 0.9) 55%,
    rgba(214, 111, 26, 0.92) 100%
  );
}
.vat[data-type="collaborative"] .vat-liquid {
  background: linear-gradient(
    180deg,
    rgba(106, 223, 255, 0.95) 0%,
    rgba(7, 186, 239, 0.9) 55%,
    rgba(0, 138, 179, 0.92) 100%
  );
}
.vat[data-type="tenacious"] .vat-liquid {
  background: linear-gradient(
    180deg,
    rgba(180, 232, 125, 0.95) 0%,
    rgba(130, 194, 74, 0.9) 55%,
    rgba(95, 160, 46, 0.92) 100%
  );
}

.vat-wave {
  position: absolute;
  left: -10%;
  right: -10%;
  height: 22px;
  z-index: 2;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: top 0.85s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.vat.is-filling .vat-wave {
  opacity: 1;
  animation: wave-bob 1.1s ease-in-out infinite;
}

@keyframes wave-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(4px);
  }
}

.vat-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.65rem 0.25rem 0;
  text-align: center;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
}

.vat-label img {
  width: clamp(28px, 3.2cqi, 52px);
  height: clamp(28px, 3.2cqi, 52px);
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

.vat[data-type="dynamic"] .vat-label img {
  width: clamp(22px, 2.6cqi, 42px);
  height: clamp(30px, 3.6cqi, 56px);
}

.vat-label span {
  font-size: clamp(0.95rem, 1.7cqi, 1.55rem);
  line-height: 1.1;
}

.travelers {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.traveler {
  position: absolute;
  width: clamp(42px, 3.6cqi, 72px);
  height: clamp(42px, 3.6cqi, 72px);
  transform: translate(-50%, -50%);
  transition: none;
  will-change: left, top, transform;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.4));
}

.traveler .swirl-point {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: spin 1.2s linear infinite;
}

.traveler.is-dropping {
  transition:
    top 0.55s cubic-bezier(0.4, 0, 1, 1),
    transform 0.55s ease,
    opacity 0.55s ease;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .traveler .swirl-point,
  .vat.is-filling .vat-wave {
    animation: none;
  }

  .vat-liquid,
  .vat-wave {
    transition: none;
  }
}
