/* Clarity journey transitions — driven by --u (0 = complexity, 1 = clarity)
   Active while dragging; resting state handled in clarity-rest.css */

:root {
  --u: 0;
  --chaos: calc(1 - var(--u));
  --urgency-progress: 0;
  /* Portrait + venn both start at 0% — stay in sync */
  --portrait-shrink: clamp(0, var(--u), 1);
  /* Venn slot px captured from row at u=0; fallback ~300px */
  --venn-slot-px: 18.75rem;
  --venn-exit: 0;
  --venn-space: 0;
  --venn-slide: 0;
  /* Set in JS from layout measurement */
  --headline-budget-height: auto;
  --headline-font-size: 1.333rem;
  --headline-line-height: 1.3;
  --headline-grow: 0;
  --headline-morph: 0;
  --headline-slot-height: auto;
}

body.clarity-journey {
  --chaos: calc(1 - var(--u));
  --width-site: calc(1280px - var(--u) * 300px);
  --urgency-visible: calc(1 - var(--urgency-progress));
  --cx-urgency-red-dark: #c0392b;
  --cx-headline-start-size: 1.333rem;
  --cx-headline-copy-max: 80%;
  --cx-venn-copy-gap: 1.5rem;
  --cx-venn-slot-scale: 1;
  --cx-hero-portrait-w: 20.056rem;
  --cx-hero-portrait-h: 29.5rem;
  --cx-hero-portrait-gap: 4rem;
  --cx-slider-thumb-fill: color-mix(
    in srgb,
    var(--cx-urgency-red-dark) calc((1 - var(--u)) * 100%),
    var(--color-ink)
  );
  --cx-slider-label-size: calc(0.8rem - var(--u) * 0.2rem);
  --cx-slider-label-gap: calc(1rem - var(--u) * 0.35rem);
  --cx-slider-label-mb: calc(0.85rem - var(--u) * 0.25rem);
  --cx-slider-pad-top: calc(0.5rem - var(--u) * 0.15rem);
  --cx-slider-pad-bottom: calc(1.075rem - var(--u) * 0.35rem);
  --cx-slider-thumb-size: calc(1.5rem - var(--u) * 0.45rem);
  overflow-x: clip;
  max-width: 100%;
  min-width: 900px;
  /* Pull: body + header move up; .cx-page pad stays fixed so headline–header gap holds */
  padding-top: calc(var(--cx-urgency-height) * var(--urgency-visible));
}

body.clarity-journey .cx-page {
  overflow-x: clip;
  max-width: 100%;
}

body.clarity-journey .cx-page {
  padding-top: var(--cx-top-chrome);
}

body.clarity-journey .cx-header.site-header {
  top: calc(var(--cx-urgency-height) * var(--urgency-visible));
  min-height: var(--cx-layout-header-h-live, var(--cx-layout-header-h));
  height: var(--cx-layout-header-h-live, var(--cx-layout-header-h));
  padding-top: calc(
    var(--cx-header-pad-top-complex, 1.333rem) +
    var(--u) * (var(--cx-header-pad-top-compact, 2.333rem) - var(--cx-header-pad-top-complex, 1.333rem))
  );
  padding-bottom: calc(
    var(--cx-header-pad-bottom-complex, 1.333rem) +
    var(--u) * (var(--cx-header-pad-bottom-compact, 1.667rem) - var(--cx-header-pad-bottom-complex, 1.333rem))
  );
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  transition:
    height 0.35s ease,
    min-height 0.35s ease,
    padding-top 0.35s ease,
    padding-bottom 0.35s ease,
    top 0.35s ease;
}

body.clarity-journey .chaos-urgency {
  transform: translateY(calc(-100% * var(--urgency-progress)));
}

body.clarity-journey .cx-nav--complex.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.clarity-journey .cx-nav--complex a[data-threshold] {
  transition: opacity 0.35s ease, filter 0.35s ease;
}

body.clarity-journey .cx-nav--complex a[data-threshold].is-faded {
  display: none;
}

body.clarity-journey .cx-nav--complex #nav-how-i-work {
  --nav-prefix-t: 0;
}

body.clarity-journey .cx-nav--complex #nav-how-i-work .cx-nav__prefix {
  display: inline-block;
  max-width: calc((1 - var(--nav-prefix-t)) * 5ch);
  overflow: hidden;
  white-space: nowrap;
  vertical-align: bottom;
  opacity: calc(1 - var(--nav-prefix-t));
  transition: opacity 0.25s ease, max-width 0.35s ease;
}

