/* The site-wide effects layer (docs/FX.md). Loaded after site.css by
   src/components/Fx.astro, only while site_settings "fx.off" is not "1".
   <html data-fx> is calm | normal | loud (the header switch; reduced motion starts calm).
   Rules for normal and loud sit under :where(html:not([data-fx="calm"])) so they add no
   specificity: anything more specific in site.css (a ghost button, a playing card) wins. */

@property --fx-spin {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@property --fx-pan {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

@keyframes fx-spin { to { --fx-spin: 360deg; } }
@keyframes fx-pan { from { --fx-pan: 0%; } to { --fx-pan: 100%; } }
@keyframes fx-drift { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }
@keyframes fx-pop { from { opacity: 0; translate: 0 -6px; scale: 0.96; } to { opacity: 1; translate: 0 0; scale: 1; } }

/* ---- The switch (all modes) ---- */
.fx-switch { position: relative; display: inline-flex; }
.fx-switch-btn {
  anchor-name: --fx-switch;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.fx-switch-btn:hover { background: var(--wash); border-color: var(--border-hover); }
.fx-meter { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.fx-meter i { display: block; width: 3px; border-radius: 2px; background: var(--metal-bright); opacity: 0.3; }
.fx-meter i:nth-child(1) { height: 5px; }
.fx-meter i:nth-child(2) { height: 9px; }
.fx-meter i:nth-child(3) { height: 14px; }
.fx-switch-btn[data-mode="calm"] .fx-meter i:nth-child(1),
.fx-switch-btn[data-mode="normal"] .fx-meter i:nth-child(-n + 2),
.fx-switch-btn[data-mode="loud"] .fx-meter i {
  opacity: 1;
  background: linear-gradient(var(--accent2), var(--accent1));
}
@keyframes fx-meter { 0%, 100% { scale: 1 1; } 50% { scale: 1 0.45; } }
.fx-switch-btn[data-mode="loud"] .fx-meter i { transform-origin: bottom; animation: fx-meter 0.7s ease-in-out infinite; }
.fx-switch-btn[data-mode="loud"] .fx-meter i:nth-child(2) { animation-delay: -0.23s; }
.fx-switch-btn[data-mode="loud"] .fx-meter i:nth-child(3) { animation-delay: -0.46s; }
@media (max-width: 719px) {
  .fx-switch-label { display: none; }
  .fx-switch-btn { padding: 0 0.75rem; }
}
.fx-menu {
  position: fixed;
  inset: auto;
  top: calc(var(--header) + 0.4rem);
  right: 1rem;
  width: min(19rem, calc(100vw - 2rem));
  margin: 0;
  padding: 0.55rem;
  border-radius: 1.1rem;
  border: 1px solid var(--metal-edge);
  background: rgba(10, 10, 20, 0.94);
  color: var(--text);
  box-shadow: var(--shadow), 0 0 40px -10px var(--accent1);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  z-index: 60;
}
@supports (position-anchor: --fx-switch) {
  .fx-menu {
    position-anchor: --fx-switch;
    top: calc(anchor(bottom) + 0.5rem);
    right: anchor(right);
    position-try-fallbacks: flip-inline;
  }
}
.fx-menu[hidden] { display: none; }
.fx-menu:popover-open { animation: fx-pop 0.22s ease both; }
.fx-menu-title { margin: 0.25rem 0.75rem 0.45rem; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.fx-option {
  display: grid;
  gap: 0.1rem;
  width: 100%;
  margin: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 0.8rem;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.fx-option + .fx-option { margin-top: 0.2rem; }
.fx-option:hover { background: var(--wash); }
.fx-option[aria-checked="true"] { border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 12%, transparent); }
.fx-option-name { font-weight: 700; }
.fx-option-note { font-size: 0.8rem; color: var(--muted); }

/* ---- Calm: still what site.css keeps moving ---- */
html[data-fx="calm"] .display,
html[data-fx="calm"] .aperture,
html[data-fx="calm"] .section-title-glow,
html[data-fx="calm"] .section-title-glow::after,
html[data-fx="calm"] .section-head-panel::before,
html[data-fx="calm"] .shop-cta,
html[data-fx="calm"] .shop-cta-chip { animation: none !important; }
html[data-fx="calm"] .section-head-panel::before { opacity: 0; }
html[data-fx="calm"] .cursor { display: none !important; }

/* ---- Page-to-page transitions (cross-document View Transitions) ---- */
@view-transition {
  navigation: auto;
  types: fx-nav;
}
html[data-fx="calm"]::view-transition-group(*),
html[data-fx="calm"]::view-transition-old(*),
html[data-fx="calm"]::view-transition-new(*) { animation-duration: 0.12s; }
html:not([data-fx="calm"]):active-view-transition-type(fx-nav)::view-transition-old(root) {
  animation: fx-leave 0.75s cubic-bezier(0.7, 0, 0.3, 1) both;
}
html:not([data-fx="calm"]):active-view-transition-type(fx-nav)::view-transition-new(root) {
  animation: fx-iris 0.85s cubic-bezier(0.7, 0, 0.3, 1) both;
}
html:not([data-fx="calm"])::view-transition-group(fx-hero) {
  animation-duration: 0.8s;
  animation-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
}
@keyframes fx-leave {
  to { opacity: 0; scale: 0.92; filter: blur(10px) saturate(1.8) hue-rotate(50deg); }
}
@keyframes fx-iris {
  from { clip-path: circle(0% at var(--fx-x, 50%) var(--fx-y, 40%)); filter: brightness(2.4) contrast(1.4) saturate(0.4); }
  55% { filter: brightness(1.35) contrast(1.1) saturate(1); }
  to { clip-path: circle(150% at var(--fx-x, 50%) var(--fx-y, 40%)); filter: none; }
}

/* ---- Normal and loud ---- */

/* The liquid-chrome background canvas (assets/js/fx/chrome-bg.js), between site.css's
   background picture (body::before) and its colour scrims (body::after). */
.fx-chrome-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
  transition: opacity 1.4s ease;
}
.fx-chrome-bg.is-on { opacity: 0.6; }
html[data-fx="loud"] .fx-chrome-bg.is-on { opacity: 0.85; }

:where(html:not([data-fx="calm"])) {
  scrollbar-color: var(--metal-bright) var(--bg);
}

/* The header: a chrome line that runs along its bottom edge, and a spinning chrome monogram. */
:where(html:not([data-fx="calm"])) .topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent1), #fff, var(--accent2), transparent, var(--accent3), #fff, transparent) 0 0 / 200% 100%;
  animation: fx-drift 6s linear infinite alternate;
  pointer-events: none;
}
:where(html:not([data-fx="calm"])) .monogram {
  border-color: transparent;
  background:
    radial-gradient(circle, var(--bg) 0 64%, transparent 66%),
    conic-gradient(from var(--fx-spin), #fff, var(--metal), var(--accent1), #fff, var(--accent2), var(--metal-deep), #fff);
  color: #fff;
  box-shadow: 0 0 14px -2px var(--accent1);
  animation: fx-spin 6s linear infinite;
}

/* The scroll bar along the top: chrome with a glow. */
:where(html:not([data-fx="calm"])) .scroll-progress {
  height: 3px;
  background: linear-gradient(90deg, var(--accent1), #fff, var(--accent2), #fff, var(--accent3));
  box-shadow: 0 0 10px var(--accent2), 0 0 22px var(--accent1);
}

/* Liquid-chrome titles: bright steel with a dark reflection band and the section's colour,
   on the angle site.css already sweeps (--title-angle) and the hero's --sheen. */
:where(html:not([data-fx="calm"])) .section-head .char,
:where(html:not([data-fx="calm"])) .section-head h2 {
  background-image: linear-gradient(
    var(--title-angle),
    #ffffff 0%,
    #e8eef4 14%,
    #6b7889 30%,
    #ffffff 44%,
    color-mix(in srgb, var(--section-accent) 62%, #ffffff) 56%,
    #8d9aab 70%,
    #ffffff 84%,
    #cfd8e2 100%
  );
}
:where(html:not([data-fx="calm"])) .display {
  background-image: linear-gradient(var(--sheen), #ffffff, #dfe6ee 12%, #5b6876 26%, #ffffff 38%, var(--grad-lilac) 52%, #8d9aab 66%, #ffffff 78%, var(--grad-mint) 92%);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
}
:where(html:not([data-fx="calm"])) .writing-title {
  background: linear-gradient(110deg, #ffffff 0%, #cfd8e2 18%, #6b7889 32%, #ffffff 46%, var(--grad-lilac) 60%, #9aa7b6 74%, #ffffff 88%) var(--fx-pan) 50% / 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: fx-pan 7s ease-in-out infinite alternate;
}

/* Section dividers: the glowing line along each section's top runs like molten metal. */
:where(html:not([data-fx="calm"])) .section::before {
  background: linear-gradient(90deg, transparent, var(--section-accent) 12%, #fff 25%, var(--section-accent) 38%, transparent 50%, var(--section-accent) 62%, #fff 75%, var(--section-accent) 88%, transparent) 0 0 / 200% 100%;
  animation: fx-drift 5s linear infinite;
}

/* Cards: an iridescent edge that turns slowly and lights up under the cursor (::after),
   a soft light that follows the cursor across the card (::before), and a scroll-in. */
:where(html:not([data-fx="calm"])) :where(.card, .bundle-item) { position: relative; }
:where(html:not([data-fx="calm"])) :where(.card, .bundle-item)::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(380px circle at var(--lx, 50%) var(--ly, -60%), color-mix(in srgb, var(--section-accent, var(--accent2)) 26%, transparent), transparent 55%);
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}
:where(html:not([data-fx="calm"])) :where(.card, .bundle-item).fx-lit::before { opacity: 1; }
:where(html:not([data-fx="calm"])) .card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(from var(--fx-spin), transparent 0deg, var(--accent1) 40deg, #fff 70deg, var(--accent2) 100deg, transparent 150deg, transparent 210deg, var(--accent3) 250deg, #fff 280deg, var(--section-accent, var(--accent1)) 310deg, transparent 360deg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0.6;
  pointer-events: none;
  /* Turns only under the pointer: dozens of cards repainting their edge every frame
     cost ~15 fps on scroll (speed pass, 2026-11-17). At rest the edge holds its angle. */
  animation: fx-spin 10s linear infinite paused;
  transition: opacity 0.35s ease, padding 0.35s ease;
}
:where(html:not([data-fx="calm"])) .card:is(:hover, .fx-lit, :focus-within)::after { opacity: 1; padding: 1.5px; animation-play-state: running; }
@keyframes fx-card-in {
  from { scale: 0.88; filter: brightness(1.9) opacity(0); }
  to { scale: 1; filter: none; }
}
@supports (animation-timeline: view()) {
  :where(html:not([data-fx="calm"])) .card {
    animation: fx-card-in linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 75%;
  }
}

/* Section panels: the cursor light, layered over site.css's own background. */
:where(html:not([data-fx="calm"])) .section-head-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: radial-gradient(320px circle at var(--lx, 50%) var(--ly, -80%), color-mix(in srgb, var(--section-accent) 30%, transparent), transparent 60%);
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}
:where(html:not([data-fx="calm"])) .section-head-panel.fx-lit::after { opacity: 1; }

/* Buttons: a gradient that drifts, a glint that follows the cursor, a lift. */
:where(html:not([data-fx="calm"])) .button {
  background:
    radial-gradient(90px circle at var(--lx, -50%) var(--ly, 50%), rgba(255, 255, 255, 0.7), transparent 70%),
    linear-gradient(90deg, var(--accent1), var(--accent2), var(--accent3), var(--accent1));
  background-size: 100% 100%, 300% 100%;
  animation: fx-drift 8s ease-in-out infinite alternate;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 10px 30px -12px var(--accent1);
  transition: box-shadow 0.25s ease, translate 0.25s ease;
}
:where(html:not([data-fx="calm"])) .button:hover {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4), 0 14px 40px -10px var(--accent2), 0 0 26px -6px var(--accent1);
}
:where(html:not([data-fx="calm"])) :where(.menu-btn, .icon-btn, .fx-switch-btn).fx-lit {
  background:
    radial-gradient(70px circle at var(--lx, 50%) var(--ly, 50%), rgba(255, 255, 255, 0.22), transparent 70%),
    var(--glass);
}

/* ---- Turn it up (loud) ---- */

/* The page throbs with the playing song's bass (--fx-bass, from assets/js/spectrum.js). */
html[data-fx="loud"] body::after { opacity: calc(1 - var(--fx-bass, 0) * 0.45); }
html[data-fx="loud"] .section-title-glow { scale: calc(1 + var(--fx-bass, 0) * 0.05); transform-origin: left center; }
html[data-fx="loud"] .card::after { opacity: calc(0.55 + var(--fx-bass, 0) * 0.45); animation-duration: 4s; }
html[data-fx="loud"] .section::before { animation-duration: 1.6s; }

/* Glitching titles. */
@keyframes fx-glitch {
  0% { translate: 0 0; clip-path: inset(0 0 0 0); }
  15% { translate: -4px 1px; clip-path: inset(8% 0 58% 0); filter: drop-shadow(-3px 0 #ff2a6d) drop-shadow(3px 0 #05d9e8); }
  30% { translate: 4px -1px; clip-path: inset(62% 0 6% 0); }
  45% { translate: -2px 0; clip-path: inset(28% 0 34% 0); filter: drop-shadow(3px 0 #ff2a6d) drop-shadow(-3px 0 #05d9e8) hue-rotate(80deg); }
  60% { translate: 3px 1px; clip-path: inset(0 0 78% 0); }
  75% { translate: -1px -1px; clip-path: inset(44% 0 18% 0); }
  100% { translate: 0 0; clip-path: inset(0 0 0 0); filter: none; }
}
html[data-fx="loud"] :is(.section-head h2, .writing-title, .card h3, .brand-name):hover { animation: fx-glitch 0.45s steps(1, end) 2; }
html[data-fx="loud"] .display:hover { animation: fx-glitch 0.45s steps(1, end) 2, sheen 16s linear infinite; }

/* The molten cursor and the confetti (assets/js/fx/overdrive.js). */
html[data-fx="loud"] .cursor { display: none !important; }
.fx-molten {
  position: fixed;
  inset: 0;
  z-index: 95;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.fx-molten.is-on { opacity: 1; }
.fx-confetti {
  position: fixed;
  inset: 0;
  z-index: 96;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.fx-melt-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
html.fx-melting main,
html.fx-melting .topbar,
html.fx-melting .site-foot { filter: url(#fx-melt); }

/* Flingable cards. */
html[data-fx="loud"] .card { cursor: grab; }
html[data-fx="loud"] .card.fx-flung {
  z-index: 20;
  cursor: grabbing;
  user-select: none;
  transition: none !important;
  box-shadow: 0 40px 80px -24px #000, 0 0 46px -6px var(--accent1);
}

/* ---- Accessibility: a device that asks for more contrast (all modes) ----
   Solid white titles instead of chrome gradients, no moving background, no cursor or
   confetti layers, no shimmering card edges. The layout and the switch stay. */
@media (prefers-contrast: more) {
  .fx-chrome-bg,
  .fx-molten,
  .fx-confetti,
  .fx-pool { display: none !important; }
  .card::after { display: none !important; }
  .section-head .char,
  .section-head h2,
  .display,
  .writing-title {
    background: none !important;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    text-shadow: none !important;
  }
  .hero :is(.kicker, .tagline, .lede),
  .writing-body > p,
  .writing-cards .writing-open > p {
    -webkit-mask-image: none !important;
    mask-image: none !important;
  }
}

/* ---- Scrolling first (speed pass 2) ----
   While the page scrolls (html.fx-scrolling, set by assets/js/fx/fx.js) the endless
   decorative animations hold still; scroll-driven ones keep going. Measured on the live
   site: the title glow and angle sweep alone took Normal from 60 fps down to the 40s. */
html.fx-scrolling :is(.section-title-glow, .monogram, .display, .button, .writing-title, .private-tool .card-media img, .shop-cta, .shop-cta-chip),
html.fx-scrolling .section-title-glow::after,
html.fx-scrolling .section-head-panel::before,
html.fx-scrolling .card::after,
html.fx-scrolling .section::before,
html.fx-scrolling .topbar::after {
  animation-play-state: paused !important;
}
