/* ==========================================================================
   Signals AI page (owner feedback 2026-11-09, second pass).
   - .talk / .sai-stage: "Talk to SAI" with the whole SAI room as a soft,
     feathered scene and SAI's costumes standing around the phone.
   - .sai-gallery: "Play, chat and work", a slowly drifting row of phones.
   - .travel: "how a question travels", a paper line diagram.
   - .brain-constellation: the brain band with what SAI is built on.
   Motion lives in js/signals-ai.js (30 fps, paused off screen / hidden,
   still under prefers-reduced-motion).
   ========================================================================== */

/* --- Talk to SAI ----------------------------------------------------------- */

.talk-section { overflow-x: clip; }

.talk {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 8fr);
  gap: clamp(var(--space-8), 4vw, var(--space-16));
  align-items: center;
}

.talk-copy { position: relative; z-index: 2; }
.talk-copy ul { padding-left: 1.1em; }
.talk-copy li { margin-bottom: var(--space-2); }

.sai-stage {
  position: relative;
  isolation: isolate;
  aspect-ratio: 13 / 10;
  max-height: 760px;
  width: 100%;
}

/* The room: wide, soft and slightly desaturated, feathered into the page on every side (no box). */
.sai-room {
  position: absolute;
  z-index: 0;
  left: -10%;
  right: -3%;
  top: 2%;
  aspect-ratio: 16 / 10;
  pointer-events: none;
  /* a soft rounded band: horizontal x vertical fades, no oval rim */
  -webkit-mask-image:
    linear-gradient(to right, transparent 0, rgba(0, 0, 0, .45) 10%, #000 24%, #000 76%, rgba(0, 0, 0, .45) 90%, transparent 100%),
    linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, .5) 8%, #000 20%, #000 74%, rgba(0, 0, 0, .5) 88%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent 0, rgba(0, 0, 0, .45) 10%, #000 24%, #000 76%, rgba(0, 0, 0, .45) 90%, transparent 100%),
    linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, .5) 8%, #000 20%, #000 74%, rgba(0, 0, 0, .5) 88%, transparent 100%);
  mask-composite: intersect;
}
.sai-room img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(.62) contrast(.92) brightness(1.03);
  opacity: .9;
}
:root[data-theme="dark"] .sai-room img { filter: saturate(.55) brightness(.62) contrast(.95); opacity: .75; }

/* The phone stands on the floor in the middle of the room. */
.sai-phone {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 0;
  width: 30%;
  transform: translateX(-50%);
}
.sai-phone figcaption { text-align: center; }
.sai-phone .shot-frame { box-shadow: 0 0 0 1px var(--rule-strong), 0 22px 44px rgba(40, 36, 30, .28); }

/* SAI's costumes, placed by their feet (--x, --y) and sized for depth (--h), all in % of the stage. */
.sai-crowd { position: absolute; inset: 0; margin: 0; padding: 0; list-style: none; z-index: 2; }

.npc {
  position: absolute;
  left: var(--x);
  top: var(--y);
  height: var(--h);
  aspect-ratio: 150 / 220;
  transform: translate(-50%, -100%);
  z-index: 1;
  outline: none;
}
.npc:nth-child(n+5):nth-child(-n+7), .npc:nth-child(n+14):nth-child(-n+16) { z-index: 2; }
.npc:nth-child(n+8):nth-child(-n+9), .npc:nth-child(n+17) { z-index: 3; }

/* A soft contact shadow on the floor. */
.npc::before {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  bottom: -3%;
  height: 9%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(52, 40, 28, .3), transparent);
}
.npc picture, .npc img { display: block; width: 100%; height: 100%; }
.npc img {
  object-fit: contain;
  transform-origin: 50% 100%;
  will-change: transform;
  filter: drop-shadow(0 1px 1px rgba(30, 30, 40, .18));
}

.npc-name {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translate(-50%, 4px);
  padding: 1px 8px;
  white-space: nowrap;
  font-family: var(--font-label);
  font-size: var(--fs-label);
  letter-spacing: .04em;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--rule-strong);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 5;
}
.npc:hover .npc-name, .npc:focus-visible .npc-name { opacity: 1; transform: translate(-50%, 0); }
.npc:focus-visible img { outline: 2px solid var(--accent); outline-offset: 2px; }
.npc:hover, .npc:focus-visible { z-index: 6; }