body.clarity-journey .cx-nav--complex #nav-how-i-work .cx-nav__gap {
  display: inline-block;
  width: calc((1 - var(--nav-prefix-t)) * 0.25em);
  overflow: hidden;
  vertical-align: bottom;
  opacity: calc(1 - var(--nav-prefix-t));
  transition: opacity 0.25s ease, width 0.35s ease;
}

/* ——— Logo — u-driven shrink; TM fades by ~50% ——— */
body.clarity-journey .cx-logo__name {
  font-size: calc(1.778rem - var(--u) * 0.667rem);
  transition: font-size 0.35s ease;
}

body.clarity-journey .cx-logo__tm {
  opacity: calc(1 - var(--u) * 2);
  transition: opacity 0.35s ease;
}

/* ——— Nav crossfade ——— */
body.clarity-journey .cx-header__inner {
  position: relative;
  min-height: 0;
}

body.clarity-journey .cx-nav--complex {
  display: flex;
}

body.clarity-journey.is-nav-simplified .cx-nav--complex {
  display: none;
}

body.clarity-journey .cx-nav--clarity {
  display: none;
  align-items: center;
}

body.clarity-journey.is-nav-simplified .cx-nav--clarity {
  display: flex;
}

/* ——— Hero ——— */
body.clarity-journey .cx-hero__bg img {
  opacity: calc(0.26 * clamp(0, 1 - var(--u) / 0.55, 1));
}

body.clarity-journey .cx-hero__slider-block {
  position: relative;
  z-index: 2;
}

body.clarity-journey .cx-hero__portrait {
  opacity: 1;
  width: var(--cx-hero-portrait-w);
  height: var(--cx-hero-portrait-h);
  margin-top: auto;
  margin-bottom: -1.5rem;
  align-self: flex-end;
  overflow: visible;
  pointer-events: calc((1 - var(--portrait-shrink)) * 1);
  transform: scale(calc(1 - var(--portrait-shrink)));
  transform-origin: bottom left;
}

body.clarity-journey .cx-hero__portrait img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: bottom left;
}

body.clarity-journey .cx-hero {
  overflow-x: visible;
  overflow-y: hidden;
}

body.clarity-journey .cx-hero__headline-row {
  position: relative;
  align-items: flex-start;
  gap: 0;
  overflow-x: visible;
}

body.clarity-journey .cx-hero__venn {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  width: calc(var(--venn-slot-px) * var(--cx-venn-slot-scale, 1));
  height: auto;
  flex: none;
  transform-origin: top right;
  opacity: calc((1 - max(0, (var(--venn-exit) - 0.92) / 0.08)) * (1 - var(--headline-morph)));
  transform: translateX(var(--venn-slide, 0));
  pointer-events: calc((1 - var(--venn-exit)) * (1 - var(--headline-morph)) * 1);
}

body.clarity-journey .cx-hero__copy {
  position: relative;
  z-index: 0;
  flex: 1 1 100%;
  flex-grow: 1;
  min-width: 0;
  max-width: var(--cx-headline-copy-max, 80%);
  margin-right: calc(
    (var(--venn-slot-px) * var(--cx-venn-slot-scale, 1) + var(--cx-venn-copy-gap, 1.5rem))
    * (1 - var(--venn-space, 0))
  );
}

body.clarity-journey .cx-hero__eyebrow {
  min-height: var(--cx-eyebrow-reserved-height, auto);
  margin-bottom: max(0.5rem, calc(1rem - var(--cx-hero-lift) * 0.15));
  overflow: visible;
  pointer-events: none;
}

body.clarity-journey .cx-hero__eyebrow .eyebrow-skill,
body.clarity-journey .cx-hero__eyebrow .eyebrow-sep {
  transition: opacity 0.35s ease, filter 0.35s ease;
}

body.clarity-journey .cx-hero__eyebrow .eyebrow-skill.is-faded,
body.clarity-journey .cx-hero__eyebrow .eyebrow-sep.is-faded {
  opacity: 0;
  filter: blur(2px);
  position: absolute;
  width: 0;
  overflow: hidden;
  pointer-events: none;
}

body.clarity-journey .cx-hero__title-complex {
  display: block;
  position: relative;
  box-sizing: border-box;
  min-height: var(--headline-slot-height, var(--headline-budget-height, auto));
  max-width: calc(
    var(--headline-morph) * var(--cx-rest-title-max-w)
    + (1 - var(--headline-morph)) * 100%
  );
  font-size: var(--headline-font-size, var(--cx-headline-start-size, 1.333rem));
  line-height: var(--headline-line-height, 1.3);
  letter-spacing: calc(-0.02em * (var(--headline-grow) * (1 - var(--headline-morph)) + var(--headline-morph)));
  text-align: left;
}

