/* Ray J. Bonklon — the home-page companion (public/companion.js).
   PEXODUS-NATIVE STYLING. Every value below is taken from the two places the real product defines
   its look, not invented:
     - the Webflow template's own tokens/recipes (public/override.css + the export stylesheet):
       --border--primary, --background--primary/secondary/tertiary, --_structure---radius--large,
       --_elements---button-small--*, --text--alternate  — the .process-card-small surface and the
       .button-secondary-small pill are reproduced verbatim.
     - the live surface's nested-panel idiom (src/components/live/*): a card that CLIPS its own
       rounded frame, with the rig ATTACHED TO ITS BOTTOM edge.

   LAYOUT, top to bottom:
     .rayj-head      title + close (in flow)
     .rayj-stage     the rig, ABSOLUTE, pinned to the panel's BOTTOM (like live-stage.tsx puts the
                     character at `absolute bottom-0 left-1/2`), so the dog stands on the panel's
                     bottom edge instead of floating in the middle.
     .rayj-controls  ABSOLUTE, overlaying the bottom of the dog — the two pills sit ON him.
   The panel OWNS its height; the stage and controls are both taken out of flow against it. */

.rayj {
  position: fixed;
  /* SAME horizontal offset as the music pill (`.music-pill { right: 20px }`), so the two stack in
     one column. */
  right: 20px;
  /* FIXED offset, per the owner: 128px desktop, 96px on mobile (see the media query below). This
     replaced a runtime measurement of the capsule — the character now sits at one absolute height
     regardless of what the player is doing, which is predictable to design against. */
  bottom: 128px;
  z-index: 998; /* just under the music pill's 999 */
  font-family: var(--_typography---family--body, Inter, sans-serif);
  letter-spacing: -0.006em;
}

/* ---------- the 64x64 pill ----------
   The pill IS the collapsed panel: expanding swaps them, so the character reads as one object that
   grows. The pill is hidden (not removed) while expanded, so the corner anchor never moves. */
