/* grain/ai/ai.css — the AI-interaction MODULE's styling: the "AI is acting" spotlight.
   Optional: include this ONLY when you use GRAIN's AI interface. The design system
   (grain/styles/grain.css + the b-* atoms) works without it. (AI-INTERFACE §5c) */

/* When the AI (not the user) drives a surface, the page dims and a LAMP — one traveling
   frame — glides onto the touched surface. Calm, monochrome, no shadows on content. */
/* THE LAMP MODEL (the root design): the spotlight is ONE fixed-position element whose rect
   glides between surfaces; the dim is the lamp's own cutout shadow, so hole and veil travel
   together. The lit element is NEVER restyled — a rect is a rect, so every surface kind
   (card, list, row, input) gets the same treatment by construction (this designed out the
   old per-kind lit CSS, grain lesson 8). The veil color is ONE theme token, --ai-veil, set
   once in the theme (variables.css) so every page fades the same; the default below (a
   gentle ink dim) applies if a theme doesn't set it. */
.ai-lamp {
  position: fixed; top: 0; left: 0; z-index: var(--z-ai-veil, 9000);
  border-radius: var(--radius-md);   /* no border — the lamp is just the lit hole in the veil */
  /* the dim IS the lamp's shadow: everything outside the frame recedes, and it MOVES with it */
  box-shadow: 0 0 0 200vmax var(--ai-veil, color-mix(in srgb, var(--ink) 22%, transparent));
  opacity: 0; pointer-events: none;
  /* the focus-switch glide — the lamp EASES onto the new surface, soft start and landing,
     like a page transition (keep the duration ≤ the reasoner's SETTLE so it lands before
     the AI acts). Travel rides `transform` (composited — GPU, never janked by layout);
     only the box's size interpolates in layout, and it's one element. */
  transform: translate3d(50vw, 50vh, 0);
  will-change: transform;   /* transform only — promoting width/height forces extra invalidations */
  transition: opacity 0.35s ease,
              transform var(--ai-focus-move, 0.4s) var(--ai-focus-ease, ease),
              width     var(--ai-focus-move, 0.4s) var(--ai-focus-ease, ease),
              height    var(--ai-focus-move, 0.4s) var(--ai-focus-ease, ease);
}
.ai-lamp.is-on { opacity: 1; }
/* The click-catcher: invisible (the lamp's shadow carries the dim) but it still owns the
   interrupt gesture — clicking anywhere while the AI acts asks it to stop. AI surfaces that
   stay live during a run (chat, console, the acting label) sit above it at --z-ai-surface. */
.ai-backdrop {
  position: fixed; inset: 0; z-index: var(--z-ai-veil, 9000);
  background: transparent; pointer-events: none;
}
.ai-backdrop.is-on { pointer-events: auto; }
/* .ai-spotlit stays as the SEMANTIC marker for the surface under the lamp (tests, per-kind
   data-attr logic in the dispatcher) — it carries no visual of its own in the lamp model. */
/* scroll-margin gives the lit surface breathing room from the scroll region's top/bottom edges
   when the dispatcher scrolls it into view (block:"start") — so it never butts the top bar. */
.ai-spotlit { position: relative; scroll-margin-top: var(--space-4); scroll-margin-bottom: var(--space-4); }
/* the "AI clicked here" pulse. Self-sufficient: .is-click alone renders it (position:relative
   anchors its own ::before), so pulsing never silently no-ops for want of a sibling .ai-spotlit.
   (.ai-spotlit already establishes a positioned context, so spotlit elements are unaffected.) */
.is-click { position: relative; }
.is-click::before {     /* ::before so it never collides with a button's ::after caret */
  content: ""; position: absolute; inset: -4px;
  border: 1px solid var(--ink); border-radius: inherit;
  animation: ai-click 0.5s ease-out;
  pointer-events: none;
}
@keyframes ai-click { from { transform: scale(1); opacity: 0.7; } to { transform: scale(1.12); opacity: 0; } }
.ai-acting-label {
  position: fixed; top: var(--space-4); left: 50%; transform: translateX(-50%); z-index: var(--z-ai-surface, 9002);
  font-family: var(--font-grain); font-size: var(--text-sm); color: var(--ink);
  background: var(--paper); border: var(--border); border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-3);
}

