/* ==========================================================================
   Houshare Builders — Modern layer
   Intro loader, page transitions, smooth scroll, cursor, magnetic buttons,
   split-text reveals, floating header, pinned project showcase, grain.
   Loaded after styles.css; everything here degrades gracefully.
   ========================================================================== */

/* ---------- Smooth scroll (Lenis) ---------- */
html.lenis, html.lenis body { height: auto; }
html.lenis-smooth { scroll-behavior: auto !important; }
.lenis-smooth [data-lenis-prevent] { overscroll-behavior: contain; }
html.lenis-stopped { overflow: hidden; }

/* ---------- Page transitions (cross-document View Transitions) ---------- */
@view-transition { navigation: auto; }
::view-transition { background: var(--night); }
::view-transition-old(root) { animation: vtOld .8s var(--ease-in-out) both; }
::view-transition-new(root) { animation: vtNew .9s var(--ease-in-out) both; }
@keyframes vtOld { to { transform: translateY(-8%) scale(.96); opacity: .35; filter: blur(2px); } }
@keyframes vtNew { from { clip-path: inset(100% 0 0 0); transform: translateY(6%); } to { clip-path: inset(0 0 0 0); transform: none; } }

/* ---------- Grain + scroll progress ---------- */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 95; pointer-events: none; opacity: .055;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.scroll-progress {
  position: fixed; left: 0; top: 0; right: 0; height: 2px; z-index: 70; pointer-events: none;
  background: var(--bronze-2); transform-origin: 0 50%; transform: scaleX(var(--sp, 0));
}

/* ---------- Floating "pill" header once scrolled ---------- */
.header .container {
  transition: height .6s var(--ease), margin .6s var(--ease), padding .6s var(--ease), background .5s var(--ease),
    border-radius .6s var(--ease), box-shadow .5s var(--ease), max-width .6s var(--ease), width .6s var(--ease);
}
.header.is-scrolled { background: transparent; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
.header.is-scrolled .container {
  width: calc(100% - 2 * var(--gutter)); max-width: calc(var(--max) - 2 * var(--gutter));
  height: 64px; margin-top: 10px; padding: 0 8px 0 22px; border-radius: 999px;
  background: rgba(247, 241, 234, .8);
  backdrop-filter: saturate(170%) blur(20px); -webkit-backdrop-filter: saturate(170%) blur(20px);
  box-shadow: 0 18px 50px -24px rgba(34, 21, 14, .45), inset 0 0 0 1px rgba(34, 21, 14, .07);
}
.header.is-scrolled .logo svg { height: 36px; }
.header.is-scrolled .logo__name { font-size: 19px; }
.menu-open .header .container { width: 100%; max-width: var(--max); height: 100%; margin-top: 0; padding: 0 var(--gutter); background: transparent; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; }

/* ---------- Text roll on hover (nav + buttons) ---------- */
.roll { position: relative; display: inline-block; overflow: hidden; vertical-align: top; line-height: 1.25; }
.roll > span { display: block; position: relative; transition: transform .6s var(--ease); }
.roll > span::after { content: attr(data-t); position: absolute; left: 0; top: 100%; white-space: nowrap; }
a:hover > .roll > span, button:hover > .roll > span { transform: translateY(-100%); }

/* ---------- Split-text reveals ---------- */
.split .wd {
  display: inline-block; overflow: hidden; vertical-align: top;
  padding: 0 .1em .14em; margin: 0 -.1em -.14em;
}
.split .wd > span {
  display: inline-block; transform: translateY(108%) rotate(4deg); transform-origin: 0 100%;
  transition: transform 1.1s var(--ease); transition-delay: calc(var(--wi, 0) * 45ms);
}
.split.split-in .wd > span { transform: none; }

.footer__wordmark .ch {
  display: inline-block; opacity: 0; transform: translateY(45%); filter: blur(8px);
  transition: opacity 1s var(--ease), transform 1.2s var(--ease), filter 1s var(--ease);
  transition-delay: calc(var(--ci, 0) * 55ms);
}
.footer__wordmark.split-in .ch { opacity: 1; transform: none; filter: none; }

/* ---------- Custom cursor (fine pointers only) ---------- */
.cursor {
  position: fixed; left: 0; top: 0; z-index: 9990; pointer-events: none;
  width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .9); mix-blend-mode: difference;
  display: grid; place-items: center; opacity: 0;
  transition: width .5s var(--ease), height .5s var(--ease), margin .5s var(--ease), background .4s, border-color .4s, opacity .3s;
}
.cursor.on { opacity: 1; }
.cursor.is-link { width: 64px; height: 64px; margin: -32px 0 0 -32px; background: rgba(255, 255, 255, .95); border-color: transparent; }
.cursor.is-down { width: 26px; height: 26px; margin: -13px 0 0 -13px; }
.cursor.is-label {
  width: 104px; height: 104px; margin: -52px 0 0 -52px; mix-blend-mode: normal;
  background: var(--bronze); border-color: transparent; box-shadow: 0 20px 40px -18px rgba(0, 0, 0, .5);
}
.cursor__label {
  color: var(--white); font: 600 13px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase;
  opacity: 0; transform: scale(.6); transition: opacity .3s, transform .5s var(--ease);
}
.cursor.is-label .cursor__label { opacity: 1; transform: none; }
.cursor.is-hidden { opacity: 0; }
@media (pointer: fine) {
  .has-cursor .proj-card__view { display: none; }
}

