/* ==========================================================================
   DEEP VEIN / Free-build sector
   A wide, pans/zooms construction field with DSP-inspired sci-fi HUD.
   ========================================================================== */

.view-root[data-page="factory"] {
  overflow: hidden;
  background: #071219;
}

/* The construction sector collapses the navigation into an icon rail, DSP style. */
@media (min-width: 1021px) {
  .app-shell.is-immersive {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .app-shell.is-immersive .sidebar {
    background:
      linear-gradient(180deg, rgba(60, 153, 148, 0.06), transparent 24%),
      #081218;
    border-right-color: rgba(96, 190, 184, 0.12);
  }

  .app-shell.is-immersive .side-brand {
    justify-content: center;
    padding: 0;
  }

  .app-shell.is-immersive .side-brand > div:last-child,
  .app-shell.is-immersive .nav-label,
  .app-shell.is-immersive .nav-text,
  .app-shell.is-immersive .side-power,
  .app-shell.is-immersive .side-account-info,
  .app-shell.is-immersive .side-account .icon-btn {
    display: none;
  }

  .app-shell.is-immersive .side-brand .brand-mark {
    width: 35px;
    height: 35px;
  }

  .app-shell.is-immersive .side-nav {
    padding: 20px 9px 0;
    gap: 7px;
  }

  .app-shell.is-immersive .nav-item {
    justify-content: center;
    min-height: 43px;
    padding: 0;
  }

  .app-shell.is-immersive .nav-item.is-active {
    color: var(--cyan);
    background: rgba(85, 205, 193, 0.09);
    border-color: rgba(104, 211, 199, 0.13);
  }

  .app-shell.is-immersive .nav-item.is-active::before {
    left: -10px;
    top: 10px;
    bottom: 10px;
    background: var(--cyan);
    box-shadow: 0 0 14px rgba(102, 212, 197, 0.4);
  }

  .app-shell.is-immersive .nav-icon {
    width: 22px;
    height: 22px;
  }

  .app-shell.is-immersive .nav-icon svg {
    width: 21px;
    height: 21px;
  }

  .app-shell.is-immersive .nav-badge {
    position: absolute;
    right: 5px;
    top: 4px;
    min-width: 13px;
    height: 13px;
    padding: 0 2px;
    font-size: 6px;
  }

  .app-shell.is-immersive .side-account {
    justify-content: center;
    padding: 14px 0;
  }

  .app-shell.is-immersive .topbar {
    padding-left: 20px;
  }
}

.factory-screen {
  --cell-w: 56px;
  --cell-h: 45px;
  --cell-gap: 4px;
  --board-pad: 10px;
  position: relative;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 11px 15px 10px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 76% -10%, rgba(55, 180, 182, 0.13), transparent 42%),
    radial-gradient(ellipse at 12% 110%, rgba(215, 147, 56, 0.08), transparent 40%),
    linear-gradient(180deg, #08161d, #071016 70%);
}

/* --------------------------------------------------------------------------
   Top line
   -------------------------------------------------------------------------- */

.factory-topline {
  flex: 0 0 auto;
  min-height: 43px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 3px;
}

.factory-location {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 210px;
}

.factory-location-icon {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid rgba(108, 222, 211, 0.22);
  border-radius: 7px;
  background:
    linear-gradient(145deg, rgba(108, 222, 211, 0.13), rgba(108, 222, 211, 0.02)),
    #0d1d22;
  color: var(--cyan);
  box-shadow: inset 0 0 16px rgba(108, 222, 211, 0.06);
}

.factory-location-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; }

.factory-location strong {
  display: block;
  color: #edf4ef;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.factory-location span {
  display: flex;
  margin-top: 2px;
  color: #6f8585;
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.factory-location > .factory-site-chip {
  margin: 0 0 0 4px;
  padding: 4px 7px;
  border: 1px solid rgba(231, 190, 100, 0.24);
  border-radius: 2px;
  color: #d9c07d;
  font-size: 6px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  background: rgba(231, 190, 100, 0.045);
}

.factory-head-spacer { flex: 1; }

.factory-mode-switch {
  flex: 0 0 auto;
  padding: 3px;
  border: 1px solid rgba(130, 191, 188, 0.14);
  border-radius: 7px;
  background: rgba(5, 16, 20, 0.62);
}

.factory-mode-switch .mode-btn {
  min-width: 42px;
  padding: 6px 9px;
  border-radius: 4px;
  color: #6c8583;
  font-size: 9px;
}

.factory-mode-switch .mode-btn:hover { color: #dfe9e4; }
.factory-mode-switch .mode-btn.is-active {
  color: #e9fffa;
  background: rgba(81, 191, 183, 0.2);
  box-shadow: inset 0 0 0 1px rgba(114, 231, 220, 0.18);
}
.factory-mode-switch .mode-btn.danger.is-active {
  color: #ffb0a7;
  background: rgba(218, 93, 84, 0.16);
  box-shadow: inset 0 0 0 1px rgba(230, 122, 113, 0.2);
}

.factory-icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(131, 183, 179, 0.14);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
  color: #8ba3a0;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.factory-icon-btn:hover {
  color: var(--gold);
  border-color: rgba(242, 182, 68, 0.35);
  background: rgba(242, 182, 68, 0.07);
}

.factory-icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.65; }
.factory-dock-toggle { display: grid; }

.factory-maintenance-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid rgba(242, 182, 68, 0.28);
  border-radius: 6px;
  background: rgba(242, 182, 68, 0.06);
  color: #d9c383;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.factory-maintenance-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.factory-maintenance-btn strong { color: var(--gold); font-size: 9px; font-weight: 700; }
.factory-maintenance-btn:hover:not(:disabled) {
  color: #fff0c5;
  border-color: rgba(242, 182, 68, 0.55);
  background: rgba(242, 182, 68, 0.13);
}
.factory-maintenance-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
@media (max-width: 1180px) {
  .factory-maintenance-btn .maintenance-label { display: none; }
}

/* --------------------------------------------------------------------------
   Viewport / sky
   -------------------------------------------------------------------------- */

.factory-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(103, 196, 192, 0.14);
  border-radius: 15px;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(40, 121, 127, 0.12), transparent 52%),
    linear-gradient(180deg, #07151c, #071017);
  box-shadow:
    inset 0 0 90px rgba(0, 0, 0, 0.42),
    0 14px 40px rgba(0, 0, 0, 0.2);
  cursor: grab;
  touch-action: none;
}

.factory-screen:not(.is-pan-mode) .factory-viewport { cursor: default; }
.factory-viewport.is-pan-mode,
.factory-viewport.is-space-pan { cursor: grab; }
.factory-viewport.is-panning { cursor: grabbing; }

.factory-void {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(7, 22, 28, 0.2), rgba(3, 9, 12, 0.62)),
    radial-gradient(ellipse at 47% 48%, rgba(24, 75, 81, 0.06), transparent 60%),
    url("https://renderfarm-1389434004.cos.ap-shanghai.myqcloud.com/deep-vein/assets/21301183bbc9db3f5c72ce1906d97148222e4dd7e04474ab0b3dd80b62104073/nebula.webp") center / cover no-repeat;
}

.factory-background-planet {
  position: absolute;
  right: -160px;
  bottom: -560px;
  width: 900px;
  height: 900px;
  background: url("https://renderfarm-1389434004.cos.ap-shanghai.myqcloud.com/deep-vein/assets/6a46078c16bc9b16cd191364946730685339fc943ff365340bbb78c3979a8196/planet.webp") center / contain no-repeat;
  opacity: 0.26;
  filter: saturate(0.8) brightness(0.62) blur(0.3px);
  transform: rotate(8deg);
  animation: factory-planet-drift 18s ease-in-out infinite;
}

@keyframes factory-planet-drift {
  0%, 100% { transform: rotate(8deg) translateY(0); }
  50% { transform: rotate(9deg) translateY(-12px); }
}

.factory-stars,
.factory-stars::before,
.factory-stars::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(207, 240, 231, 0.75) 0 0.7px, transparent 1.3px),
    radial-gradient(circle at 37% 72%, rgba(127, 219, 207, 0.55) 0 0.6px, transparent 1.2px),
    radial-gradient(circle at 64% 24%, rgba(225, 240, 234, 0.7) 0 0.6px, transparent 1.2px),
    radial-gradient(circle at 84% 62%, rgba(242, 182, 68, 0.4) 0 0.7px, transparent 1.4px),
    radial-gradient(circle at 25% 46%, rgba(190, 225, 219, 0.42) 0 0.6px, transparent 1.2px);
  background-size: 330px 240px, 280px 330px, 410px 280px, 370px 290px, 250px 390px;
  opacity: 0.55;
}

.factory-stars::before { transform: translate(40px, 20px) scale(1.15); opacity: 0.35; }
.factory-stars::after { transform: translate(-50px, 70px) scale(0.8); opacity: 0.25; }

.factory-orbit {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 1180px;
  height: 470px;
  border: 1px solid rgba(89, 214, 203, 0.07);
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(-16deg);
}

.factory-orbit.orbit-b {
  width: 850px;
  height: 300px;
  border-color: rgba(242, 182, 68, 0.055);
  transform: translate(-50%, -50%) rotate(18deg);
}

