/* COMPANYOS — Neural Company Brain + light stage polish
   Jarvis/neural swarm is scoped to stage 1 only. */

:root {
  --brain-ink: #11110F;
  --brain-paper: #FBF9F3;
  --brain-canvas: #F4EFE4;
  --brain-blue: #1B49D8;
  --brain-muted: #5F5A53;
  --brain-ease: cubic-bezier(.16, 1, .3, 1);
}

@keyframes brainPulse {
  0%, 100% { transform: scale(1); opacity: .55; }
  50% { transform: scale(1.65); opacity: 0; }
}

@keyframes brainGlow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(27, 73, 216, 0)); }
  50% { filter: drop-shadow(0 0 10px rgba(27, 73, 216, .45)); }
}

@keyframes brainDash {
  to { stroke-dashoffset: -120; }
}

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

@keyframes brainChipIn {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes brainShimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

@keyframes cnBlink {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

@keyframes neuralLive {
  0%, 100% { opacity: .45; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.25); }
}

@keyframes feedIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.brain-fx-host {
  position: relative;
  isolation: isolate;
}

/* —— Neural stage (indexed layer only) —— */
.brain-neural-stage {
  position: relative;
  overflow: hidden;
}

.brain-neural-stage .brain-svg-dim {
  opacity: 1;
  filter: none;
  transition: opacity .5s var(--brain-ease), filter .5s var(--brain-ease);
}

.brain-neural-stage[data-jarvis="work"] .brain-svg-dim {
  opacity: .18;
  filter: grayscale(.12);
}

.brain-neural {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .45s var(--brain-ease), visibility .45s;
}

.brain-neural-stage[data-jarvis="work"] .brain-neural {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.brain-neural-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.brain-neural-hud {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brain-neural-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 10px/1 "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--brain-muted);
  background: rgba(251, 249, 243, .88);
  border: 1px solid rgba(17, 17, 15, .14);
  border-radius: 999px;
  padding: 7px 10px;
}

.brain-neural-live {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1B49D8;
  box-shadow: 0 0 0 3px rgba(27, 73, 216, .16);
  animation: neuralLive 1.4s ease-in-out infinite;
}

.brain-neural-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.brain-neural-metrics span {
  font: 500 10px/1 "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: .04em;
  color: var(--brain-ink);
  background: rgba(251, 249, 243, .9);
  border: 1px solid rgba(17, 17, 15, .12);
  border-radius: 8px;
  padding: 6px 8px;
}

.brain-agent-rail {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 7;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  pointer-events: auto;
}

.brain-agent-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 9px;
  border-radius: 12px;
  border: 1px solid rgba(17, 17, 15, .16);
  background: rgba(251, 249, 243, .94);
  box-shadow: 0 8px 20px rgba(17, 17, 15, .08);
  cursor: pointer;
  text-align: left;
  transition: border-color .2s ease, transform .2s var(--brain-ease), box-shadow .2s ease;
}

.brain-agent-card:hover {
  transform: translateY(-1px);
  border-color: rgba(27, 73, 216, .35);
}

.brain-agent-card[data-active="1"] {
  border-color: rgba(27, 73, 216, .55);
  box-shadow: 0 0 0 1px rgba(27, 73, 216, .12), 0 10px 22px rgba(27, 73, 216, .14);
}

.brain-agent-card[data-busy="1"] .brain-agent-avatar {
  animation: neuralLive 1.1s ease-in-out infinite;
}

.brain-agent-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  color: #FFFDF8;
  background: var(--agent-color, #11110F);
  font: 700 9px/1 "Syne", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .02em;
}

.brain-agent-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brain-agent-name {
  font: 700 11px/1.1 "Syne", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--brain-ink);
}

.brain-agent-role {
  font: 500 9px/1.1 "IBM Plex Mono", ui-monospace, monospace;
  color: var(--brain-muted);
}

