/* ============================================================
   PLUMB MOTION & MICRO-INTERACTIONS
   Driven by [data-motion] (off/subtle/standard/expressive)
   and [data-radius] / [data-grain] / [data-accent] body attrs.
   ============================================================ */

:root {
  /* Motion intensity multiplier: 0..1.5 (set by JS based on tweak) */
  --motion-mult: 1;

  /* Accent — defaults to Prussian, overridden by JS */
  --accent: #1B3A5C;
  --accent-fg: #FFFFFF;
  --accent-08: rgba(27, 58, 92, 0.08);
  --accent-15: rgba(27, 58, 92, 0.15);
  --accent-30: rgba(27, 58, 92, 0.30);

  /* Radius scale */
  --r: 3px;
  --r-card: 4px;

  /* Hairline weight */
  --hl: 1px;

  /* Grain layer opacity */
  --grain: 0;

  /* Hero gradient strength */
  --hero-grad: 0;

  /* CTA arrow style (handled per-button class) */
}

body[data-motion="off"] {
  --motion-mult: 0;
}
body[data-motion="subtle"] {
  --motion-mult: 0.55;
}
body[data-motion="expressive"] {
  --motion-mult: 1.4;
}

/* ───── Universal reveal — opt-in via .reveal-fx ───── */
.reveal-fx {
  opacity: 0;
  transform: translateY(calc(20px * var(--motion-mult)));
  transition:
    opacity calc(750ms * var(--motion-mult, 1)) cubic-bezier(0.22, 0.61, 0.36, 1),
    transform calc(820ms * var(--motion-mult, 1)) cubic-bezier(0.22, 0.61, 0.36, 1),
    filter calc(820ms * var(--motion-mult, 1)) cubic-bezier(0.22, 0.61, 0.36, 1);
  filter: blur(calc(2px * var(--motion-mult)));
  will-change: opacity, transform, filter;
}
.reveal-fx.in {
  opacity: 1;
  transform: none;
  filter: none;
}

/* Stagger children — set --i on each child or use nth-child fallback */
.reveal-fx > * {
  transition: inherit;
  transition-delay: calc(var(--i, 0) * 60ms * var(--motion-mult));
}

/* Per-stagger pattern */
.stagger > .stx {
  opacity: 0;
  transform: translateY(calc(14px * var(--motion-mult)));
  transition:
    opacity calc(620ms * var(--motion-mult, 1)) cubic-bezier(0.22, 0.61, 0.36, 1),
    transform calc(620ms * var(--motion-mult, 1)) cubic-bezier(0.22, 0.61, 0.36, 1);
}
.stagger.in > .stx { opacity: 1; transform: none; }
.stagger.in > .stx:nth-child(1) { transition-delay: calc(0ms * var(--motion-mult)); }
.stagger.in > .stx:nth-child(2) { transition-delay: calc(70ms * var(--motion-mult)); }
.stagger.in > .stx:nth-child(3) { transition-delay: calc(140ms * var(--motion-mult)); }
.stagger.in > .stx:nth-child(4) { transition-delay: calc(210ms * var(--motion-mult)); }
.stagger.in > .stx:nth-child(5) { transition-delay: calc(280ms * var(--motion-mult)); }
.stagger.in > .stx:nth-child(6) { transition-delay: calc(350ms * var(--motion-mult)); }
.stagger.in > .stx:nth-child(7) { transition-delay: calc(420ms * var(--motion-mult)); }
.stagger.in > .stx:nth-child(8) { transition-delay: calc(490ms * var(--motion-mult)); }

/* ───── Section morph: a soft radial sweep marks the boundary
        between sections as you scroll past them ───── */
.section-morph {
  position: relative;
}
.section-morph::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at var(--mx, 50%) 0%,
    var(--accent-08) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 1200ms ease-out;
}
.section-morph.in::before { opacity: calc(0.6 * var(--motion-mult)); }

