/* =========================================================================
   Cabinhub News — Ember, the newsroom's agent (component styles).

   The character itself is drawn on a <canvas> by the ported renderer in
   js/ember-character.js (the MIT-licensed upstream canvas-2D renderer, renamed
   to Ember at the module boundary). This file dresses the host, the trigger,
   the status label, the assistant panel and the three preference fallbacks.

   Colour comes only from css/tokens.css: the wardrobe sets --m-accent,
   --m-aura and --m-ring per tone, and everything below reads those three. No
   new colour, radius, spacing or duration is declared here.

   Three preference blocks are part of the contract, not decoration:
   prefers-reduced-motion (the canvas animation is also skipped in JS; the
   still frame stays legible through pose/outfit), prefers-reduced-transparency
   (the panel turns solid), forced-colors (the canvas is swapped for an SVG
   silhouette that keeps a system-palette outline).
   ========================================================================= */

.mascot {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  --m-accent: var(--accent);
  --m-aura: 0.10;
  --m-ring: 0.24;
}

/* --------------------------------------------------------------- trigger --
   Sized with its neighbours in the masthead controls (css/chrome.css), so the
   row keeps one rhythm. It takes the 44px tap token (measured live 2026-11-17:
   it was the only primary masthead control under it); the character fills it. */
.mascot__trigger {
  appearance: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 2px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background-color var(--dur-1) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .mascot__trigger:hover { background: var(--paper-2); }
}
.mascot__trigger:active { background: var(--paper-3); }

/* The canvas is the character. Its pixel size is set in JS (dpr-aware), so CSS
   only fixes the layout box and lets it paint at any scale. */
.mascot__canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  /* The ported body is a light warm-grey superellipsoid; a hairline shadow keeps
     it from dissolving into the light paper. The tone aura behind it (below)
     carries the Ember colour. */
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.3));
}

/* A warm, tone-coloured aura behind the character. It makes the assistant read
   as Ember's presence (not a bare grey blob) and shows the tone at a glance,
   without recolouring the verbatim upstream body. */
.mascot__trigger::before {
  content: "";
  position: absolute;
  inset: 3px;
  z-index: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--m-accent) 0%, transparent 70%);
  opacity: calc(var(--m-aura) * 1.2);
  pointer-events: none;
}

/* A still SVG silhouette shown only in forced-colors, where a canvas raster is
   not guaranteed to stay visible. Decorative (aria-hidden in the markup). */
.mascot__fallback {
  display: none;
  width: 100%;
  height: 100%;
}

/* The short spoken-by-sight label ("Working", "Needs approval"). It is
   aria-hidden: the single polite live region carries the full sentence, so a
   screen reader never hears this twice. Shown only where the masthead has room. */
.mascot__now {
  display: none;
  font-size: var(--fs-label);
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12ch;
}
@media (min-width: 1024px) {
  .mascot__now { display: inline-block; }
}

/* ------------------------------------------------ state, with motion off --
   The still frames. Each is legible without animation: the pose (yaw/pitch) and
   the outfit are drawn by the renderer, and these rules add the one posture a
   stylesheet can carry. */
.mascot[data-state="stopped"] .mascot__canvas,
.mascot[data-state="stopped"] .mascot__fallback { opacity: 0.5; }
.mascot[data-state="unknown"] .mascot__canvas,
.mascot[data-state="unknown"] .mascot__fallback { opacity: 0.62; }

/* ----------------------------------------------------------------- panel --
   A sheet laid over the masthead: the newsroom's own paper, a strong hairline,
   no shadow (tokens.css). It is not a modal: it takes no focus on open, it is
   not a focus trap, and Escape or a click outside closes it. */
.mascot__panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 30;
  width: min(300px, calc(100vw - 2rem));
  padding: var(--sp-3) var(--sp-4);
  background: var(--canvas);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-md);
  text-align: left;
  animation: m-ember-panel-in var(--dur-1) var(--ease) both;
}
/* The sheet takes the bar's light blend where the engine can mix colours; the
   opaque --canvas above is the fallback, so the panel never paints transparent
   in an engine without color-mix. */
@supports (background: color-mix(in srgb, red 20%, transparent)) {
  .mascot__panel {
    background: color-mix(in srgb, var(--canvas) 94%, transparent);
    backdrop-filter: saturate(1.05) blur(12px);
    -webkit-backdrop-filter: saturate(1.05) blur(12px);
  }
}
@keyframes m-ember-panel-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.mascot__panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  margin: 0 0 var(--sp-2);
}
.mascot__panel-name {
  font-family: var(--font-brand);
  font-size: var(--fs-title);
  color: var(--ink);
}
.mascot__panel-agent {
  font-size: var(--fs-label);
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mascot__status {
  margin: 0;
  font-size: var(--fs-small);
  line-height: 1.45;
  color: var(--ink-soft);
}
.mascot__meta {
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-label);
  color: var(--ink-faint);
}
.mascot__meta:empty { display: none; }