.factory-horizon-glow {
  position: absolute;
  left: -5%;
  right: -5%;
  bottom: -46%;
  height: 64%;
  border-radius: 50% 50% 0 0;
  background: radial-gradient(ellipse at 50% 10%, rgba(54, 147, 150, 0.16), transparent 62%);
  filter: blur(12px);
}

.factory-void::before {
  content: "";
  position: absolute;
  right: -180px;
  bottom: -610px;
  width: 920px;
  height: 920px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 28%, rgba(73, 179, 172, 0.18), rgba(12, 42, 48, 0.04) 52%, transparent 69%),
    radial-gradient(circle at 50% 50%, rgba(8, 24, 30, 0.4), transparent 70%);
  border: 1px solid rgba(109, 218, 205, 0.08);
  box-shadow: inset 0 30px 90px rgba(95, 232, 216, 0.05);
}

.factory-void::after {
  content: "";
  position: absolute;
  left: -260px;
  top: -230px;
  width: 560px;
  height: 560px;
  border-radius: 50%;
  border: 1px solid rgba(242, 182, 68, 0.045);
  background: radial-gradient(circle at 60% 60%, rgba(242, 182, 68, 0.045), transparent 60%);
  filter: blur(1px);
}

/* --------------------------------------------------------------------------
   World / board
   -------------------------------------------------------------------------- */

.factory-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
  transition: opacity 0.24s ease;
}

.factory-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(42, var(--cell-w));
  grid-auto-rows: var(--cell-h);
  gap: var(--cell-gap);
  width: max-content;
  padding: var(--board-pad);
  border: 1px solid rgba(112, 224, 211, 0.26);
  border-radius: 15px;
  background-color: #0b1412;
  background-image:
    linear-gradient(180deg, rgba(6, 20, 24, 0.16), rgba(3, 11, 14, 0.3)),
    radial-gradient(ellipse at 50% 30%, rgba(8, 26, 24, 0.08), transparent 66%),
    url("https://renderfarm-1389434004.cos.ap-shanghai.myqcloud.com/deep-vein/assets/6d9798c32afce95d81c5820500e5644ecb52a07279c5aa7f084ddc77dc1afa04/land/image_0.webp");
  background-size:
    auto,
    auto,
    34.13px 34.13px;
  background-repeat: no-repeat, no-repeat, repeat;
  background-position: center, center, 0 0;
  box-shadow:
    inset 0 0 120px rgba(0, 0, 0, 0.34),
    0 26px 70px rgba(0, 0, 0, 0.34),
    0 0 0 8px rgba(28, 88, 92, 0.09),
    0 0 60px rgba(56, 167, 166, 0.04);
  touch-action: pan-y;
  user-select: none;
}

.factory-board::before {
  display: none;
}

.factory-cell {
  position: relative;
  min-width: 0;
  aspect-ratio: auto;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--ink-dim);
  overflow: hidden;
  contain: layout paint style;
  touch-action: pan-y;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.factory-cell:nth-child(13n + 5) {
  background: transparent;
}

.factory-board.is-painting,
.factory-board.is-painting .factory-cell {
  touch-action: none;
}

.factory-board.is-demolishing .factory-cell {
  touch-action: none;
}

.factory-screen .factory-cell::before {
  display: none;
}

.factory-cell.is-empty::before {
  display: none;
}

