/* ─────────────────────────────────────────────────────────
   motion.css — shared motion, cursor, curtain, grain,
                texture, accent, corner chrome, hero readout.
   Every page links this file.
   ───────────────────────────────────────────────────────── */

/* ─── Accent tokens (theme-aware) ────────────────────── */
:root { --accent: #8B1E2D; }               /* deep oxblood */
[data-theme="dark"] { --accent: #D94452; } /* vermillion  */

/* Create a stacking context on body so negative-z chrome is contained */
body { isolation: isolate; }

/* ─── Background grid (below everything) ─────────────── */
.grid-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
  background-image:
    linear-gradient(to right, rgba(0,0,0,0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0,0,0,0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: 0 0;
  transition: opacity 0.45s ease;
}
[data-theme="dark"] .grid-bg {
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.04) 1px, transparent 1px);
}

/* ─── Mouse spotlight (above grid+grain, below content) ── */
.spotlight {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background: radial-gradient(
    400px circle at var(--sx, 50%) var(--sy, 50%),
    rgba(255,255,255,0.05),
    transparent 65%
  );
  opacity: 0;
  transition: opacity 0.45s ease;
}
.spotlight.active { opacity: 1; }
[data-theme="dark"] .spotlight {
  background: radial-gradient(
    400px circle at var(--sx, 50%) var(--sy, 50%),
    rgba(255,255,255,0.035),
    transparent 65%
  );
}

/* ─── Hairlines top & bottom of viewport ─────────────── */
.hairline-top, .hairline-bottom {
  position: fixed;
  left: 0; right: 0;
  height: 1px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  pointer-events: none;
  z-index: 201;
}
.hairline-top    { top: 0; }
.hairline-bottom { bottom: 0; }

/* ─── Corner chrome: date, live, progress line ───────── */
.chrome {
  font-family: ui-monospace, 'SF Mono', Menlo, 'Cascadia Mono', Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--text) 40%, transparent);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 201;
}
.corner-date {
  position: fixed;
  bottom: 14px;
  left: 20px;
}
/* Vertical scroll progress line on right edge of viewport */
.corner-progress {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 60vh;
  pointer-events: none;
  z-index: 201;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  overflow: hidden;
}
.corner-progress .corner-progress-fill {
  position: absolute;
  inset: 0;
  transform-origin: top;
  transform: scaleY(var(--progress, 0));
  background: var(--accent);
  will-change: transform;
  transition: transform 0.1s linear;
}

@media (max-width: 700px) {
  .corner-date     { left: 14px; bottom: 10px; font-size: 9px; }
  .corner-progress { height: 40vh; }
}

/* ─── Hero readout (index + portfolio) ───────────────── */
.hero-readout {
  font-family: ui-monospace, 'SF Mono', Menlo, 'Cascadia Mono', Consolas, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.9;
  text-align: right;
  color: color-mix(in srgb, var(--text) 40%, transparent);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.hero-readout > .row {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: end;
  gap: 0 18px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 700ms cubic-bezier(0.22,1,0.36,1),
              transform 700ms cubic-bezier(0.22,1,0.36,1);
}
.hero-readout .row .label { color: color-mix(in srgb, var(--text) 28%, transparent); }
.hero-readout .row .val   { color: color-mix(in srgb, var(--text) 55%, transparent); }
.hero-readout.in > .row { opacity: 1; transform: translateY(0); }
.hero-readout.in > .row:nth-child(1) { transition-delay: 1700ms; }
.hero-readout.in > .row:nth-child(2) { transition-delay: 1800ms; }
.hero-readout.in > .row:nth-child(3) { transition-delay: 1900ms; }
.hero-readout.in > .row:nth-child(4) { transition-delay: 2000ms; }

@media (max-width: 960px) {
  .hero-readout { display: none; }
}

/* ─── Project number: accent + stroke→fill reveal ────── */
.proj-num {
  color: var(--accent);
  font-size: 13px !important; /* was 11px; ~1.2× larger */
}
.proj-num [data-count] {
  color: transparent;
  -webkit-text-stroke: 1px var(--accent);
  transition: color 800ms cubic-bezier(0.22,1,0.36,1);
  will-change: color;
}
.proj-num.in [data-count],
.proj-num [data-count].counting {
  color: var(--accent);
}

/* ─── Count-up flash-to-accent for stat numbers ──────── */
[data-count] {
  transition: color 600ms cubic-bezier(0.22,1,0.36,1);
}
.stat-num [data-count].counting,
.page-count [data-count].counting {
  color: var(--accent);
}

/* ─── Accent hooks: link hover underline wipe ────────── */
a:not(.logo):not(.toggle):not(.nav-dot):not(.back-link):not(.contact-row):not(.btn-enter):not(.arrow-btn):not(.skip-link) {
  position: relative;
}

/* ─── Active nav dot uses accent ─────────────────────── */
.nav-dot { background: var(--accent); }

/* ─── Custom scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--pill, #CECCC6);
  border-radius: 2px;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted, #767370); }
html { scrollbar-width: thin; scrollbar-color: var(--pill, #CECCC6) transparent; }

/* ─── Grain overlay (global, above existing body::before) ── */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  opacity: 0.025;
  mix-blend-mode: multiply;
  transition: opacity 0.45s ease;
}
[data-theme="dark"] .grain {
  opacity: 0.045;
  mix-blend-mode: screen;
}

