/* Element Tycoon: the interactive lab table (js/lab.js). See DESIGN.md sections 2a, 5 and 10. */

.lab-root {
  --lab-ink: #3a4a66;
  --lab-boost: 1;
  --lab-mix-ms: 1500ms;
  --lab-tube-color: #bdd5ff;
  --lab-medium-color: #ff9cc4;
  --lab-font-head: "Fredoka", "Baloo 2", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --lab-font-body: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  position: relative;
  width: 100%;
  height: 360px;
  overflow: hidden;
  border-radius: 16px;
  /* Matches the drawn wall and table. The stage keeps its aspect ratio; wide containers show these bands at the sides. */
  background: linear-gradient(180deg, #f6f9ff 0%, #e4eefc 82.7%, #fbe6cb 82.8%, #f2d2ab 87.4%, #ecc59a 87.5%, #ddb083 100%);
  box-shadow: inset 0 0 0 1px rgba(58, 74, 102, 0.08);
  font-family: var(--lab-font-body);
  color: var(--lab-ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.lab-stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 640px;
  height: 360px;
  transform-origin: 0 0;
}

.lab-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 640px;
  height: 360px;
  overflow: visible;
  pointer-events: none;
}

.lab-svg text { font-family: var(--lab-font-head); }

.lab-caption {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  fill: #a8784c;
  opacity: 0.75;
}

.lab-flaskwrap {
  position: absolute;
  inset: 0;
  transform-origin: 320px 246px;
}

.lab-balls {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.lab-fx,
.lab-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------ balls */

.lab-ball {
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 32px;
  pointer-events: auto;
  cursor: pointer;
  will-change: transform;
  transition: width 0.25s ease, height 0.25s ease;
}

.lab-ball-face,
.lab-flyer .lab-ball-face,
.lab-fxball .lab-ball-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.95) 0 9%, var(--c, #cfe8ff) 40%, var(--c2, #9fb8d8) 100%);
  border: 1.5px solid rgba(58, 74, 102, 0.6);
  box-shadow: inset 0 -2px 3px rgba(38, 50, 74, 0.12), 0 1px 2px rgba(38, 50, 74, 0.25);
  color: var(--ink, #26324a);
  box-sizing: border-box;
}

.lab-ball .lab-ball-face {
  animation: lab-bob 2.4s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}

.lab-on-heat .lab-ball .lab-ball-face { animation-duration: 0.9s; }

.lab-ball-label {
  font-family: var(--lab-font-head);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: -0.02em;
  pointer-events: none;
}

.lab-ball:hover .lab-ball-face { filter: brightness(1.06); border-color: var(--lab-ink); }

/* A label too long for its ball shows the item's picture on a pale disc in the item colour (DESIGN.md 11.16).
   The ring keeps the item colour. The face clips the picture to a circle. */
.lab-ball-face.is-art {
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, #fff 0 30%, var(--cp, #f1f5fb) 80%);
  border: 1.5px solid rgba(58, 74, 102, 0.6);
  box-shadow: inset 0 0 0 2.5px var(--c, #cfe8ff), 0 1px 2px rgba(38, 50, 74, 0.25);
}
.lab-ball-face.is-art .lab-ball-label { display: none; }
.lab-ball-art {
  position: absolute;
  left: -9%;
  top: -11%;
  width: 118%;
  height: 118%;
  pointer-events: none;
  -webkit-user-drag: none;
}
/* Gloss on top of the picture, so the disc still reads as a ball. */
.lab-ball-face.is-art::after {
  content: "";
  position: absolute;
  left: 18%;
  top: 12%;
  width: 26%;
  height: 18%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  transform: rotate(-30deg);
  pointer-events: none;
}
.lab-ball-face.is-short .lab-ball-label { letter-spacing: -0.04em; }

.lab-ball-badge {
  position: absolute;
  right: -9px;
  top: -9px;
  display: none;
  padding: 1px 5px;
  border-radius: 9px;
  background: var(--lab-ink, #3a4a66);
  color: #fff;
  font: 600 10px/1.3 var(--lab-font-head, "Fredoka", system-ui, sans-serif);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(38, 50, 74, 0.3);
}

.lab-ball.has-badge { z-index: 2; }
.lab-ball.has-badge .lab-ball-badge,
.lab-flyer .lab-ball-badge,
.lab-fxball .lab-ball-badge { display: block; }

.lab-ball-out {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.lab-ball-merge {
  pointer-events: none;
  opacity: 0;
  transition: transform 0.24s ease-in, opacity 0.24s ease-in;
}

@keyframes lab-bob {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  30% { transform: translate(0.6px, -1.4px) rotate(-3deg); }
  65% { transform: translate(-0.6px, 0.8px) rotate(2deg); }
}

/* Flying balls live on document.body, outside .lab-root. */
.lab-flyer {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9000;
  pointer-events: none;
  font-family: "Fredoka", "Baloo 2", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  will-change: transform;
  filter: drop-shadow(0 4px 6px rgba(38, 50, 74, 0.22));
}

.lab-flyer .lab-ball-label,
.lab-fxball .lab-ball-label {
  font-family: "Fredoka", "Baloo 2", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

/* "+N" after a tap adds to the flask (DESIGN.md 11.17). Lives on document.body like the flyers. */
.lab-plus {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9002;
  pointer-events: none;
  margin: -14px 0 0 -6px;
  padding: 1px 8px 2px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(38, 50, 74, 0.22), inset 0 0 0 2px #7fd6a6;
  color: #23865a;
  font: 700 16px/1.3 "Fredoka", "Baloo 2", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
  will-change: transform, opacity;
}

.lab-ghost {
  z-index: 9001;
  filter: drop-shadow(0 8px 10px rgba(38, 50, 74, 0.28));
}

.lab-ghost .lab-ball-face { border-width: 2px; border-color: #3a4a66; }

body.lab-dragging,
body.lab-dragging * { cursor: grabbing !important; }

.lab-draggable {
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.lab-fxball {
  position: absolute;
  z-index: 3;
}

/* ------------------------------------------------------------ hit areas and focus */

.lab-hit,
.lab-mascot,
.lab-lock,
.lab-chip {
  pointer-events: auto;
  font: inherit;
  color: inherit;
}

.lab-hit {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.lab-hit:focus { outline: none; }

.lab-hover-heat .lab-eq-heat,
.lab-hover-electricity .lab-eq-electricity,
.lab-hover-light .lab-eq-light,
.lab-hover-pressure .lab-eq-pressure,
.lab-hover-tube .lab-rack,
.lab-hover-beaker .lab-beaker,
.lab-root:not(.lab-mixing).lab-hover-mix .lab-mix {
  filter: drop-shadow(0 0 3px #ffffff) drop-shadow(0 0 7px rgba(91, 157, 255, 0.5));
}

.lab-lock-heat.lab-hover-heat .lab-eq-heat,
.lab-lock-electricity.lab-hover-electricity .lab-eq-electricity,
.lab-lock-light.lab-hover-light .lab-eq-light,
.lab-lock-pressure.lab-hover-pressure .lab-eq-pressure {
  filter: grayscale(1) drop-shadow(0 0 6px rgba(91, 157, 255, 0.6));
  opacity: 0.4;
}

.lab-hit:focus-visible,
.lab-mascot:focus-visible,
.lab-chip:focus-visible {
  outline: 3px solid #3d7cf0;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.85);
}

.lab-hit-mix { touch-action: none; }

/* ------------------------------------------------------------ locked equipment */

.lab-eq { transition: opacity 0.35s ease, filter 0.35s ease; }

.lab-lock-heat .lab-eq-heat,
.lab-lock-electricity .lab-eq-electricity,
.lab-lock-light .lab-eq-light,
.lab-lock-pressure .lab-eq-pressure {
  filter: grayscale(1);
  opacity: 0.28;
}

.lab-lock {
  position: absolute;
  display: none;
  align-items: center;
  gap: 3px;
  margin: 0;
  padding: 2px 7px 2px 5px;
  border: 2px solid var(--lab-ink);
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(38, 50, 74, 0.18);
  font: 600 12px/1.2 var(--lab-font-head);
  white-space: nowrap;
  cursor: pointer;
  /* Price tags grow less than other labels on small scenes. They must stay clear of the apparatus. */
  --lab-tag-boost: min(var(--lab-boost), 1.25);
  transform: translate(-50%, -50%) scale(var(--lab-tag-boost));
  transition: transform 0.15s ease;
}

.lab-lock:hover { transform: translate(-50%, -50%) scale(calc(var(--lab-tag-boost) * 1.08)); }
.lab-lock-icon { font-size: 11px; }

.lab-lock-heat .lab-lock[data-cond="heat"],
.lab-lock-electricity .lab-lock[data-cond="electricity"],
.lab-lock-light .lab-lock[data-cond="light"],
.lab-lock-pressure .lab-lock[data-cond="pressure"] { display: inline-flex; }

/* The battery's clip leads only show once the kit is owned (DESIGN.md 11.6). */
.lab-lock-electricity .lab-leads { display: none; }

/* ------------------------------------------------------------ Bunsen burner */

.lab-knob {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);
}

.lab-on-heat .lab-knob { transform: rotate(90deg); }

.lab-flame-wrap {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scale(0.1, 0);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1), opacity 0.2s ease;
}

.lab-on-heat .lab-flame-wrap { transform: scale(1); opacity: 1; }
.lab-mixing.lab-on-heat .lab-flame-wrap { transform: scale(1.3, 1.45); }

.lab-flame {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.lab-on-heat .lab-flame { animation: lab-flicker 0.32s ease-in-out infinite alternate; }
.lab-mixing.lab-on-heat .lab-flame { animation-duration: 0.12s; }

.lab-flame-b {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.lab-on-heat .lab-flame-b { animation: lab-flicker-b 0.45s ease-in-out infinite alternate; }

@keyframes lab-flicker {
  0% { transform: scale(1, 1) skewX(0deg); }
  35% { transform: scale(0.94, 1.08) skewX(-3deg); }
  70% { transform: scale(1.05, 0.95) skewX(2deg); }
  100% { transform: scale(0.97, 1.05) skewX(-1deg); }
}

@keyframes lab-flicker-b {
  0% { transform: scale(1, 1); }
  50% { transform: scale(0.9, 1.12); }
  100% { transform: scale(1.06, 0.92); }
}

.lab-heat-glow { opacity: 0; transition: opacity 0.5s ease; }
.lab-on-heat .lab-heat-glow { opacity: 1; }

/* ------------------------------------------------------------ electrolysis kit */

.lab-switch-nub {
  fill: #9aa3b4;
  transition: transform 0.22s cubic-bezier(0.3, 1.5, 0.5, 1), fill 0.2s ease;
}

.lab-on-electricity .lab-switch-nub { transform: translateX(16px); fill: #4cd08a; }

.lab-led { fill: #d5dbe6; transition: fill 0.2s ease; }
.lab-on-electricity .lab-led { fill: #5cff9d; filter: drop-shadow(0 0 3px #5cff9d); }

.lab-sparks { opacity: 0; transition: opacity 0.2s ease; }
.lab-on-electricity .lab-sparks { opacity: 1; }

.lab-spark {
  stroke: #fff36b;
  stroke-width: 2.6;
  opacity: 0;
  filter: drop-shadow(0 0 3px #ffe14d);
}

.lab-spark-dot { fill: #fff8b0; opacity: 0; filter: drop-shadow(0 0 4px #ffe14d); }

.lab-on-electricity .lab-spark { animation: lab-crackle 0.7s steps(1, end) infinite; }
.lab-on-electricity .lab-spark.s2 { animation-delay: -0.23s; }
.lab-on-electricity .lab-spark.s3 { animation-delay: -0.47s; }
.lab-on-electricity .lab-spark-dot { animation: lab-crackle 0.5s steps(1, end) infinite; }
.lab-on-electricity .lab-spark-dot.d2 { animation-delay: -0.25s; }
.lab-mixing.lab-on-electricity .lab-spark,
.lab-mixing.lab-on-electricity .lab-spark-dot { animation-duration: 0.28s; stroke-width: 3.4; }

@keyframes lab-crackle {
  0% { opacity: 1; }
  12% { opacity: 0; }
  40% { opacity: 0.85; }
  48% { opacity: 0; }
  100% { opacity: 0; }
}

/* ------------------------------------------------------------ UV lamp */

.lab-bulb { fill: #f3eeff; transition: fill 0.25s ease; }
.lab-on-light .lab-bulb { fill: #d6b4ff; filter: drop-shadow(0 0 6px #b98cff); }

.lab-cone { opacity: 0; transition: opacity 0.35s ease; }
.lab-on-light .lab-cone { opacity: 1; animation: lab-cone-pulse 2.6s ease-in-out infinite; }
.lab-mixing.lab-on-light .lab-cone { animation-duration: 0.5s; }

@keyframes lab-cone-pulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

.lab-cord { transition: transform 0.2s ease; }
.lab-cord-pull .lab-cord { animation: lab-cord 0.4s ease; }

@keyframes lab-cord {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(9px); }
}

/* ------------------------------------------------------------ pressure clamp */

.lab-clamp { transition: transform 0.4s cubic-bezier(0.3, 1.6, 0.5, 1); }
.lab-on-pressure .lab-clamp { transform: translateY(20px); }

.lab-needle {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: rotate(-70deg);
  transition: transform 0.6s cubic-bezier(0.3, 1.4, 0.5, 1) 0.15s;
}

.lab-on-pressure .lab-needle { transform: rotate(58deg); }

.lab-needle-wrap {
  transform-box: view-box;
  transform-origin: 384px 13px;
}

.lab-on-pressure .lab-needle-wrap { animation: lab-needle 0.9s ease-in-out infinite; }
.lab-mixing.lab-on-pressure .lab-needle-wrap { animation-duration: 0.18s; }

@keyframes lab-needle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(4deg); }
}

.lab-press-lever {
  transform-box: view-box;
  transform-origin: 436px 206px;
  transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);
}

.lab-on-pressure .lab-press-lever { transform: rotate(42deg); }

/* ------------------------------------------------------------ catalyst tube */

.lab-tube-glass { fill: #eef6ff; fill-opacity: 0.8; }

.lab-tube-fill { opacity: 0; transition: opacity 0.3s ease; }
.lab-tube-stuff { fill: var(--lab-tube-color); }
.lab-tube.is-filled .lab-tube-fill { opacity: 1; }

.lab-tube-label {
  font-weight: 600;
  fill: var(--lab-ink);
  stroke: #ffffff;
  stroke-width: 3px;
  paint-order: stroke;
}

.lab-tube-empty {
  font-size: 18px;
  font-weight: 600;
  fill: #b7c3d8;
}

.lab-tube.is-filled .lab-tube-empty { display: none; }

.lab-tube.is-filled {
  filter: drop-shadow(0 0 5px var(--lab-tube-color));
  animation: lab-glow 2.4s ease-in-out infinite;
}

.lab-mixing .lab-tube.is-filled { animation-duration: 0.45s; }

@keyframes lab-glow {
  0%, 100% { filter: drop-shadow(0 0 3px var(--lab-tube-color)); }
  50% { filter: drop-shadow(0 0 9px var(--lab-tube-color)); }
}

.lab-tube-in .lab-tube {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: lab-squash 0.45s ease;
}

@keyframes lab-squash {
  0%, 100% { transform: scale(1, 1); }
  30% { transform: scale(1.1, 0.92); }
  60% { transform: scale(0.96, 1.05); }
}

/* ------------------------------------------------------------ medium beaker */

.lab-beaker {
  transform-box: view-box;
  transform-origin: 460px 222px;
}

.lab-beaker-liquid {
  fill: var(--lab-medium-color);
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.3, 1.4, 0.5, 1), fill 0.3s ease;
}

.lab-beaker.is-filled .lab-beaker-liquid { opacity: 0.85; transform: translateY(0); }

.lab-beaker-label {
  font-weight: 600;
  fill: var(--lab-ink);
  stroke: #ffffff;
  stroke-width: 3px;
  paint-order: stroke;
}

.lab-beaker-empty {
  font-size: 10px;
  font-weight: 500;
  fill: #a9b6cc;
}

.lab-beaker.is-filled .lab-beaker-empty { display: none; }

.lab-beaker-in .lab-beaker { animation: lab-beaker-wiggle 0.5s ease; }

@keyframes lab-beaker-wiggle {
  0%, 100% { transform: rotate(0deg); }
  30% { transform: rotate(-4deg); }
  65% { transform: rotate(2deg); }
}

.lab-pour .lab-beaker { animation: lab-pour var(--lab-mix-ms) ease-in-out both; }
.lab-pour-reduced .lab-beaker { animation: lab-pour-small var(--lab-mix-ms) ease-in-out both; }

@keyframes lab-pour {
  0% { transform: translate(0, 0) rotate(0deg); }
  22% { transform: translate(-106px, -184px) rotate(-10deg); }
  34% { transform: translate(-106px, -184px) rotate(-55deg); }
  66% { transform: translate(-106px, -184px) rotate(-58deg); }
  80% { transform: translate(-106px, -184px) rotate(-5deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes lab-pour-small {
  0%, 100% { transform: rotate(0deg); }
  40%, 60% { transform: rotate(-12deg); }
}

.lab-stream {
  stroke: var(--lab-medium-color);
  opacity: 0;
  stroke-dasharray: 6 5;
}

.lab-pour .lab-stream { animation: lab-stream var(--lab-mix-ms) linear both; }

@keyframes lab-stream {
  0%, 33% { opacity: 0; stroke-dashoffset: 0; }
  38% { opacity: 0.95; }
  64% { opacity: 0.95; }
  68%, 100% { opacity: 0; stroke-dashoffset: -60; }
}

.lab-flask-liquid {
  fill: var(--lab-medium-color);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.5s ease;
}

.lab-liquid-on .lab-flask-liquid { opacity: 0.5; transform: translateY(0); }

/* ------------------------------------------------------------ MIX lever */

.lab-mix-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  fill: #ff5f86;
}

/* ------------------------------------------------------------ drop target halos */

.lab-halo {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.lab-halo-flask { left: 224px; top: 76px; width: 192px; height: 192px; border-radius: 50%; }
.lab-halo-tube { left: 42px; top: 120px; width: 60px; height: 178px; border-radius: 30px; }
.lab-halo-beaker { left: 446px; top: 206px; width: 92px; height: 104px; border-radius: 18px; }

.lab-halo.is-valid {
  opacity: 1;
  background: radial-gradient(closest-side, rgba(120, 220, 170, 0.22), rgba(120, 220, 170, 0));
  box-shadow: 0 0 0 3px rgba(76, 200, 140, 0.55), 0 0 22px 6px rgba(76, 200, 140, 0.3);
  animation: lab-halo 1.1s ease-in-out infinite;
}

.lab-halo.is-valid.is-hover {
  background: radial-gradient(closest-side, rgba(120, 220, 170, 0.38), rgba(120, 220, 170, 0));
  box-shadow: 0 0 0 4px rgba(76, 200, 140, 0.85), 0 0 30px 10px rgba(76, 200, 140, 0.45);
  transform: scale(1.04);
}

.lab-halo.is-active.is-hover:not(.is-valid) {
  opacity: 1;
  box-shadow: 0 0 0 3px rgba(240, 120, 120, 0.6);
  background: rgba(255, 160, 160, 0.1);
}

@keyframes lab-halo {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.15); }
}

.lab-anchor {
  position: absolute;
  left: 270px;
  top: 120px;
  width: 100px;
  height: 110px;
}

/* ------------------------------------------------------------ reaction effects */

.lab-flash {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 0 22%, var(--c, #ffe27a) 45%, rgba(255, 255, 255, 0) 70%);
  pointer-events: none;
  z-index: 2;
}

.lab-confetti {
  position: absolute;
  border-radius: 3px;
  background: var(--c, #ffe27a);
  box-shadow: 0 0 0 1px rgba(58, 74, 102, 0.25);
  pointer-events: none;
  z-index: 2;
}

.lab-puff {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #f2f4f8, #b9c1cf 70%);
  box-shadow: 0 0 0 1.5px rgba(58, 74, 102, 0.25);
  pointer-events: none;
  z-index: 2;
}

.lab-sparkle {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  background: #ffffff;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  filter: drop-shadow(0 0 3px var(--c, #ffe27a));
}

/* ------------------------------------------------------------ legend on the table front */

.lab-legend {
  position: absolute;
  left: 150px;
  top: 318px;
  width: 300px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  align-content: flex-end;
  gap: 4px;
  pointer-events: none;
  transform: scale(var(--lab-boost));
  /* A second row of long labels (DESIGN.md 11.14) grows upward over the tabletop instead of past the scene edge. */
  transform-origin: 50% 100%;
}

.lab-legend-hint {
  font: 600 12px/1.2 var(--lab-font-head);
  color: #a8784c;
  opacity: 0.85;
}

.lab-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 0;
  padding: 1px 7px 1px 4px;
  border: 1.5px solid rgba(58, 74, 102, 0.45);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  font: 600 11px/1.3 var(--lab-font-head);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.lab-chip:hover { transform: translateY(-1px); }

.lab-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(58, 74, 102, 0.45);
}

.lab-chip-count { color: #6b7790; }

.lab-legend-kinds {
  font: 600 10px/1 var(--lab-font-head);
  color: #a8784c;
  margin-left: 2px;
}

/* ------------------------------------------------------------ Fizz, the mascot, and the speech bubble (DESIGN.md 11.5) */

.lab-mascot {
  position: absolute;
  left: 4px;
  top: 2px;
  width: 62px;
  height: 88px;
  margin: 0;
  padding: 2px 4px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  transform-origin: 50% 80%;
}

.lab-mascot svg {
  display: block;
  width: 54px;
  height: 66px;
  overflow: visible;
  transform-origin: 50% 100%;
  animation: lab-mascot-idle 3.2s ease-in-out infinite;
}

.lab-mascot-name {
  display: block;
  width: max-content;
  margin: 1px auto 0;
  padding: 0 8px;
  border: 1.5px solid var(--lab-ink);
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(38, 50, 74, 0.18);
  font: 700 11px/1.35 var(--lab-font-head);
  letter-spacing: 0.05em;
  color: var(--lab-ink);
}

.lab-mascot:hover .lab-mascot-name { background: #fff3a0; }

.lab-mascot[data-mood="excited"] svg { animation: lab-mascot-hop 0.7s ease-in-out infinite; }
.lab-mascot[data-mood="sleepy"] svg { animation: lab-mascot-doze 4.2s ease-in-out infinite; }
.lab-mascot[data-mood="sad"] svg { animation: lab-mascot-droop 4s ease-in-out infinite; }
.lab-mascot[data-mood="annoyed"] svg { animation: lab-mascot-huff 1.6s ease-in-out infinite; }
.lab-mascot.is-speaking svg { animation: lab-mascot-talk 0.5s ease-in-out 3; }

@keyframes lab-mascot-idle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-2px) rotate(-2deg); }
}

@keyframes lab-mascot-talk {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  40% { transform: translateY(-3px) scale(0.97, 1.04); }
}

@keyframes lab-mascot-hop {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  15% { transform: translateY(0) scale(1.05, 0.94); }
  45% { transform: translateY(-5px) scale(0.97, 1.04); }
}

@keyframes lab-mascot-doze {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  50% { transform: rotate(5deg) translateY(1px); }
}

@keyframes lab-mascot-droop {
  0%, 100% { transform: translateY(1px) scale(1, 0.98); }
  50% { transform: translateY(0) scale(1, 1); }
}

@keyframes lab-mascot-huff {
  0%, 100% { transform: scale(1, 1); }
  20% { transform: scale(1.04, 0.97); }
  40% { transform: scale(1, 1); }
}

/* Face parts. Each mood shows its own eyes, mouth and extra. */
.m-liquid { fill: #9ee6c8; transition: fill 0.4s ease; }
.lab-mascot[data-mood="excited"] .m-liquid { fill: #ffd98a; }
.lab-mascot[data-mood="think"] .m-liquid { fill: #b9dcff; }
.lab-mascot[data-mood="surprised"] .m-liquid { fill: #ffe2a6; }
.lab-mascot[data-mood="sad"] .m-liquid { fill: #b7c9f3; }
.lab-mascot[data-mood="sleepy"] .m-liquid { fill: #d6cbf5; }
.lab-mascot[data-mood="annoyed"] .m-liquid { fill: #ffb9b9; }

.m-cheek { fill: #ffb4c8; opacity: 0.85; }
.lab-mascot[data-mood="annoyed"] .m-cheek { fill: #ff7f98; }
.lab-mascot[data-mood="sad"] .m-cheek,
.lab-mascot[data-mood="sleepy"] .m-cheek { opacity: 0.45; }

.lab-mascot .m-eyes,
.lab-mascot .m-mouth,
.lab-mascot .m-x { display: none; }

.lab-mascot[data-mood="neutral"] .m-e-open,
.lab-mascot[data-mood="neutral"] .m-m-smile,
.lab-mascot[data-mood="happy"] .m-e-happy,
.lab-mascot[data-mood="happy"] .m-m-grin,
.lab-mascot[data-mood="excited"] .m-e-star,
.lab-mascot[data-mood="excited"] .m-m-grin,
.lab-mascot[data-mood="excited"] .m-x-spark,
.lab-mascot[data-mood="think"] .m-e-think,
.lab-mascot[data-mood="think"] .m-m-side,
.lab-mascot[data-mood="think"] .m-x-q,
.lab-mascot[data-mood="surprised"] .m-e-wide,
.lab-mascot[data-mood="surprised"] .m-m-o,
.lab-mascot[data-mood="surprised"] .m-x-wow,
.lab-mascot[data-mood="sad"] .m-e-sad,
.lab-mascot[data-mood="sad"] .m-m-frown,
.lab-mascot[data-mood="sad"] .m-x-tear,
.lab-mascot[data-mood="sleepy"] .m-e-closed,
.lab-mascot[data-mood="sleepy"] .m-m-small,
.lab-mascot[data-mood="sleepy"] .m-x-zzz,
.lab-mascot[data-mood="annoyed"] .m-e-annoyed,
.lab-mascot[data-mood="annoyed"] .m-m-flat,
.lab-mascot[data-mood="annoyed"] .m-x-anger { display: inline; }

/* Blink every few seconds. */
.m-blink {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: lab-blink 4.6s ease-in-out infinite;
}

@keyframes lab-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

.m-x-zzz text {
  font: 700 9px/1 var(--lab-font-head);
  fill: #7d70cf;
  stroke: #ffffff;
  stroke-width: 2.4px;
  paint-order: stroke;
  opacity: 0;
  animation: lab-zzz 2.7s ease-out infinite;
}

.m-x-zzz .z2 { font-size: 10.5px; animation-delay: 0.9s; }
.m-x-zzz .z3 { font-size: 12.5px; animation-delay: 1.8s; }

@keyframes lab-zzz {
  0% { opacity: 0; transform: translate(-2px, 5px); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translate(4px, -6px); }
}

.m-x-q {
  font: 700 15px/1 var(--lab-font-head);
  fill: #3d7cf0;
  stroke: #ffffff;
  stroke-width: 2.6px;
  paint-order: stroke;
  animation: lab-q 1.4s ease-in-out infinite;
}

@keyframes lab-q {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.m-x-spark polygon {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: lab-twinkle 0.9s ease-in-out infinite;
}

.m-x-spark .s2 { animation-delay: 0.3s; }
.m-x-spark .s3 { animation-delay: 0.6s; }

@keyframes lab-twinkle {
  0%, 100% { transform: scale(0.6) rotate(0deg); opacity: 0.6; }
  50% { transform: scale(1.15) rotate(20deg); opacity: 1; }
}

.m-x-anger {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: lab-anger 0.8s ease-in-out infinite;
}

@keyframes lab-anger {
  0%, 100% { transform: scale(0.85); }
  50% { transform: scale(1.12); }
}

.m-x-tear { animation: lab-tear 2.2s ease-in infinite; }

@keyframes lab-tear {
  0%, 30% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(6px); opacity: 0; }
}

.m-bub { fill: #9ee6c8; opacity: 0; }
.lab-mascot .m-bub { animation: lab-mbub 2.6s ease-in infinite; }
.lab-mascot .m-bub.b2 { animation-delay: 1.3s; }
.lab-mascot[data-mood="sleepy"] .m-bub { animation: none; }

@keyframes lab-mbub {
  0% { opacity: 0; transform: translateY(6px); }
  30% { opacity: 0.9; }
  100% { opacity: 0; transform: translateY(-8px); }
}

.lab-bubble {
  position: absolute;
  left: 70px;
  top: 10px;
  box-sizing: border-box;
  /* Ends left of the flask neck (x 295) so puffs and pours stay visible. On small scenes --lab-boost enlarges it.
     It then reaches x 390 at most and stays clear of the price tags on the right. */
  max-width: 222px;
  padding: 8px 12px;
  border: 2px solid var(--lab-ink);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(38, 50, 74, 0.16);
  font: 700 13px/1.35 var(--lab-font-body);
  color: #26324a;
  overflow-wrap: break-word;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  cursor: pointer;
  /* The bubble grows from near its top edge. A lower origin pushed the top border out of the scene at the phone boost of about 1.35. */
  transform-origin: 0 12px;
  transform: scale(calc(var(--lab-boost) * 0.85));
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.3, 1.5, 0.5, 1), visibility 0s linear 0.25s;
  z-index: 5;
}

.lab-bubble.is-long { padding: 7px 11px; font-size: 12.5px; line-height: 1.32; }
.lab-bubble.is-xlong { max-width: 224px; font-size: 12px; line-height: 1.3; }

.lab-bubble::before {
  content: "";
  position: absolute;
  left: -9px;
  top: 20px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-left: 2px solid var(--lab-ink);
  border-bottom: 2px solid var(--lab-ink);
  transform: rotate(45deg);
  border-bottom-left-radius: 3px;
}

.lab-bubble.is-shown {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(var(--lab-boost));
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.3, 1.5, 0.5, 1), visibility 0s;
}

.lab-bubble.is-shown:hover { border-color: #3d7cf0; }

/* ------------------------------------------------------------ long mix (DESIGN.md 11.2) */

.lab-mixstop { stop-color: var(--lab-mixc, #ffffff); transition: stop-color 0.7s ease; }

.lab-mix-glow { opacity: 0; transition: opacity 0.5s ease; }

.lab-mixring {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1;
}

.lab-mix-long .lab-mixring { opacity: 1; }

.lab-ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 8;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 1.5px rgba(38, 50, 74, 0.3));
}

.lab-ring-fill {
  fill: none;
  stroke: var(--lab-ringc, #4cc48a);
  stroke-width: 4.5;
  stroke-linecap: round;
  transition: stroke 0.6s ease;
}

.lab-countdown {
  position: absolute;
  left: 352px;
  top: 64px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 1px 8px 1px 5px;
  border: 2px solid var(--lab-ink);
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(38, 50, 74, 0.18);
  font: 700 13px/1.25 var(--lab-font-head);
  color: var(--lab-ink);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.5);
  transform-origin: 0 50%;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.3, 1.5, 0.5, 1), background 0.2s ease;
  z-index: 3;
}

.lab-mix-long .lab-countdown { opacity: 1; transform: scale(var(--lab-boost)); }
.lab-mix-peak .lab-countdown { background: #fff3a0; }

.lab-countdown-icon {
  display: inline-block;
  font-size: 11px;
  animation: lab-hourglass 1s ease-in-out infinite;
}

@keyframes lab-hourglass {
  0%, 70% { transform: rotate(0deg); }
  100% { transform: rotate(180deg); }
}

.lab-mixbub {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff 0 22%, rgba(255, 255, 255, 0.45) 55%, rgba(255, 255, 255, 0.12) 100%);
  box-shadow: 0 0 0 1.3px var(--c, #9ad0ff);
  pointer-events: none;
  z-index: 1;
}

.lab-stagepulse {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--c, #ffffff) 0%, rgba(255, 255, 255, 0) 100%);
  pointer-events: none;
  z-index: 1;
}

.lab-shock {
  position: absolute;
  box-sizing: border-box;
  border-radius: 50%;
  border: 6px solid var(--c, #ffe27a);
  box-shadow: 0 0 18px var(--c, #ffe27a), inset 0 0 12px rgba(255, 255, 255, 0.8);
  pointer-events: none;
  z-index: 2;
}

/* Balls glow in the mix colour and shrink a little as they get ready to merge. */
.lab-mix-long .lab-ball .lab-ball-face {
  box-shadow: 0 0 calc(var(--lab-bglow, 0) * 14px) calc(var(--lab-bglow, 0) * 3px) var(--lab-bglowc, #ffffff), inset 0 -2px 3px rgba(38, 50, 74, 0.12);
  scale: calc(1 - var(--lab-bglow, 0) * 0.2);
  transition: box-shadow 0.3s ease, scale 0.3s ease;
}

.lab-mix-long .lab-ball { cursor: default; }

/* The apparatus works harder at the climax of a long mix. */
.lab-mix-peak .lab-flaskwrap { animation: lab-rattle 0.14s linear infinite; }
.lab-mix-big.lab-mix-peak .lab-flaskwrap { animation-duration: 0.09s; }
.lab-mix-peak.lab-on-heat .lab-flame-wrap { transform: scale(1.5, 1.75); }
.lab-mix-long .lab-tube.is-filled { animation-duration: 0.45s; }

@keyframes lab-rattle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-1.3deg); }
  75% { transform: rotate(1.3deg); }
}

/* ------------------------------------------------------------ rich tooltip on flask balls (ui.js content) */

.lab-richtip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9100;
  max-width: 280px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(38, 50, 74, 0.94);
  color: #ffffff;
  font: 700 13px/1.35 "Nunito", "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.lab-richtip.is-shown { opacity: 1; }

.lab-richtip-act {
  display: block;
  margin-top: 5px;
  font-size: 11.5px;
  font-weight: 600;
  opacity: 0.75;
}

/* ------------------------------------------------------------ tooltip (on document.body) */

.lab-tipbox {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9100;
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #3a4a66;
  color: #ffffff;
  font: 700 13px/1.3 "Nunito", "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 4px 12px rgba(38, 50, 74, 0.25);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.lab-tipbox.is-shown { opacity: 1; transform: translateY(0); }

/* ------------------------------------------------------------ narrow screens */

.lab-narrow .lab-caption { display: none; }

/* Small scenes (phones): the switches get bigger invisible hit areas. They stay clear of the beaker and the flask. */
.lab-narrow .lab-hit-heat { transform: scale(1.2, 1.6); }
.lab-narrow .lab-hit-electricity { transform: scale(1.15, 1.2); }
.lab-narrow .lab-hit-pressure { transform: scale(1.35); transform-origin: 50% 85%; }
.lab-narrow .lab-hit-light { transform: scale(1.2, 1); }

/* ------------------------------------------------------------ reduced motion */

.lab-reduced .lab-ball .lab-ball-face,
.lab-reduced .lab-mascot svg,
.lab-reduced .lab-mascot .m-bub,
.lab-reduced .m-blink,
.lab-reduced .m-x-spark polygon,
.lab-reduced .m-x-anger,
.lab-reduced .m-x-q,
.lab-reduced .m-x-tear,
.lab-reduced .lab-countdown-icon,
.lab-reduced.lab-mix-peak .lab-flaskwrap,
.lab-reduced .lab-tube.is-filled,
.lab-reduced .lab-halo.is-valid,
.lab-reduced.lab-on-pressure .lab-needle-wrap,
.lab-reduced .lab-tube-in .lab-tube,
.lab-reduced .lab-beaker-in .lab-beaker {
  animation: none;
}

.lab-reduced.lab-on-heat .lab-flame { animation-duration: 0.9s; }
.lab-reduced.lab-on-electricity .lab-spark,
.lab-reduced.lab-on-electricity .lab-spark-dot { animation-duration: 1.6s; }
.lab-reduced.lab-on-light .lab-cone { animation: none; opacity: 0.9; }

/* Reduced motion keeps the Zzz but without movement. */
.lab-reduced .m-x-zzz text { animation: none; opacity: 0.9; }

@media (prefers-reduced-motion: reduce) {
  .lab-ball .lab-ball-face,
  .lab-mascot svg,
  .lab-mascot .m-bub,
  .m-blink,
  .lab-countdown-icon,
  .lab-mix-peak .lab-flaskwrap,
  .lab-tube.is-filled,
  .lab-halo.is-valid,
  .lab-on-pressure .lab-needle-wrap {
    animation: none;
  }
}

/* Phones (DESIGN.md 11.19): the flask contents legend reads at about 11 px on screen. */
.lab-narrow .lab-chip { font-size: 14px; padding: 1px 8px 1px 5px; }
.lab-narrow .lab-chip-dot { width: 11px; height: 11px; }
.lab-narrow .lab-legend-hint { font-size: 14px; }
