/* ============================================
   UI.CSS: interaction layer (loaded async, after pages.css)
   Paint-only by design: nothing here changes an element's size or position in the flow, so this file landing
   late can never cause a layout shift. Layout for new components lives in critical CSS / page.css instead.
   Patterns adapted (re-implemented in plain CSS/JS, no React) from free, MIT-licensed sources:
   Lenis (darkroom.engineering), Magic UI (Magic Card, Border Beam, Blur Fade, Scroll Progress, Grid Pattern),
   SmoothUI (motion accordion), ShaderGradient (look of the hero gradient; own shader).
   Tuned to the Designit Design System: no glow, no blur, no scale; hairline highlights, grainy spectrum washes.
   Every motion respects prefers-reduced-motion.
   ============================================ */

@property --ui-so { syntax: '<number>'; inherits: false; initial-value: 0; }
@property --ui-beam { syntax: '<percentage>'; inherits: false; initial-value: 0%; }

:root {
  --ui-ease: cubic-bezier(.16, 1, .3, 1);
  --ui-grad: #fff;
}

/* --- Lenis smooth scroll (from lenis/dist/lenis.css) --- */
html.lenis, html.lenis body { height: auto; }
html.lenis { scroll-behavior: auto; }
.lenis:not(.lenis-autoToggle).lenis-stopped { overflow: clip; }
.lenis [data-lenis-prevent] { overscroll-behavior: contain; }
.lenis.lenis-smooth iframe { pointer-events: none; }

/* --- Scroll progress (Magic UI "Scroll Progress") --- */
.ui-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 1001;
  transform-origin: 0 50%; transform: scaleX(0);
  background: #fff; pointer-events: none;
}

/* --- Hero + closing CTA: shader gradient canvas and grid pattern --- */
.ui-stage { position: relative; isolation: isolate; overflow: hidden; }
.ui-stage > .ui-shader {
  position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%; display: block;
  opacity: 0; transition: opacity 1.8s ease; pointer-events: none;
  -webkit-mask-image: linear-gradient(to top, transparent 0, #000 14%);
  mask-image: linear-gradient(to top, transparent 0, #000 14%);
}
.ui-stage > .ui-shader.on { opacity: 1; }

/* No WebGL: a still, grainy wash in the spectrum's blue / violet / magenta */
.ui-stage.ui-noshader::after {
  content: ""; position: absolute; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(60% 55% at 28% 100%, rgba(65,133,244,.34), transparent 70%),
    radial-gradient(55% 50% at 55% 100%, rgba(134,95,194,.32), transparent 70%),
    radial-gradient(50% 45% at 80% 100%, rgba(215,94,178,.28), transparent 70%);
}
/* Hero and CTA body copy: a touch brighter so it clears 4.5:1 at the wash's brightest frame */
html body .ui-stage :is(.subtitle,p):not(.page-meta):not(#_) { color: rgba(255, 255, 255, .85); }
/* Magic UI "Grid Pattern", faded out with a radial mask */
.geo-hero.ui-stage::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: 64px 64px; background-position: 50% 0;
  -webkit-mask-image: radial-gradient(ellipse 60% 55% at 50% 35%, #000 20%, transparent 72%);
  mask-image: radial-gradient(ellipse 60% 55% at 50% 35%, #000 20%, transparent 72%);
}
/* Magic UI "Border Beam" as a travelling light along the top edge of the closing CTA */
.geo-cta-section.ui-stage::before {
  content: ""; position: absolute; left: 8%; right: 8%; top: 0; height: 1px; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120px 1px at var(--ui-beam) 0, #fff, transparent),
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .16) 20%, rgba(255, 255, 255, .16) 80%, transparent);
  animation: ui-beam 6s linear infinite;
}
@keyframes ui-beam { from { --ui-beam: 0%; } to { --ui-beam: 100%; } }

/* --- Hairline spotlight (Magic UI "Magic Card" reduced to the system's hairline language) ---
   ui.js injects one empty <span class="ui-spot"> per card and sets --mx/--my from the pointer.
   The card's 1px border brightens around the cursor; there is no fill, no colour, no glow. */
.ui-spot-host { position: relative; }
.ui-spot {
  position: absolute; inset: -1px; z-index: 2; border-radius: inherit; padding: 1px; pointer-events: none;
  background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 0%), rgba(255, 255, 255, .85), transparent 65%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0; transition: opacity .2s cubic-bezier(.2, 0, .2, 1);
}
@media (hover: hover) and (pointer: fine) { .ui-spot-host:hover > .ui-spot { opacity: 1; } }
.ground-light .ui-spot { background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 0%), rgba(0, 0, 0, .55), transparent 65%); }