/* ─── Curtain page transition ─────────────────────────── */
.curtain {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: var(--bg, #F6F5F0);
  transform: translateY(0);    /* covers on first paint */
  pointer-events: none;
  will-change: transform;
}
.curtain.reveal {
  transform: translateY(-101%);
  transition: transform 200ms cubic-bezier(0.76, 0, 0.24, 1);
}
.curtain.parked {
  transform: translateY(101%);
  transition: none;
}
.curtain.exit {
  transform: translateY(0);
  transition: transform 200ms cubic-bezier(0.76, 0, 0.24, 1);
}
/* Arriving from the boot sequence: curtain stays covering on first paint,
   then fades its opacity to 0 so the portfolio eases in (rather than
   dropping in abruptly after the boot overlay). */
html.from-boot .curtain {
  transform: translateY(0) !important;
  opacity: 1;
  transition: opacity 200ms ease-out;
}
html.from-boot.boot-fading .curtain {
  opacity: 0;
}

/* ─── Custom cursor ───────────────────────────────────── */
.cursor {
  position: fixed;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text);
  pointer-events: none;
  z-index: 9999;
  transform: translate3d(-50%, -50%, 0);
  transition: width 0.2s ease, height 0.2s ease, background 0.2s ease;
  mix-blend-mode: difference;
  opacity: 0;
}

.cursor.active {
  opacity: 1;
}

.cursor.hovering {
  width: 32px;
  height: 32px;
}

@media (pointer: coarse) {
  .cursor { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor { display: none; }
}

/* ─── Universal active-press feedback ────────────────── */
a, button, .pill, .proj-tag, .project-row, .photo {
  transition-property: transform, opacity, color, background, border-color;
}
a:active, button:active, .pill:active, .proj-tag:active,
.photo:active, .project-row:active {
  transform: scale(0.975);
}

/* ─── Magnetic wrapper ───────────────────────────────── */
.magnetic {
  display: inline-block;
  will-change: transform;
}

/* ─── Clip-path image reveal ─────────────────────────── */
.reveal-clip {
  clip-path: inset(100% 0 0 0);
  -webkit-clip-path: inset(100% 0 0 0);
  transition: clip-path 1s cubic-bezier(0.22,1,0.36,1),
              -webkit-clip-path 1s cubic-bezier(0.22,1,0.36,1);
}
.reveal-clip.visible {
  clip-path: inset(0 0 0 0);
  -webkit-clip-path: inset(0 0 0 0);
}

/* Image scale-on-hover wrapper */
.img-frame {
  position: relative;
  overflow: hidden;
  display: block;
}
.img-frame > img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.6s cubic-bezier(0.25,0.46,0.45,0.94),
              filter 0.6s cubic-bezier(0.25,0.46,0.45,0.94);
  will-change: transform;
}
.img-frame:hover > img {
  transform: scale(1.03);
}

/* ─── Text split lines (mask-up) ─────────────────────── */
/* overflow: clip + margin gives glyph side-bearings breathing room;
   .done sets overflow: visible once the animation settles. */
.split-line-wrap {
  display: block;
  overflow: hidden;            /* fallback */
  overflow: clip;
  overflow-clip-margin: 0.5em;
  padding-bottom: 0.05em;
}
.split-line-wrap.done { overflow: visible; }
.split-line {
  display: block;
  transform: translateY(110%);
  will-change: transform;
}
.split-line.in {
  transform: translateY(0);
  transition: transform 900ms cubic-bezier(0.22,1,0.36,1);
}
.split-line.done { will-change: auto; }

/* Word-level split (for hero) */
.splitting .word {
  display: inline-block;
  overflow: hidden;            /* fallback */
  overflow: clip;
  overflow-clip-margin: 0.5em;
}
.splitting.done .word { overflow: visible; }
.splitting .word .char,
.splitting.word-mask .word {
  display: inline-block;
  transform: translateY(110%);
  will-change: transform;
  transition: transform 900ms cubic-bezier(0.22,1,0.36,1);
  transition-delay: calc(60ms * var(--word-index, var(--char-index, 0)));
}
.splitting.in .word .char,
.splitting.word-mask.in .word {
  transform: translateY(0);
}