body.clarity-journey .cx-hero__title-complex .frag-ideas-break {
  display: none;
}

body.clarity-journey .cx-hero__title-complex.is-final-phrase .frag-ideas-break {
  display: inline;
}

body.clarity-journey .cx-hero__title-clarity {
  display: none;
}

body.clarity-journey .cx-hero__title .frag {
  display: inline;
  transition: opacity 0.35s ease, filter 0.35s ease;
}

body.clarity-journey .cx-hero__title .frag.is-faded {
  opacity: 0;
  filter: blur(2px);
  position: absolute;
  width: 0;
  overflow: hidden;
  pointer-events: none;
}

body.clarity-journey .cx-hero__title .frag-prefix-i,
body.clarity-journey .cx-hero__title .frag-s2-to,
body.clarity-journey .cx-hero__title .frag-verb-plain,
body.clarity-journey .cx-hero__title .frag-proto-and {
  opacity: 0;
  display: none;
}

body.clarity-journey .cx-hero__title .frag-prefix-i.is-visible,
body.clarity-journey .cx-hero__title .frag-s2-to.is-visible,
body.clarity-journey .cx-hero__title .frag-verb-plain.is-visible,
body.clarity-journey .cx-hero__title .frag-proto-and.is-visible {
  opacity: 1;
  display: inline;
}

body.clarity-journey .cx-hero__title .frag-verb-ing.is-faded {
  display: none;
}

@media (min-width: 769px) {
  body.clarity-journey .cx-hero__content {
    margin-left: calc((var(--cx-hero-portrait-w) + var(--cx-hero-portrait-gap)) * (1 - var(--portrait-shrink)));
  }
}

body.clarity-journey .cx-hero__inner {
  padding-top: calc(
    var(--cx-hero-pad-top) * (1 - var(--headline-morph))
    + var(--headline-morph) * var(--cx-rest-hero-pad-top)
  );
  padding-bottom: 1.5rem;
  align-items: flex-start;
  min-height: calc(29.5rem + var(--cx-hero-pad-top) + 1.5rem - var(--cx-hero-lift) + var(--u) * 2rem);
}

@media (max-width: 768px) {
  body.clarity-journey {
    min-width: 0;
  }

  body.journey-layout-lock.clarity-journey .cx-hero__inner {
    min-height: 0;
    padding-bottom: 0;
  }

  body.clarity-journey .cx-hero__title-complex {
    min-height: auto;
    max-width: 100%;
  }
}

@media (min-width: 769px) {
  body.clarity-journey .cx-hero__inner {
    min-height: auto;
  }

  body.clarity-journey .cx-hero__portrait {
    margin-top: 0;
  }
}

body.clarity-journey .cx-hero__content {
  justify-content: flex-start;
  gap: 0.625rem;
  padding-bottom: 0;
}

body.clarity-journey .cx-slider__heading {
  opacity: calc(1 - var(--u) * 3);
  pointer-events: calc((1 - var(--u) * 2) * 1);
}

body.clarity-journey .cx-slider__here {
  color: var(--cx-urgency-red-dark);
  opacity: calc(1 - var(--u) * 1.5);
}

body.clarity-journey .cx-slider {
  padding: var(--cx-slider-pad-top) var(--cx-slider-pad-x) var(--cx-slider-pad-bottom);
}

body.clarity-journey .cx-slider__labels {
  font-size: var(--cx-slider-label-size);
  gap: var(--cx-slider-label-gap);
  margin-bottom: var(--cx-slider-label-mb);
}

body.clarity-journey .cx-slider__label--from {
  opacity: calc(1 - var(--u) * 0.6);
}

/* ——— Below-hero rhythm (journey) ——— */
body.clarity-journey .cx-ai-ticker {
  padding-block: 2rem 1.5rem;
}

body.clarity-journey .cx-noise {
  padding-block: 2rem 0.25rem;
}

body.clarity-journey {
  --cx-layout-header-h-live: calc(
    var(--cx-layout-header-h-complex, 82px) -
    var(--u) * (var(--cx-layout-header-h-complex, 82px) - var(--cx-layout-header-h-compact, 56px))
  );
  --fold-collapse: clamp(0, (var(--u) - 0.72) / 0.24, 1);
  --work-rest-lift: clamp(0, (var(--u) - 0.78) / 0.18, 1);
}