@media (max-width: 899px) {
  .talk { grid-template-columns: 1fr; }
  .sai-stage { aspect-ratio: auto; height: clamp(520px, 150vw, 720px); max-width: 560px; justify-self: center; }
  .sai-room { left: -6%; right: -6%; top: 0; bottom: 4%; aspect-ratio: auto;
    -webkit-mask-image:
      linear-gradient(to right, transparent 0, #000 16%, #000 84%, transparent 100%),
      linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, .5) 12%, #000 26%, #000 76%, transparent 100%);
    mask-image:
      linear-gradient(to right, transparent 0, #000 16%, #000 84%, transparent 100%),
      linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, .5) 12%, #000 26%, #000 76%, transparent 100%); }
  .sai-phone { width: min(56%, 240px); bottom: 0; }
  .npc { display: none; }
  .npc.is-m { display: block; left: var(--mx); top: var(--my); height: var(--mh); }
}

/* --- Play, chat and work: the drifting gallery ----------------------------- */

.sai-gallery {
  position: relative;
  overflow: hidden;
  padding-block: var(--space-6) var(--space-4);
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 5%, #000 95%, transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 5%, #000 95%, transparent 100%);
}

.sai-gallery-track {
  display: flex;
  justify-content: center;
  gap: clamp(var(--space-6), 3vw, var(--space-12));
  width: max-content;
  min-width: 100%;
  padding-inline: var(--gutter);
  will-change: transform;
}

/* When every phone fits, no edge fade and no drift (js/signals-ai.js sets .is-fit). */
.sai-gallery.is-fit { -webkit-mask-image: none; mask-image: none; }

/* Five phones fit inside the page gutters on laptops and up (20 px slack for a scrollbar). */
.sai-gallery .shot-phone { flex: none; width: clamp(170px, calc((100vw - 20px - 2 * var(--gutter) - 4 * clamp(var(--space-6), 3vw, var(--space-12))) / 5), 260px); margin: 0; }
.sai-gallery .shot-phone figcaption { text-align: center; }
.sai-gallery .shot-frame {
  position: relative;
  transition: transform .45s cubic-bezier(.2, .7, .2, 1), box-shadow .45s ease;
}

/* A soft highlight sweeping across the glass (position set by js/signals-ai.js). */
.sai-gallery .shot-frame::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 22px;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 255, 255, .26) 48%, rgba(255, 255, 255, .08) 53%, transparent 62%);
  background-size: 300% 100%;
  background-repeat: no-repeat;
  background-position: var(--sheen, 120%) 0;
}

.sai-gallery .shot-phone:hover .shot-frame,
.sai-gallery .shot-phone:focus-within .shot-frame {
  transform: translateY(-14px) scale(1.03);
  box-shadow: 0 0 0 1px var(--rule-strong), 0 30px 50px rgba(30, 30, 40, .3);
}

@media (max-width: 899px), (prefers-reduced-motion: reduce) {
  .sai-gallery {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-mask-image: none;
    mask-image: none;
  }
  .sai-gallery::-webkit-scrollbar { display: none; }
  .sai-gallery-track { justify-content: flex-start; padding-inline: var(--space-4); }
  .sai-gallery .shot-phone { scroll-snap-align: center; width: min(62vw, 240px); }
}

/* --- Private by design: how a question travels ---------------------------- */

.private-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(var(--space-8), 4vw, var(--space-16));
  align-items: center;
}

.travel { margin: 0; justify-self: center; width: 100%; max-width: 720px; }
.travel svg { display: block; width: 100%; height: auto; overflow: visible; }
.travel figcaption { margin-top: var(--space-2); color: var(--muted); font-size: var(--fs-small); text-align: center; }