/* Char rotate reveal (photography title) */
.splitting.char-rotate .char {
  display: inline-block;
  opacity: 0;
  transform: rotateX(20deg) translateY(20%);
  will-change: transform, opacity;
  transition:
    opacity 600ms cubic-bezier(0.22,1,0.36,1),
    transform 700ms cubic-bezier(0.22,1,0.36,1);
  transition-delay: calc(30ms * var(--char-index, 0));
}
.splitting.char-rotate.in .char {
  opacity: 1;
  transform: rotateX(0deg) translateY(0);
}

/* ─── Blur-in tagline ────────────────────────────────── */
.blur-in {
  filter: blur(8px);
  opacity: 0;
  will-change: filter, opacity;
}
.blur-in.in {
  filter: blur(0);
  opacity: 1;
  transition: filter 900ms cubic-bezier(0.22,1,0.36,1),
              opacity 900ms cubic-bezier(0.22,1,0.36,1);
}
.blur-in.done { will-change: auto; filter: none; }

/* ─── Section-label underline grow ───────────────────── */
.section-label span {
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 800ms cubic-bezier(0.22,1,0.36,1);
  will-change: transform;
}
.section-label.in span { transform: scaleX(1); }

/* ─── Generic fade-up (GSAP-managed or CSS fallback) ─── */
.fade-up {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 700ms cubic-bezier(0.22,1,0.36,1),
              transform 700ms cubic-bezier(0.22,1,0.36,1);
  will-change: transform, opacity;
}
.fade-up.in {
  opacity: 1;
  transform: translateY(0);
}
.fade-up.done { will-change: auto; }

/* Stagger pill/tag row */
.stagger-row > * {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 550ms cubic-bezier(0.22,1,0.36,1),
              transform 550ms cubic-bezier(0.22,1,0.36,1);
}
.stagger-row.in > * {
  opacity: 1;
  transform: translateY(0);
}

/* ─── Scroll-down line grow ──────────────────────────── */
.hero-scroll-line {
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 900ms 0.9s cubic-bezier(0.22,1,0.36,1);
  animation: none !important;
}
.hero-scroll-line.in { transform: scaleX(1); }
.hero-scroll-line.breathe {
  animation: scrollLineBreathe 1.6s ease-in-out infinite !important;
}
@keyframes scrollLineBreathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ─── Active nav indicator (portfolio.html) ──────────── */
nav { position: relative; }
.nav-dot {
  position: absolute;
  bottom: -6px;
  left: 0;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--text, #181715);
  opacity: 0;
  transform: translate3d(0, 0, 0);
  transition: transform 400ms cubic-bezier(0.22,1,0.36,1),
              opacity 300ms ease, left 400ms cubic-bezier(0.22,1,0.36,1);
  pointer-events: none;
  will-change: transform, left;
}
.nav-dot.visible { opacity: 1; }

/* ─── Header shrink on scroll ────────────────────────── */
header {
  transition: height 0.35s cubic-bezier(0.4,0,0.2,1),
              background 0.4s, border-color 0.4s, backdrop-filter 0.4s,
              padding 0.35s cubic-bezier(0.4,0,0.2,1);
}
header.scrolled { height: 48px; }

/* ─── Count-up readable numerals ─────────────────────── */
.counting, [data-count] {
  font-variant-numeric: tabular-nums;
}

/* ─── Learn-More arrow + underline hover ─────────────── */
.btn-enter,
a[href$=".html"] {
  position: relative;
}
.arrow-btn {
  position: relative;
  overflow: hidden;
}
.arrow-btn svg {
  transition: transform 250ms cubic-bezier(0.4,0,0.2,1);
}
.arrow-btn:hover svg {
  transform: translateX(6px);
}

/* ─── Back link (project detail) ─────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.back-link .back-arrow {
  display: inline-block;
  transition: transform 250ms cubic-bezier(0.4,0,0.2,1);
}
.back-link:hover .back-arrow {
  transform: translateX(-4px);
}

/* ─── Lazy image placeholder ─────────────────────────── */
img.lazy-blur {
  filter: blur(12px);
  opacity: 0.75;
  transition: filter 600ms ease, opacity 600ms ease;
}
img.lazy-blur.loaded {
  filter: blur(0);
  opacity: 1;
}

/* ─── Reduced motion ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .curtain { display: none !important; }
  .fade-up, .stagger-row > *, .split-line, .blur-in,
  .reveal-clip, .splitting .word .char, .splitting.word-mask .word,
  .splitting.char-rotate .char, .section-label span, .hero-scroll-line {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    clip-path: inset(0) !important;
    -webkit-clip-path: inset(0) !important;
    transition: none !important;
    animation: none !important;
  }
  .grain { opacity: 0 !important; }
}
