/* =========================================================
   POLISH — universal premium layer, applied to BOTH
   portfolio.html and project.html.
   - Custom cursor (desktop only)
   - Cinematic preloader (first visit per session)
   - Film-grain overlay (fixed, mix-blend-mode)
   - Hover spotlight on tiles + magnetic CTAs

   No hardcoded brand colors — uses --scarlet (portfolio) with
   fallback to --ruby (project). Local --pl-* vars contain the
   layout-level tunables.
   ========================================================= */

:root {
  /* Shared accent fallback chain — portfolio defines --scarlet,
     project defines --ruby. This var resolves to whichever exists. */
  --pl-accent:        var(--scarlet, var(--ruby, #9b1c20));
  --pl-accent-bright: var(--scarlet-bright, var(--ruby-light, var(--ruby, #9b1c20)));
  --pl-bg:            var(--bg, #0d0a08);
  --pl-fg:            var(--parchment, var(--text, #d4c8b8));
  --pl-fg-dim:        var(--parchment-dim, var(--text-faint, #6e6358));
  --pl-mono:          'JetBrains Mono', ui-monospace, monospace;
  /* Tunables */
  --pl-cursor-size:        28px;
  --pl-cursor-size-hover:  72px;
  --pl-cursor-dot:         5px;
  --pl-grain-opacity:      0.035;
  --pl-spot-size:          480px;
  --pl-spot-alpha:         0.14;
  --pl-preload-duration:   800ms;
}

/* =========================================================
   1. FILM GRAIN OVERLAY
   ========================================================= */
.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9990;
  opacity: var(--pl-grain-opacity);
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320' viewBox='0 0 320 320'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 320px 320px;
  background-repeat: repeat;
}
@media (prefers-reduced-motion: reduce) {
  .grain-overlay { display: none; }
}

/* =========================================================
   2. CUSTOM CURSOR — desktop only
   ========================================================= */
.cursor-dot, .cursor-ring {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 9999;
  border-radius: 50%;
  will-change: transform, width, height;
  transform: translate3d(calc(var(--cx, -100) * 1px), calc(var(--cy, -100) * 1px), 0)
             translate(-50%, -50%);
}
.cursor-dot {
  width: var(--pl-cursor-dot);
  height: var(--pl-cursor-dot);
  background: var(--pl-accent);
  z-index: 10000;
}
.cursor-ring {
  width: var(--pl-cursor-size);
  height: var(--pl-cursor-size);
  border: 1.5px solid var(--pl-accent);
  background: color-mix(in srgb, var(--pl-accent) 6%, transparent);
  transition: width 0.22s cubic-bezier(0.22, 1, 0.36, 1),
              height 0.22s cubic-bezier(0.22, 1, 0.36, 1),
              border-color 0.2s ease,
              background 0.2s ease;
  display: grid;
  place-items: center;
}
.cursor-ring__label {
  font-family: var(--pl-mono);
  font-size: 9px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--pl-fg);
  opacity: 0;
  transition: opacity 0.18s ease;
  white-space: nowrap;
}
/* Hover state — grow + show label */
.cursor-ring.is-hover {
  width: var(--pl-cursor-size-hover);
  height: var(--pl-cursor-size-hover);
  border-color: var(--pl-accent-bright);
  background: color-mix(in srgb, var(--pl-accent) 22%, transparent);
}
.cursor-ring.is-hover .cursor-ring__label { opacity: 1; }
/* Click compression */
.cursor-ring.is-down {
  width: calc(var(--pl-cursor-size) * 0.6);
  height: calc(var(--pl-cursor-size) * 0.6);
}
/* Hide native cursor when our custom one is active */
body.has-custom-cursor,
body.has-custom-cursor * { cursor: none !important; }
/* Don't hide on form fields — keep IBeam */
body.has-custom-cursor input,
body.has-custom-cursor textarea,
body.has-custom-cursor select { cursor: text !important; }
body.has-custom-cursor input + .cursor-dot,
body.has-custom-cursor textarea + .cursor-dot { /* no-op selector kept simple */ }
/* Disable entirely on touch / reduced-motion */
@media (pointer: coarse), (prefers-reduced-motion: reduce) {
  .cursor-dot, .cursor-ring { display: none !important; }
  body.has-custom-cursor,
  body.has-custom-cursor * { cursor: auto !important; }
}

/* =========================================================
   3. CINEMATIC PRELOADER
   ========================================================= */
.preloader {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: var(--pl-bg);
  display: grid;
  place-items: center;
  grid-template-rows: 1fr auto auto 1fr;
  gap: 0.6rem;
  font-family: var(--pl-mono);
  color: var(--pl-fg);
  overflow: hidden;
}
.preloader__count {
  grid-row: 2;
  display: flex;
  align-items: baseline;
  gap: 0.2em;
  font-size: clamp(64px, 14vw, 220px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.preloader__count .num   { color: var(--pl-accent-bright); font-variant-numeric: tabular-nums; }
.preloader__count .div   { color: var(--pl-fg-dim); font-size: 0.45em; }
.preloader__count .total { color: var(--pl-fg-dim); font-size: 0.45em; }
.preloader__label {
  grid-row: 3;
  font-size: 11px;
  letter-spacing: 5px;
  color: var(--pl-fg-dim);
  text-transform: uppercase;
}
.preloader__label::before { content: '· '; color: var(--pl-accent); }
.preloader__label::after  { content: ' ·'; color: var(--pl-accent); }
/* Scarlet wipe line at bottom that fills 0 → 100% in sync with counter */
.preloader__wipe {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  width: 100%;
  background: color-mix(in srgb, var(--pl-accent) 30%, transparent);
}
.preloader__wipe::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--pl-accent);
  transform-origin: left;
  transform: scaleX(calc(var(--pl-progress, 0) / 100));
  transition: transform 0.05s linear;
  box-shadow: 0 0 12px var(--pl-accent);
}
/* Closing — slides up like a curtain */
.preloader.is-done {
  transform: translateY(-100%);
  transition: transform 0.65s cubic-bezier(0.76, 0, 0.24, 1);
}
@media (prefers-reduced-motion: reduce) {
  .preloader.is-done { transform: none; opacity: 0; transition: opacity 0.2s; }
}

/* =========================================================
   4. HOVER SPOTLIGHT — for cards/tiles/projects
   Applied via .has-spotlight class (added by JS to candidates).
   ========================================================= */
.has-spotlight {
  position: relative;
  isolation: isolate;
}
.has-spotlight::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(
    var(--pl-spot-size) circle
    at calc(var(--sx, 50) * 1%) calc(var(--sy, 50) * 1%),
    color-mix(in srgb, var(--pl-accent) calc(var(--pl-spot-alpha) * 100%), transparent),
    transparent 60%
  );
  opacity: 0;
  transition: opacity 0.35s ease;
  mix-blend-mode: screen;
}
.has-spotlight:hover::after { opacity: 1; }
@media (prefers-reduced-motion: reduce), (pointer: coarse) {
  .has-spotlight::after { display: none; }
}

/* =========================================================
   6. MARQUEE MASSIF — XXL Playfair italic, slow infinite scroll.
   Brand layout-level text (no project content). Sits between hero
   and Featured section.
   ========================================================= */
.marquee-band {
  position: relative;
  height: clamp(170px, 24vh, 300px);
  overflow: hidden;
  /* Grid + place-items gives cleaner optical centering for italic glyphs
     than flex (which centers the box, not the visual mass). */
  display: grid;
  place-items: center start;
  background: var(--pl-bg);
  border-top: 1px solid color-mix(in srgb, var(--pl-accent) 20%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--pl-accent) 20%, transparent);
  /* radial bloom matching brand ambiance */
  background-image:
    radial-gradient(ellipse at 20% 50%, color-mix(in srgb, var(--pl-accent) 6%, transparent) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, color-mix(in srgb, var(--pl-accent) 8%, transparent) 0%, transparent 60%);
}
.marquee-band__track {
  font-family: 'Playfair Display', 'Times New Roman', serif;
  font-style: italic;
  font-weight: 900;
  /* Slightly smaller + positive letter-spacing eliminates the italic-stem
     collisions that read as "artifacts" at huge sizes. */
  font-size: clamp(68px, 11vw, 180px);
  letter-spacing: 0.005em;
  line-height: 0.95;
  white-space: nowrap;
  /* Solid muted fill — no text-stroke (stroke + transparent fill on huge italic
     Playfair produces aliasing artifacts on the curves and stems). */
  color: color-mix(in srgb, var(--pl-fg) 22%, transparent);
  animation: marquee-scroll 38s linear infinite;
  will-change: transform;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
.marquee-band__track .star   { color: var(--pl-accent); }
.marquee-band__track .accent { color: var(--pl-accent); font-style: italic; }
@keyframes marquee-scroll {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-25%, 0, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .marquee-band__track { animation: none; transform: translateX(-12.5%); }
}

/* =========================================================
   7. 3D TILT CARDS — perspective + rotateX/Y from mouse.
   Activated by JS adding `.tilt-card` class to interactive cards.
   ========================================================= */
.tilt-card {
  transform-style: preserve-3d;
  transform:
    perspective(1000px)
    rotateX(calc(var(--rx, 0) * 1deg))
    rotateY(calc(var(--ry, 0) * 1deg))
    translateZ(0);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.4s ease;
  will-change: transform;
}
.tilt-card:hover {
  box-shadow:
    0 25px 50px -12px color-mix(in srgb, var(--pl-accent) 35%, transparent),
    0 0 24px color-mix(in srgb, var(--pl-accent) 12%, transparent);
}
@media (pointer: coarse), (prefers-reduced-motion: reduce) {
  .tilt-card { transform: none; }
  .tilt-card:hover { box-shadow: none; }
}

/* =========================================================
   8. WEBGL SHADER BACKGROUND — fluid scarlet noise behind hero.
   Canvas injected by JS into .p-hero (portfolio.html only).
   ========================================================= */
#shader-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;           /* lighter so G + content read clearer; perf-friendlier */
  mix-blend-mode: screen;
}
.p-hero #particles { z-index: 1; }
.p-hero .p-hero__bg-glyph { z-index: 2; }
.p-hero .p-hero__inner { z-index: 3; position: relative; }

/* Boost the giant background "G" so it punches through the shader fluid noise.
   Overrides the muted default (opacity 0.08, scarlet-deep) from portfolio.css. */
.p-hero .p-hero__bg-glyph {
  color: #fff;
  opacity: 0.32;
  /* Soft scarlet halo for depth — keeps the "ember through smoke" feeling */
  text-shadow:
    0 0 60px  color-mix(in srgb, var(--pl-accent) 35%, transparent),
    0 0 140px color-mix(in srgb, var(--pl-accent) 22%, transparent),
    0 0 240px color-mix(in srgb, var(--pl-accent) 12%, transparent);
  mix-blend-mode: screen;
}

/* =========================================================
   9. ENHANCED PRELOADER — brand mark + corner brackets
   ========================================================= */
.preloader__brand {
  grid-row: 1;
  align-self: end;
  font-family: 'Playfair Display', 'Times New Roman', serif;
  font-style: italic;
  font-weight: 700;
  font-size: clamp(13px, 1.4vw, 20px);
  letter-spacing: 0.08em;
  color: var(--pl-fg-dim);
  margin-bottom: 1rem;
  opacity: 0;
  animation: pl-fade-in 0.5s ease 0.1s forwards;
}
.preloader__brand .sep { color: var(--pl-accent); margin: 0 0.5em; font-style: normal; }
/* Corner brackets — Wanted Poster style */
.preloader::before,
.preloader::after {
  content: '';
  position: absolute;
  width: 40px;
  height: 40px;
  pointer-events: none;
  opacity: 0;
  animation: pl-fade-in 0.5s ease 0.2s forwards;
}
.preloader::before {
  top: 30px;
  left: 30px;
  border-top: 1.5px solid var(--pl-accent);
  border-left: 1.5px solid var(--pl-accent);
}
.preloader::after {
  bottom: 30px;
  right: 30px;
  border-bottom: 1.5px solid var(--pl-accent);
  border-right: 1.5px solid var(--pl-accent);
}
@keyframes pl-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   10. HERO ENTRANCE CHOREOGRAPHY — portfolio.html
   Triggered by `body.choreo-go` (set by polish.js after preloader done).
   Cascades pretitle → title letters → subtitle → CTA → meta strips.
   ========================================================= */
.p-hero__inner [data-enter] {
  opacity: 0;
  transform: translateY(28px);
  filter: blur(8px);
  transition:
    opacity 1.1s cubic-bezier(0.16, 1, 0.3, 1),
    transform 1.1s cubic-bezier(0.16, 1, 0.3, 1),
    filter 1.1s cubic-bezier(0.16, 1, 0.3, 1);
  transition-delay: calc(var(--enter-i, 0) * 0.09s);
}
body.choreo-go .p-hero__inner [data-enter] {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}
/* Letter-split for hero title — applied via JS */
.p-hero__inner .hero-char {
  display: inline-block;
  opacity: 0;
  transform: translateY(48px) rotateX(-35deg);
  transform-origin: bottom center;
  transition:
    opacity 0.95s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.95s cubic-bezier(0.16, 1, 0.3, 1);
  transition-delay: calc(0.45s + var(--char-i, 0) * 0.04s);
}
.p-hero__inner .hero-char--space { width: 0.3em; }
body.choreo-go .p-hero__inner .hero-char {
  opacity: 1;
  transform: translateY(0) rotateX(0);
}
@media (prefers-reduced-motion: reduce) {
  .p-hero__inner [data-enter],
  .p-hero__inner .hero-char {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    transition: none;
  }
}

/* =========================================================
   5. MAGNETIC CTAs — universal for .btn elements on portfolio
   (project.html already has its own magnetic logic on .btn.primary/outline).
   Sets transform from JS-applied --mx/--my.
   ========================================================= */
.btn[data-magnetic] {
  transform: translate3d(calc(var(--mx, 0) * 1px), calc(var(--my, 0) * 1px), 0);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              background 0.2s, color 0.2s, border-color 0.2s;
  will-change: transform;
}
@media (pointer: coarse), (prefers-reduced-motion: reduce) {
  .btn[data-magnetic] { transform: none; }
}

/* =========================================================
   11. 3D MODEL VIEWER — <model-viewer> wrapper
   Lazy-loaded via polish.js. Section auto-hidden if no model3dUrl.
   ========================================================= */
.model3d-section {
  --m3-bg: color-mix(in srgb, var(--bg, #0a0608) 90%, var(--ruby, var(--scarlet, #7a1518)));
  --m3-corner-size: 32px;
  --m3-corner-thick: 1.5px;
}
.model3d-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background:
    radial-gradient(ellipse at 50% 50%, color-mix(in srgb, var(--ruby, var(--scarlet)) 12%, transparent) 0%, transparent 60%),
    var(--m3-bg);
  border: 1px solid color-mix(in srgb, var(--ruby, var(--scarlet)) 25%, transparent);
  overflow: hidden;
}
model-viewer#model3d-viewer {
  width: 100%;
  height: 100%;
  display: block;
  --poster-color: transparent;
  --progress-bar-color: var(--ruby, var(--scarlet, #7a1518));
  --progress-bar-height: 2px;
  --progress-mask: none;
}
.model3d-poster {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-color: var(--m3-bg);
  filter: blur(2px) brightness(0.7);
}
.model3d-ar-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 5;
  padding: 10px 16px;
  background: var(--ruby, var(--scarlet, #7a1518));
  color: var(--bg, var(--parchment, #fff));
  border: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.model3d-ar-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px color-mix(in srgb, var(--ruby, var(--scarlet)) 40%, transparent);
}
@media (pointer: fine) { .model3d-ar-btn { display: none; } }
.model3d-corners { position: absolute; inset: 0; pointer-events: none; }
.model3d-corners > span {
  position: absolute;
  width: var(--m3-corner-size);
  height: var(--m3-corner-size);
  border: 0 solid var(--ruby, var(--scarlet, #7a1518));
}
.model3d-corners > span:nth-child(1) { top: 14px; left: 14px;   border-top-width: var(--m3-corner-thick); border-left-width: var(--m3-corner-thick); }
.model3d-corners > span:nth-child(2) { top: 14px; right: 14px;  border-top-width: var(--m3-corner-thick); border-right-width: var(--m3-corner-thick); }
.model3d-corners > span:nth-child(3) { bottom: 14px; left: 14px; border-bottom-width: var(--m3-corner-thick); border-left-width: var(--m3-corner-thick); }
.model3d-corners > span:nth-child(4) { bottom: 14px; right: 14px;border-bottom-width: var(--m3-corner-thick); border-right-width: var(--m3-corner-thick); }
.model3d-hint {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 3px;
  color: color-mix(in srgb, var(--text-dim, var(--parchment-dim, #888)) 90%, transparent);
  text-transform: uppercase;
  pointer-events: none;
  z-index: 4;
  opacity: 0.7;
  transition: opacity 0.4s;
}
.model3d-hint .sep { color: var(--ruby, var(--scarlet, #7a1518)); }
.model3d-wrapper:hover .model3d-hint { opacity: 0; }
@media (max-width: 700px) {
  .model3d-wrapper { aspect-ratio: 4 / 5; }
  .model3d-hint { font-size: 8px; letter-spacing: 1.5px; gap: 6px; top: 12px; }
  .model3d-corners > span { width: 22px; height: 22px; }
}

/* =========================================================
   12. PAGE TRANSITION CURTAIN — full-screen scarlet wipe
   ========================================================= */
.page-curtain {
  position: fixed;
  inset: 0;
  z-index: 10002;
  background:
    radial-gradient(ellipse at center, color-mix(in srgb, var(--pl-accent) 90%, #000) 0%, var(--pl-accent) 100%);
  pointer-events: none;
  transform: translateY(100%);
  will-change: transform;
}
.page-curtain__mark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Playfair Display', 'Times New Roman', serif;
  font-style: italic;
  font-weight: 900;
  font-size: clamp(60px, 12vw, 180px);
  color: color-mix(in srgb, var(--pl-fg) 90%, transparent);
  letter-spacing: -0.02em;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
}
.page-curtain.is-covering {
  transform: translateY(0);
  transition: transform 0.45s cubic-bezier(0.76, 0, 0.24, 1);
}
.page-curtain.is-covering .page-curtain__mark {
  opacity: 1;
  transition: opacity 0.3s ease 0.15s;
}
.page-curtain.is-revealing {
  transform: translateY(0);
  animation: pageCurtainReveal 0.6s cubic-bezier(0.76, 0, 0.24, 1) forwards;
}
.page-curtain.is-revealing .page-curtain__mark {
  opacity: 1;
  animation: pageCurtainMark 0.45s ease forwards;
}
@keyframes pageCurtainReveal { to { transform: translateY(-100%); } }
@keyframes pageCurtainMark { to { opacity: 0; transform: translate(-50%, -150%); } }
@media (prefers-reduced-motion: reduce) {
  .page-curtain.is-covering,
  .page-curtain.is-revealing { transition: opacity 0.2s; transform: none; opacity: 1; }
  .page-curtain.is-revealing { opacity: 0; }
}

/* =========================================================
   13. CURSOR SCOPE MODE — gun scope reticle on weapon imagery
   ========================================================= */
.cursor-ring.is-scope {
  width: 110px;
  height: 110px;
  border-width: 1px;
  border-color: var(--pl-accent);
  background: transparent;
}
.cursor-ring.is-scope::before,
.cursor-ring.is-scope::after { content: ''; position: absolute; }
.cursor-ring.is-scope::before {
  top: 8%;
  bottom: 8%;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom,
    var(--pl-accent) 0%, var(--pl-accent) 32%,
    transparent 40%, transparent 60%,
    var(--pl-accent) 68%, var(--pl-accent) 100%);
}
.cursor-ring.is-scope::after {
  left: 8%;
  right: 8%;
  top: 50%;
  height: 1px;
  transform: translateY(-50%);
  background: linear-gradient(to right,
    var(--pl-accent) 0%, var(--pl-accent) 32%,
    transparent 40%, transparent 60%,
    var(--pl-accent) 68%, var(--pl-accent) 100%);
}
.cursor-ring.is-scope .cursor-ring__label { display: none; }

/* =========================================================
   24. PALETTE SWATCH STAGGER REVEAL (project page)
   Pure CSS — triggered by the existing .is-visible class set on
   .palette-section by project-render.js IntersectionObserver.
   Fast (0.5s per swatch with 60ms stagger) so the palette feels
   alive but doesn't keep the user waiting.
   ========================================================= */
.palette-section .palette-grid .swatch {
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.palette-section.is-visible .palette-grid .swatch {
  opacity: 1;
  transform: translateY(0);
}
.palette-section.is-visible .swatch:nth-child(1) { transition-delay: 0.05s; }
.palette-section.is-visible .swatch:nth-child(2) { transition-delay: 0.11s; }
.palette-section.is-visible .swatch:nth-child(3) { transition-delay: 0.17s; }
.palette-section.is-visible .swatch:nth-child(4) { transition-delay: 0.23s; }
.palette-section.is-visible .swatch:nth-child(5) { transition-delay: 0.29s; }
.palette-section.is-visible .swatch:nth-child(6) { transition-delay: 0.35s; }
.palette-section.is-visible .swatch:nth-child(7) { transition-delay: 0.41s; }
.palette-section.is-visible .swatch:nth-child(8) { transition-delay: 0.47s; }
@media (prefers-reduced-motion: reduce) {
  .palette-section .palette-grid .swatch {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* =========================================================
   21. VARIABLE FONT WEIGHT MORPH ON SCROLL
   H1 hero starts thin (wght 400) and morphs to black (900) as the user
   scrolls past the hero. Signature micro-detail — JS sets --hero-wght.
   ========================================================= */
.p-hero__inner h1,
.p-hero__inner .h-hero {
  font-weight: normal !important; /* let font-variation-settings drive */
  font-variation-settings: "wght" var(--hero-wght, 420);
  transition: font-variation-settings 0.18s linear;
}
@media (prefers-reduced-motion: reduce) {
  .p-hero__inner h1,
  .p-hero__inner .h-hero { font-variation-settings: "wght" 900; }
}

/* =========================================================
   22. KONAMI "MODE DÉMON" — ↑↑↓↓←→←→ B A → 22s of chaos
   Hue-shifted red, intensified grain, marquee gone wild, page jitter.
   Easter egg, viral potential, fades back to normal automatically.
   ========================================================= */
body.demon-mode {
  filter: contrast(1.18) saturate(1.45) hue-rotate(-5deg);
  animation: demon-jitter 0.12s infinite;
}
body.demon-mode .grain-overlay { opacity: 0.18 !important; mix-blend-mode: hard-light !important; }
body.demon-mode .marquee-band__track { animation-duration: 8s !important; }
body.demon-mode #shader-bg { opacity: 0.95 !important; }
body.demon-mode .cursor-ring { border-color: #ff0033; box-shadow: 0 0 28px rgba(255, 0, 51, 0.6); }
body.demon-mode .cursor-dot { background: #ff0033; }
body.demon-mode .scroll-progress { background: linear-gradient(90deg, #ff0033, #800019); box-shadow: 0 0 14px #ff0033; }
body.demon-mode::after {
  content: '妖怪 · MODE DÉMON ACTIVÉ · 妖怪';
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10003;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 4px;
  color: #ff0033;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px 18px;
  border: 1px solid #ff0033;
  pointer-events: none;
  animation: demon-blink 0.5s infinite;
}
@keyframes demon-jitter {
  0%, 100% { transform: translate3d(0, 0, 0); }
  25%      { transform: translate3d(1px, -1px, 0); }
  75%      { transform: translate3d(-1px, 1px, 0); }
}
@keyframes demon-blink {
  0%, 60%, 100% { opacity: 1; }
  70%           { opacity: 0.2; }
}
@media (prefers-reduced-motion: reduce) {
  body.demon-mode { animation: none; }
}

/* =========================================================
   23. BRAND CREST SCROLL MILESTONE — at ~50% scroll, a SVG
   crest (X + circle + diamond) draws itself in over 1.4s,
   wordmark fades in, full thing dismisses after 1.8s. Once per session.
   ========================================================= */
.brand-crest {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center,
    color-mix(in srgb, var(--pl-bg) 70%, transparent) 0%,
    transparent 70%);
  transition: opacity 0.55s cubic-bezier(0.76, 0, 0.24, 1);
}
.brand-crest.is-on  { opacity: 1; }
.brand-crest.is-off { opacity: 0; }
.brand-crest__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}
.brand-crest__svg {
  width: clamp(120px, 18vw, 240px);
  height: clamp(120px, 18vw, 240px);
  fill: none;
  stroke: var(--pl-accent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 18px color-mix(in srgb, var(--pl-accent) 70%, transparent));
}
.brand-crest__svg line,
.brand-crest__svg circle,
.brand-crest__svg polygon {
  stroke-dasharray: 700;
  stroke-dashoffset: 700;
  animation: brand-crest-draw 1.3s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}
.brand-crest__svg circle  { animation-delay: 0.15s; }
.brand-crest__svg polygon { animation-delay: 0.35s; stroke: color-mix(in srgb, var(--pl-accent) 75%, #fff); }
@keyframes brand-crest-draw { to { stroke-dashoffset: 0; } }
.brand-crest__wordmark {
  font-family: 'Playfair Display', 'Times New Roman', serif;
  font-style: italic;
  font-weight: 700;
  font-size: clamp(13px, 1.5vw, 19px);
  letter-spacing: 0.22em;
  color: var(--pl-fg);
  opacity: 0;
  animation: brand-crest-text 0.6s ease 0.85s forwards;
}
.brand-crest__wordmark .sep { color: var(--pl-accent); margin: 0 0.4em; font-style: normal; }
@keyframes brand-crest-text { to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .brand-crest__svg line,
  .brand-crest__svg circle,
  .brand-crest__svg polygon { stroke-dasharray: none; stroke-dashoffset: 0; animation: none; }
}

/* =========================================================
   14. CLICK RIPPLE — scarlet wave from pointer-down point
   ========================================================= */
.click-ripple {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--pl-accent);
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  opacity: 0.45;
  z-index: 99;
  animation: click-ripple-grow 0.72s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  will-change: transform, opacity;
}
@keyframes click-ripple-grow {
  to { transform: translate(-50%, -50%) scale(60); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .click-ripple { display: none; }
}

/* =========================================================
   20. CURSOR-DRIVEN REVEAL MASK
   Two stacked images: the alt one is clipped to a circle that
   follows the cursor (CSS vars --mx/--my in %). JS in polish.js
   updates the vars on mousemove. Hidden on touch / reduced-motion.
   ========================================================= */
.reveal-mask {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
  --rm-radius: 90px;
  --mx: 50%;
  --my: 50%;
}
.reveal-mask__main,
.reveal-mask__alt {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.reveal-mask__main { position: relative; z-index: 1; }
.reveal-mask__alt {
  position: absolute;
  inset: 0;
  z-index: 2;
  clip-path: circle(0 at var(--mx) var(--my));
  -webkit-clip-path: circle(0 at var(--mx) var(--my));
  transition: clip-path 0.22s cubic-bezier(0.22, 1, 0.36, 1),
              -webkit-clip-path 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}
.reveal-mask.is-active .reveal-mask__alt {
  clip-path: circle(var(--rm-radius) at var(--mx) var(--my));
  -webkit-clip-path: circle(var(--rm-radius) at var(--mx) var(--my));
}
/* Soft scarlet ring trace at the mask boundary for branded feel */
.reveal-mask::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(circle var(--rm-radius) at var(--mx) var(--my),
    transparent calc(100% - 4px),
    color-mix(in srgb, var(--scarlet, var(--ruby, var(--pl-accent))) 65%, transparent) calc(100% - 1px),
    transparent 100%);
  opacity: 0;
  transition: opacity 0.25s ease;
  mix-blend-mode: screen;
}
.reveal-mask.is-active::after { opacity: 1; }
/* "REVEAL · ATELIER" hint that flashes on first hover */
.reveal-mask__hint {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 4;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--scarlet, var(--ruby, var(--pl-accent)));
  background: color-mix(in srgb, var(--bg, #0d0a08) 80%, transparent);
  padding: 6px 10px;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.reveal-mask:hover .reveal-mask__hint {
  opacity: 1;
  transform: translateY(0);
}
@media (pointer: coarse), (prefers-reduced-motion: reduce) {
  .reveal-mask__alt,
  .reveal-mask::after,
  .reveal-mask__hint { display: none !important; }
}

/* =========================================================
   19. STICKY SCROLL NARRATIVE (Featured section variant)
   Apple/Stripe-style 2-col: pinned visual on the left, scrolling
   text beats on the right. Visual swaps per beat via JS.
   Active when f.narrativeBeats[] is set in Supabase.
   ========================================================= */
.feat--narrative {
  --fn-gap:           clamp(2rem, 5vw, 6rem);
  --fn-visual-top:    12vh;
  --fn-visual-height: 74vh;
  --fn-beat-spacing:  clamp(30vh, 50vh, 65vh);
  display: block;
}
.feat-narrative__intro {
  max-width: 56ch;
  margin: 0 0 clamp(2rem, 5vw, 4rem);
}
.feat-narrative__title {
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-style: italic;
  font-size: clamp(2rem, 4.5vw, 3.8rem);
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--parchment-light, #fff);
  margin: 0.6rem 0;
}
.feat-narrative__lede {
  font-size: clamp(15px, 1.4vw, 18px);
  line-height: 1.65;
  color: var(--parchment, #d4c8b8);
  max-width: 56ch;
}
.feat-narrative__split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: var(--fn-gap);
  align-items: start;
  position: relative;
}
.feat-narrative__visual-wrap {
  position: sticky;
  top: var(--fn-visual-top);
  height: var(--fn-visual-height);
  align-self: start;
}
.feat-narrative__visual {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg-card, #1a1512);
  border: 1px solid var(--scarlet-border, rgba(122, 21, 24, 0.35));
}
.feat-narrative__visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.55s ease, transform 0.9s cubic-bezier(0.22, 1, 0.36, 1);
  transform: scale(1);
}
.feat-narrative__visual img.is-swapping { opacity: 0.4; transform: scale(1.04); }
.feat-narrative__placeholder {
  width: 100%; height: 100%;
  background:
    radial-gradient(ellipse at 30% 30%, color-mix(in srgb, var(--scarlet, var(--ruby)) 16%, transparent), transparent 60%),
    var(--bg-card, #1a1512);
}
.feat-narrative__beats {
  display: flex;
  flex-direction: column;
  padding: 0 0 30vh;
}
.feat-beat {
  min-height: var(--fn-beat-spacing);
  padding: 8vh 0;
  opacity: 0.32;
  transform: translateY(8px);
  transition: opacity 0.7s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}
.feat-beat.is-active {
  opacity: 1;
  transform: translateY(0);
}
.feat-beat__kicker {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--scarlet-bright, var(--ruby, #9b1c20));
  text-transform: uppercase;
  padding-left: 18px;
  position: relative;
}
.feat-beat__kicker::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 12px;
  height: 1px;
  background: var(--scarlet-bright, var(--ruby));
  transform: translateY(-50%);
}
.feat-beat__heading {
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-size: clamp(1.8rem, 4.5vw, 3.6rem);
  line-height: 1.05;
  letter-spacing: -0.015em;
  color: var(--parchment-light, #fff);
  margin: 0.6rem 0 1rem;
}
.feat-beat__heading .accent {
  color: var(--scarlet-bright, var(--ruby));
  font-style: italic;
}
.feat-beat__body {
  font-size: clamp(15px, 1.35vw, 17px);
  line-height: 1.7;
  color: var(--parchment-dark, #a89880);
  max-width: 52ch;
  margin: 0;
}
.feat-narrative__outro {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: clamp(3rem, 6vw, 5rem);
}
@media (max-width: 900px) {
  .feat-narrative__split {
    grid-template-columns: 1fr;
  }
  .feat-narrative__visual-wrap {
    position: relative;
    top: 0;
    height: 60vh;
    margin-bottom: 2rem;
  }
  .feat-beat {
    min-height: auto;
    padding: 4vh 0;
    /* On mobile we don't pin the visual, so don't fade the beats */
    opacity: 1;
    transform: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .feat-beat { opacity: 1; transform: none; transition: none; }
  .feat-narrative__visual img { transition: none; }
}

/* =========================================================
   16. SCROLL PROGRESS BAR — fixed top, scarlet, scroll-driven.
   Injected by polish.js if not already present. Uses native
   scroll-driven animations on modern browsers, JS fallback else.
   ========================================================= */
.scroll-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg,
    var(--pl-accent),
    color-mix(in srgb, var(--pl-accent) 55%, #000));
  transform-origin: 0 0;
  transform: scaleX(0);
  z-index: 10001;
  pointer-events: none;
  box-shadow: 0 0 10px color-mix(in srgb, var(--pl-accent) 60%, transparent);
  will-change: transform;
}
@supports (animation-timeline: scroll()) {
  .scroll-progress {
    animation: pl-scrollgrow linear;
    animation-timeline: scroll(root);
  }
  @keyframes pl-scrollgrow { to { transform: scaleX(1); } }
}

/* =========================================================
   15. MASK REVEAL — cinema-grade entry animation on cards
   Triggered by IntersectionObserver (.mask-revealed class).
   Clip-path inset reveals the element from bottom upward,
   layered with a fade so it doesn't pop in cold.
   ========================================================= */
.mask-reveal {
  clip-path: inset(100% 0 0 0);
  -webkit-clip-path: inset(100% 0 0 0);
  opacity: 0;
  transition:
    clip-path 1.1s cubic-bezier(0.76, 0, 0.24, 1),
    -webkit-clip-path 1.1s cubic-bezier(0.76, 0, 0.24, 1),
    opacity 0.7s ease 0.2s;
  will-change: clip-path, opacity;
}
.mask-reveal.mask-revealed {
  clip-path: inset(0);
  -webkit-clip-path: inset(0);
  opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  .mask-reveal,
  .mask-reveal.mask-revealed {
    clip-path: none;
    -webkit-clip-path: none;
    opacity: 1;
    transition: none;
  }
}