.brain-agent-state {
  font: 500 9px/1.2 "IBM Plex Mono", ui-monospace, monospace;
  color: #1B49D8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.brain-agent-feed {
  position: absolute;
  top: 52px;
  right: 12px;
  width: min(240px, 46%);
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.brain-feed-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(17, 17, 15, .92);
  color: #FFFDF8;
  font: 500 11.5px/1.35 "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  box-shadow: 0 10px 24px rgba(17, 17, 15, .16);
  animation: feedIn .4s var(--brain-ease) both;
}

.brain-feed-agent {
  font: 700 10px/1 "Syne", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #9DB4FF;
}

.brain-feed-action {
  flex: 1 1 100%;
  color: rgba(255, 253, 248, .92);
}

.brain-feed-conf {
  font: 500 9px/1 "IBM Plex Mono", ui-monospace, monospace;
  color: rgba(255, 253, 248, .65);
}

.brain-feed-hitl {
  font: 700 9px/1 "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: .08em;
  color: #11110F;
  background: #F0C36A;
  border-radius: 999px;
  padding: 3px 6px;
}

.brain-feed-item[data-kind="handoff"] .brain-feed-agent { color: #E8C39E; }
.brain-feed-item[data-kind="hitl"] { box-shadow: 0 0 0 1px rgba(240, 195, 106, .45), 0 10px 24px rgba(17, 17, 15, .16); }

/* Stage polish (non-neural) */
[data-brain-stage] {
  z-index: 2;
  transition: opacity .55s var(--brain-ease), transform .55s var(--brain-ease), filter .55s ease !important;
}

[data-brain-stage][data-brain-active="1"] {
  filter: saturate(1.05);
}

[data-brain-stage="0"] > span:not(:first-child) {
  animation: brainChipIn .55s var(--brain-ease) both, brainFloat 4.8s ease-in-out infinite;
  will-change: transform;
}

[data-brain-stage="0"] > span:nth-child(2) { animation-delay: .02s, 0s; }
[data-brain-stage="0"] > span:nth-child(3) { animation-delay: .08s, .2s; }
[data-brain-stage="0"] > span:nth-child(4) { animation-delay: .14s, .4s; }
[data-brain-stage="0"] > span:nth-child(5) { animation-delay: .2s, .1s; }
[data-brain-stage="0"] > span:nth-child(6) { animation-delay: .26s, .35s; }
[data-brain-stage="0"] > span:nth-child(7) { animation-delay: .32s, .55s; }
[data-brain-stage="0"] > span:nth-child(8) { animation-delay: .38s, .15s; }
[data-brain-stage="0"] > span:nth-child(9) { animation-delay: .44s, .45s; }

[data-brain-stage="0"][data-brain-active="1"] > span:not(:first-child) {
  border-color: rgba(27, 73, 216, .35) !important;
  box-shadow: 0 0 0 1px rgba(27, 73, 216, .08);
}

[data-brain-stage="1"] svg line {
  stroke-dasharray: 8 6;
  animation: brainDash 4s linear infinite;
}

[data-brain-stage="1"] svg circle {
  animation: brainGlow 2.4s ease-in-out infinite;
}

[data-brain-stage="1"] svg circle:nth-of-type(1) { animation-delay: 0s; }
[data-brain-stage="1"] svg circle:nth-of-type(2) { animation-delay: .2s; }
[data-brain-stage="1"] svg circle:nth-of-type(3) { animation-delay: .4s; }
[data-brain-stage="1"] svg circle:nth-of-type(4) { animation-delay: .6s; }
[data-brain-stage="1"] svg circle:nth-of-type(5) { animation-delay: .8s; }
[data-brain-stage="1"] svg circle:nth-of-type(6) { animation-delay: 1s; }

[data-brain-stage="1"] svg rect {
  animation: brainGlow 2.8s ease-in-out infinite;
}

[data-brain-label] {
  position: relative;
  transition: opacity .4s ease, transform .4s var(--brain-ease), color .35s ease !important;
}

[data-brain-label][data-brain-active="1"] {
  opacity: 1 !important;
  transform: translateX(4px);
  color: var(--brain-ink);
}

[data-brain-label][data-brain-active="1"]::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 22%;
  bottom: 22%;
  width: 3px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--brain-blue), #11110F);
  box-shadow: 0 0 12px rgba(27, 73, 216, .35);
}

