/* ═══════════════════════════════════════════════════════════════════════
   THE REDESIGN'S SHARED CORE

   Linked on every page the redesign's release row is lit for
   (lib/page-redesign.js marks the document <html data-rd="…">), ahead of
   that page's own layer:

     public/css/redesign-pages.css       the market overview, the sector
                                         scoreboard and the options screener
     public/css/redesign-edgematrix.css  the EdgeMatrix pages
     public/css/redesign-upgrade.css     the plans on /upgrade
     public/css/redesign-market.css      the signed-in /market page

   It holds what they share and nothing a single page needs alone: the
   roles, the motion, the shared pieces, and the print and reduced-motion
   rules.

   COLOUR, TYPE AND GEOMETRY COME FROM theme.css. Nothing below names a
   colour of its own: the roles are mapped onto the palette the reader is
   wearing, in the mode they chose, and the corner radii are scaled from the
   palette's own --radius, so a square palette stays square.

   MOTION IS OPT-OUT. Every transition and animation of the redesign is
   switched off under prefers-reduced-motion, and nothing is hidden until a
   script shows it: with scripting off, a page reads top to bottom as
   written.

   AN ANIMATION FILLS BACKWARDS ONLY. One that kept filling after it had
   played would keep its block a layer of its own, and anything floating out
   of that block (a search's list of matches, a menu) would be painted under
   whatever follows it on the page. The one exception is the line driven by
   the scroll position, which has no end to play to.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── roles ─────────────────────────────────────────────────────────── */