.mascot__meter {
  height: 2px;
  margin-top: var(--sp-3);
  background: var(--paper-3);
  border-radius: 1px;
  overflow: hidden;
}
.mascot__meter[hidden] { display: none; }
.mascot__meter span {
  display: block;
  height: 100%;
  background: var(--m-accent);
  transform-origin: left center;
  transition: transform var(--dur-2) var(--ease);
}

/* --------------------------------------------------------------- the ask --
   The assistant's own question box. It routes to the existing search view, so
   this is the one agentic affordance the reader can reach from the character. */
.mascot__ask {
  display: flex;
  gap: var(--sp-2);
  margin: var(--sp-3) 0 0;
}
.mascot__ask-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--sp-2) var(--sp-3);
  font: inherit;
  font-size: var(--fs-small);
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
}
.mascot__ask-input::placeholder { color: var(--ink-faint); }
.mascot__ask-btn {
  flex: 0 0 auto;
  padding: var(--sp-2) var(--sp-3);
  font: inherit;
  font-size: var(--fs-small);
  color: var(--accent-ink);
  background: var(--m-accent);
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.mascot__ask-btn:hover { filter: brightness(1.05); }
.mascot__ask--brief .mascot__ask-btn { background: var(--paper-3); color: var(--ink); }

/* The compact trigger's pointer to the docked assistant. */
.mascot__open {
  width: 100%;
  margin-top: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  font: inherit;
  font-size: var(--fs-small);
  color: var(--accent-ink);
  background: var(--m-accent);
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
}

/* The assistant's answers: the ranked headlines it just searched or briefed. */
.mascot__results {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  max-height: 42vh;
  margin-top: var(--sp-2);
  overflow-y: auto;
}
.mascot__results[hidden] { display: none; }
.mascot__results-head {
  margin: 0 0 2px;
  font-size: var(--fs-label);
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}
.mascot__result {
  display: block;
  padding: var(--sp-2);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  color: var(--ink);
  text-decoration: none;
}
.mascot__result:hover { background: var(--paper-3); }
.mascot__result-title { display: block; font-size: var(--fs-small); font-weight: 600; line-height: 1.3; }
.mascot__result-snippet { display: block; margin-top: 2px; font-size: var(--fs-label); line-height: 1.35; color: var(--ink-soft); }
.mascot__note { margin: var(--sp-2) 0 0; font-size: var(--fs-label); color: var(--ink-soft); }
.mascot__note[hidden] { display: none; }
.mascot__retry {
  margin-left: var(--sp-1);
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------------------------------------------------- the docked companion --
   The prominent assistant: a real, always-visible presence bottom-right on every
   route, at a size a reader perceives (not a favicon). The panel sits above the
   character and is open by default on a wide screen. */
.agent-dock {
  position: fixed;
  right: clamp(0.75rem, 2vw, 1.5rem);
  bottom: clamp(0.75rem, 2vw, 1.5rem);
  z-index: 40;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: var(--sp-2);
  width: min(344px, calc(100vw - 1.5rem));
  max-width: calc(100vw - 1.5rem);
}
.agent-dock .mascot__trigger {
  width: 132px;
  height: 132px;
  padding: 0;
}
.agent-dock .mascot__now { display: none; }
.agent-dock .mascot__panel {
  position: relative;
  top: auto;
  right: auto;
  width: min(344px, calc(100vw - 1.5rem));
  max-height: 70vh;
  margin: 0;
  overflow: auto;
}
@media (max-width: 767px) {
  .agent-dock .mascot__trigger { width: 96px; height: 96px; }
  .agent-dock .mascot__panel { width: calc(100vw - 1.5rem); }
}

/* ------------------------------------------------------------ preferences --
   Reduced motion: the canvas animation is skipped in JS, and this switches off
   the one CSS gesture (the panel slide) and every hover transition. The
   still-frame rules above stay in force, which is what keeps a state legible. */
@media (prefers-reduced-motion: reduce) {
  .mascot *,
  .mascot *::before,
  .mascot *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* The panel is opaque paper in the newsroom; engines that blend it with the
   bar behind get a solid sheet when the reader asks for less transparency. */
@media (prefers-reduced-transparency: reduce) {
  .mascot__panel {
    background: var(--canvas);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

/* In forced-colours modes a gradient-filled canvas can vanish. Swap it for the
   SVG silhouette and keep the character, the panel and the status in the system
   palette so nothing disappears. */
@media (forced-colors: active) {
  .mascot__canvas { display: none; }
  .mascot__fallback { display: block; fill: Canvas; stroke: CanvasText; stroke-width: 2; }
  .mascot__now { color: CanvasText; }
  .mascot__panel {
    background: Canvas;
    border-color: CanvasText;
  }
  .mascot__trigger { border: 1px solid CanvasText; }
  .mascot__ask-input,
  .mascot__ask-btn {
    color: ButtonText;
    background: ButtonFace;
    border: 1px solid ButtonText;
  }
  .mascot__meter span { background: Highlight; }
}