/* Case-study cards: the system has no scale or lift on hover; only the arrow label tracks the cursor state */
.work-card .wc-more, .card .card-more, .problem-row .route { transition: color .2s cubic-bezier(.2, 0, .2, 1); }

/* --- Scroll-linked active stage / step (process timelines): brighter hairline, no colour --- */
.stage, .step { transition: border-color .2s cubic-bezier(.2, 0, .2, 1); }
.stage.ui-active, .step.ui-active { border-color: rgba(255, 255, 255, .6); }
.ground-light .stage.ui-active, .ground-light .step.ui-active { border-color: rgba(0, 0, 0, .35); }

/* --- FAQ: always open (see ds-below.css); nothing to animate --- */

/* --- Logo marquee pause control (layout lives in page.css) --- */
.logo-pause {
  color: var(--text-tertiary); background: rgba(255, 255, 255, .04); border: 1px solid var(--border-subtle);
  transition: color .2s, border-color .2s, background-color .2s;
}
.logo-pause:hover, .logo-pause:focus-visible { color: #fff; border-color: var(--border-strong); }
.logo-pause:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* --- Fade-rise reveal (Magic UI "Blur Fade" without the blur). Only applied by ui.js to elements below the fold. --- */
.ui-pre { opacity: 0; transform: translate3d(0, 14px, 0); }
.ui-pre.ui-in {
  opacity: 1; transform: none;
  transition: opacity .5s var(--ui-ease), transform .6s var(--ui-ease);
  transition-delay: calc(var(--ui-i, 0) * 50ms);
}

/* --- Number ticker (Magic UI "Number Ticker"; main.js animates [data-count], real figures only) --- */
[data-count] { font-variant-numeric: tabular-nums; }

/* --- Desktop nav: underline that grows on hover --- */
@media (min-width: 769px) {
  .navbar .nav-links .nav-top {
    background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat;
    transition: color .25s, background-size .4s var(--ui-ease);
  }
  .navbar .nav-links .nav-top:hover, .navbar .nav-links .nav-top.active { background-size: 100% 1px; }
}

@media print {
  .ui-pre { opacity: 1 !important; transform: none !important; }
  .ui-progress, .ui-shader, .ui-spot, .logo-pause { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .ui-pre, .ui-pre.ui-in { opacity: 1; transform: none; transition: none; }
  .geo-cta-section.ui-stage::before { animation: none; --ui-beam: 50%; }
  .ui-shader { transition: none; }
}

/* --- Card interactions (paint-only). The system says hover darkens or brightens a hairline and nothing scales;
       motion is carried by the arrow, which travels 4px (Doherty threshold: feedback inside 100ms). --- */
.arw { transition: transform .2s cubic-bezier(.2, 0, .2, 1); }
@media (hover: hover) {
  a.card:hover .arw, .work-card:hover .arw, .problem-row:hover .arw, .route:focus-visible .arw { transform: translateX(4px); }
  .problem-row { transition: border-color .2s cubic-bezier(.2, 0, .2, 1), background-color .2s cubic-bezier(.2, 0, .2, 1); }
  .problem-row:hover { border-color: rgba(255, 255, 255, .5); }
  .ground-light .problem-row:hover { border-color: rgba(0, 0, 0, .2); background-color: #f4f4f4; }
  .problem-row:hover .route span:not(.arw) { color: rgba(255, 255, 255, .85); }
  .ground-light .problem-row:hover .route span:not(.arw) { color: rgba(0, 0, 0, .8); }
}
/* Case-study cards: a glass chip floats over the image on hover (a floating layer, so glass is allowed) */
.work-card { position: relative; }
.work-card::after {
  content: "Read case study \2197"; position: absolute; top: 16px; right: 16px; z-index: 3;
  padding: 8px 14px; border-radius: 9999px; font-size: 13px; font-weight: 500; letter-spacing: -.011em; color: #fff;
  background: rgba(0, 0, 0, .7); -webkit-backdrop-filter: saturate(180%) blur(16px); backdrop-filter: saturate(180%) blur(16px);
  border: 1px solid rgba(255, 255, 255, .25);
  opacity: 0; transform: translateY(-4px); transition: opacity .2s cubic-bezier(.2, 0, .2, 1), transform .2s cubic-bezier(.2, 0, .2, 1);
  pointer-events: none;
}
@media (hover: hover) { .work-card:hover::after { opacity: 1; transform: none; } }
.work-card:focus-visible::after { opacity: 1; transform: none; }
.work-card img { transition: filter .2s cubic-bezier(.2, 0, .2, 1); }
@media (hover: hover) { .work-card:hover img { filter: brightness(.82); } }

/* Press state: the system reuses the darkened value; no scale */
html body .btn-primary:not(#_):active, html body .nav-cta:not(#_):active { background: #cfcfcf !important; border-color: #cfcfcf !important; }
.btn-outline:active { background: rgba(255, 255, 255, .14); }

/* --- Contact dock (glass floating layer; main.js builds it after the hero) --- */
.dock {
  position: fixed; right: 24px; bottom: 24px; z-index: 9000; display: flex; align-items: center; gap: 6px; padding: 6px;
  border-radius: 9999px; border: 1px solid rgba(255, 255, 255, .22);
  background: rgba(0, 0, 0, .78); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  opacity: 0; visibility: hidden; transform: translateY(12px);
  transition: opacity .2s cubic-bezier(.2, 0, .2, 1), transform .2s cubic-bezier(.2, 0, .2, 1), visibility 0s linear .2s;
}
.dock.on { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .dock { background: #000; } }
.dock-main {
  height: 44px; padding: 0 20px; border-radius: 9999px; background: #fff; color: #000; border: 0;
  font: 600 15px/1 Inter, 'Inter Fallback', sans-serif; letter-spacing: -.022em; cursor: pointer;
  transition: background-color .2s cubic-bezier(.2, 0, .2, 1);
}
.dock-main:hover { background: #e3e3e3; }
.dock-main:active { background: #cfcfcf; }
.dock-i {
  position: relative; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9999px; color: rgba(255, 255, 255, .85); text-decoration: none;
  transition: background-color .2s cubic-bezier(.2, 0, .2, 1), color .2s cubic-bezier(.2, 0, .2, 1);
}
.dock-i:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.dock-tip {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translate(-50%, 4px); white-space: nowrap;
  padding: 6px 10px; border-radius: 8px; font-size: 13px; color: #fff; background: rgba(0, 0, 0, .8);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border: 1px solid rgba(255, 255, 255, .2);
  opacity: 0; pointer-events: none; transition: opacity .12s cubic-bezier(.2, 0, .2, 1), transform .12s cubic-bezier(.2, 0, .2, 1);
}
@media (hover: hover) { .dock-i:hover .dock-tip { opacity: 1; transform: translate(-50%, 0); } }
.dock-i:focus-visible .dock-tip { opacity: 1; transform: translate(-50%, 0); }
.dock-x {
  width: 32px; height: 32px; margin-left: 2px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9999px; color: rgba(255, 255, 255, .65); background: transparent; border: 0; cursor: pointer;
}
.dock-x:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.dock :focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@media (max-width: 640px) {
  .dock { left: 12px; right: 12px; bottom: 12px; justify-content: space-between; }
  .dock-main { flex: 1; }
  .dock-tip { display: none; }
}
@media print { .dock, .ann-bar { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  .arw, .dock, .work-card::after, .dock-tip { transition: none; }
}
