/* THE LAB (every Worker Fren) and the FREN MAKER 6900 build bay: the site's enamel panels and phosphor CRTs */
:root {
  --ph: #7dffa6; --ph-2: #3ecf7a; --ph-dim: #1f3a28; --amber: #e0a92a; --rust: #e8703a;
  --crt: #040805; --crt-line: #142319;
}

/* ── THE LAB ── */
.lab-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 2px 4px; }
.lab-counts { display: flex; gap: 6px; flex-wrap: wrap; }
.lab-count {
  display: grid; gap: 1px; min-width: 76px; padding: 5px 9px 4px; background: var(--crt); border-radius: 2px;
  box-shadow: inset 0 0 0 1.5px #090909, inset 0 0 0 2.5px #3a3a38;
}
.lab-count span { font: 8px var(--pixel); letter-spacing: 0.14em; color: #4f6355; }
.lab-count b { font: 600 17px/1.1 var(--mono); color: var(--ph); text-shadow: 0 0 8px rgba(125, 255, 166, 0.45); }
.lab-count.ready b { color: var(--ph); }
.lab-count.building b { color: var(--amber); text-shadow: 0 0 8px rgba(224, 169, 42, 0.4); }
.lab-filters { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.lab-filters button {
  font: 9px var(--pixel); letter-spacing: 0.12em; padding: 7px 9px 6px; cursor: pointer; color: #2b2d2a;
  background: linear-gradient(#ecebe6, #cfcec7); border: 0; border-radius: 2px; box-shadow: 0 2px 0 #121212, inset 0 0 0 1px #121212;
}
.lab-filters button.on { color: var(--ph); background: #0a120c; text-shadow: 0 0 6px rgba(125, 255, 166, 0.6); }
.lab-filters button:active { transform: translateY(1px); box-shadow: 0 1px 0 #121212, inset 0 0 0 1px #121212; }
.lab-note { min-height: 1.2em; font-size: 11px; color: #6f8474; padding: 0 2px; }
.lab-revealall { margin: 2px 0 0; }

.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; margin: 10px 0 12px; }
.lab-tile {
  all: unset; box-sizing: border-box; cursor: pointer; display: grid; gap: 5px; padding: 5px; background: #0b0d0b;
  border-radius: 3px; box-shadow: 0 0 0 2px #121212, 0 3px 0 2px #121212; transition: transform 0.12s, box-shadow 0.12s;
}
.lab-tile:hover, .lab-tile:focus-visible { transform: translateY(-2px); box-shadow: 0 0 0 2px #121212, 0 5px 0 2px #121212, 0 0 18px rgba(125, 255, 166, 0.25); }
.lab-tile.mine { box-shadow: 0 0 0 2px var(--ph-2), 0 3px 0 2px #121212; }
.lab-screen { position: relative; display: block; aspect-ratio: 1; overflow: hidden; background: var(--crt); border-radius: 2px; }
.lab-screen img { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.lab-screen img.pending { opacity: 0.85; }
.lab-screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
}
.lab-scan {
  position: absolute; left: 0; right: 0; height: 22%; top: -22%; pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(224, 169, 42, 0.28), transparent);
  animation: lab-scan 2.4s linear infinite;
}
@keyframes lab-scan { to { top: 100%; } }
.lab-foot { display: flex; align-items: center; gap: 6px; font: 9px var(--pixel); letter-spacing: 0.1em; color: #9fb3a4; }
.lab-foot b { font-weight: 400; color: #e4f5e7; }
.lab-foot em { font-style: normal; color: #061008; background: var(--ph); padding: 1px 4px 0; border-radius: 1px; }
.lab-foot .lamp { margin-left: auto; }
.lab-more { grid-column: 1 / -1; justify-self: center; }

/* lamps: waiting dim, at work amber and blinking, done green, failed rust */
.lamp { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #26302a; box-shadow: inset 0 0 0 1px #0a0a0a; flex: none; }
.lamp.done, .lamp.revealed, .lamp.ready { background: var(--ph); box-shadow: 0 0 8px var(--ph), inset 0 0 0 1px #0a0a0a; }
.lamp.ready { animation: lamp-pulse 1.6s ease-in-out infinite; }
.lamp.work, .lamp.building, .lamp.dispatch { background: var(--amber); box-shadow: 0 0 8px var(--amber), inset 0 0 0 1px #0a0a0a; animation: lamp-blink 0.9s steps(2) infinite; }
.lamp.bad, .lamp.retry { background: var(--rust); box-shadow: 0 0 8px var(--rust), inset 0 0 0 1px #0a0a0a; }
@keyframes lamp-blink { 50% { opacity: 0.35; } }
@keyframes lamp-pulse { 50% { box-shadow: 0 0 2px var(--ph), inset 0 0 0 1px #0a0a0a; } }

/* ── the build bay ── */
dialog.bay { padding: 0; border: 0; background: transparent; max-width: min(940px, 96vw); width: 100%; max-height: 96vh; overflow: auto; color: var(--term-ink, #8fa293); }
@media (min-width: 721px) { .bay-crt { max-height: calc(96vh - 260px); justify-self: center; width: min(100%, calc(96vh - 260px)); } }
.bay-stations { max-height: calc(96vh - 250px); overflow: auto; }
dialog.bay::backdrop { background: rgba(4, 7, 5, 0.78); backdrop-filter: blur(3px); }
.bay-panel { position: relative; width: auto; margin: 0; animation: bay-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes bay-in { from { transform: translateY(14px) scale(0.98); opacity: 0; } }
.bay-x {
  margin-left: auto; font: 11px var(--pixel); cursor: pointer; width: 26px; height: 22px; border: 0; border-radius: 2px;
  background: linear-gradient(#ecebe6, #cfcec7); box-shadow: 0 2px 0 #121212, inset 0 0 0 1px #121212; color: #2b2d2a;
}
.bay-sub { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 8px 4px 10px; font-size: 12px; color: #2b2d2a; }
.bay-sub b { font: 11px var(--pixel); letter-spacing: 0.12em; color: #121212; }
.bay-sub span { color: #4a4d47; }
.bay-sub a { color: #1f6b3d; }
.bay-body { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 720px) { .bay-body { grid-template-columns: 1fr; } }

/* the CRT the fren is printed on */
.bay-crt {
  position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 10px / 12px; background: var(--crt);
  box-shadow: 0 0 0 3px #9d9c96, 0 0 0 6px #121212, inset 0 0 50px rgba(0, 0, 0, 0.85);
}
.bay-crt > * { position: absolute; }
.bay-grid {
  inset: 0; opacity: 0.55;
  background:
    linear-gradient(var(--crt-line) 1px, transparent 1px) 0 0 / 8.333% 8.333%,
    linear-gradient(90deg, var(--crt-line) 1px, transparent 1px) 0 0 / 8.333% 8.333%;
}
.bay-crt.assembled .bay-grid { opacity: 0; transition: opacity 0.6s; }
.bay-pending, .bay-final, .bay-layers, .bay-layers img { inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.bay-layers img { position: absolute; }
.bay-pending { opacity: 0.55; filter: saturate(0.6); transition: opacity 0.4s; }
.bay-pending.fade { opacity: 0.18; }
.bay-final { animation: final-in 0.5s ease-out; }
@keyframes final-in { from { filter: brightness(2.2) saturate(0); } }
.bay-layers img.print { animation: print 1.15s steps(42, end) both; }
@keyframes print { from { clip-path: inset(0 0 100% 0); filter: brightness(1.8) hue-rotate(60deg); } 90% { filter: none; } to { clip-path: inset(0 0 0 0); } }
.bay-layers img.flash { animation: lens 1.15s ease-out both; }
@keyframes lens { 0% { filter: brightness(1); } 18% { filter: brightness(2.6) drop-shadow(0 0 10px var(--ph)); } 100% { filter: none; } }
.bay-head {
  left: 0; right: 0; top: -2px; height: 2px; opacity: 0; pointer-events: none;
  background: var(--ph); box-shadow: 0 0 12px 3px rgba(125, 255, 166, 0.7);
}
.bay-head.run { animation: head 1.15s linear both; }
@keyframes head { 0% { top: 0; opacity: 1; } 96% { opacity: 1; } 100% { top: 100%; opacity: 0; } }
.bay-hud {
  left: 10px; top: 9px; font: 9px var(--pixel); letter-spacing: 0.16em; color: var(--ph);
  text-shadow: 0 0 6px rgba(125, 255, 166, 0.7); background: rgba(4, 8, 5, 0.6); padding: 3px 6px 2px; border-radius: 2px;
}
.bay-stamp {
  right: 14px; bottom: 16px; font: 13px var(--pixel); letter-spacing: 0.14em; color: var(--ph); padding: 7px 10px 5px;
  border: 2px solid var(--ph); border-radius: 3px; transform: rotate(-6deg); background: rgba(4, 8, 5, 0.72);
  text-shadow: 0 0 8px rgba(125, 255, 166, 0.8); box-shadow: 0 0 14px rgba(125, 255, 166, 0.35); animation: stamp 0.35s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}
@keyframes stamp { from { transform: rotate(-6deg) scale(2.2); opacity: 0; } }
.bay-scan {
  inset: 0; pointer-events: none; border-radius: inherit;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px), radial-gradient(120% 120% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55));
}

/* the five stations */
.bay-stations { list-style: none; margin: 0; padding: 10px 12px; display: grid; gap: 6px; align-content: start; background: var(--crt); border-radius: 3px; box-shadow: inset 0 0 0 1.5px #090909, inset 0 0 0 2.5px #3a3a38; }
.bay-st { display: grid; grid-template-columns: 12px auto 1fr; grid-template-areas: "lamp tag name" ". who who" ". why why"; gap: 2px 8px; align-items: center; padding: 7px 4px 8px; border-bottom: 1px dashed #1c2a20; }
.bay-st:last-child { border-bottom: 0; }
.bay-st .lamp { grid-area: lamp; }
.bay-st-tag { grid-area: tag; font: 10px var(--pixel); letter-spacing: 0.12em; color: #e4f5e7; }
.bay-st-name { grid-area: name; font-size: 11px; color: #5d7363; text-align: right; }
.bay-st-who { grid-area: who; font-size: 11px; color: #8fa293; min-height: 1em; }
.bay-st-who b { color: var(--ph); font-weight: 500; }
.bay-st-why { grid-area: why; font-size: 11.5px; line-height: 1.35; color: #c9dccd; font-style: italic; }
.bay-st-why:empty { display: none; }
.bay-st.now { background: linear-gradient(90deg, rgba(224, 169, 42, 0.1), transparent 70%); }
.bay-st[data-state="done"] .bay-st-tag { color: var(--ph); }

/* the log and the action */
.bay-log { list-style: none; margin: 12px 0 0; padding: 7px 10px; min-height: 64px; font-size: 11px; line-height: 1.5; background: var(--crt); border-radius: 3px; color: #6f8474; box-shadow: inset 0 0 0 1.5px #090909, inset 0 0 0 2.5px #3a3a38; }
.bay-log li b { font-weight: 500; color: #4f6355; margin-right: 6px; }
.bay-log li:last-child { color: #c9dccd; }
.bay-log li.ok { color: var(--ph-2); }
.bay-log li.bad { color: var(--rust); }
.bay-act { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 12px 2px 4px; }
.bay-act .swap-go[hidden] { display: none; }
/* the floor's keys: buy from the treasury (the bay's lit key), sell to it (an enamel key); replay steps back beside them */
.bay-trade { min-width: 250px; }
.bay-trade.sell { color: #2b2d2a; background: linear-gradient(#f2f1eb, #cfcec7); }
.bay-act:has(.bay-trade:not([hidden])) .bay-go[data-act="replay"] { min-width: 0; color: #2b2d2a; background: linear-gradient(#f2f1eb, #cfcec7); }
@media (max-width: 720px) { .bay-act { grid-template-columns: 1fr; } }
.bay-status { font-size: 12px; line-height: 1.45; color: #2b2d2a; }
.bay-status.ok { color: #1f6b3d; }
.bay-status.bad { color: #a8431c; }
.bay-status a { color: inherit; }
.bay-go { min-width: 250px; }

@media (prefers-reduced-motion: reduce) {
  .lab-scan, .lamp, .bay-layers img.print, .bay-layers img.flash, .bay-head.run, .bay-stamp, .bay-panel, .bay-final { animation: none !important; }
}

/* ── CONTRACTS ── */
.ct-links { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 2px 4px; }
.ct-links .fp-btn { text-decoration: none; }
.ct-links .ct-os { background: linear-gradient(#3a9bff, #2081e2); color: #fff; }
.ct-list { margin: 10px 0 12px; padding: 8px 12px; background: var(--crt); border-radius: 3px; box-shadow: inset 0 0 0 1.5px #090909, inset 0 0 0 2.5px #3a3a38; }
.ct-group { font: 9px var(--pixel); letter-spacing: 0.16em; color: var(--ph); padding: 10px 0 4px; border-bottom: 1px solid #1c2a20; }
.ct-group:first-child { padding-top: 2px; }
.ct-row { margin: 0; display: grid; grid-template-columns: minmax(150px, 0.9fr) minmax(0, 1.6fr) auto; gap: 4px 14px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed #17231b; font-size: 12px; }
.ct-row:last-child { border-bottom: 0; }
.ct-name { color: #e4f5e7; }
.ct-role { color: #6f8474; }
.ct-addr { font-family: var(--mono); color: #9fdcb3; text-decoration: none; white-space: nowrap; }
.ct-addr:hover { color: var(--ph); text-decoration: underline; }
@media (max-width: 640px) { .ct-row { grid-template-columns: 1fr auto; } .ct-role { grid-column: 1 / -1; order: 3; } }

/* a phone: the bay fills the screen, the CRT a little smaller, the reveal key held at the bottom while the stations scroll */
@media (max-width: 720px) {
  dialog.bay { max-width: 100vw; width: 100vw; max-height: 100vh; max-height: 100dvh; margin: auto 0 0; }
  .bay-panel { border-radius: 14px 14px 0 0; padding: 14px 14px 0; border-bottom: 0; }
  .bay-sub { padding: 6px 2px 8px; font-size: 11px; }
  .bay-crt { width: min(100%, 66vh); justify-self: center; }
  .bay-stations { max-height: none; }
  .bay-act {
    position: sticky; bottom: 0; z-index: 3; margin: 10px -14px 0; padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, #dddcd6, #c9c8c1); border-top: 2px solid rgba(18, 18, 18, 0.5); box-shadow: 0 -12px 22px -12px rgba(0, 0, 0, 0.45);
  }
  .bay-act:not(:has(.swap-go:not([hidden]))):not(:has(.bay-status:not(:empty))) { display: none; }
  .bay-go, .bay-trade { min-width: 0; width: 100%; }
  .bay-act { gap: 8px; }
}