html[data-rd] {
  --rd-plane: var(--bg);
  --rd-surface: var(--bg-1);
  --rd-surface-2: var(--bg-2);
  --rd-ink: var(--text);
  --rd-ink-2: var(--text-dim);
  --rd-muted: var(--text-mute);
  --rd-ring: var(--border);
  --rd-base: var(--border-strong, var(--border));
  --rd-wash: color-mix(in srgb, var(--accent) 10%, transparent);
  --rd-wash-2: color-mix(in srgb, var(--accent) 18%, transparent);
  --rd-mono: var(--mono, ui-monospace, Menlo, monospace);
  --rd-sans: var(--sans, system-ui, sans-serif);
  --rd-display: var(--font-display, var(--sans, system-ui, sans-serif));
  /* Corners, scaled from the palette's own: used for border-radius only. */
  --rd-r: clamp(0px, calc(var(--radius, 6px) * 2.5), 18px);
  --rd-r-sm: clamp(0px, calc(var(--radius, 6px) * 2), 14px);
  --rd-r-xs: clamp(0px, calc(var(--radius, 6px) * 1.34), 10px);
  /* A pill on the rounded palettes, the palette's own small corner on the
     square ones. */
  --rd-pill: clamp(var(--radius-sm, 4px), calc((var(--radius, 6px) - 4.5px) * 999), 999px);
  --rd-ease: cubic-bezier(.2, .7, .2, 1);
  /* The header's own page column tokens, as the pages set them. */
  --home-mono: var(--rd-mono);
  overflow-x: clip;
  scroll-behavior: smooth;
  /* Anchors clear the header and, on the overview, the section rail. */
  scroll-padding-top: calc(var(--nav-h, 62px) + 72px);
}
/* A light page lifts its cards off the plane rather than sinking them. */
html[data-rd][data-mode="light"] {
  --rd-surface: color-mix(in srgb, var(--bg) 38%, #fff);
  --rd-surface-2: var(--bg-1);
}
html[data-rd] *, html[data-rd] *::before, html[data-rd] *::after { box-sizing: border-box; }
html[data-rd] body {
  /* The full window, with a gutter that grows with it: the pages' own frame,
     which the shared header and footer read too. */
  --page-measure: 100%;
  --page-gutter: clamp(20px, 3vw, 48px);
  margin: 0;
  background: var(--rd-plane);
  color: var(--rd-ink);
  font: 15px/1.55 var(--rd-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
/* The hidden attribute hides, whatever display a class below sets. */
html[data-rd] [hidden] { display: none !important; }
html[data-rd] button, html[data-rd] a { -webkit-tap-highlight-color: transparent; }
/* Resets with no weight of their own (:where), so any rule below that names
   a class decides a button's type or a link's colour. */
:where(html[data-rd] main) :where(button) { font: inherit; }
:where(html[data-rd] main) :where(a) { color: inherit; }
html[data-rd] main :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── motion ────────────────────────────────────────────────────────── */
@keyframes rd-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes rd-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rd-wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes rd-row { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes rd-sweep { from { background-position: 120% 0; } to { background-position: -120% 0; } }
@keyframes rd-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* Set by the script on blocks below the fold, and lifted as each scrolls in. */
.rd-reveal { opacity: 0; transform: translateY(18px); }
.rd-reveal.rd-in {
  opacity: 1; transform: none;
  transition: opacity .7s var(--rd-ease), transform .7s var(--rd-ease);
  transition-delay: calc(var(--rd-i, 0) * 80ms);
}
/* Rows drawn by a click (a sort, a view switch), never by a timed refresh:
   the script marks the table for a moment as the click lands. */
[data-rd-anim] tbody tr { animation: rd-row .34s var(--rd-ease) backwards; }
[data-rd-anim] tbody tr:nth-child(2) { animation-delay: 18ms; }
[data-rd-anim] tbody tr:nth-child(3) { animation-delay: 36ms; }
[data-rd-anim] tbody tr:nth-child(4) { animation-delay: 54ms; }
[data-rd-anim] tbody tr:nth-child(5) { animation-delay: 72ms; }
[data-rd-anim] tbody tr:nth-child(6) { animation-delay: 90ms; }
[data-rd-anim] tbody tr:nth-child(7) { animation-delay: 108ms; }
[data-rd-anim] tbody tr:nth-child(8) { animation-delay: 126ms; }
[data-rd-anim] tbody tr:nth-child(9) { animation-delay: 144ms; }
[data-rd-anim] tbody tr:nth-child(n+10) { animation-delay: 160ms; }

/* ── shared pieces ─────────────────────────────────────────────────── */
.rd-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.rd-card { background: var(--rd-surface); border: 1px solid var(--rd-ring); border-radius: var(--rd-r); padding: 20px; }
.rd-btn {
  all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  font: 600 14px/1.2 var(--rd-sans); color: var(--rd-ink); background: var(--rd-surface);
  border: 1px solid var(--rd-base); border-radius: var(--rd-pill); padding: 9px 16px;
  transition: border-color .18s, background .18s, color .18s, transform .18s var(--rd-ease);
}
.rd-btn:hover { border-color: var(--rd-ink-2); }
.rd-btn:active { transform: scale(.97); }
.rd-btn.rd-primary { background: var(--rd-ink); color: var(--rd-plane); border-color: var(--rd-ink); }
.rd-btn.rd-sm { font-size: 13px; padding: 6px 12px; }
.rd-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Toggle tabs: one row of pills, the chosen one filled with ink. */
.rd-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.rd-tab {
  all: unset; box-sizing: border-box; cursor: pointer; white-space: nowrap;
  font: 600 13.5px/1.2 var(--rd-sans); color: var(--rd-ink-2);
  border: 1px solid var(--rd-base); border-radius: var(--rd-pill); padding: 7px 14px;
  transition: background .2s, color .2s, border-color .2s, transform .18s var(--rd-ease);
}
.rd-tab:hover { color: var(--rd-ink); border-color: var(--rd-ink-2); }
.rd-tab:active { transform: scale(.97); }
.rd-tab[aria-selected="true"], .rd-tab[aria-pressed="true"], .rd-tab[aria-current="true"] {
  background: var(--rd-ink); color: var(--rd-plane); border-color: var(--rd-ink);
}
.rd-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A numbered section heading. */
.rd-sec-head { display: grid; grid-template-columns: auto 1fr; column-gap: 18px; align-items: baseline; margin-bottom: 24px; }
.rd-sec-no { font: 700 13px/1 var(--rd-mono); color: var(--rd-muted); letter-spacing: .1em; font-variant-numeric: tabular-nums; }
.rd-sec-head h2 { margin: 0; font: var(--display-weight, 700) clamp(26px, 2.8vw, 36px)/1.12 var(--rd-display); letter-spacing: -.02em; text-wrap: balance; }
.rd-sec-head p { grid-column: 2; margin: 10px 0 0; color: var(--rd-ink-2); max-width: 70ch; font-size: 16px; }
.rd-note { margin: 12px 0 0; font-size: 13px; color: var(--rd-muted); }

/* The section rail: where on the page you are, and one press to another part. */
.rd-rail {
  position: sticky; top: var(--nav-h, 62px); z-index: 20;
  display: flex; gap: 4px; align-items: center; overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--page-gutter)) 18px; padding: 10px var(--page-gutter);
  background: color-mix(in srgb, var(--rd-plane) 84%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent; transition: border-color .25s;
}
.rd-rail::-webkit-scrollbar { display: none; }
.rd-rail.rd-stuck { border-bottom-color: var(--rd-ring); }
.rd-rail a {
  flex: none; text-decoration: none; white-space: nowrap; font: 600 13px/1 var(--rd-sans); color: var(--rd-ink-2);
  padding: 8px 12px; border-radius: var(--rd-pill); border: 1px solid transparent;
  transition: background .2s, color .2s, border-color .2s;
}
.rd-rail a:hover { background: var(--rd-surface-2); color: var(--rd-ink); }
.rd-rail a[aria-current="true"] { background: var(--rd-ink); color: var(--rd-plane); }

/* ── on paper, and for a reader who asked for no motion ────────────── */
/* On paper: every block shown whether or not it was scrolled to, nothing pinned. */
@media print {
  .rd-reveal { opacity: 1 !important; transform: none !important; }
  .rd-rail { position: static; }
  html[data-rd] body::before { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html[data-rd] { scroll-behavior: auto; }
  html[data-rd] *, html[data-rd] *::before, html[data-rd] *::after { transition: none !important; animation: none !important; }
  .rd-reveal { opacity: 1; transform: none; }
}
