/* Pending surfaces get their own palette before the agents can place artwork. */
@media screen {
  body.home-page {
    --swarm-opening-paint: var(--ht-dark, #07151e);
    --swarm-story-paint: var(--ht-bg, #eef3f6);
    --swarm-contact-paint: var(--ht-surface, #e3ebf1);
    --swarm-footer-paint: var(--ht-dark, #07151e);
    --swarm-entry-paint: var(--swarm-opening-paint);
  }
  html body.home-page:is([data-swarm-layout="poster"], [data-swarm-layout="swiss"], [data-swarm-layout="brand"], [data-swarm-layout="terminal"], [data-swarm-layout="magazine"]) {
    --swarm-opening-paint: var(--swarm-paper);
    --swarm-story-paint: var(--swarm-paper);
    --swarm-contact-paint: var(--swarm-surface);
  }
  html[data-docnil-brand="active"] body.home-page {
    --swarm-opening-paint: var(--dn-brand-paper, #e7e6e1);
    --swarm-footer-paint: var(--dn-brand-carbon, #080808);
  }
  html[data-swarm-boot="story"] body.home-page { --swarm-entry-paint: var(--swarm-story-paint); }
  html[data-swarm-boot="contact"] body.home-page { --swarm-entry-paint: var(--swarm-contact-paint); }
  html[data-swarm-boot="footer"] body.home-page { --swarm-entry-paint: var(--swarm-footer-paint); }
  html[data-swarm-boot] body.home-page {
    background: var(--swarm-entry-paint) !important;
  }
  html[data-swarm-boot] body.home-page::before,
  html[data-swarm-boot] body.home-page::after,
  html[data-swarm-boot] body.home-page > :not(.skip-link),
  html[data-swarm-boot] body.home-page > :not(.skip-link) * {
    visibility: hidden !important;
  }

  body.home-page[data-swarm-construction] [data-swarm-pending]:not([data-swarm-placing]),
  body.home-page[data-swarm-construction] [data-swarm-pending]:not([data-swarm-placing]) * {
    visibility: hidden !important;
  }
  body.home-page[data-swarm-construction] [data-swarm-pending][data-swarm-placing] {
    pointer-events: none !important;
  }

  body.home-page :is(.dn-header, #vision) { --swarm-surface-paint: var(--swarm-opening-paint); }
  body.home-page :is(#agency, #approach, #services) { --swarm-surface-paint: var(--swarm-story-paint); }
  body.home-page :is(#logos-studio, #contact) { --swarm-surface-paint: var(--swarm-contact-paint); }
  body.home-page .site-footer { --swarm-surface-paint: var(--swarm-footer-paint); }
  body.home-page #docnil-signal-board { --swarm-surface-paint: var(--dn-brand-paper, #e7e6e1); }

  body.home-page[data-swarm-construction] [data-swarm-unstarted] {
    background-color: var(--swarm-surface-paint, var(--swarm-story-paint)) !important;
    background-image: none !important;
    background-size: 100% 100% !important;
    background-position: top left !important;
    background-repeat: no-repeat !important;
    border-color: transparent !important;
    box-shadow: none !important;
  }
  /* These transparent chapter panes sit over the shared hero/agency paint.
     Giving them a color of their own would draw a rectangle over that stage. */
  body.home-page[data-swarm-construction] :is([data-hero-panel], [data-agency-panel])[data-swarm-unstarted] {
    background-color: transparent !important;
  }
  body.home-page[data-swarm-construction] [data-swarm-unstarted] :is(
    .hero-signal-topline, .agency-story-topline, .bc-topbar, .bc-controls,
    .cap-index-list, .begin-bottom, .footer-bottom, .dn-signal-spread, .dn-signal-directory-title
  ) {
    border-color: transparent !important;
  }
  body.home-page[data-swarm-construction] [data-swarm-unstarted]::before,
  body.home-page[data-swarm-construction] [data-swarm-unstarted]::after {
    visibility: hidden !important;
  }
  /* The fixed dust stays visible over completed sections, below waiting paint. */
  body.home-page[data-swarm-construction] :is(main > section, .site-footer, #footer-signature)[data-swarm-unstarted] {
    position: relative;
    z-index: 6;
  }

  /* Feather only the incoming edge. Because this is spatial, fast scrolling
     does not have to wait for an intersection callback or a palette tween. */
  body.home-page #agency { --swarm-previous-paint: var(--swarm-opening-paint); }
  body.home-page #logos-studio { --swarm-previous-paint: var(--swarm-story-paint); }
  body.home-page .site-footer { --swarm-previous-paint: var(--swarm-contact-paint); }
  html:not(.motion-off) body.home-page[data-swarm-construction] :is(
    #agency, [data-agency-stage], #logos-studio, .site-footer, .site-footer[data-swarm-unstarted] #footer-signature
  )[data-swarm-unstarted] {
    background-image: linear-gradient(
      to bottom, var(--swarm-previous-paint), var(--swarm-surface-paint) clamp(56px, 12svh, 120px)
    ) !important;
  }
}

/* Optional DOC N.I.L. grain has important declarations in this named layer. */
@layer dnSignalBrand {
  @media screen {
    html[data-docnil-brand="active"][data-swarm-boot] body.home-page {
      background: var(--swarm-entry-paint) !important;
    }
    html[data-docnil-brand="active"] body.home-page[data-swarm-construction] [data-swarm-unstarted] {
      outline: none !important;
    }
    html[data-docnil-brand="active"] body.home-page[data-swarm-construction] :is(.dn-header, .site-footer)[data-swarm-unstarted] {
      background-color: var(--swarm-surface-paint) !important;
      background-image: none !important;
      border-color: transparent !important;
    }
    html[data-docnil-brand="active"]:not(.motion-off) body.home-page[data-swarm-construction] .site-footer[data-swarm-unstarted] {
      background-image: linear-gradient(
        to bottom, var(--swarm-previous-paint), var(--swarm-surface-paint) clamp(56px, 12svh, 120px)
      ) !important;
    }
  }
}
/* The rebuild console is mounted only on the homepage. */
.swarm-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 120;
}
.swarm-station, .swarm-log {
  --swarm-console-ink: #f5f1ed;
  --swarm-console-muted: #c7c3c1;
  --swarm-console-line: #ffffff27;
  --swarm-accent: #ffc08a;
  color: var(--swarm-console-ink);
  font: 500 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
  position: fixed;
  z-index: 121;
  isolation: isolate;
}
.swarm-station {
  display: flex;
  align-items: center;
  gap: 6px;
  left: max(222px, calc(210px + env(safe-area-inset-left)));
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: calc(100vw - 24px);
}
.swarm-station .swarm-trigger, .swarm-panel > summary, .swarm-log {
  border: 1px solid var(--swarm-console-line);
  background: linear-gradient(120deg, #272c35f5, #12171ef7 58%, #2b211df7);
  box-shadow: inset 0 1px #ffffff21, 0 10px 32px #0006;
  color: var(--swarm-console-ink);
}
.swarm-station .swarm-trigger {
  display: grid;
  grid-template-columns: 25px 1fr 15px;
  align-items: center;
  gap: 8px;
  text-align: left;
  min-height: 46px;
  padding: 6px 12px 6px 8px;
  border-radius: 13px !important;
  line-height: 1.25;
  cursor: pointer;
}
.swarm-station .swarm-trigger:hover, .swarm-panel > summary:hover {
  background: linear-gradient(120deg, #383f49, #24262d 58%, #453128);
}
.swarm-station :is(button, summary):focus-visible {
  outline: 2px solid #ffc08a;
  outline-offset: 3px;
}
.swarm-trigger small {
  display: block;
  font-size: 9px;
  color: var(--swarm-console-muted);
  margin-top: 3px;
}
.swarm-mark {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border: 1px solid #ffc08a45;
  border-radius: 7px;
  color: var(--swarm-accent);
  background: #ffc08a12;
  font-size: 15px;
}
.swarm-arrow { color: var(--swarm-accent); }
.swarm-trigger[data-building] .swarm-mark { animation: swarm-control-spin 2.4s linear infinite; }
@keyframes swarm-control-spin { to { transform: rotate(1turn); } }

.swarm-panel { color: var(--swarm-console-ink); }
.swarm-panel > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 5px 9px;
  list-style: none;
  border-radius: 9px;
  cursor: pointer;
  font-size: 10px;
}
.swarm-panel > summary::-webkit-details-marker { display: none; }
.swarm-panel > summary .swarm-count { color: var(--swarm-accent); }
.swarm-panel-content {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 0;
  width: min(365px, calc(100vw - 24px - env(safe-area-inset-left)));
  max-height: min(470px, calc(100svh - 155px));
  overflow: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
  padding: 14px;
  background: linear-gradient(130deg, #252a32, #11151a 72%);
  border: 1px solid var(--swarm-console-line);
  border-radius: 14px;
  box-shadow: 0 20px 62px #0008, inset 0 1px #ffffff21;
}
.swarm-tasks {
  display: grid;
  gap: 5px;
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}
.swarm-tasks li {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr) 44px;
  align-items: baseline;
  gap: 6px;
  padding: 0 0 4px;
  border-bottom: 1px solid var(--swarm-console-line);
  font-size: 10px;
}
.swarm-tasks strong { color: var(--swarm-agent-color); }
.swarm-tasks small { text-align: right; color: var(--swarm-console-muted); }
.swarm-tasks li:is([data-state="moving"], [data-state="placing"], [data-state="filling"], [data-state="checking"], [data-state="noting"]) small { color: #8fc4ef; }
.swarm-tasks li[data-state="done"] small { color: #a6e4ba; }
.swarm-picker {
  border: 0;
  padding: 0;
  margin: 0 0 12px;
  min-width: 0;
}
.swarm-picker legend { margin-bottom: 7px; font-size: 10px; color: var(--swarm-console-muted); }
.swarm-picker > div { display: flex; flex-wrap: wrap; gap: 5px; }
.swarm-station .swarm-picker button {
  min-height: 31px;
  padding: 5px 7px;
  border: 1px solid var(--swarm-console-line);
  border-radius: 7px;
  background: #252a33;
  color: var(--swarm-console-ink);
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}
.swarm-station .swarm-picker button[aria-pressed="true"] {
  color: #fff5e9;
  background: #62402d;
  border-color: #ffc08a9e;
}
html[data-dn-theme] body .swarm-station .swarm-trigger,
html[data-dn-theme] body .swarm-station .swarm-picker button {
  --glass-button-ink: var(--swarm-console-ink);
  --glass-button-border: var(--swarm-console-line);
  --glass-button-surface: linear-gradient(120deg, #303641, #171c24 58%, #30221c);
  --glass-button-hover: linear-gradient(120deg, #414956, #242a35 58%, #493428);
  --glass-button-shadow: inset 0 1px #ffffff21, 0 9px 25px #0005;
  --glass-button-focus: var(--swarm-accent);
}
html[data-dn-theme] body .swarm-station .swarm-picker button {
  --glass-button-surface: #252a33;
  border-radius: 7px !important;
}
html[data-dn-theme] body .swarm-station .swarm-picker button[aria-pressed="true"] {
  --glass-button-surface: #62402d;
  --glass-button-border: #ffc08a9e;
}
.swarm-follow {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  margin-bottom: 6px;
  font-size: 10px;
  cursor: pointer;
}
.swarm-follow input { width: 15px; height: 15px; accent-color: #6bbdff; }
.swarm-follow input:focus-visible { outline: 2px solid #6bbdff; outline-offset: 3px; }

/* Same single-line, ice-blue glass ticker as the portfolio presentation. */
.swarm-log {
  --swarm-log-safe-top: calc(env(safe-area-inset-top) + 12px);
  top: var(--swarm-log-safe-top);
  transform: translateY(max(0px, calc(var(--swarm-log-top, 12px) - var(--swarm-log-safe-top))));
  right: max(14px, 5vw);
  left: auto;
  width: min(525px, calc(100vw - 28px));
  height: 29px;
  padding: 0 12px;
  border: 1px solid #6bbdff45;
  border-radius: 999px;
  background: #0b0f16ed;
  box-shadow: 0 10px 30px #0006;
  box-sizing: border-box;
  align-items: center;
  gap: 9px;
  font-size: 10px;
  display: flex;
  color: #cfe6ff;
  opacity: 0;
  pointer-events: none;
}
.swarm-log[data-visible] { opacity: 1; }
.swarm-log[data-follow] { width: min(380px, calc(100vw - 28px)); height: 25px; transition: opacity .28s ease, transform .16s ease-out; }
.swarm-log[data-follow] progress { display: none; }
.swarm-log-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: .055em;
  color: #8fc4ef;
}
.swarm-log-head b { inline-size: 13ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #eef6ff; font-weight: 500; }
.swarm-log-head i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6bbdff;
  box-shadow: 0 0 10px #6bbdff;
}
.swarm-log-line {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  border-inline-start: 1px solid #6bbdff4f;
  padding-inline-start: 8px;
  white-space: nowrap;
}
.swarm-log-line span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: swarm-ticker-type 380ms steps(24, end) both;
}
@keyframes swarm-ticker-type { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }
.swarm-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.swarm-log progress {
  width: clamp(16px, 5vw, 56px);
  height: 3px;
  accent-color: #6bbdff;
}
@media (max-width: 530px) {
  .swarm-log-head { letter-spacing: 0; }
  .swarm-log-head i { display: none; }
}
@media (max-width: 760px) {
  .swarm-station {
    left: max(12px, env(safe-area-inset-left));
    bottom: calc(61px + env(safe-area-inset-bottom));
  }
  .swarm-tasks li { grid-template-columns: 64px minmax(0, 1fr) 44px; font-size: 10px; }
}
@media (max-width: 760px) and (min-height: 600px) {
  html.hero-scroll-enabled body.home-page .hero-signal-controls {
    bottom: max(116px, calc(116px + env(safe-area-inset-bottom)));
  }
}
@media (prefers-reduced-motion: reduce) {
  .swarm-trigger[data-building] .swarm-mark, .swarm-log-line span { animation: none; }
}
html.motion-off :is(.swarm-trigger[data-building] .swarm-mark, .swarm-log-line span) { animation: none; }