.travel .tv-line, .travel .tv-dash, .travel .tv-icon, .travel .tv-ticks { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.travel .tv-q { stroke: var(--accent-deco); stroke-width: 1.4; }
.travel .tv-a { stroke: var(--highlight-deco); stroke-width: 1.4; }
.travel .tv-dash { stroke-dasharray: 4 5; }
.travel .tv-icon { stroke: var(--accent); stroke-width: 1.3; }
.travel .tv-icon circle { fill: var(--surface); }
.travel .tv-ticks { stroke: var(--rule-strong); stroke-width: 1; }
.travel .tv-dot { fill: var(--surface); stroke: var(--accent-deco); stroke-width: 1.4; }
.travel text { font-family: var(--font-label); letter-spacing: .02em; }
.travel .tv-h { font-size: 17px; font-weight: 600; fill: var(--text); }  /* SVG user units (scale with the diagram) */
.travel .tv-s { font-size: 15px; fill: var(--muted); }
.travel .tv-n { font-size: 15px; fill: var(--highlight); }
.travel .tv-a-label { fill: var(--highlight); }
.travel .tv-pulse circle:first-child { opacity: .22; }
.travel .tv-pulse-q circle, .travel .tv-pulse-b circle { fill: var(--accent-deco); }
.travel .tv-pulse-a circle { fill: var(--highlight-deco); }

@media (max-width: 899px) {
  .private-grid { grid-template-columns: 1fr; }
}
/* Phones: the diagram is ~350 px wide, so its labels are drawn larger in SVG units (~17 / 15 px on screen). */
@media (max-width: 600px) {
  .travel .tv-h { font-size: 21px; }
  .travel .tv-s { font-size: 18px; }
  .travel .tv-n { font-size: 16.5px; }
}


/* --- The brain band with what SAI is built on ------------------------------ */

.brain-built { margin-top: var(--head-gap); }

.brain-panel.brain-constellation {
  --ff-y: calc(var(--feather) * 1.4);
  --ff-x: 2.5%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 1.15fr) minmax(0, 1fr);
  align-items: center;
  height: auto;
  min-height: clamp(460px, 36vw, 640px);
  margin: 0;
  padding: calc(var(--feather) * 1.4 + 1rem) max(8vw, 24px);
}

.brain-constellation > canvas.brain-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.brain-cell {
  position: relative;
  align-self: stretch;
  min-height: 380px;
}
.brain-cell > canvas[data-brain-cloud] { position: absolute; inset: 0; width: 100%; height: 100%; }
.brain-cell > .brand-caption {
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  margin: 0;
  white-space: nowrap;
  font-family: var(--font-label);
  font-size: var(--fs-label);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #a9cbe4;
}

.built-col { position: relative; display: grid; gap: clamp(var(--space-6), 2.4vw, var(--space-8)); }
.built-left { text-align: right; justify-items: end; }
.built-left .built-group:nth-child(2) { margin-right: 2.4vw; }
.built-right .built-group:nth-child(2) { margin-left: 2.4vw; }

.built-h {
  margin: 0 0 6px;
  font-family: var(--font-label);
  font-size: var(--fs-label);
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #b9d6ea;
}
.built-group ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.built-group li {
  position: relative;
  font-family: var(--font-label);
  font-size: var(--fs-body);
  letter-spacing: .02em;
  line-height: 1.35;
  color: #eaf6ff;
}
.built-note { color: #a9cbe4; font-size: var(--fs-small); margin-inline-start: 4px; }

/* The luminous node each name hangs from (the lines to the brain are drawn in canvas.brain-links). */
.built-group .node {
  position: absolute;
  top: .62em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9f3ff;
  box-shadow: 0 0 6px 2px rgba(95, 211, 255, .55), 0 0 16px 4px rgba(95, 211, 255, .18);
}
.built-left .node { right: -18px; }
.built-right .node { left: -18px; }
.built-right li { padding-left: 0; }

.built-caption {
  margin: var(--space-4) auto 0;
  max-width: var(--wrap);
  padding-inline: var(--space-4);
  text-align: center;
  font-family: var(--font-label);
  font-size: var(--fs-body);
  letter-spacing: .02em;
  color: var(--muted);
}

@media (max-width: 899px) {
  .brain-panel.brain-constellation {
    --ff-y: 56px;
    --ff-x: 3%;
    grid-template-columns: 1fr;
    min-height: 0;
    padding: 68px var(--space-6);
    row-gap: var(--space-4);
  }
  .brain-constellation > canvas.brain-links { display: none; }
  .brain-cell { min-height: 0; height: clamp(240px, 70vw, 380px); }
  .brain-cell > .brand-caption { white-space: normal; text-align: center; width: 90%; bottom: -4px; }
  .built-col { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4) var(--space-6); text-align: left; justify-items: start; }
  .built-col .built-group:nth-child(2) { margin: 0; }
  .built-col .built-group:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .built-group li { font-size: var(--fs-small); padding-left: 14px; }
  .built-group .node { left: 0; right: auto; top: .55em; width: 5px; height: 5px; }
  .built-note { display: block; margin: 0; }
}