/* interrupt confirm — "ask the AI to stop?" (mediated, never a force-kill).
   A native modal <dialog>: top-layer, focus-trap, Escape-to-close come free. The bare
   element is transparent (the spotlight backdrop already dims); only the card shows. */
.ai-confirm { border: 0; padding: 0; background: transparent; opacity: 0; transition: opacity 0.18s ease; }
.ai-confirm[open] { opacity: 1; }
@starting-style { .ai-confirm[open] { opacity: 0; } }   /* fade in from display:none */
.ai-confirm::backdrop { background: transparent; }      /* the .ai-backdrop beneath already provides the dim */
.ai-confirm__card {
  background: var(--paper); border: 1px solid var(--ink); border-radius: var(--radius-md);
  padding: var(--space-5); max-width: 24rem; text-align: center;
}
.ai-confirm__msg { margin: 0 0 var(--space-4); }
.ai-confirm__actions { display: flex; gap: var(--space-3); justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  .ai-lamp { transition: none; }
  .ai-confirm { transition: none; }
  .is-click::before { animation: none; display: none; }
}

/* ---- X-RAY: see the page as the AI sees it (grain/scripts/xray.js) --------------------
   A dev-mode overlay: outline every operable surface and label it with kind + accepted
   verbs. Purely presentational — xray.js sets `data-xray` on <html> and stamps each
   [data-surface] with a `data-xray-label`; this draws them. Tokens only, so it re-skins
   with the theme. It's the visual twin of the terminal's `context` command. */
html[data-xray] [data-surface] {
  outline: 1px dashed var(--color-accent, var(--ink));
  outline-offset: 2px;
  position: relative;   /* anchor the label; dev-mode only (may shift abs-positioned children) */
}
html[data-xray] [data-surface]::after {
  content: attr(data-xray-label);
  position: absolute; top: 0; right: 0; z-index: var(--z-ai-surface, 9002);
  font-family: var(--font-grain); font-size: var(--text-xs); line-height: 1;
  padding: var(--space-1) var(--space-2);
  color: var(--color-accent, var(--ink));
  background: var(--color-bg, var(--paper));
  border: 1px solid var(--color-line, var(--ink));
  border-radius: var(--radius-sm);
  pointer-events: none; white-space: nowrap;
}

/* ---- honest presence (the AI-online indicator) ---------------------------------------
   The dispatcher stamps <body data-ai-online="true|false"> by OUTCOME (server `ready`
   handshake received / client door actually loaded — ai-dispatch.js). A consumer's presence
   indicator shows three states: waking (default, nothing reported yet), online, offline.
   The wording inside the spans is the consumer's. */
.presence__on, .presence__off { display: none; }
body[data-ai-online] .presence__wait { display: none; }
body[data-ai-online="true"]  .presence__on  { display: inline; }
body[data-ai-online="false"] .presence__off { display: inline; }
/* the presence STAR is its own element (so its color tracks transport health, apart from the
   wording): muted while waking, the accent hue when online, faint when offline. */
.presence__star { color: var(--color-muted); }
body[data-ai-online="true"]  .presence__star { color: var(--color-accent); }
body[data-ai-online="false"] .presence__star { color: var(--ink-faint); }

/* ---- presence GATING: when the door's reply channel is down, AI controls are visibly
   disabled (not silently dead). Consumers mark AI-only controls [data-ai-run] (a trigger that
   drives the AI) or [data-ai-gate] (a composer/region gated on the AI). The dispatcher also
   no-ops submit() when offline (belt-and-braces) — this is the honest visual half. */
body[data-ai-online="false"] [data-ai-run],
body[data-ai-online="false"] [data-ai-gate] {
  pointer-events: none; opacity: 0.5; cursor: not-allowed;
}
