/* ============================================================
   PREVIEW OVERRIDES — rotating-text highlight + per-letter roll
   Loaded ONLY by index.preview.html. Originals untouched.
   Works together with preview-rotating.js.

   Goal:
     - The purple highlight box stays STATIONARY and only resizes
       its width to fit each word's length.
     - The word's LETTERS roll vertically, staggered from a random
       pivot letter (handled in preview-rotating.js).
   ============================================================ */

/* ---- Stacked logo: enlarged for clear visibility (preview) ----
   The stacked mark+wordmark has internal whitespace, so it needs to
   render large to read well. Give the nav a taller bar to fit it. */
:root { --nav-h: 65px; }
.nav .logo__img { height: 44px; }
.footer__about .logo__img { height: 102px; }

/* The host IS the stationary purple box now. It keeps the base
   rules from reactbits.css (overflow:hidden, fixed height,
   position:relative, width transition) and just gains the fill.

   IMPORTANT: styles.css gives `.hero h1 em` and `.section-title em`
   a gradient `background-clip: text` (the original gradient-text
   look). That clips ANY background to the element's own text — and
   our host has no direct text (the letters live in child spans), so
   the purple would be clipped to nothing and stay invisible. So we
   must (a) out-specify those rules and (b) reset the clip back to
   border-box so the solid purple actually paints as a box. */
.mx-fx-rot,
.hero h1 em.mx-fx-rot,
.section-title em.mx-fx-rot {
  background: color-mix(in srgb, var(--purple) 99%, transparent);   /* near-solid indigo pill — opacity raised ~80% from the earlier softened 55% (per user) */
  -webkit-background-clip: border-box;
  background-clip: border-box;
  border-radius: 0.18em;   /* curved corners; em-based so it scales with the heading */
  /* A rolling word has will-change:transform -> its own compositing layer,
     which would otherwise BLEED past overflow:hidden during the animation.
     clip-path clips composited descendants reliably (incl. the rounded
     corners); translateZ(0) promotes the box so children clip to it. */
  /* Rounded clip for the rolling words. Words animate `top` (not transform),
     so they stay on the main thread and are reliably clipped here. */
  -webkit-clip-path: inset(0 round 0.18em);
  clip-path: inset(0 round 0.18em);
}

/* Hero rotating box: a bit taller (and matching line-height to re-centre
   the word) so tall italic-serif glyphs — descenders like g/y/p, ascenders,
   flourishes — get breathing room and aren't clipped or touching the edges.
   Scoped to the hero so the inline section-title boxes keep their alignment. */
.hero h1 em.mx-fx-rot {
  height: 1.36em;
  line-height: 1.36em;
  margin-top: 0.22em;   /* breathing room between "results with" and the box */
}

/* Hero sub: widen so the longer sentence wraps to TWO lines, not three. */
.hero__sub { max-width: 780px; }

/* Section-title rotating pill flows INLINE right after the static text (per user) —
   it no longer drops to its own line below. The hero pill stays a centred block
   (handled by `.hero h1 em.mx-fx-rot` above). */
.section-title em.mx-fx-rot { display: inline-flex; }
/* keep the leading word + its rotating pill together so the pill never drops to its
   own line below (e.g. "…get <pill>" stays beside "get"). */
.section-title .mx-keep { white-space: nowrap; }

/* Each word is a stacked layer inside the box. Layers are absolutely
   positioned so the outgoing and incoming words can overlap while the
   letters roll. The 0.32em side padding insets the text from the box
   edges and is included when the box width is measured. */
.pr-stage {
  position: absolute;
  left: 0;
  top: 0;
  white-space: pre;            /* keep spaces; never wrap */
  padding: 0 0.32em;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  line-height: inherit;
  color: #fff;
  -webkit-text-fill-color: #fff;
}