.rayj-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border--primary, #ffffff0f);
  border-radius: var(--_structure---radius--round, 999px);
  background-color: var(--background--primary, #ffffff0a);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  /* the template's own card inset highlight (.process-card-small / .music-pill) */
  box-shadow: inset 0 1px 2px #ffffff0f, inset 0 0.5px 0.5px #ffffff14;
  cursor: pointer;
  transition: border-color 0.3s, opacity 0.25s, visibility 0.25s;
  position: relative;
  z-index: 2;
}
.rayj-pill:hover {
  border-color: var(--border--secondary, #ffffff14);
}
.rayj-pill:focus-visible {
  outline: 2px solid var(--text--brand, #ff4c1f);
  outline-offset: 2px;
}
/* The rig is 1000x839; crop to the head so the face fills the 64px circle. */
.rayj-pill-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 18%;
  transform: scale(1.9);
  transform-origin: 50% 22%;
}

/* THE PILL FACE — a purpose-built 1:1 avatar, not a crop of the rig.
   `companion-avatar.webp` is a 512x512 square: the head and shoulders feathered into the SAME
   dithered backdrop as the panel, so the face does NOT fill the frame (the art shows on all four
   sides) and the pill reads as the same painting as the panel it opens. `cover` on a square source
   in a square box is a no-op crop, so nothing is cut. */
.rayj-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  display: block;
}
.rayj[data-expanded="true"] .rayj-pill {
  /* The expanded panel takes over the corner. No transform here — a scale would leave the pill
     measuring 59px instead of its 64px spec. */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------- the panel: the native .process-card-small surface ---------- */
.rayj-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(320px, calc(100vw - 40px));
  /* The panel owns the height the rig stands in. Overflow-hidden is what trims the dog to the
     card's rounded frame, exactly like .process-card-small / the live nested panels. */
  height: 400px;
  max-height: calc(100vh - 140px);
  overflow: hidden;
  border: 1px solid var(--border--primary, #ffffff0f);
  border-radius: var(--_structure---radius--large, 24px);
  /* INK, not the template's 6% white fill: the dithered backdrop is the surface, and a translucent
     card over it washed the art out. */
  background-color: var(--color-ink, #050100);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: inset 0 1px 2px #ffffff14, inset 0 0.5px 0.5px #ffffff1f;

  /* THE EXPANSION — the 64x64 pill growing into the panel, in the repo's own motion language.
     Both origins sit on the pill's corner, and the closed scale is 0.2 because the panel is 320px
     wide (64 / 320 = 0.2): at rest the collapsed panel IS the pill's footprint, so opening reads as
     one object expanding rather than a second surface appearing. Timings are the tokens from
     app/globals.css: `content-in` 300ms cubic-bezier(0.33,1,0.68,1) to open, `content-out` 400ms
     cubic-bezier(0.25,0.1,0.25,1) to close. */
  transform-origin: 100% 100%;
  opacity: 0;
  visibility: hidden;
  transform: scale(0.2);
  transition: opacity 400ms cubic-bezier(0.25, 0.1, 0.25, 1),
    transform 400ms cubic-bezier(0.25, 0.1, 0.25, 1), visibility 400ms;
}
.rayj[data-expanded="true"] .rayj-panel {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  transition: opacity 300ms cubic-bezier(0.33, 1, 0.68, 1),
    transform 300ms cubic-bezier(0.33, 1, 0.68, 1), visibility 300ms;
}

/* WHILE THE ONBOARDING TOUR RUNS he is ABOVE the dimming overlay. The tour's spotlight is a z-index
   2147483000 cutout whose box-shadow darkens everything else; the companion must not be dimmed,
   because he is the one narrating. `data-tour` is set by companion.js on the tour events. */
.rayj[data-tour="true"] {
  z-index: 2147483002;
}

/* THE REAL BACKDROP — GENUINE PIXEL DITHERING.
   The artwork is composited onto ink, cover-cropped, then reduced at the panel's OWN size
   (320x400 — not 2x, which the browser would downscale and average into grey) against a 16-colour
   palette median-cut from the BRIGHT source, so the dots keep real contrast. Saved LOSSLESS: a
   lossy encode smeared 12 colours into 4,722 and turned the dither into a gradient (measured).
   Generated by scripts/dither-backdrop.py with the published kernels (Tanner Helland's reference):
   Floyd-Steinberg, Jarvis-Judice-Ninke, Stucki, Burkes, Sierra, Atkinson, Bayer 4x4/8x8, and none.
   A `.png` sibling is the fallback for browsers without WebP (OBS's older CEF among them). */
.rayj-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: var(--color-ink, #050100);
  /* Default variant is NONE: the plain greyscale artwork, no dithering. The operator panel swaps this
     for a `companion-bg-<algo>` variant when someone wants a texture. */
  background-image: url("/companion-bg-none.webp");
  background-image: image-set(url("/companion-bg-none.webp") type("image/webp"), url("/companion-bg-none.png") type("image/png"));
  /* ONE DITHER CELL = ONE CSS PIXEL: `100% 100%` is a 1:1 map at the panel's own size, and
     `pixelated` stops the browser bilinear-averaging the pattern at devicePixelRatio 2 — the
     reason an earlier build read as a flat dark wash instead of a dither. */
  background-size: 100% 100%;
  background-position: 0 0;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

/* ---------- head (in flow, above the rig) ---------- */
.rayj-head {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 20px 20px 0;
}
.rayj-title {
  /* The site's HEADING face, exactly as `h1-h6` use it in app/globals.css:
     --font-display (Parkinsans) / weight 500 / -0.02em. It was rendering in the body font before. */
  color: var(--text--primary, #fff);
  font-family: var(--_typography---family--heading, "Parkinsans", "Inter", Arial, sans-serif);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.02em;
  text-transform: none;
}
.rayj-status {
  margin-top: 2px;
  color: var(--text--tertiary, #ffffffa3);
  font-size: 12px;
  line-height: 1.4;
}
.rayj-close {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  /* the .button-secondary-small pill, rendered as an icon-only control */
  border-radius: var(--_elements---button-small--border-radius, 99px);
  background-color: var(--white--16, #ffffff29);
  color: var(--text--primary, #fff);
  cursor: pointer;
  transition: background-color 0.3s;
}
.rayj-close:hover {
  background-color: var(--white--24, #ffffff3d);
}
.rayj-close:focus-visible {
  outline: 2px solid var(--text--brand, #ff4c1f);
  outline-offset: 2px;
}

/* ---------- the rig, ATTACHED TO THE PANEL'S BOTTOM ----------
   Mirrors live-stage.tsx: `absolute bottom-0 left-1/2` + an inline translateX(-50%). Height-driven
   so the base's aspect ratio is never distorted; the panel's overflow:hidden trims the card frame
   around him.

   HEIGHT: the rig sits UNDER the head (which is ~62px tall) and the controls overlap its foot.
   The rig's aspect is 1000:839, so the height is chosen to keep the WIDTH inside the panel's
   content box (318px at the 320px card): 266px * 1.1919 = 317px — the shoulders are never cut. */
.rayj-stage {
  position: absolute;
  bottom: 0;
  left: 50%;
  z-index: 1;
  height: 266px;
  transform: translateX(-50%);
  pointer-events: none;
}
.rayj-base {
  display: block;
  height: 100%;
  width: auto;
  max-width: none;
}
.rayj-mouth {
  position: absolute;
  pointer-events: none;
}

/* ---------- the two control pills: ABSOLUTE, OVERLAYING the dog's bottom ----------
   Both are the template's own .button-secondary-small recipe: 32px tall, 99px radius,
   --white--80 fill, --text--alternate (dark) label, and the template's two-layer shadow. They sit
   ON TOP of the rig (z 3), pinned to the panel's bottom edge. */
.rayj-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
}
.rayj-talk,
.rayj-audio {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--_elements---button-small--gap, 6px);
  height: var(--_elements---button-small--size, 32px);
  padding: var(--_elements---button-small--vertical-padding, 6px)
    var(--_elements---button-small--horizontal-padding, 10px);
  border: 0;
  border-radius: var(--_elements---button-small--border-radius, 99px);
  background-color: var(--white--80, #fffc);
  color: var(--text--alternate, #050100);
  font-family: var(--_typography---family--body, Inter, sans-serif);
  font-size: var(--_elements---button-small--font-size, 12px);
  font-weight: var(--_elements---button-small--font-weight, 500);
  line-height: var(--_elements---button-small--line-height, 1.5);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.3s;
  box-shadow: 0 2px 2px -1px #0a020014, 0 0.5px 1px #0a020014, inset 0 3px 3px #fff;
}
.rayj-talk:hover,
.rayj-audio:hover {
  background-color: var(--white--90, #ffffffe6);
}
.rayj-talk:focus-visible,
.rayj-audio:focus-visible {
  outline: 2px solid var(--text--brand, #ff4c1f);
  outline-offset: 2px;
}
/* The primary action is the brand fill — .button-primary-small, the template's own accent pill. */
.rayj-talk {
  background-color: var(--background--brand, #ff4c1f);
  color: var(--text--primary, #fff);
}
.rayj-talk:hover {
  background-color: var(----primary--orange-hover, #ff5c33);
}
.rayj-talk.is-listening {
  background-color: var(--white--80, #fffc);
  color: var(--text--alternate, #050100);
}
/* "Enable audio" is a toggle: aria-pressed=false means muted, so it dims to the quiet fill. */
.rayj-audio[aria-pressed="false"] {
  background-color: var(--background--tertiary, #ffffff14);
  color: var(--text--tertiary, #ffffffa3);
  box-shadow: inset 0 2px 8px #ffffff0a, inset 0 1px 3px #ffffff1a, inset 0 0.5px 0.5px #ffffff1f;
}
.rayj-talk-label {
  line-height: inherit;
}

/* ================================================================ THE OPERATOR PILL
   A TEMPORARY dev control on the home page: type a line instead of speaking it. It reproduces
   the live stage's operator dock (src/components/live/operator-dock.tsx) rather than inventing a
   second pattern, using the same app tokens the dock's Tailwind classes resolve to:
     card   rounded-md (16px) · border-border-primary · bg-background-primary · p-4 (16px)
            shadow-card-glow · backdrop-blur-xl (24px)
     input  rounded-pill (99px) · bg-background-secondary · min-h-9 (36px) · px-3 · text-sm
            shadow-inset-soft · placeholder text-quaternary
     send   Button size="sm" primary: h-8 · px-2.5 · text-xs · rounded-pill · bg-brand
   z-index 1001: above the music pill (999) and the companion (998), and above the Webflow nav
   overlay (1000) — the dock is a dev tool and must never be buried.
   It is deliberately NOT hidden by Ctrl+E (that key belongs to the OBS-captured stage). */
.rayj-op {
  position: fixed;
  /* To the LEFT of the whole companion column (companion is 320px wide, 20px inset). The operator
     card is 240px + a 48px handle, so anchoring its RIGHT edge at 356px keeps both controls
     readable at once and never stacks one over the other. */
  right: 356px;
  bottom: 78px;
  z-index: 1001;
  font-family: var(--_typography---family--body, Inter, sans-serif);
  letter-spacing: -0.006em;
}

/* The 48px round handle — the dock's own toggle recipe. */
.rayj-op-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--border--primary, #ffffff0f);
  border-radius: var(--_structure---radius--round, 999px);
  background-color: var(--background--primary, #ffffff0a);
  color: var(--text--quaternary, #ffffff8f);
  box-shadow: inset 0 1px 2px #ffffff0f, inset 0 0.5px 0.5px #ffffff14;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: color 0.3s, background-color 0.3s;
}
.rayj-op-handle:hover {
  color: var(--text--primary, #fff);
}
.rayj-op-handle:focus-visible {
  outline: 2px solid var(--text--brand, #ff4c1f);
  outline-offset: 2px;
}

/* The card — the dock's panel recipe (rounded-md / 16px, p-4, shadow-card-glow).
   It opens ABOVE the handle (the dock's own placement): the handle stays at the bottom-right of
   the operator column, clear of the companion, and the card rises into empty page space. */
.rayj-op-panel {
  position: absolute;
  right: 0;
  bottom: 60px; /* above the 48px handle + 12px */
  width: 240px;
  padding: 16px;
  border: 1px solid var(--border--primary, #ffffff0f);
  border-radius: var(--radius-md, 16px);
  background-color: var(--background--primary, #ffffff0a);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  box-shadow: inset 0 4px 12px -2px #f77f5b3d, inset 0 4px 8px #ffffff0f, inset 0 2px 3px #ffffff14,
    inset 0 1px 1px #ffffff1f, 0 2px 2px -1px #0a02001f, 0 1px 1px -0.5px #0a02001f;
}
.rayj-op-panel[hidden] {
  display: none;
}

.rayj-op-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.rayj-op-title {
  color: var(--text--tertiary, #ffffffa3);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.rayj-op-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--_structure---radius--round, 999px);
  background-color: transparent;
  color: var(--text--quaternary, #ffffff8f);
  cursor: pointer;
  transition: color 0.3s, background-color 0.3s;
}
.rayj-op-close:hover {
  color: var(--text--primary, #fff);
  background-color: var(--background--secondary, #ffffff0f);
}

/* The compose row: the dock's Input (rounded-pill, min-h-9) + Button size="sm". */
.rayj-op-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.rayj-op-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border--primary, #ffffff0f);
  border-radius: var(--radius-pill, 99px);
  background-color: var(--background--secondary, #ffffff0f);
  color: var(--text--primary, #fff);
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  outline: none;
  box-shadow: inset 0 1px 2px #ffffff0f, inset 0 0.5px 0.5px #ffffff14;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: border-color 0.3s;
}
.rayj-op-input::placeholder {
  color: var(--text--quaternary, #ffffff8f);
}
.rayj-op-input:hover,
.rayj-op-input:focus {
  border-color: var(--border--tertiary, #ffffff1f);
}
.rayj-op-input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.rayj-op-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-pill, 99px);
  background-color: var(--background--brand, #ff4c1f);
  color: var(--text--primary, #fff);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s;
}
.rayj-op-send:hover {
  background-color: #ff5c33;
}
.rayj-op-send:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* The new-visitor replay row: the dock's SECONDARY button (border, no fill) so it reads as a
   dev/destructive-ish action rather than the primary "send". */
.rayj-op-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border--primary, #ffffff0f);
}
.rayj-op-reset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border--primary, #ffffff0f);
  border-radius: var(--radius-pill, 99px);
  background-color: transparent;
  color: var(--text--secondary, #ffffffb8);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s, border-color 0.3s;
}
.rayj-op-reset:hover {
  background-color: var(--background--secondary, #ffffff0f);
  border-color: var(--border--tertiary, #ffffff1f);
}
.rayj-op-reset:focus-visible {
  outline: 2px solid var(--text--brand, #ff4c1f);
  outline-offset: 2px;
}

/* The dither switcher: a wrapping grid of the dock's small secondary pills, the active one brand. */
.rayj-op-dithers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.rayj-op-dither {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border--primary, #ffffff0f);
  border-radius: var(--radius-pill, 99px);
  background-color: transparent;
  color: var(--text--tertiary, #ffffffa3);
  font: inherit;
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.3s, background-color 0.3s, border-color 0.3s;
}
.rayj-op-dither:hover {
  color: var(--text--primary, #fff);
  background-color: var(--background--secondary, #ffffff0f);
}
.rayj-op-dither.is-active {
  border-color: var(--background--brand, #ff4c1f);
  background-color: var(--background--brand, #ff4c1f);
  color: var(--text--primary, #fff);
}
.rayj-op-dither:focus-visible {
  outline: 2px solid var(--text--brand, #ff4c1f);
  outline-offset: 2px;
}

.rayj-op-status {
  margin: 12px 0 0;
  color: var(--text--tertiary, #ffffffa3);
  font-size: 11px;
  line-height: 1.4;
}
.rayj-op-note {
  margin: 8px 0 0;
  color: var(--text--quaternary, #ffffff8f);
  font-size: 11px;
  line-height: 1.4;
}

@media screen and (max-width: 767px) {
  /* A phone has no room for two adjacent columns, and the companion's EXPANDED panel covers most
     of the right side. So the operator moves to the TOP-right here, where the companion never
     reaches, and its card opens DOWNWARD from the handle. */
  .rayj-op {
    right: 20px;
    bottom: auto;
    top: 96px;
  }
  .rayj-op-panel {
    top: 60px;
    bottom: auto;
    width: min(240px, calc(100vw - 40px));
  }
}

/* Between 768px and the point where two columns fit (companion 320 + gap + operator 240), the
   side-by-side anchor would overflow the left edge, so move it to the top there too. */
@media screen and (min-width: 768px) and (max-width: 900px) {
  .rayj-op {
    right: 20px;
    bottom: auto;
    top: 96px;
  }
  .rayj-op-panel {
    top: 60px;
    bottom: auto;
  }
}

/* ---------- small screens ---------- */
@media screen and (max-width: 767px) {
  .rayj {
    /* Fixed mobile offset (96px) and the capsule's own 20px right inset, so the pill stays in the
       same column as the player on phones. */
    right: 20px;
    bottom: 96px;
  }
  .rayj-panel {
    width: min(320px, calc(100vw - 32px));
    height: 360px;
    max-height: calc(100vh - 120px);
  }
  .rayj-stage {
    height: 264px;
  }
  .rayj-head {
    padding: 16px 16px 0;
  }
}
@media screen and (max-width: 991px) and (max-height: 620px) {
  .rayj-panel {
    height: 300px;
    max-height: calc(100vh - 108px);
  }
  .rayj-stage {
    height: 220px;
  }
  .rayj-controls {
    bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rayj-pill,
  .rayj-panel,
  .rayj-talk,
  .rayj-audio,
  .rayj-close {
    transition: none;
  }
}