/* ---------- Hero: scroll cue ---------- */
.hero__inner, .hero__media, .page-hero--img .bg, .page-hero--img .container { will-change: transform; }

/* ---------- Intro loader (home, once per session) ---------- */
html.intro::after { content: ""; position: fixed; inset: 0; background: var(--night); z-index: 9998; }
html.intro .hero__title .line > span,
html.intro .hero .fade-up,
html.intro .hero__media img { animation-play-state: paused; }
html.intro body { overflow: hidden; }

.loader {
  position: fixed; inset: 0; z-index: 9999; background: var(--night); color: var(--paper);
  display: grid; place-items: center; clip-path: inset(0 0 0 0);
}
.loader.out { clip-path: inset(0 0 100% 0); transition: clip-path 1s var(--ease-in-out); }
.loader.out .loader__inner { transform: translateY(-60px); opacity: 0; transition: transform 1s var(--ease-in-out), opacity .6s; }
.loader__inner { display: flex; align-items: center; gap: 22px; }
.loader__mark { width: clamp(72px, 9vw, 104px); }
.loader__mark svg { width: 100%; height: auto; display: block; overflow: visible; }
.loader__mark .hs-h { clip-path: inset(100% 0 0 0); }
.loader__mark .hs-s { clip-path: inset(0 0 0 100%); --logo-s: #c49464; }
.loader.go .hs-h { animation: hsWipeUp 1s var(--ease) .1s forwards; }
.loader.go .hs-s { animation: hsWipeIn 1.1s var(--ease) .55s forwards; }
@keyframes hsWipeUp { to { clip-path: inset(0 0 0 0); } }
@keyframes hsWipeIn { to { clip-path: inset(0 0 0 0); } }
@keyframes lhRise { to { transform: none; } }
.loader__word { display: flex; flex-direction: column; gap: 8px; }
.loader__name { font-family: var(--brand); font-weight: 400; font-size: clamp(34px, 5vw, 60px); line-height: 1; letter-spacing: .12em; display: flex; }
.loader__name span { display: inline-block; overflow: hidden; padding: 0 .02em .1em; margin-bottom: -.1em; }
.loader__name span i { display: inline-block; font-style: normal; transform: translateY(110%); }
.loader.go .loader__name span i { animation: lhRise 1s var(--ease) forwards; animation-delay: calc(.55s + var(--li) * 45ms); }
.loader__sub { font-size: 11px; font-weight: 600; letter-spacing: .5em; text-transform: uppercase; color: var(--bronze-2); opacity: 0; }
.loader.go .loader__sub { animation: fadeUp 1s var(--ease) 1s forwards; }
.loader__count {
  position: absolute; right: var(--gutter); bottom: calc(var(--gutter) - 10px);
  font-family: var(--serif); font-size: clamp(64px, 11vw, 160px); line-height: 1; color: rgba(247, 241, 234, .14);
  font-variant-numeric: tabular-nums;
}
.loader__bar { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: var(--bronze-2); transform-origin: 0 50%; transform: scaleX(var(--lp, 0)); }

/* ---------- Pinned horizontal project showcase ---------- */
.showcase { position: relative; background: var(--paper); }
.showcase__pin {
  position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden;
  display: flex; flex-direction: column; justify-content: center; gap: clamp(28px, 4vh, 52px);
  padding-top: 40px;
}
.showcase__head { display: flex; justify-content: space-between; align-items: flex-end; gap: 32px; }
.showcase__side { display: flex; align-items: center; gap: 28px; }
.showcase__count { display: flex; align-items: center; gap: 12px; font-family: var(--serif); font-size: 28px; font-variant-numeric: tabular-nums; }
.showcase__count i { width: 46px; height: 1px; background: var(--ink); opacity: .35; }
.showcase__count span:last-child { color: var(--muted); }
.showcase__track {
  display: flex; align-items: flex-end; gap: clamp(18px, 2.2vw, 36px);
  padding: 0 var(--gutter); will-change: transform; position: relative;
}
.rail-card { flex: none; display: block; position: relative; }
.rail-card__media { height: min(52vh, 560px); aspect-ratio: 4 / 3; overflow: hidden; border-radius: 6px; background: var(--paper-3); position: relative; }
.rail-card--tall .rail-card__media { aspect-ratio: 4 / 5; }
.rail-card__media img { width: 118%; max-width: none; height: 100%; object-fit: cover; margin-left: -9%; transition: scale 1.4s var(--ease); will-change: transform; }
.rail-card:hover .rail-card__media img { scale: 1.05; }
.rail-card__media::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(20, 12, 7, .35), transparent 40%); opacity: 0; transition: opacity .6s var(--ease); }
.rail-card:hover .rail-card__media::after { opacity: 1; }
.rail-card__meta { display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 16px; margin-top: 18px; }
.rail-card__n { font-size: 12px; font-weight: 600; letter-spacing: .14em; color: var(--bronze); }
.rail-card__meta h3 { font-size: clamp(22px, 1.9vw, 30px); line-height: 1.1; }
.rail-card__meta div span { display: block; font-size: 14px; color: var(--muted); margin-top: 4px; }
.rail-card__tag { font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.rail-end {
  flex: none; height: min(52vh, 560px); aspect-ratio: 3 / 4; border-radius: 6px; margin-bottom: 64px;
  background: var(--night); color: var(--paper); display: flex; flex-direction: column; justify-content: space-between; padding: 32px;
  transition: background .5s var(--ease);
}
.rail-end:hover { background: var(--bronze); }
.rail-end__circle { width: 84px; height: 84px; border-radius: 50%; border: 1px solid rgba(247, 241, 234, .4); display: grid; place-items: center; align-self: flex-end; transition: transform .6s var(--ease); }
.rail-end__circle svg { width: 26px; height: 26px; transform: rotate(-45deg); }
.rail-end:hover .rail-end__circle { transform: rotate(45deg); }
.rail-end__t { font-family: var(--serif); font-size: clamp(36px, 3.4vw, 54px); line-height: 1; }
.rail-end__t em { display: block; color: var(--bronze-2); }
.rail-end:hover .rail-end__t em { color: var(--paper); }
.showcase__foot { display: flex; align-items: center; gap: 28px; }
.showcase__bar { flex: 1; height: 1px; background: var(--line); position: relative; overflow: hidden; }
.showcase__bar span { position: absolute; inset: 0; background: var(--ink); transform-origin: 0 50%; transform: scaleX(var(--rp, 0)); }
.showcase__hint { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.showcase__hint svg { width: 16px; height: 16px; animation: nudge 1.8s var(--ease) infinite; }
@keyframes nudge { 50% { transform: translateX(6px); } }

/* Touch / small screens: native swipe rail instead of pinning */
@media (max-width: 900px), (prefers-reduced-motion: reduce) {
  .showcase { height: auto !important; padding: clamp(80px, 11vw, 140px) 0; }
  .showcase__pin { position: relative; height: auto; overflow: visible; padding-top: 0; }
  .showcase__track {
    overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; transform: none !important;
    scroll-padding: 0 var(--gutter); padding-bottom: 4px; align-items: stretch;
  }
  .showcase__track::-webkit-scrollbar { display: none; }
  .rail-card, .rail-end { scroll-snap-align: start; }
  .showcase__hint { display: none; }
}
@media (max-width: 900px) {
  .showcase__head { flex-direction: column; align-items: flex-start; }
  .showcase__side { width: 100%; justify-content: space-between; }
  .rail-card { width: 80vw; }
  .rail-card__media, .rail-card--tall .rail-card__media { height: auto; aspect-ratio: 4 / 5; }
  .rail-card__media img { width: 100%; margin-left: 0; }
  .rail-card__meta { grid-template-columns: auto 1fr; }
  .rail-card__tag { display: none; }
  .rail-end { width: 64vw; height: auto; aspect-ratio: auto; margin-bottom: 0; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  .split .wd > span, .footer__wordmark .ch { transform: none; opacity: 1; filter: none; }
  .cursor, .loader, .scroll-progress { display: none !important; }
  html.intro::after { display: none; }
}

/* Hero title: give italic descenders/overhangs room inside the line masks */
.hero__title .line { padding: 0 .08em .16em; margin: 0 -.08em -.16em; }