/* Each WORD rolls vertically as one unit; the box's overflow:hidden clips it. */
.pr-word {
  display: inline-block;
  white-space: pre;
  position: relative;   /* so the JS-animated `top` actually moves it */
  top: 0;
  /* We animate `top` (NOT transform) on purpose: a transform-animated
     element is promoted to its own compositing layer, which bleeds past
     the box's overflow/clip in this engine. `top` stays on the main
     thread, so overflow/clip-path reliably clips the rolling word. */
}

/* Reduced motion: no rolling, words just sit in the box. */
@media (prefers-reduced-motion: reduce) {
  .mx-fx-rot { transition: none !important; }
  .pr-word { transition: none !important; top: 0 !important; }
}

/* ---- Stock-research Quality/Value/Momentum meters ----
   These .bar spans were `display:inline`, so `height:6px` was ignored and
   they rendered ~23px tall (chunky, inconsistent with the rest of the site).
   Make them block so the 6px height applies and they read as thin, uniform
   meters like every other bar on the page. */
.s-research__factor .bar { display: block; width: 100%; height: 6px; }

/* ---- Market-cap elastic slider: remove the over-drag stretch glitch ----
   The track stretched (scaleX) past the ends and the spring overshot, so the
   fill "extended itself" beyond the thumb/endpoints. Pin the track (no
   stretch) and use a non-overshooting ease so the fill ends exactly at the
   thumb and never auto-extends. */
.elasticslider { --es-spring: cubic-bezier(.22, .61, .36, 1); }
.elasticslider__track { transform: none !important; }

/* ---- AI Screener: entrance animation when chip swaps the results ---- */
@keyframes prScreenerIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.s-screener__results.pr-screener-swap .s-screener__row {
  animation: prScreenerIn 0.32s ease both;
}
.s-screener__results.pr-screener-swap .s-screener__row:nth-child(2) { animation-delay: 0.06s; }
.s-screener__results.pr-screener-swap .s-screener__row:nth-child(3) { animation-delay: 0.12s; }
@media (prefers-reduced-motion: reduce) {
  .s-screener__results.pr-screener-swap .s-screener__row { animation: none; }
}

/* ---- Stock Research: entrance animation when a tab swaps the metrics ---- */
.s-research__metrics.pr-research-swap .s-research__metric {
  animation: prScreenerIn 0.3s ease both;
}
.s-research__metrics.pr-research-swap .s-research__metric:nth-child(2) { animation-delay: 0.03s; }
.s-research__metrics.pr-research-swap .s-research__metric:nth-child(3) { animation-delay: 0.06s; }
.s-research__metrics.pr-research-swap .s-research__metric:nth-child(4) { animation-delay: 0.09s; }
.s-research__metrics.pr-research-swap .s-research__metric:nth-child(5) { animation-delay: 0.12s; }
.s-research__metrics.pr-research-swap .s-research__metric:nth-child(6) { animation-delay: 0.15s; }
@media (prefers-reduced-motion: reduce) {
  .s-research__metrics.pr-research-swap .s-research__metric { animation: none; }
}

/* ---- DotGrid background ----
   Fixed full-viewport canvas behind ALL content. The page background
   (body) shows through: dark in dark mode (existing), white in light
   mode. Dots are painted by preview-dotgrid.js (same color both modes). */
.pr-dotgrid {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;            /* above the body background, below content */
  pointer-events: none;   /* never intercept clicks; physics uses window events */
  display: block;
  opacity: 0.6;           /* dots at 60% visibility — 80% of the previous 0.75
                             (per user), taken down again after the grid was
                             doubled in density */
}
/* MeritX Orb (WebGL hero background) — sits over the dotgrid, below content.
   opacity/transform are driven by mx-orb.js for the scroll parallax + fade. */