.factory-board.is-building .factory-cell.is-empty:hover,
.factory-screen.is-build-mode .factory-cell.is-empty:hover {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.factory-board.is-building .factory-cell.is-empty:hover::before,
.factory-screen.is-build-mode .factory-cell.is-empty:hover::before {
  background: transparent;
  box-shadow: none;
}

.factory-board.is-demolishing .factory-cell:hover {
  border-color: rgba(236, 105, 105, 0.6);
  background: rgba(190, 55, 55, 0.11);
}

.factory-cell.is-selected {
  z-index: 5;
  border-color: rgba(242, 182, 68, 0.68) !important;
  box-shadow:
    inset 0 0 0 1px rgba(242, 182, 68, 0.18),
    0 0 18px rgba(242, 182, 68, 0.16) !important;
}

.factory-cell.is-belt {
  border-color: rgba(90, 202, 192, 0.2);
  background: rgba(16, 50, 55, 0.4);
}

.factory-cell.is-belt .belt-bed {
  position: absolute;
  inset: 30% 0;
  border-top: 1px solid rgba(154, 240, 227, 0.34);
  border-bottom: 1px solid rgba(5, 19, 23, 0.6);
  background:
    repeating-linear-gradient(90deg, transparent 0 7px, rgba(8, 22, 24, 0.45) 7px 9px),
    linear-gradient(180deg, #315b5c, #1a373a);
  box-shadow: inset 0 3px 4px rgba(0, 0, 0, 0.18);
}

.factory-cell.is-belt .belt-motion {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 18%;
  transform: translateY(-50%);
  opacity: 0.9;
  background: repeating-linear-gradient(90deg, transparent 0 6px, rgba(130, 249, 232, 0.44) 6px 8px, transparent 8px 14px);
  animation: factoryBeltFlow 0.78s linear infinite;
}

@keyframes factoryBeltFlow {
  to { background-position: 14px 0; }
}

.factory-cell.is-belt[data-dir="left"] .belt-motion { animation-direction: reverse; }
.factory-cell.is-belt[data-dir="up"] .belt-motion,
.factory-cell.is-belt[data-dir="down"] .belt-motion {
  display: block;
  left: 50%;
  right: auto;
  top: 0;
  bottom: 0;
  width: 18%;
  height: auto;
  transform: translateX(-50%);
  background: repeating-linear-gradient(0deg, transparent 0 6px, rgba(130, 249, 232, 0.44) 6px 8px, transparent 8px 14px);
}

.factory-cell.is-belt[data-dir="up"] .belt-motion { animation-name: factoryBeltFlowVertical; animation-direction: reverse; }
.factory-cell.is-belt[data-dir="down"] .belt-motion { animation-name: factoryBeltFlowVertical; animation-direction: normal; }

@keyframes factoryBeltFlowVertical {
  to { background-position: 0 14px; }
}

.factory-cell.is-belt[data-dir="up"] .belt-bed,
.factory-cell.is-belt[data-dir="down"] .belt-bed {
  inset: 0 30%;
  border-top: 0;
  border-bottom: 0;
  border-left: 1px solid rgba(154, 240, 227, 0.34);
  border-right: 1px solid rgba(5, 19, 23, 0.6);
  background:
    repeating-linear-gradient(0deg, transparent 0 7px, rgba(8, 22, 24, 0.45) 7px 9px),
    linear-gradient(90deg, #315b5c, #1a373a);
}

.factory-cell.is-belt .belt-arrow { opacity: 0.65; }
.factory-cell.is-belt[data-dir="right"] .belt-arrow { border-left-color: #a6eee4; }
.factory-cell.is-belt[data-dir="left"] .belt-arrow { border-right-color: #a6eee4; }
.factory-cell.is-belt[data-dir="up"] .belt-arrow { border-bottom-color: #a6eee4; }
.factory-cell.is-belt[data-dir="down"] .belt-arrow { border-top-color: #a6eee4; }

.factory-cell.is-machine {
  border-color: rgba(132, 191, 184, 0.14);
  background:
    linear-gradient(180deg, rgba(117, 197, 191, 0.06), transparent 53%),
    #102127;
}

/* Terrain-forward machines: no tile plate or frame behind the sprite. */
.factory-screen .factory-cell.is-machine,
.factory-screen .factory-cell.is-machine.is-running,
.factory-screen .factory-cell.is-machine[data-type] {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

/* Belts / pipes keep their moving bed, but lose the dark cell plate. */
.factory-screen .factory-cell.is-belt,
.factory-screen .factory-cell.is-pipe {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

/* Intake / settlement terminal: keep the art and labels, drop the plate. */
.factory-screen .factory-cell.is-logistics[data-type] {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.factory-cell.is-machine.is-running {
  border-color: rgba(102, 226, 216, 0.36);
  box-shadow: inset 0 0 20px rgba(82, 195, 187, 0.08);
}

.factory-cell.is-machine[data-type="refiner"] {
  background:
    radial-gradient(ellipse at 50% 64%, rgba(242, 168, 70, 0.18), transparent 66%),
    #122228;
}

.factory-cell.is-machine[data-type="purifier"] {
  background:
    radial-gradient(ellipse at 50% 64%, rgba(87, 220, 208, 0.17), transparent 66%),
    #0f2026;
}

.factory-cell.is-machine[data-type="compressor"] {
  background:
    radial-gradient(ellipse at 50% 64%, rgba(199, 119, 78, 0.16), transparent 66%),
    #132026;
}

.factory-cell.is-machine[data-type="dieselGen"] {
  background:
    radial-gradient(ellipse at 50% 64%, rgba(240, 185, 74, 0.15), transparent 66%),
    #122126;
}

.factory-cell.is-machine[data-type="coalGen"] {
  background:
    radial-gradient(ellipse at 50% 64%, rgba(235, 113, 65, 0.16), transparent 66%),
    #141f23;
}

.factory-cell.is-machine .machine-slot {
  inset: 3px 3px 7px;
}

.factory-cell.is-machine .machine-art {
  filter: brightness(1.24) saturate(1.16) drop-shadow(0 3px 3px rgba(0, 0, 0, 0.38));
}

.factory-cell.is-machine.is-running .machine-slot > img.machine-art {
  filter: brightness(1.26) saturate(1.2) drop-shadow(0 0 7px rgba(242, 182, 68, 0.28)) drop-shadow(0 3px 3px rgba(0, 0, 0, 0.38));
}

.factory-cell.is-machine .machine-badge-row {
  left: 4px;
  top: 3px;
}

.factory-cell.is-machine .machine-level {
  border: 1px solid rgba(255, 211, 111, 0.16);
  background: rgba(6, 17, 19, 0.74);
  color: #ffd775;
}

.factory-cell.is-machine .machine-name-mini {
  background: rgba(7, 18, 20, 0.72);
  color: #8cb9b3;
}

.factory-cell.is-machine .machine-progress {
  left: 4px;
  right: 4px;
  bottom: 3px;
  height: 2px;
  background: rgba(0, 0, 0, 0.46);
}

.factory-cell.is-machine .machine-progress i {
  background: linear-gradient(90deg, #55cdc0, #e9fffa);
  box-shadow: 0 0 6px rgba(113, 235, 220, 0.5);
}

.factory-cell.is-machine .machine-led { background: #42615e; box-shadow: none; }
.factory-cell.is-machine.is-running .machine-led {
  background: #78ebde;
  box-shadow: 0 0 7px rgba(120, 235, 222, 0.7);
}

.factory-cell.is-machine-pop .machine-slot {
  animation: factoryMachinePop 0.42s ease;
}

@keyframes factoryMachinePop {
  40% { filter: brightness(1.7); transform: scale(1.04); }
}

/* Logistics ---------------------------------------------------------------- */

.factory-cell.is-logistics {
  border-color: rgba(119, 208, 199, 0.2);
  background:
    radial-gradient(ellipse at 50% 55%, rgba(92, 225, 212, 0.15), transparent 65%),
    rgba(11, 35, 39, 0.78);
}

.factory-cell.is-logistics.is-sink {
  border-color: rgba(242, 182, 68, 0.24);
  background:
    radial-gradient(ellipse at 50% 55%, rgba(242, 182, 68, 0.13), transparent 65%),
    rgba(28, 31, 24, 0.78);
}

.factory-cell.is-logistics.is-intake.is-pulsing {
  animation: factorySourcePulse 0.5s ease;
}

/* 2x2 logistics facilities read as one large plot, not a tile. */
.factory-cell.is-hub-part {
  border-color: rgba(108, 193, 184, 0.12);
  background:
    radial-gradient(ellipse at 50% 48%, rgba(74, 151, 146, 0.07), transparent 65%),
    rgba(10, 29, 33, 0.5);
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.16);
}

.factory-cell.is-hub-large {
  z-index: 6;
  overflow: visible;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.factory-cell.is-hub-large .logistics-cell-art {
  top: 3px;
  left: 3px;
  right: auto;
  bottom: auto;
  width: calc(var(--cell-w) * 2 + var(--cell-gap) - 6px);
  height: calc(var(--cell-h) * 2 + var(--cell-gap) - 9px);
  padding: 4px 5px 15px;
  border: 1px solid rgba(113, 217, 203, 0.22);
  border-radius: 6px;
  background:
    radial-gradient(ellipse at 50% 74%, rgba(77, 222, 208, 0.13), transparent 64%),
    linear-gradient(145deg, rgba(27, 52, 54, 0.92), rgba(10, 27, 31, 0.96));
  box-shadow:
    inset 0 0 22px rgba(92, 220, 203, 0.07),
    0 4px 14px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.factory-cell.is-hub-large.is-sink .logistics-cell-art {
  border-color: rgba(236, 193, 107, 0.23);
  background:
    radial-gradient(ellipse at 50% 74%, rgba(233, 178, 82, 0.12), transparent 64%),
    linear-gradient(145deg, rgba(47, 48, 35, 0.92), rgba(26, 27, 22, 0.96));
}

.factory-cell.is-hub-large .logistics-cell-art svg {
  width: 96%;
  height: 93%;
  filter: brightness(1.08) saturate(1.08) drop-shadow(0 4px 5px rgba(0, 0, 0, 0.38));
}

.factory-cell.is-hub-large .logistics-cell-label {
  left: 8px;
  right: auto;
  top: calc(var(--cell-h) * 2 + var(--cell-gap) - 16px);
  bottom: auto;
  width: calc(var(--cell-w) * 2 + var(--cell-gap) - 16px);
  z-index: 6;
  padding: 2px 5px;
  border-radius: 2px;
  background: rgba(5, 18, 20, 0.68);
}

.factory-cell.is-hub-large.is-sink .logistics-cell-label { background: rgba(25, 23, 15, 0.68); }
.factory-cell.is-hub-large .logistics-cell-label span { font-size: 6.5px; color: #d7f1eb; }
.factory-cell.is-hub-large .logistics-cell-label small { font-size: 6px; color: #9bbab3; }

.factory-cell.is-hub-large .logistics-beacon {
  right: calc(var(--cell-w) * -1 - var(--cell-gap) + 7px);
  top: 7px;
  z-index: 6;
}

.factory-cell.is-hub-large .logistics-store-mark {
  left: calc(var(--cell-w) + var(--cell-gap) - 30px);
  top: 8px;
  z-index: 6;
  font-size: 5px;
}

.factory-cell.is-hub-large.is-selected .logistics-cell-art {
  border-color: rgba(255, 213, 126, 0.72);
  box-shadow:
    inset 0 0 30px rgba(103, 229, 213, 0.12),
    0 0 0 1px rgba(255, 207, 104, 0.32),
    0 0 24px rgba(242, 182, 68, 0.12);
}

.factory-cell.is-hub-large.is-selected::before {
  inset: 2px;
}

.factory-cell.is-hub-large .logistics-cell-art::after {
  content: "LARGE PLOT · 2×2";
  position: absolute;
  right: 6px;
  bottom: 4px;
  z-index: 2;
  color: rgba(139, 190, 180, 0.42);
  font-family: var(--mono);
  font-size: 4.5px;
  letter-spacing: 0.08em;
  pointer-events: none;
}

@keyframes factorySourcePulse {
  50% { filter: brightness(1.7); box-shadow: 0 0 25px rgba(96, 228, 214, 0.25); }
}

.logistics-cell-art {
  position: absolute;
  inset: 4px 6px 13px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.logistics-cell-art svg {
  width: 90%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.34));
}

.logistics-cell-label {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 3px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  font-family: var(--mono);
  font-size: 5.5px;
  letter-spacing: 0.01em;
  color: #b3d6ce;
  white-space: nowrap;
}

.logistics-cell-label small {
  color: #75938d;
  font-size: 5px;
}

.logistics-beacon {
  position: absolute;
  right: 5px;
  top: 5px;
  z-index: 3;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7ff0df;
  box-shadow: 0 0 8px rgba(107, 239, 222, 0.7);
  animation: logisticsBeacon 2.2s ease-in-out infinite;
}

.is-sink .logistics-beacon {
  background: var(--gold);
  box-shadow: 0 0 8px rgba(242, 182, 68, 0.55);
}

@keyframes logisticsBeacon {
  50% { opacity: 0.35; }
}

.logistics-store-mark {
  position: absolute;
  left: 4px;
  top: 4px;
  z-index: 3;
  padding: 1px 3px;
  border: 1px solid rgba(102, 212, 197, 0.2);
  border-radius: 2px;
  background: rgba(4, 17, 20, 0.8);
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 4.5px;
  letter-spacing: 0.04em;
}

.logistics-inspector-art {
  background:
    radial-gradient(ellipse at 50% 80%, rgba(86, 213, 201, 0.12), transparent 70%),
    #0b171b !important;
}

/* Items & markers ----------------------------------------------------------- */

.factory-board .factory-items-layer {
  position: absolute;
  inset: var(--board-pad);
  z-index: 14;
  pointer-events: none;
}

.factory-item {
  transition: left 180ms linear, top 180ms linear;
  will-change: left, top;
  position: absolute;
  z-index: 14;
  width: clamp(11px, 1.45vw, 18px);
  aspect-ratio: 4 / 3;
  height: auto;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.6)) saturate(1.15);
  transition: left 0.28s linear, top 0.28s linear;
}

.factory-output-float {
  position: absolute;
  z-index: 25;
  right: 2px;
  top: 2px;
  max-width: 110px;
  padding: 2px 4px;
  border-radius: 2px;
  background: var(--gold);
  color: #211606;
  font-family: var(--mono);
  font-size: 6.5px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  animation: factoryOutputFloat 1.15s ease-out forwards;
}

.factory-output-float.is-store {
  background: var(--cyan);
  color: #06201c;
}

@keyframes factoryOutputFloat {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-18px); }
}

.factory-empty-hint {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 310px;
  transform: translate(-50%, -50%);
  color: #567875;
  font-size: 9px;
  line-height: 1.8;
  text-align: center;
  pointer-events: none;
}

.factory-empty-hint.is-hidden { display: none; }
.factory-empty-hint strong {
  display: block;
  margin-bottom: 5px;
  color: #80a7a1;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.12em;
}

/* --------------------------------------------------------------------------
   Floating viewport UI
   -------------------------------------------------------------------------- */

.factory-coordinates {
  position: absolute;
  z-index: 7;
  left: 14px;
  top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 9px;
  border: 1px solid rgba(106, 199, 193, 0.12);
  border-radius: 5px;
  background: rgba(4, 14, 18, 0.62);
  color: #7fafaa;
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.08em;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.factory-coordinates span:last-child { color: rgba(242, 182, 68, 0.75); }

.factory-floating-tip {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(530px, calc(100% - 760px));
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgba(102, 212, 197, 0.13);
  border-radius: 6px;
  background: rgba(5, 19, 22, 0.75);
  color: #8eaaa2;
  font-size: 8px;
  line-height: 1.6;
  backdrop-filter: blur(9px);
  pointer-events: none;
}

.factory-floating-tip strong { color: var(--cyan); font-weight: 600; }
.factory-floating-tip svg { width: 12px; height: 12px; color: var(--cyan); }

.factory-camera-controls {
  position: absolute;
  z-index: 8;
  left: 14px;
  top: 52px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px;
  border: 1px solid rgba(102, 198, 192, 0.13);
  border-radius: 7px;
  background: rgba(5, 18, 22, 0.7);
  backdrop-filter: blur(8px);
}

.camera-btn {
  display: grid;
  place-items: center;
  width: 29px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: #7f9b98;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.camera-btn:hover {
  color: var(--cyan);
  background: rgba(85, 206, 195, 0.09);
}

.camera-btn.is-active {
  color: var(--cyan);
  border-color: rgba(102, 212, 197, 0.28);
  background: rgba(84, 192, 182, 0.13);
}

.camera-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.camera-separator { height: 1px; margin: 2px 4px; background: rgba(136, 185, 179, 0.12); }

.factory-minimap {
  position: absolute;
  z-index: 8;
  left: 14px;
  bottom: 14px;
  width: 178px;
  height: 94px;
  overflow: hidden;
  border: 1px solid rgba(105, 204, 198, 0.18);
  border-radius: 6px;
  background:
    linear-gradient(rgba(101, 194, 188, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(101, 194, 188, 0.06) 1px, transparent 1px),
    rgba(4, 16, 20, 0.82);
  background-size: 10px 10px, 10px 10px, auto;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.32);
  cursor: crosshair;
  backdrop-filter: blur(8px);
}

.minimap-grid { position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.4); }

.minimap-cells { position: absolute; inset: 7px 7px 14px; }
.mini-cell {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 1px;
  transform: translate(-50%, -50%);
  background: rgba(88, 210, 199, 0.75);
  box-shadow: 0 0 3px rgba(88, 210, 199, 0.45);
}
.mini-cell.intake { width: 5px; height: 5px; border-radius: 50%; background: #6fe7d7; box-shadow: 0 0 7px rgba(111, 231, 215, 0.65); }
.mini-cell.sink { width: 5px; height: 5px; background: var(--gold); box-shadow: 0 0 6px rgba(242, 182, 68, 0.55); }
.mini-cell.belt { width: 2px; height: 2px; opacity: 0.55; }
.mini-cell.machine { width: 4px; height: 4px; border-radius: 0; background: #8dbdb7; }
.mini-cell.miner { width: 5px; height: 5px; border-radius: 0; background: #ffcf6e; box-shadow: 0 0 6px rgba(255, 207, 110, 0.6); }
.mini-cell.ore { width: 4px; height: 4px; border-radius: 50%; background: var(--ore-color, #b79a6a); box-shadow: 0 0 5px var(--ore-color, #b79a6a); opacity: 0.85; }

.minimap-viewport {
  position: absolute;
  z-index: 3;
  min-width: 8px;
  min-height: 8px;
  border: 1px solid rgba(102, 212, 197, 0.5);
  background: rgba(102, 212, 197, 0.055);
  box-shadow: 0 0 9px rgba(102, 212, 197, 0.08);
  pointer-events: none;
}

.minimap-label {
  position: absolute;
  left: 7px;
  bottom: 3px;
  color: rgba(154, 196, 188, 0.5);
  font-family: var(--mono);
  font-size: 5.5px;
  letter-spacing: 0.12em;
}

.factory-camera-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  padding: 6px 10px;
  border: 1px solid rgba(94, 173, 169, 0.1);
  border-radius: 5px;
  background: rgba(4, 15, 18, 0.5);
  color: #6f8581;
  font-family: var(--mono);
  font-size: 6.5px;
  letter-spacing: 0.03em;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(5px);
}

.factory-camera-hint span { display: flex; align-items: center; gap: 4px; }
.factory-camera-hint svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.6; }

/* Ambient traffic over the build site */
.factory-drone {
  position: absolute;
  z-index: 5;
  width: 58px;
  height: 37px;
  pointer-events: none;
  opacity: 0.34;
  filter: brightness(0.8) saturate(0.8) drop-shadow(0 7px 8px rgba(0, 0, 0, 0.3));
  will-change: transform;
}

.factory-drone svg {
  width: 100%;
  height: 100%;
  animation: drone-hover 3.8s ease-in-out infinite;
}

.factory-drone .drone-rotor {
  transform-box: fill-box;
  transform-origin: center;
  animation: drone-rotor 0.2s linear infinite alternate;
}

.factory-drone .drone-rotor-b { animation-direction: alternate-reverse; animation-delay: -0.07s; }

.factory-drone.drone-a {
  top: 16%;
  left: 11%;
  animation: drone-patrol-a 26s ease-in-out infinite;
}

.factory-drone.drone-b {
  top: 12%;
  right: 31%;
  width: 43px;
  height: 28px;
  opacity: 0.24;
  animation: drone-patrol-b 33s ease-in-out infinite;
}

.factory-drone.drone-c {
  left: 29%;
  bottom: 17%;
  width: 34px;
  height: 22px;
  opacity: 0.19;
  animation: drone-patrol-c 22s ease-in-out infinite;
}

@keyframes drone-hover {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-5px) rotate(1deg); }
}

@keyframes drone-rotor {
  to { transform: scaleX(0.35); opacity: 0.35; }
}

@keyframes drone-patrol-a {
  0%, 100% { transform: translate(0, 0); }
  28% { transform: translate(86px, -16px); }
  57% { transform: translate(34px, 42px); }
  80% { transform: translate(-42px, -4px); }
}

@keyframes drone-patrol-b {
  0%, 100% { transform: translate(0, 0); }
  34% { transform: translate(-102px, 34px); }
  65% { transform: translate(-20px, 76px); }
}

@keyframes drone-patrol-c {
  0%, 100% { transform: translate(0, 0); }
  42% { transform: translate(128px, -18px); }
  74% { transform: translate(46px, -50px); }
}

.factory-drone .art-blink { animation-duration: 1.5s; }

/* Live process effects on working machinery */
.factory-cell.is-machine .machine-slot::before,
.factory-cell.is-machine .machine-slot::after {
  content: "";
  position: absolute;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
}

.factory-cell.is-machine.is-running .machine-slot::after {
  right: 19%;
  bottom: 22%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: radial-gradient(circle, #bafff2, rgba(79, 220, 203, 0.18) 60%, transparent 70%);
  box-shadow:
    0 0 5px rgba(129, 255, 236, 0.5),
    -6px -3px 0 -1px rgba(145, 255, 237, 0.25),
    5px -7px 0 -1px rgba(145, 255, 237, 0.16);
  animation: factoryMachineSpark 1.9s ease-out infinite;
}

.factory-cell.is-machine.is-running .machine-slot::before {
  left: 48%;
  bottom: 47%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(189, 241, 229, 0.38), transparent 68%);
  filter: blur(1px);
  animation: factoryMachineExhaust 2.8s ease-out infinite;
}

.factory-cell.is-machine[data-type="refiner"].is-running .machine-slot::after,
.factory-cell.is-machine[data-type="dieselGen"].is-running .machine-slot::after,
.factory-cell.is-machine[data-type="coalGen"].is-running .machine-slot::after {
  background: radial-gradient(circle, #ffda8f, rgba(242, 151, 66, 0.2) 58%, transparent 72%);
  box-shadow:
    0 0 6px rgba(255, 184, 89, 0.55),
    -5px -4px 0 -1px rgba(255, 185, 88, 0.24),
    4px -8px 0 -1px rgba(255, 185, 88, 0.16);
}

.factory-cell.is-machine[data-type="compressor"].is-running .machine-slot::before,
.factory-cell.is-machine[data-type="coalGen"].is-running .machine-slot::before {
  width: 10px;
  height: 10px;
  background: radial-gradient(circle, rgba(146, 162, 158, 0.3), transparent 68%);
  animation-duration: 3.4s;
}

.factory-cell.is-machine[data-type="purifier"].is-running .machine-slot::after {
  background: radial-gradient(circle, #c5fff7, rgba(122, 237, 255, 0.22) 58%, transparent 72%);
}

@keyframes factoryMachineSpark {
  0% { opacity: 0; transform: translateY(2px) scale(0.7); }
  18% { opacity: 0.9; }
  100% { opacity: 0; transform: translateY(-19px) translateX(5px) scale(0.2); }
}

@keyframes factoryMachineExhaust {
  0% { opacity: 0; transform: translateY(4px) scale(0.55); }
  25% { opacity: 0.65; }
  100% { opacity: 0; transform: translateY(-24px) translateX(-6px) scale(1.8); }
}

/* Deep pulse is a mining-site effect only; the build deck stays neutral. */

@media (max-width: 760px) {
  .factory-background-planet { opacity: 0.16; }
  .factory-drone.drone-a { width: 38px; height: 24px; opacity: 0.24; }
  .factory-drone.drone-b,
  .factory-drone.drone-c { display: none; }
}

/* --------------------------------------------------------------------------
   Information dock
   -------------------------------------------------------------------------- */

.factory-dock {
  position: absolute;
  z-index: 9;
  right: 14px;
  top: 14px;
  bottom: auto;
  width: 306px;
  max-height: calc(100% - 28px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(104, 195, 189, 0.18);
  border-radius: 11px;
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.04), transparent 29%),
    rgba(6, 22, 27, 0.9);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(16px);
  transform: translateX(calc(100% + 18px));
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

.factory-screen.is-dock-open .factory-dock {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.factory-dock-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px;
  border-bottom: 1px solid rgba(130, 191, 184, 0.11);
  background: rgba(5, 17, 20, 0.45);
}

.factory-dock-tabs { display: flex; gap: 3px; }

.factory-dock-tabs button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: #78928e;
  font-size: 8.5px;
  cursor: pointer;
}

.factory-dock-tabs button svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.factory-dock-tabs button:hover { color: #d4e5df; }
.factory-dock-tabs button.is-active {
  border-color: rgba(102, 212, 197, 0.18);
  background: rgba(86, 199, 189, 0.11);
  color: #dff8f1;
}

.factory-dock-close { display: grid; width: 25px; height: 25px; }
.factory-dock-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(106, 180, 174, 0.3) transparent;
}

.factory-dock-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 0;
  color: #e4f1eb;
  font-size: 10px;
  font-weight: 600;
}

.factory-dock-title small {
  color: #526c68;
  font-family: var(--mono);
  font-size: 6px;
  font-weight: 400;
  letter-spacing: 0.08em;
}

.factory-dock-panel .panel-head { display: none; }
.factory-dock-panel .panel-body { padding: 10px 12px 12px; }
.factory-dock-panel .power-dashboard { padding: 10px 12px 12px; }
.factory-dock-panel .grid-meter-top strong { font-size: 22px; color: #f0faf5; }
.factory-dock-panel .grid-meter-top strong small { color: #76908b; }
.factory-dock-panel .grid-meter-top span { color: #85a19c; }

.factory-dock .inspector-head { align-items: flex-start; }
.factory-dock .inspector-art {
  width: 69px;
  height: 58px;
  border-color: rgba(113, 189, 183, 0.15);
  background: #081519;
}
.factory-dock .inspector-art svg { width: 64px; height: 54px; }
.factory-dock .inspector-empty { padding: 28px 15px; line-height: 1.8; }
.factory-dock .inspector-warning {
  border-color: rgba(230, 123, 93, 0.19);
  background: rgba(176, 69, 42, 0.12);
  color: #e7aa93;
}
.factory-dock .inspector-stats { gap: 4px; }
.factory-dock .inspector-stat { background: rgba(255, 255, 255, 0.018); }
.factory-dock .inspector-actions .btn { font-size: 8.5px; }
.factory-dock .rail-note { font-size: 8px; }
.factory-dock .panel-section + .panel-section { border-top-color: rgba(120, 180, 173, 0.1); }
.factory-dock .power-source-list { margin-top: 7px; }
.factory-dock .power-source-row { color: #869f9a; }
.factory-dock .power-source-row strong { color: #c7ded8; }
.factory-dock .bill-line { background: rgba(255, 255, 255, 0.02); }
.factory-dock .fuel-mini { border-color: rgba(117, 177, 171, 0.1); background: rgba(255, 255, 255, 0.016); }
.factory-dock .fuel-mini strong { color: #cfdfda; }

/* --------------------------------------------------------------------------
   Build hotbar
   -------------------------------------------------------------------------- */

.factory-hotbar {
  position: relative;
  z-index: 12;
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  gap: 9px;
  min-height: 95px;
  padding: 8px 9px;
  border: 1px solid rgba(103, 194, 187, 0.14);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.028), transparent 60%),
    rgba(5, 17, 21, 0.9);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.13);
}

.hotbar-label {
  flex: 0 0 112px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding-left: 5px;
  border-right: 1px solid rgba(117, 178, 171, 0.1);
}

.build-cat-tabs {
  display: flex;
  gap: 2px;
}

.build-cat-btn {
  flex: 1;
  min-width: 0;
  padding: 2px 1px;
  border: 1px solid rgba(112, 181, 172, 0.13);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.018);
  color: #667f7a;
  font-family: var(--mono);
  font-size: 5.5px;
  line-height: 1.4;
  cursor: pointer;
}

.build-cat-btn:hover { color: #d7c07b; border-color: rgba(242, 182, 68, 0.28); }
.build-cat-btn.is-active {
  color: #f1d38a;
  border-color: rgba(242, 182, 68, 0.42);
  background: rgba(242, 182, 68, 0.08);
}

.hotbar-label span {
  color: #516a66;
  font-family: var(--mono);
  font-size: 6.5px;
  letter-spacing: 0.16em;
}

.hotbar-label strong {
  color: #c7ded7;
  font-size: 9px;
  font-weight: 500;
  line-height: 1.4;
}

.hotbar-cards {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: stretch;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(94, 166, 160, 0.25) transparent;
}

.factory-copy-hud {
  position: absolute;
  z-index: 24;
  left: 50%;
  bottom: 74px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(680px, calc(100% - 32px));
  padding: 8px 12px;
  border: 1px solid rgba(242, 182, 68, 0.35);
  border-radius: 6px;
  background: rgba(7, 18, 20, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.factory-copy-hud[hidden] { display: none; }
.factory-copy-hud strong {
  flex: 0 0 auto;
  color: #f4d28b;
  font-size: 9px;
  font-weight: 600;
}
.factory-copy-hud span {
  overflow: hidden;
  color: #b8d7cf;
  font-family: var(--mono);
  font-size: 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.factory-copy-hud small {
  flex: 0 0 auto;
  color: #7b9a92;
  font-family: var(--mono);
  font-size: 6px;
  white-space: nowrap;
}
.factory-cell.is-copy-selected {
  outline: 2px solid rgba(242, 182, 68, 0.8);
  outline-offset: -2px;
  background: rgba(242, 182, 68, 0.12);
}
.factory-board.is-selecting { cursor: crosshair; }
.factory-board.is-pasting { cursor: copy; }
.factory-cell.is-paste-preview {
  outline: 2px solid rgba(99, 218, 203, 0.6);
  outline-offset: -2px;
  background: rgba(77, 184, 170, 0.12);
}
.factory-cell.is-paste-preview.is-paste-invalid {
  outline-color: rgba(231, 107, 91, 0.8);
  background: rgba(183, 62, 49, 0.16);
}
@media (max-width: 680px) {
  .factory-copy-hud { bottom: 64px; flex-wrap: wrap; gap: 4px 8px; }
  .factory-copy-hud small { width: 100%; }
}

.factory-hotbar .build-card {
  position: relative;
  flex: 0 0 92px;
  min-width: 92px;
  max-width: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 5px 5px;
  border: 1px solid rgba(108, 177, 171, 0.1);
  border-radius: 6px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.026), transparent 48%),
    rgba(13, 32, 37, 0.65);
  color: #7f9893;
  text-align: center;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.factory-hotbar .build-card { touch-action: none; user-select: none; cursor: grab; }
.factory-hotbar .build-card:active { cursor: grabbing; }
.factory-palette-drag-visual { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.factory-palette-drag-line { position: absolute; height: 2px; transform-origin: 0 50%; background: rgba(126, 239, 213, 0.85); box-shadow: 0 0 8px rgba(126, 239, 213, 0.55); }
.factory-palette-drag-device { position: absolute; transform: translate(-50%, -50%); padding: 7px 10px; border: 1px solid rgba(126, 239, 213, 0.7); border-radius: 4px; background: rgba(8, 28, 29, 0.92); color: #d8fff3; font: 9px var(--mono); box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.factory-hotbar .build-card:hover {
  border-color: rgba(108, 218, 206, 0.35);
  background: rgba(22, 55, 59, 0.7);
  transform: translateY(-1px);
}

.factory-hotbar .build-card.is-active {
  border-color: rgba(115, 234, 220, 0.66);
  background:
    linear-gradient(160deg, rgba(95, 220, 207, 0.13), transparent 60%),
    rgba(18, 47, 51, 0.86);
  color: #ecfffa;
  box-shadow: inset 0 0 0 1px rgba(100, 222, 209, 0.1), 0 0 18px rgba(77, 200, 188, 0.08);
}

.factory-hotbar .build-card.is-out { opacity: 0.65; }
.factory-hotbar .build-card.is-active.is-out { opacity: 0.85; }
.factory-hotbar .hotkey {
  position: absolute;
  left: 4px;
  top: 4px;
  display: grid;
  place-items: center;
  min-width: 11px;
  height: 11px;
  padding: 0 2px;
  border: 1px solid rgba(122, 185, 178, 0.16);
  border-radius: 2px;
  color: #637d78;
  background: rgba(3, 13, 15, 0.5);
  font-family: var(--mono);
  font-size: 5.5px;
  font-weight: 400;
}

.factory-hotbar .build-stock {
  position: absolute;
  right: 4px;
  top: 4px;
  min-width: 13px;
  padding: 1px 3px;
  border: 0;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.35);
  color: #8ca49e;
  font-family: var(--mono);
  font-size: 6px;
}

.factory-hotbar .build-stock.zero { color: #e88d7f; }

.factory-hotbar .build-art {
  width: 46px;
  height: 38px;
  display: grid;
  place-items: center;
  overflow: hidden;
  filter: brightness(1.14) saturate(1.08);
}

.factory-hotbar .build-card strong {
  display: block;
  width: 100%;
  overflow: hidden;
  color: #c6dad3;
  font-size: 9px;
  font-weight: 500;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.factory-hotbar .build-card.is-active strong { color: #f3fffb; }
.factory-hotbar .build-meta {
  display: flex;
  gap: 3px;
  color: #728b85;
  font-family: var(--mono);
  font-size: 6.8px;
  white-space: nowrap;
}

.factory-hotbar .build-meta b { color: #cba761; font-weight: 500; }
.factory-hotbar .build-quick-buy {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 12px;
  height: 12px;
  border: 1px solid rgba(122, 182, 176, 0.18);
  border-radius: 2px;
  background: rgba(12, 34, 37, 0.9);
  color: #b0a16f;
  font-family: var(--mono);
  font-size: 8px;
  line-height: 9px;
  cursor: pointer;
}

.factory-hotbar .build-quick-buy:hover {
  border-color: rgba(242, 182, 68, 0.4);
  background: rgba(242, 182, 68, 0.12);
  color: var(--gold);
}

.hotbar-side {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding-left: 2px;
  border-left: 1px solid rgba(117, 178, 171, 0.1);
}

.hotbar-tool {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 7px;
  border: 1px solid rgba(113, 180, 173, 0.13);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.018);
  color: #829c96;
  cursor: pointer;
}

.hotbar-tool:hover { color: var(--gold); border-color: rgba(242, 182, 68, 0.24); }
.hotbar-tool svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.hotbar-tool span { color: #dfc078; font-family: var(--mono); font-size: 11px; }
.hotbar-tool kbd {
  padding: 1px 3px;
  border: 1px solid rgba(125, 181, 174, 0.16);
  border-radius: 2px;
  color: #6d857f;
  font-family: var(--mono);
  font-size: 5.5px;
}

.hotbar-dir {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hotbar-dir-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: #819d96;
  font-family: var(--mono);
  font-size: 5.5px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.hotbar-dir-label kbd {
  padding: 0 2px;
  border: 1px solid rgba(124, 186, 177, 0.16);
  border-radius: 2px;
  color: #a5bdb5;
  font-size: 5.5px;
}

.hotbar-dir-row {
  display: flex;
  gap: 3px;
}

.hotbar-dir-btn,
.dir-btn {
  display: grid;
  place-items: center;
  width: 22px;
  height: 21px;
  padding: 0;
  border: 1px solid rgba(112, 181, 172, 0.14);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.018);
  color: #6e8b85;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.hotbar-dir-btn:hover,
.dir-btn:hover {
  color: #e1c47d;
  border-color: rgba(242, 182, 68, 0.3);
}

.hotbar-dir-btn.is-active,
.dir-btn.is-active {
  color: #f4d27c;
  border-color: rgba(242, 182, 68, 0.45);
  background: rgba(242, 182, 68, 0.1);
  box-shadow: inset 0 0 8px rgba(242, 182, 68, 0.06);
}

.factory-build-dir {
  display: none;
}

@media (max-width: 1020px) {
  .factory-build-dir.is-visible {
    position: absolute;
    z-index: 9;
    right: 10px;
    bottom: 11px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 5px 4px 7px;
    border: 1px solid rgba(113, 191, 181, 0.22);
    border-radius: 4px;
    background: rgba(6, 22, 25, 0.86);
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(6px);
  }

  .factory-build-dir > span {
    color: #84a39c;
    font-family: var(--mono);
    font-size: 5.5px;
    letter-spacing: 0.04em;
    white-space: nowrap;
  }

  .factory-build-dir-row {
    display: flex;
    gap: 3px;
  }

  .factory-build-dir .dir-btn {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
}

/* Build direction preview over empty cells */
.factory-board.is-painting[data-build-dir="right"] .factory-cell.is-empty:hover::after,
.factory-board.is-painting[data-build-dir="down"] .factory-cell.is-empty:hover::after,
.factory-board.is-painting[data-build-dir="left"] .factory-cell.is-empty:hover::after,
.factory-board.is-painting[data-build-dir="up"] .factory-cell.is-empty:hover::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(242, 182, 68, 0.4));
}

.factory-board.is-painting[data-build-dir="right"] .factory-cell.is-empty:hover::after {
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  border-left: 7px solid rgba(247, 207, 118, 0.92);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

.factory-board.is-painting[data-build-dir="left"] .factory-cell.is-empty:hover::after {
  left: 7px;
  top: 50%;
  transform: translateY(-50%);
  border-right: 7px solid rgba(247, 207, 118, 0.92);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

.factory-board.is-painting[data-build-dir="up"] .factory-cell.is-empty:hover::after {
  left: 50%;
  top: 7px;
  transform: translateX(-50%);
  border-bottom: 7px solid rgba(247, 207, 118, 0.92);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.factory-board.is-painting[data-build-dir="down"] .factory-cell.is-empty:hover::after {
  left: 50%;
  bottom: 7px;
  transform: translateX(-50%);
  border-top: 7px solid rgba(247, 207, 118, 0.92);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}

.hotbar-keys {
  color: #586f6a;
  font-family: var(--mono);
  font-size: 5.5px;
  line-height: 1.7;
  white-space: nowrap;
}

.hotbar-keys kbd {
  padding: 0 2px;
  border: 1px solid rgba(122, 178, 171, 0.14);
  border-radius: 2px;
  color: #829791;
  font-size: 5.5px;
}

/* Tooltip/tip palette within the new factory */
.factory-floating-tip > svg {
  flex: 0 0 auto;
  color: var(--cyan);
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1280px) {
  .factory-dock { width: 286px; }
  .factory-floating-tip { max-width: min(440px, calc(100% - 620px)); }
  .factory-location { min-width: 170px; }
  .factory-location strong { font-size: 11px; }
  .factory-location span { font-size: 6.5px; }
}

@media (max-width: 1020px) {
  .factory-location > .factory-site-chip { display: none; }
  .view-root[data-page="factory"] {
    height: calc(100dvh - var(--topbar-h) - 64px);
    overflow: hidden;
  }

  .factory-screen {
    height: calc(100dvh - var(--topbar-h) - 64px);
    min-height: 0;
    padding: 8px 9px 8px;
    gap: 6px;
    --cell-w: 52px;
    --cell-h: 42px;
  }

  .factory-topline {
    gap: 7px;
    min-height: 36px;
  }

  .factory-location { min-width: 0; gap: 6px; }
  .factory-location-icon { width: 27px; height: 27px; }
  .factory-location-icon svg { width: 15px; height: 15px; }
  .factory-location strong { font-size: 10px; }
  .factory-location span { display: none; }
  .factory-mode-switch .mode-btn { min-width: 34px; padding: 5px 7px; font-size: 8px; }
  .factory-topline .pill { display: none; }
  .factory-icon-btn { width: 27px; height: 27px; }
  .factory-icon-btn[data-action="reclaim-line"],
  .factory-icon-btn[data-view="shop"],
  .factory-icon-btn[data-action="camera-reset"] { display: none; }
  .factory-dock-toggle { display: grid; }

  .factory-viewport { border-radius: 10px; }
  .factory-coordinates { left: 8px; top: 8px; font-size: 6px; padding: 4px 6px; gap: 7px; }
  .factory-floating-tip { display: none; }
  .factory-camera-controls { left: 8px; top: 38px; padding: 3px; gap: 2px; }
  .camera-btn { width: 26px; height: 25px; }
  .camera-btn svg { width: 13px; height: 13px; }
  .factory-minimap { display: none; }
  .factory-camera-hint { display: none; }

  .factory-dock {
    right: 7px;
    top: 7px;
    bottom: auto;
    width: min(306px, calc(100vw - 24px));
    max-height: calc(100% - 14px);
    transform: translateX(calc(100% + 18px));
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s ease, opacity 0.22s ease;
  }

  .factory-screen.is-dock-open .factory-dock {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .factory-dock-close { display: grid; }

  .factory-hotbar {
    min-height: 87px;
    padding: 6px 7px;
    gap: 6px;
  }

  .hotbar-label {
    display: flex;
    flex: 0 0 58px;
    padding-left: 2px;
    gap: 2px;
  }
  .hotbar-label > span,
  .hotbar-label > strong { display: none; }
  .build-cat-tabs { flex-direction: column; gap: 2px; }
  .build-cat-btn { flex: 0 0 auto; padding: 5px 2px; font-size: 5.5px; }
  .hotbar-side { display: none; }
  .factory-hotbar .build-card {
    flex-basis: 76px;
    min-width: 76px;
    max-width: 76px;
    padding-top: 6px;
  }
  .factory-hotbar .build-art { width: 37px; height: 31px; }
  .factory-hotbar .build-card strong { font-size: 7.5px; }
  .factory-hotbar .build-meta { font-size: 5.7px; }
  .factory-hotbar .hotkey { display: none; }
}

@media (max-width: 760px) {
  .factory-topline {
    display: grid;
    grid-template-columns: 27px minmax(0, 1fr) 27px;
    grid-template-areas: "location modes dock";
    gap: 8px;
    align-items: center;
  }

  .factory-location { grid-area: location; display: flex; min-width: 0; }
  .factory-location > div:last-child { display: none; }
  .factory-location-icon { width: 27px; height: 27px; }
  .factory-head-spacer,
  .factory-topline > .pill,
  .factory-icon-btn[data-action="reclaim-line"],
  .factory-icon-btn[data-view="shop"],
  .factory-icon-btn[data-action="camera-reset"] { display: none; }

  .factory-mode-switch {
    grid-area: modes;
    width: 100%;
    max-width: 224px;
    justify-self: center;
    display: flex;
  }

  .factory-mode-switch .mode-btn { flex: 1; min-width: 0; text-align: center; }
  .factory-dock-toggle { grid-area: dock; display: grid; }
}

/* Pipe transport */
.factory-cell.is-pipe {
  border-color: rgba(134, 189, 174, 0.22);
  background:
    linear-gradient(180deg, rgba(91, 164, 151, 0.055), transparent 60%),
    rgba(12, 34, 34, 0.5);
}

.factory-cell.is-pipe .belt-bed {
  inset: 34% 0;
  border-top: 1px solid rgba(173, 225, 202, 0.42);
  border-bottom: 1px solid rgba(4, 17, 16, 0.8);
  background:
    repeating-linear-gradient(90deg, transparent 0 10px, rgba(9, 30, 27, 0.55) 10px 12px),
    linear-gradient(180deg, #527a6c, #24433e 52%, #19312e);
  box-shadow: inset 0 2px 3px rgba(214, 255, 229, 0.1);
}

.factory-cell.is-pipe .belt-motion {
  height: 10%;
  background: repeating-linear-gradient(90deg, transparent 0 9px, rgba(177, 239, 185, 0.45) 9px 11px, transparent 11px 18px);
  opacity: 0.55;
}

.factory-cell.is-pipe[data-dir="up"] .belt-bed,
.factory-cell.is-pipe[data-dir="down"] .belt-bed {
  inset: 0 34%;
  border-top: 0;
  border-bottom: 0;
  border-left: 1px solid rgba(173, 225, 202, 0.42);
  border-right: 1px solid rgba(4, 17, 16, 0.8);
  background:
    repeating-linear-gradient(0deg, transparent 0 10px, rgba(9, 30, 27, 0.55) 10px 12px),
    linear-gradient(90deg, #527a6c, #24433e 52%, #19312e);
}

.factory-cell.is-pipe .belt-arrow { opacity: 0.8; }

@media (max-width: 520px) {
  .factory-mode-switch .mode-btn { min-width: 29px; padding: 5px 5px; font-size: 7.5px; }
  .factory-coordinates { display: none; }
  .factory-camera-controls { top: 8px; }
  .factory-hotbar .build-card { flex-basis: 72px; min-width: 72px; max-width: 72px; }
  .factory-hotbar .build-art { width: 35px; height: 30px; }
  .factory-hotbar .build-card strong { font-size: 7.2px; }
  .factory-hotbar .build-meta { font-size: 5.6px; }
}


/* --- bitmap FX: machine steam / power arc / lithography beam --------------- */
.factory-cell.is-machine[data-type="refiner"].is-running .machine-slot::after,
.factory-cell.is-machine[data-type="dieselGen"].is-running .machine-slot::after,
.factory-cell.is-machine[data-type="coalGen"].is-running .machine-slot::after {
  right: 6%;
  bottom: 24%;
  width: 34px;
  height: 34px;
  border-radius: 0;
  background: url("https://renderfarm-1389434004.cos.ap-shanghai.myqcloud.com/deep-vein/assets/6ee7770a2c39870fdd736754d1c219545f145f843826955abffca39cdcc87440/fx/machine-steam.webp") no-repeat;
  background-size: 1600% 100%;
  background-position: 0% 0;
  box-shadow: none;
  opacity: 1;
  mix-blend-mode: normal;
  animation: fxStripLoop 2.8s steps(15, end) infinite;
}



/* --- logistics buildings / pumps / reactor (bitmap) ------------------------ */
.logistics-cell-art img.logistics-art {
  width: 90%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.34));
}

.factory-cell.is-hub-large .logistics-cell-art img.logistics-art {
  width: 96%;
  height: 93%;
  filter: brightness(1.08) saturate(1.08) drop-shadow(0 4px 5px rgba(0, 0, 0, 0.38));
}

/* --- terrain board: green cell hover feedback ------------------------------ */
@media (hover: hover) {
  .factory-board .factory-cell:hover:not(.is-selected):not(.is-paste-preview) {
    outline: 2px solid rgba(112, 255, 166, 0.95);
    outline-offset: -2px;
    z-index: 8;
  }

  .factory-board:not(.is-demolishing) .factory-cell.is-empty:hover:not(.is-selected):not(.is-paste-preview) {
    background-color: rgba(74, 222, 128, 0.14);
    box-shadow: inset 0 0 14px rgba(74, 222, 128, 0.16);
  }

  .factory-board.is-demolishing .factory-cell:hover:not(.is-selected):not(.is-paste-preview) {
    outline-color: rgba(255, 108, 104, 0.95);
  }
}


/* ==========================================================================
   Ore veins & mining machines (factory-integrated mining)
   ========================================================================== */

/* Ore deposits are terrain: a rock plate exactly one machine cell wide, masked
   at the edges so it melts into the board texture instead of reading as a tile. */
.factory-cell.is-ore-node {
  z-index: 1;
  overflow: visible;
}

.factory-cell.is-ore-node .ore-texture {
  position: absolute;
  inset: -2px;
  border-radius: 5px;
  background-image: var(--ore-tex);
  background-repeat: no-repeat;
  background-size: 175% 175%;
  background-position: var(--ore-x, 40%) var(--ore-y, 40%);
  filter: saturate(0.66) contrast(0.96) brightness(0.8);
  -webkit-mask-image: radial-gradient(ellipse at 50% 50%, #000 42%, rgba(0, 0, 0, 0.78) 62%, transparent 86%);
  mask-image: radial-gradient(ellipse at 50% 50%, #000 42%, rgba(0, 0, 0, 0.78) 62%, transparent 86%);
  box-shadow: inset 0 0 12px 6px rgba(58, 45, 30, 0.38);
  transition: filter 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.factory-cell.is-ore-node .ore-rim {
  position: absolute;
  inset: 3px;
  border-radius: 4px;
  box-shadow: inset 0 0 14px var(--ore-color, #e8c98a);
  opacity: 0.38;
  pointer-events: none;
}

.factory-cell.is-ore-node .ore-vein-tag {
  position: absolute;
  z-index: 4;
  left: 1px;
  bottom: 1px;
  display: flex;
  align-items: baseline;
  gap: 3px;
  max-width: calc(100% - 2px);
  padding: 1px 3px;
  border-left: 2px solid var(--ore-color, #e8c98a);
  border-radius: 2px;
  background: rgba(5, 12, 10, 0.82);
  color: #e6f1e8;
  font-family: var(--mono);
  font-size: 6px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.14s ease, transform 0.14s ease;
  pointer-events: none;
}

.factory-cell.is-ore-node .ore-vein-tag b {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.factory-cell.is-ore-node .ore-vein-tag small {
  color: #ffd775;
  font-size: 5.8px;
  letter-spacing: 0.02em;
}

.factory-cell.is-ore-node:hover .ore-vein-tag,
.factory-cell.is-ore-node.is-selected .ore-vein-tag {
  opacity: 1;
  transform: none;
}

.factory-cell.is-ore-node:hover .ore-texture {
  filter: saturate(0.78) contrast(1) brightness(0.86);
}

.factory-cell.is-ore-node .ore-tier {
  position: absolute;
  z-index: 4;
  top: 1px;
  right: 1px;
  padding: 0 2px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 2px;
  background: rgba(4, 10, 9, 0.72);
  font-family: var(--mono);
  font-size: 5.4px;
  line-height: 1.5;
  letter-spacing: 0.04em;
  color: #c6d6cc;
  pointer-events: none;
}

.factory-cell.is-ore-node .ore-tier.tier-1 { color: #b9c9b1; border-color: rgba(185, 201, 177, 0.4); }
.factory-cell.is-ore-node .ore-tier.tier-2 { color: #8fe0ff; border-color: rgba(143, 224, 255, 0.45); }
.factory-cell.is-ore-node .ore-tier.tier-3 { color: #ffcf6e; border-color: rgba(255, 207, 110, 0.5); }
.factory-cell.is-ore-node .ore-tier.tier-4 { color: #d4b0ff; border-color: rgba(212, 176, 255, 0.5); }

.factory-cell.is-ore-node.is-ore-locked .ore-texture {
  filter: grayscale(0.65) brightness(0.6);
}

.factory-cell.is-ore-node .ore-lock {
  position: absolute;
  z-index: 4;
  left: 2px;
  top: 2px;
  padding: 0 2px;
  border-radius: 2px;
  background: rgba(96, 20, 20, 0.85);
  color: #ffb1a6;
  font-family: var(--mono);
  font-size: 5.2px;
  letter-spacing: 0.04em;
}

/* Objects standing on a vein keep a tiny ore-coloured beacon. */
.factory-cell .ore-underlay-dot {
  position: absolute;
  z-index: 6;
  right: 3px;
  bottom: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ore-color, #e8c98a);
  box-shadow: 0 0 6px var(--ore-color, #e8c98a);
  opacity: 0.75;
  pointer-events: none;
}

/* --- Mining machines ------------------------------------------------------ */

.factory-cell.is-miner {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.factory-cell.is-miner .machine-slot {
  inset: 0 0 9px;
  z-index: 2;
}

.factory-cell.is-miner .miner-vein-glow {
  position: absolute;
  z-index: 1;
  left: 14%;
  right: 14%;
  bottom: 1px;
  height: 34%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 100%, var(--ore-color, #e8c98a), transparent 70%);
  opacity: 0.32;
  filter: blur(2px);
  pointer-events: none;
}

.factory-cell.is-miner .rig-art {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(1.16) saturate(1.1) drop-shadow(0 3px 3px rgba(0, 0, 0, 0.4));
}

.factory-cell.is-miner.is-running .rig-art {
  filter: brightness(1.22) saturate(1.16) drop-shadow(0 0 7px rgba(242, 182, 68, 0.26)) drop-shadow(0 3px 3px rgba(0, 0, 0, 0.4));
}

.factory-cell.is-miner.is-running .machine-slot {
  animation: factoryMinerHum 2.6s ease-in-out infinite;
}

.factory-cell.is-miner.is-mining .machine-slot {
  animation: factoryMinerHit 0.34s ease;
}

@keyframes factoryMinerHum {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-0.8px); }
}

@keyframes factoryMinerHit {
  0% { transform: translateY(0) scale(1); }
  35% { transform: translateY(1.4px) scale(0.985); }
  100% { transform: translateY(0) scale(1); }
}

.factory-cell.is-miner .machine-badge-row {
  gap: 2px;
}

.factory-cell.is-miner .miner-ore-chip {
  position: absolute;
  z-index: 5;
  left: 3px;
  right: 3px;
  bottom: 13px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 3px;
  font-family: var(--mono);
  font-size: 5.9px;
  line-height: 1.2;
  color: #dbe9e0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
}

.factory-cell.is-miner .miner-ore-chip b {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #d7e9dc;
}

.factory-cell.is-miner .miner-ore-chip i {
  font-style: normal;
  color: #ffd775;
  font-size: 5.5px;
  opacity: 0.9;
}

.factory-cell.is-miner .miner-ore-chip.is-barren { color: #93a79b; }
.factory-cell.is-miner .miner-ore-chip.is-deep { color: #ffb27a; }

.factory-cell.is-miner .miner-ore-bar {
  position: absolute;
  z-index: 5;
  left: 4px;
  right: 4px;
  bottom: 10px;
  height: 2px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.factory-cell.is-miner .miner-ore-bar i {
  display: block;
  height: 100%;
  background: #8bd8a4;
  opacity: 0.9;
  transition: width 0.3s linear;
}

.factory-cell.is-miner .miner-out-chip {
  position: absolute;
  z-index: 5;
  right: 2px;
  top: 12px;
  padding: 0 2px;
  border-radius: 2px;
  background: rgba(6, 16, 15, 0.8);
  color: #ffd775;
  font-family: var(--mono);
  font-size: 5.4px;
  line-height: 1.5;
  pointer-events: none;
}

.factory-cell .machine-prolif {
  position: absolute;
  z-index: 7;
  top: 2px;
  right: 2px;
  padding: 0 3px;
  border: 1px solid rgba(155, 228, 111, 0.5);
  border-radius: 2px;
  background: rgba(30, 56, 30, 0.9);
  color: #cbffae;
  font-family: var(--mono);
  font-size: 5.4px;
  line-height: 1.5;
  letter-spacing: 0.03em;
}

/* --- Manual mining mode --------------------------------------------------- */

.factory-board.is-manual-mining,
.factory-board.is-manual-mining .factory-cell {
  cursor: crosshair;
}

.factory-board.is-manual-mining .factory-cell.is-machine,
.factory-board.is-manual-mining .factory-cell.is-belt,
.factory-board.is-manual-mining .factory-cell.is-logistics {
  cursor: pointer;
}

@media (hover: hover) {
  .factory-board.is-manual-mining .factory-cell:hover:not(.is-selected) {
    outline-color: rgba(242, 182, 68, 0.95);
  }

  .factory-board.is-manual-mining .factory-cell.is-empty:hover:not(.is-selected) {
    background-color: rgba(242, 182, 68, 0.12);
    box-shadow: inset 0 0 16px rgba(242, 182, 68, 0.18);
  }

  .factory-board.is-manual-mining .factory-cell.is-machine:hover:not(.is-selected) {
    outline-color: rgba(255, 118, 108, 0.95);
  }
}

/* Pick-hit effects. Positions come from the real cell box, so the burst never
   grows larger than one factory cell at the current zoom level. */
.mine-burst {
  position: fixed;
  z-index: 70;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid var(--burst-color, #e8c98a);
  opacity: 0.9;
  pointer-events: none;
  animation: mineBurst 0.62s ease-out forwards;
}

@keyframes mineBurst {
  0% { transform: translate(-50%, -50%) scale(0.22); opacity: 0.95; }
  100% { transform: translate(-50%, -50%) scale(1.18); opacity: 0; }
}

.mine-pop {
  position: fixed;
  z-index: 71;
  transform: translate(-50%, -50%);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--burst-color, #ffe8b0);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  white-space: nowrap;
  animation: minePop 0.9s ease-out forwards;
}

@keyframes minePop {
  0% { transform: translate(-50%, -50%) scale(0.7); opacity: 0; }
  18% { transform: translate(-50%, -64%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -150%) scale(0.95); opacity: 0; }
}

.factory-cell.is-ore-depleted .ore-texture {
  animation: oreDepletedFade 0.4s ease forwards;
}

@keyframes oreDepletedFade {
  to { filter: grayscale(1) brightness(0.3); opacity: 0.25; }
}

/* --- Header / dock additions --------------------------------------------- */

.factory-mode-switch .mode-btn.manual {
  color: #ffd775;
  border-color: rgba(242, 182, 68, 0.32);
}

.factory-mode-switch .mode-btn.manual svg {
  width: 11px;
  height: 11px;
  margin-right: 1px;
  vertical-align: -1px;
}

.factory-mode-switch .mode-btn.manual.is-active {
  background: linear-gradient(180deg, rgba(242, 182, 68, 0.32), rgba(242, 182, 68, 0.14));
  color: #fff0c8;
  border-color: rgba(242, 182, 68, 0.62);
  box-shadow: 0 0 12px rgba(242, 182, 68, 0.22);
}

.factory-site-chip .ore-respawn-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 2px;
  border-radius: 50%;
  background: #ffd775;
  box-shadow: 0 0 6px rgba(255, 215, 117, 0.8);
  animation: oreRespawnBlink 1.1s ease-in-out infinite;
}

@keyframes oreRespawnBlink {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.factory-dock-tabs {
  flex-wrap: wrap;
}

.factory-contract-section {
  margin-bottom: 14px;
}

.factory-contract-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 7px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(112, 224, 211, 0.14);
  font-size: 9px;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.factory-contract-head small {
  font-family: var(--mono);
  font-size: 6.5px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

.shop-actions-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ore-inspector-art {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background-color: #14110d;
  background-image: var(--ore-tex);
  background-size: 150% 150%;
  background-position: 50% 50%;
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.ore-inspector-art .ore-inspector-texture {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, transparent 22%, var(--ore-color, #e8c98a) 130%);
  opacity: 0.28;
}

.miner-inspector-art {
  display: flex;
  align-items: center;
  justify-content: center;
}

.miner-inspector-art .rig-art {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(1.1) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

@media (max-width: 1180px) {
  .factory-mode-switch .mode-btn.manual svg { display: none; }
}