.brain-fx-tour-card {
  position: relative;
  overflow: hidden;
}

.brain-fx-tour-card::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle at 30% 20%, rgba(27, 73, 216, .12), transparent 42%),
              radial-gradient(circle at 80% 70%, rgba(17, 17, 15, .06), transparent 40%);
  pointer-events: none;
  animation: brainShimmer 10s linear infinite;
  background-size: 120% 120%;
  opacity: .9;
}

.brain-fx-tour-card > * {
  position: relative;
  z-index: 1;
}

/* Tour /tour — portal stage (outside template tree) + in-flow spacer via grid margin */
.brain-tour-stage {
  position: relative;
  min-height: min(520px, 70vh);
  height: clamp(380px, 58vh, 560px);
  border: 1px solid rgba(17, 17, 15, 0.16);
  border-radius: 12px;
  background:
    radial-gradient(ellipse 70% 55% at 50% 42%, rgba(27, 73, 216, 0.08), transparent 62%),
    linear-gradient(165deg, #FBF9F3 0%, #F4EFE4 55%, #EFE8DA 100%);
  box-shadow: 0 1px 0 rgba(251, 249, 243, 0.9) inset;
  isolation: isolate;
  overflow: hidden;
}

.brain-tour-portal {
  pointer-events: auto;
  box-sizing: border-box;
}

.brain-tour-portal[data-jarvis="idle"],
.brain-hero-portal[data-jarvis="idle"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none !important;
}

.brain-tour-portal[data-jarvis="work"],
.brain-hero-portal[data-jarvis="work"] {
  opacity: 1;
  visibility: visible;
}

/* Tour hero #s1 — covers the static radial SVG well */
.brain-hero-host {
  position: relative;
}

.brain-hero-host > svg {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.brain-hero-portal {
  pointer-events: auto;
  box-sizing: border-box;
  border: 1px solid rgba(17, 17, 15, 0.14);
  border-radius: 18px;
  background:
    radial-gradient(ellipse 62% 58% at 50% 46%, rgba(27, 73, 216, 0.1), transparent 64%),
    linear-gradient(165deg, #FBF9F3 0%, #F4EFE4 52%, #EFE8DA 100%);
  box-shadow:
    0 1px 0 rgba(251, 249, 243, 0.9) inset,
    0 18px 40px rgba(17, 17, 15, 0.06);
  isolation: isolate;
  overflow: hidden;
}

.brain-hero-portal.is-reduced::before {
  content: "Cerebros";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 600 15px/1.3 "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brain-muted);
  opacity: 0.55;
}

.brain-tour-grid {
  /* Reserve vertical room for the absolute portal between intro and cards */
  margin-top: calc(clamp(28px, 3.2vw, 44px) + clamp(380px, 58vh, 560px) + 28px) !important;
}

.brain-tour-stage.is-reduced::before {
  content: "Company Brain";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 600 15px/1.3 "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brain-muted);
  opacity: 0.55;
}

@media (max-width: 900px) {
  .brain-agent-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .brain-agent-feed {
    width: min(200px, 42%);
    top: 48px;
  }
  .brain-tour-stage {
    height: clamp(320px, 56vh, 440px);
    min-height: 320px;
  }
}

@media (max-width: 560px) {
  .brain-agent-role,
  .brain-neural-metrics { display: none; }
  .brain-agent-feed { display: none; }
  .brain-agent-rail { gap: 6px; }
  .brain-tour-stage {
    height: 300px;
    min-height: 280px;
    border-radius: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-brain-stage="0"] > span:not(:first-child),
  [data-brain-stage="1"] svg line,
  [data-brain-stage="1"] svg circle,
  [data-brain-stage="1"] svg rect,
  .brain-fx-tour-card::after,
  .brain-neural-live,
  .brain-agent-card[data-busy="1"] .brain-agent-avatar,
  .brain-feed-item {
    animation: none !important;
  }
}