.mx-orb {
  position: fixed;
  /* START BELOW THE NAVBAR. The canvas used to be `inset: 0` (whole viewport),
     and because the navbar is translucent + backdrop-blurred the orb's ring
     showed straight through it and read as overlapping the nav.
     `--nav-h` is the nav's BOTTOM edge — mx-ticker.css redefines it on body to
     include the index tape, so this follows the tape automatically and still
     resolves correctly on pages that have no tape. */
  top: var(--nav-h);
  left: 0;
  /* ⚠️ width/height MUST be explicit. <canvas> is a REPLACED element, and a
     positioned replaced element with `width:auto` uses its INTRINSIC size
     rather than stretching between left/right — so relying on the four insets
     collapsed it to the canvas default (300x150), which mx-orb.js then read
     back via offsetWidth and locked in. `100%` on a fixed element resolves
     against the viewport, so this is "viewport minus the navbar". */
  width: 100%;
  height: calc(100% - var(--nav-h));
  /* ⚠️ mx-orb.js must NOT write canvas.style.width/height — inline styles beat
     this rule and the canvas would snap back to full-viewport. It sizes its
     backing store from offsetWidth/offsetHeight instead. */
  z-index: -1;
  pointer-events: none;
  display: block;
  transform-origin: 50% 42%;
  will-change: opacity, transform;
}
/* light mode: white page background (per user) */
[data-theme="light"] body { background: #ffffff; }

/* A transparent band between the Research Copilot and Insights sections
   (both sit on solid --bg-elev, which covers the grid) so the fixed DotGrid
   background shows through as a dotted divider. */
.mx-dot-band { height: clamp(64px, 8vw, 100px); background: transparent; }

/* Feature MOCK screenshots follow the theme now — light/white in light mode,
   dark in dark mode (per user). No forced-dark token override here; they inherit
   the page's :root tokens like everything else. */

/* ---- Research Copilot: clickable chips + answer reveal ---- */
.s-copilot__qrow .chip { cursor: pointer; transition: background .3s ease, border-color .3s ease, color .3s ease; }
.s-copilot__row--ai.pr-copilot-in { animation: prScreenerIn 0.34s ease both; }
@media (prefers-reduced-motion: reduce) {
  .s-copilot__row--ai.pr-copilot-in { animation: none; }
}
/* ---- Research Copilot: auto-play demo (typing caret + active chip) ---- */
.s-copilot__qrow .chip.is-active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 55%, transparent); color: var(--accent); }
.s-copilot__bubble--user.is-typing::after { content: "\258D"; margin-left: 1px; color: var(--accent); animation: prCaret .9s steps(1) infinite; }
@keyframes prCaret { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* widen the copilot frame (visual column) so the three "Try asking" prompts fit on one line */
.s-copilot__qrow .chip { font-size: 0.72rem; padding: 6px 10px; }
.s-copilot__qrow .chip::before { margin-right: 4px; }
@media (min-width: 640px) {
  .s-copilot .feat { grid-template-columns: minmax(0, 1.48fr) minmax(0, 0.78fr); gap: clamp(24px, 3.2vw, 48px); }
  .s-copilot__qrow { flex-wrap: nowrap; }
  .s-copilot__qrow .chip { white-space: nowrap; flex: 0 1 auto; }
}

/* ---- Research Copilot: navigating cursor + click ripple + staggered rows ---- */
.s-copilot__mock { position: relative; }
.pr-cursor {
  position: absolute; top: 0; left: 0; z-index: 20; width: 25px; height: 25px; pointer-events: none;
  will-change: transform; transition: transform .72s cubic-bezier(.45,.05,.2,1), opacity .3s ease;
  filter: drop-shadow(0 0 5px rgba(73,105,255,.75)) drop-shadow(0 1px 2px rgba(0,0,0,.3));
}
.pr-cursor.is-hidden { opacity: 0; }
.pr-cursor svg { width: 100%; height: 100%; display: block; transition: transform .12s ease; }
.pr-cursor.is-click svg { transform: scale(.76); }
.pr-ripple {
  position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 40%, transparent); transform: scale(0);
  animation: prRipple .55s ease-out forwards; pointer-events: none;
}
@keyframes prRipple { to { transform: scale(9); opacity: 0; } }
.s-copilot__qrow .chip { position: relative; overflow: hidden; }
@keyframes prRowIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.s-copilot__row--ai.pr-copilot-in .s-copilot__cmp tbody tr { animation: prRowIn .32s var(--d, 0ms) ease both; }
@media (prefers-reduced-motion: reduce) {
  .pr-cursor { display: none; }
  .s-copilot__row--ai.pr-copilot-in .s-copilot__cmp tbody tr { animation: none; }
}