/* ───── Tactile button system ───── */
.btn,
.tactile {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition:
    transform 140ms cubic-bezier(0.34, 1.56, 0.64, 1),
    background-color 180ms cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 180ms cubic-bezier(0.4, 0, 0.2, 1),
    border-color 180ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.btn::before,
.tactile::before {
  /* Sheen — diagonal highlight that sweeps on hover */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    115deg,
    transparent 30%,
    rgba(255,255,255,0.18) 50%,
    transparent 70%
  );
  transform: translateX(-110%);
  transition: transform 600ms cubic-bezier(0.22, 0.61, 0.36, 1);
  pointer-events: none;
  z-index: 0;
}
.btn:hover::before,
.tactile:hover::before {
  transform: translateX(110%);
}
.btn > *,
.tactile > * { position: relative; z-index: 1; }

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(26,26,26,0.18), 0 1px 0 rgba(255,255,255,0.06) inset;
}
.btn:active {
  transform: translateY(1px) scale(0.985);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.32), 0 0 0 1px rgba(0,0,0,0.05);
  transition-duration: 60ms;
}
.btn.ghost::before { display: none; }
.btn.ghost:hover {
  background: var(--accent-08);
  border-color: var(--accent-30);
  box-shadow: none;
}

/* Ripple — JS injects an .rip span at click point */
.rip {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(255,255,255,0.55), rgba(255,255,255,0) 65%);
  transform: scale(0);
  opacity: 0.6;
  animation: rip 620ms cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
  z-index: 0;
}
.btn.ghost .rip,
body[data-theme="vellum"] .btn.ghost .rip,
body[data-theme="white"] .btn.ghost .rip {
  background: radial-gradient(circle at center, var(--accent-30), transparent 65%);
}
@keyframes rip {
  to { transform: scale(2.6); opacity: 0; }
}

/* Magnetic hover — subtle pull toward cursor */
.magnet {
  transition: transform 300ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Underline-grow link */
.linkfx {
  position: relative;
  text-decoration: none;
  transition: color 160ms ease;
}
.linkfx::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 380ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.linkfx:hover::after { transform: scaleX(1); }
.linkfx:hover { opacity: 1; }

/* ───── Scroll progress rail (right edge) ───── */
.scroll-rail {
  position: fixed;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 600ms ease;
}
.scroll-rail.show { opacity: 1; }
.scroll-rail .rail-tick {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  cursor: default;
  background: transparent;
  border: 0;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(26,26,26,0.35);
  letter-spacing: 0.1em;
  text-transform: lowercase;
}
.rail-tick .rt-label {
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 240ms ease, transform 240ms ease, color 200ms ease;
  white-space: nowrap;
}
.rail-tick:hover .rt-label,
.rail-tick.on .rt-label {
  opacity: 1;
  transform: none;
}
.rail-tick .rt-mark {
  width: 18px; height: 1px;
  background: rgba(26,26,26,0.25);
  transition: width 280ms cubic-bezier(0.22, 0.61, 0.36, 1),
              background-color 200ms ease;
  display: inline-block;
}
.rail-tick.on .rt-mark { width: 30px; background: var(--accent); }
.rail-tick:hover .rt-mark { background: var(--accent); }
@media (max-width: 1100px) { .scroll-rail { display: none; } }

body[data-theme="graphite"] .scroll-rail .rail-tick { color: rgba(232,226,213,0.4); }
body[data-theme="graphite"] .scroll-rail .rail-tick .rt-mark { background: rgba(232,226,213,0.25); }

/* ───── Page-level grain layer ───── */
.grain-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='5'/><feColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0.18 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
}
body[data-theme="graphite"] .grain-layer { mix-blend-mode: screen; opacity: calc(var(--grain) * 0.7); }

/* ───── Section-enter atmosphere ───── */
.atmos {
  position: relative;
}
.atmos::after {
  content: "";
  position: absolute;
  inset: -1px 0 auto 0;
  height: 220px;
  pointer-events: none;
  background: linear-gradient(180deg, var(--accent-08), transparent 100%);
  opacity: var(--hero-grad);
}

/* Radius — applied wherever cards live */
.btn, .tactile, .input, .select,
.demo-frame, .pillars, .ba-grid, .wl-form, .ps, .hero-readout,
.cr-alert, .ba-tag, .tag, .pillar, .ba-col, .cad-pane, .cost-rail {
  border-radius: var(--r);
}
.demo-frame, .pillars, .ba-grid, .wl-form { border-radius: var(--r-card); }

/* Hairline thickness */
body[data-hairline="1.5"] .section,
body[data-hairline="1.5"] .pillars,
body[data-hairline="1.5"] .ba-grid,
body[data-hairline="1.5"] .demo-frame,
body[data-hairline="1.5"] .wl-form,
body[data-hairline="1.5"] .ps,
body[data-hairline="1.5"] .hero-readout {
  border-width: 1.5px;
}