body.journey-layout-lock.clarity-journey {
  --cx-layout-header-h: var(--cx-layout-header-h-live);
  /* Debug token: live slider-top Y from page top (approximate) */
  --cx-layout-control-y: calc(
    var(--cx-urgency-height) * var(--urgency-visible) +
    var(--cx-layout-header-h-live) +
    var(--cx-layout-hero-h) -
    var(--cx-layout-hero-pad-bottom) -
    var(--cx-layout-control-h-compact, 4.5rem)
  );
  /* Header only — body padding-top owns urgency offset (avoids double stack) */
  --cx-top-chrome: var(--cx-layout-header-h-live);
}

body.clarity-journey .cx-complex-only {
  overflow: hidden;
  transition: opacity 0.35s ease, max-height 0.45s ease, padding 0.45s ease;
}

body.clarity-journey .cx-ai-ticker {
  opacity: calc(clamp(0, 1 - var(--u) * 2, 1));
  max-height: calc(9rem * (1 - var(--fold-collapse)));
  padding-block: calc(2rem * (1 - var(--fold-collapse))) calc(1.5rem * (1 - var(--fold-collapse)));
  pointer-events: none;
}

body.clarity-journey .cx-noise {
  opacity: calc(clamp(0, 1 - (var(--u) - 0.06) * 1.3, 1));
  max-height: calc(36rem * (1 - var(--fold-collapse)));
  padding-block: calc(2rem * (1 - var(--fold-collapse))) calc(0.25rem * (1 - var(--fold-collapse)));
}

/* Selected work — always visible; intro fades; slight late settle only */
body.clarity-journey .cx-work-rest {
  display: block;
  padding-block: 3rem;
}

body.clarity-journey .cx-work-rest {
  transform: translateY(calc((1 - var(--work-rest-lift)) * 1.25rem));
  transition: transform 0.45s ease;
}

body.clarity-journey .cx-work-rest__intro {
  overflow: hidden;
  opacity: calc(clamp(0, 1 - (var(--u) - 0.03) * 1.4, 1));
  max-height: calc(clamp(0, 1 - (var(--u) - 0.03) * 1.2, 1) * 6rem);
  margin-bottom: calc(clamp(0, 1 - (var(--u) - 0.03) * 1.2, 1) * 2rem);
  transition: opacity 0.35s ease, max-height 0.4s ease, margin 0.4s ease;
}

/* Hero HR: always the section border — no crossfade with cx-hero-rule */
body.clarity-journey .cx-hero {
  border-bottom: 1px solid var(--color-rule);
}

body.clarity-journey .cx-hero-rule {
  display: none;
}

/* ——— Footer: always Contact | CV ——— */
body.clarity-journey .cx-footer__clarity {
  display: none;
}

body.clarity-journey .cx-footer__complex {
  display: flex;
  opacity: 1;
}

/* ——— Rest enter: crossfade slider → CTA panel only ——— */
body.clarity-journey .cx-hero__slider-block {
  position: relative;
}

body.clarity-journey .cx-slider__heading,
body.clarity-journey .cx-slider {
  transition: opacity 0.18s ease;
}

body.clarity-journey .cx-rest-panel[hidden] {
  display: none !important;
}