/* =========================================================================
   RESEARCH COPILOT — phones
   ========================================================================= */
@media (max-width: 639px) {
  /* Running order: the heading block, then the chat demo, then the chips and
     CTA. The mock has to land BETWEEN the copy's own children, so .feat__copy
     is dissolved with display:contents and every child ordered explicitly —
     otherwise the mock can only go wholly above or wholly below the copy.
     (styles.css also flips `.feat--reverse .feat__visual` to order:2 below
     860px, which is what buried it under the CTA in the first place.) */
  .s-copilot .feat { gap: 16px; }
  .s-copilot .feat--reverse .feat__copy { display: contents; }
  .s-copilot .feat__copy > .eyebrow          { order: 1; }
  .s-copilot .feat__copy > .tv-badge         { order: 2; justify-self: start; }
  .s-copilot .feat__copy > .section-title    { order: 3; margin-top: 0; }
  .s-copilot .feat__copy > .section-sub      { order: 4; margin-top: 0; }
  .s-copilot .feat--reverse .feat__visual    { order: 5; }
  .s-copilot .feat__copy > .s-copilot__cats  { order: 6; }
  .s-copilot .feat__copy > .btn              { order: 7; justify-self: start; }

  /* Keep the desktop's landscape shape instead of letting the chat reflow into
     a tall narrow column (aspect 0.53 -> ~1.03). The body is height-capped and
     scrolls, so it measures 602px tall at any width >= 520px; laying it out at
     the desktop 620px and zooming to fit 339px preserves the proportions.
     `zoom` (not transform:scale) so the layout box shrinks with it. */
  /* The layout width has to be derived from the viewport, not fixed: a flat
     620px x .547 zoom lands on exactly 339px, which only matches a 375px
     screen — on a 414px phone the mock stayed 339px in a 378px column and sat
     flush left, ~19px off centre. Solving (100vw - 36px of container padding)
     / .547 keeps it filling the column at any width. margin-inline:auto is a
     backstop so sub-pixel rounding can never bias it left again. */
  .s-copilot .feat__visual .mock {
    max-width: none;
    width: calc(182.8vw - 65.8px);
    zoom: .547;
    margin-inline: auto;
  }

  /* The pill sits on its own line after a <br>, but the heading's line-height
     (1.05 -> 30.2px) is shorter than the pill's own box (31.1px), and
     `vertical-align: -0.2em` then drops it another 5.8px — so it rode up into
     the descenders of "anything, get" by ~2px. Open the leading and take most
     of the baseline shift back out; the pill is never inline with text here,
     so it does not need the -0.2em nudge. */
  /* pull the three "Try asking" prompts onto a single line inside the mock —
     the third was wrapping to a row of its own. Shortening that chip's label
     bought ~74px; tightening the padding and gap covers the rest without
     shrinking the type, which is already only ~6px once the mock is zoomed. */
  .s-copilot__qrow { gap: 5px; }
  /* the 0.68rem is a safety margin, not a design call: padding + the shorter
     label alone left only ~5px of slack on the line, which a device whose font
     metrics differ slightly would wrap. At the mock's .547 zoom this is a
     0.3px change on screen. */
  .s-copilot__qrow .chip { padding: 6px 6px; font-size: 0.68rem; }

  .s-copilot .section-title { line-height: 1.45; }
  .s-copilot .section-title em.mx-fx-rot { vertical-align: -0.08em; }
}
