/* UX layer: ONE source of truth. Change a value here, every behavior follows.
   Behaviors live in ux-layer.js. Opt an element out with data-ux="off".
   Currently loaded by /preview/home only (add the two tags to base.html to go global). */
:root {
  --ux-press-scale: .97;        /* #9 instant feedback on press */
  --ux-pulse-scale: 1.06;       /* #1 pulse strength */
  --ux-pulse-ms: 380ms;
  --ux-blur: 4px;               /* #6 stage the focus: blur behind */
  --ux-stage-dim: .5;           /* #6 opacity of everything behind */
  --ux-stage-ms: 220ms;
  --ux-reveal-ms: 750ms;        /* #5 mask reveal */
  --ux-reveal-stagger: 70ms;
  --ux-swap-ms: 280ms;          /* #3 crossfade with blur */
  --ux-swap-blur: 6px;
  --ux-expand-ms: 380ms;        /* #2 expand the same element */
  --ux-min-target: 48px;        /* #7 Fitts: minimum touch target (>= 44, snapped to the 8px grid) */
  --ux-progress-delay: 400;     /* #9 Doherty: ms before the nav bar shows (read by JS) */
  --ux-ease: cubic-bezier(.2, .7, .2, 1);
}

/* ---- #9 Doherty: no tap delay, instant press response ---- */
a, button, input, summary, label { touch-action: manipulation; }
:where(.btn, button, .hn-stage, .hn-sticky):not([data-ux="off"]) { -webkit-tap-highlight-color: transparent; }
:where(.btn, button[type="submit"], .hn-sticky):not([data-ux="off"]):active {
  transform: scale(var(--ux-press-scale)); transition: transform 70ms ease-out;
}
#ux-bar {
  position: fixed; top: 0; left: 0; height: 4px; width: 0; z-index: 100; pointer-events: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); opacity: 0;
  transition: width 8s cubic-bezier(.1, .6, .2, 1), opacity .2s;
}
#ux-bar.on { width: 85%; opacity: 1; }

/* ---- #1 Pulse to confirm ---- */
@keyframes ux-pulse {
  0%   { transform: scale(1);                     box-shadow: 0 0 0 0 rgba(0, 214, 164, .55); }
  40%  { transform: scale(var(--ux-pulse-scale)); box-shadow: 0 0 0 8px rgba(0, 214, 164, 0); }
  100% { transform: scale(1);                     box-shadow: 0 0 0 0 rgba(0, 214, 164, 0); }
}
.ux-pulse { animation: ux-pulse var(--ux-pulse-ms) var(--ux-ease); }

/* ---- #2 Expand the same element: the scan card grows to hold the progress ---- */
.scan-card .scan-progress {
  display: block; overflow: hidden; max-height: 0; opacity: 0; margin: 0 var(--s2, 8px);
  transition: max-height var(--ux-expand-ms) var(--ux-ease), opacity var(--ux-expand-ms) ease, margin var(--ux-expand-ms) ease;
}
.scan-card .scan-progress[hidden] { display: block; }
.scan-card .scan-progress.ux-open { max-height: 120px; opacity: 1; margin: var(--s3, 16px) var(--s2, 8px) var(--s2, 8px); }

/* ---- #3 Crossfade with blur ---- */
.ux-swap { transition: opacity var(--ux-swap-ms) ease, filter var(--ux-swap-ms) ease; }
.ux-swap.ux-swap-out { opacity: 0; filter: blur(var(--ux-swap-blur)); }

/* ---- #5 Reveal with masks (only items below the fold get it; JS adds .ux-ready) ---- */
.ux-ready .ux-reveal {
  clip-path: inset(0 0 100% 0); opacity: 0;
  transition: clip-path var(--ux-reveal-ms) var(--ux-ease), opacity calc(var(--ux-reveal-ms) * .6) ease;
  transition-delay: calc(var(--ux-i, 0) * var(--ux-reveal-stagger));
}
.ux-ready .ux-reveal.ux-in { clip-path: inset(-24px); opacity: 1; }

/* ---- #6 Stage the focus: while the scan box is active, everything else steps back ---- */
.hn-banner, .site-header, .site-footer, .hn-sec, .hn-eyebrow, .hn-sub, .hn-gets, .hn-dogfood, .hn-line, .proof-strip {
  transition: filter var(--ux-stage-ms) ease, opacity var(--ux-stage-ms) ease;
}
.ux-staged :is(.hn-banner, .site-header, .site-footer, .hn-sec, .hn-eyebrow, .hn-sub, .hn-gets, .hn-dogfood, .hn-line, .proof-strip):not([data-ux="off"]) {
  filter: blur(var(--ux-blur)); opacity: var(--ux-stage-dim);
}
.ux-staged .hn-final .hn-final-form { filter: none; opacity: 1; }

/* menu open: the whole page behind the pill steps back (main, footer, messages) */
main, .site-footer, .messages { transition: filter var(--ux-stage-ms) ease, opacity var(--ux-stage-ms) ease; }
.ux-staged-nav :is(main, .site-footer, .messages) { filter: blur(var(--ux-blur)); opacity: var(--ux-stage-dim); }

/* ---- #7 Fitts: 44px minimum touch targets on touch screens ---- */
@media (pointer: coarse) {
  :where(.btn, button, .site-nav a, .footer-links a, .hn-sticky, .ux-more):not([data-ux="off"]) {
    min-height: var(--ux-min-target); min-width: var(--ux-min-target);
    display: inline-flex; align-items: center; justify-content: center;
  }
  .footer-links a { padding: var(--s2, 8px); }
  .hn-field input[type=text] { min-height: var(--ux-min-target); }
}

/* ---- #8 Hick: collapse long lists behind "Show N more" ---- */
.ux-collapsed-item { display: none !important; }
.ux-more {
  display: inline-flex; margin: var(--s3, 16px) auto 0; padding: var(--s2, 8px) var(--s4, 24px); border-radius: 999px; cursor: pointer;
  background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line); font: inherit; font-size: .92rem;
}
.ux-more:hover { border-color: var(--accent); }
.ux-more-wrap { display: flex; justify-content: center; margin-top: var(--s2, 8px); }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  :root { --ux-reveal-ms: 1ms; --ux-swap-ms: 1ms; --ux-expand-ms: 1ms; --ux-stage-ms: 1ms; --ux-pulse-scale: 1; }
  .ux-pulse { animation: none; }
  .ux-staged :is(.hn-banner, .site-header, .site-footer, .hn-sec, .hn-eyebrow, .hn-sub, .hn-gets, .hn-dogfood, .hn-line, .proof-strip), .ux-staged-nav :is(main, .site-footer, .messages) { filter: none; }
  #ux-bar { transition: none; }
}