body.clarity-journey .cx-rest-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  width: 100%;
  padding: 0 var(--cx-slider-pad-x);
  background: var(--cx-slider-bg, #fff);
  border: 1px solid var(--color-rule);
  border-left: 3px solid var(--color-accent);
  box-shadow: var(--cx-slider-shadow, 0 0 36px rgba(28, 28, 28, 0.22), 0 0 10px rgba(28, 28, 28, 0.1));
  box-sizing: border-box;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

body.journey-layout-lock.clarity-journey .cx-rest-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

body.clarity-journey.is-entering-rest .cx-slider__heading,
body.clarity-journey.is-entering-rest .cx-slider,
body.clarity-journey.is-resting .cx-slider__heading,
body.clarity-journey.is-resting .cx-slider {
  display: block;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.clarity-journey.is-entering-rest .cx-rest-panel,
body.clarity-journey.is-resting .cx-rest-panel {
  opacity: 1;
  pointer-events: auto;
}

/* ——— Chaos: pop, not fade ——— */
body.clarity-journey .chaos-layer {
  opacity: 1;
  pointer-events: none;
}

body.clarity-journey .chaos-layer > * {
  transition: none;
}

.chaos-pop-out {
  animation: cx-chaos-pop-vanish 0.38s cubic-bezier(0.55, 0, 1, 0.45) forwards;
  pointer-events: none !important;
}

body.clarity-journey .chaos-newsletter-wrap.chaos-pop-out {
  animation: cx-chaos-pop-vanish-tab 0.38s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

/* legacy: button-only pop target before wrap refactor */
body.clarity-journey .chaos-newsletter.chaos-pop-out {
  animation: cx-chaos-pop-vanish-tab 0.38s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes cx-chaos-pop-vanish-tab {
  0%   { transform: translateY(-50%) scale(1); opacity: 1; }
  12%  { transform: translateY(-50%) scale(1) translate(1px, -1px); opacity: 1; }
  24%  { transform: translateY(-50%) scale(1) translate(-1px, 1px); opacity: 1; }
  36%  { transform: translateY(-50%) scale(1) translate(1px, 0); opacity: 1; }
  48%  { transform: translateY(-50%) scale(1.06); opacity: 1; }
  100% { transform: translateY(-50%) scale(0); opacity: 0; }
}

.chaos-pop-finale {
  animation: cx-chaos-pop-finale 0.55s cubic-bezier(0.55, 0, 1, 0.45) forwards;
  pointer-events: none !important;
}

/* complexity-start.css sets animation:none on social — must beat that rule */
body.clarity-journey.complexity-start .chaos-social.chaos-pop-finale {
  animation: cx-chaos-pop-finale 0.55s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes cx-chaos-pop-finale {
  0%   { transform: scale(1) rotate(0deg); opacity: 1; }
  10%  { transform: scale(1.03) translate(3px, -2px) rotate(-1.5deg); opacity: 1; }
  20%  { transform: scale(1.03) translate(-3px, 2px) rotate(1.5deg); opacity: 1; }
  30%  { transform: scale(1.02) translate(2px, 0) rotate(-1deg); opacity: 1; }
  40%  { transform: scale(1.02) translate(-2px, 0) rotate(1deg); opacity: 1; }
  52%  { transform: scale(1.16) rotate(0deg); opacity: 1; }
  100% { transform: scale(0) rotate(6deg); opacity: 0; }
}

@keyframes cx-chaos-pop-vanish {
  0%   { transform: scale(1); opacity: 1; }
  12%  { transform: scale(1) translate(1px, -1px); opacity: 1; }
  24%  { transform: scale(1) translate(-1px, 1px); opacity: 1; }
  36%  { transform: scale(1) translate(1px, 0); opacity: 1; }
  48%  { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

.chaos-slide-off {
  pointer-events: none !important;
}

@media (prefers-reduced-motion: reduce) {
  body.clarity-journey .cx-hero__portrait,
  body.clarity-journey .cx-hero__venn,
  body.clarity-journey .cx-complex-only,
  body.clarity-journey .cx-work-rest__intro {
    transition: none;
  }

  .chaos-pop-out,
  .chaos-pop-finale,
  .chaos-slide-off {
    animation: none;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}

/* ——— Layout debug overlay (?debug=layout) ——— */
body.clarity-journey.has-layout-debug .cx-layout-debug {
  display: block;
}

.cx-layout-debug {
  display: none;
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 9999;
  width: min(18rem, calc(100vw - 1.5rem));
  padding: 0.65rem 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.65rem;
  line-height: 1.45;
  color: #f5f5f5;
  background: rgba(12, 12, 12, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.35rem;
  pointer-events: none;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

.cx-layout-debug__title {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #9fdcff;
}

.cx-layout-debug dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.12rem 0.65rem;
}

.cx-layout-debug dt {
  color: #aaa;
}

.cx-layout-debug dd {
  margin: 0;
  color: #fff;
  text-align: right;
}

.cx-layout-debug__delta--ok { color: #7dffb2; }
.cx-layout-debug__delta--warn { color: #ffd166; }
.cx-layout-debug__delta--bad { color: #ff7b7b; }

body.clarity-journey.has-layout-debug .cx-layout-debug__guide {
  display: block;
}

.cx-layout-debug__guide {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 9998;
}

body.clarity-journey.has-layout-debug .cx-hero__title-complex {
  outline: 1px dashed rgba(159, 220, 255, 0.85);
  outline-offset: 3px;
}

.cx-layout-debug__guide--slot {
  right: auto;
  bottom: auto;
  border: 1px dashed rgba(159, 220, 255, 0.65);
  background: rgba(159, 220, 255, 0.06);
}

.cx-layout-debug__guide--anchor {
  border-top: 2px dashed rgba(255, 209, 102, 0.85);
}

.cx-layout-debug__guide--slider {
  border-top: 2px solid rgba(127, 255, 178, 0.9);
}