/* Number count-up — uses font-feature for rolling effect */
.count-up { font-variant-numeric: tabular-nums; }

/* SVG line-draw on demo bracket re-render */
.bracket-redraw rect, .bracket-redraw circle, .bracket-redraw line, .bracket-redraw path {
  animation: dashIn 700ms cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
}
@keyframes dashIn { to { stroke-dashoffset: 0; } }

/* Reduced motion — kill all the things */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  .reveal-fx, .stagger > .stx { opacity: 1 !important; transform: none !important; filter: none !important; }
}

/* Tweak: button shape variant */
body[data-btn-style="pill"] .btn { border-radius: 999px; }
body[data-btn-style="square"] .btn { border-radius: 0; }
body[data-btn-style="outlined"] .btn:not(.ghost) {
  background: transparent;
  color: var(--color-graphite);
  border: 1px solid var(--color-graphite);
}
body[data-btn-style="outlined"] .btn:not(.ghost):hover {
  background: var(--color-graphite);
  color: var(--color-vellum);
}

/* Tweak: arrow style */
body[data-arrow="long"] .btn .arrow::before { content: "—→"; }
body[data-arrow="long"] .btn .arrow > * { display: none; }

/* Hero atmosphere variant */
body[data-hero-grad="atmospheric"] .hero {
  background:
    radial-gradient(ellipse 80% 50% at 50% 110%, var(--accent-08), transparent 70%),
    radial-gradient(ellipse 50% 40% at 10% -10%, rgba(201,169,97,0.10), transparent 70%),
    var(--bg-primary);
}
body[data-hero-grad="subtle"] .hero {
  background:
    radial-gradient(ellipse 60% 40% at 50% 100%, var(--accent-08), transparent 70%),
    var(--bg-primary);
}
body[data-theme="graphite"][data-hero-grad="atmospheric"] .hero {
  background:
    radial-gradient(ellipse 80% 50% at 50% 110%, rgba(27,58,92,0.5), transparent 70%),
    radial-gradient(ellipse 50% 40% at 10% -10%, rgba(201,169,97,0.18), transparent 70%),
    #1A1A1A;
}

/* Parallax-driven CSS vars (set via JS) */
.hero-grid {
  transform: translate3d(0, var(--py-grid, 0px), 0);
  will-change: transform;
}
.bob-stage {
  transform: translate3d(0, var(--py-bob, 0px), 0);
  will-change: transform;
}
.hero-corners .hc {
  transform: translate3d(0, var(--py-corners, 0px), 0);
}

/* Smooth scroll global */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* ───── Self-drawing hairlines ───── */
/* Apply .draw-line to any element that already has a hairline border-bottom
   or border-top — it will scale in from the left when the parent enters
   the viewport. Decorative <hr> get the same treatment via .hr-draw. */
.hr-draw {
  position: relative;
  height: 1px;
  border: 0;
  background: transparent;
  overflow: visible;
}
.hr-draw::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--border-default);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 1100ms cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: transform;
}
.reveal-fx.in .hr-draw::before,
.hr-draw.in::before { transform: scaleX(1); }

/* Auto-draw existing border separators on reveal — scope to specific places */
.section-h, .eyebrow {
  position: relative;
}
.eyebrow::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -10px;
  height: 1px;
  width: 48px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 900ms cubic-bezier(0.22, 0.61, 0.36, 1) 200ms;
}
.reveal-fx.in .eyebrow::after,
.in.eyebrow::after { transform: scaleX(1); }

/* Pillar dividers self-draw */
.pillar {
  position: relative;
}
.pillars.in .pillar::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 1px;
  background: var(--border-default);
  transform: scaleX(0);
  transform-origin: left;
  animation: drawIn 1000ms cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}
.pillars.in .pillar:nth-child(1)::before { animation-delay: 80ms; }
.pillars.in .pillar:nth-child(2)::before { animation-delay: 200ms; }
.pillars.in .pillar:nth-child(3)::before { animation-delay: 320ms; }
@keyframes drawIn { to { transform: scaleX(1); } }

/* ───── Big stat numerals — feel weighty ───── */
.ba-stat-v.count-up,
.ba-stat-v {
  font-variant-numeric: tabular-nums;
}
