/*
Theme Name: frāctus formō
Theme URI: https://fractusformo.co.uk
Author: ook
Author URI: https://fractusformo.co.uk
Description: Block theme for frāctus formō. A dark exhibition room for lit objects, with two product layouts — one for pieces that have a 3D model and get a scroll-scrubbed assembly, one for photographed objects that do not.
Requires at least: 6.6
Tested up to: 7.0
Requires PHP: 8.0
Version: 0.5.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: fractus-formo
Tags: full-site-editing, block-patterns, e-commerce, one-column, custom-colors
*/

/* Everything expressible as a design token lives in theme.json and arrives as
   --wp--preset--*. What is left here is the handful of things the editor has no
   UI for: the edge feather, the rotating gobo, the pinned stages, and grain. */

/* ── Grain and gobo, injected at wp_body_open ───────────────────────────── */
.fx-grain {
  position: fixed; inset: 0; z-index: 60; pointer-events: none;
  opacity: 0.045; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* One Cycles render of what frāctus I actually throws, turned slowly. Brand
   level, not product level — it lights the jar pages too. Pure transform, no
   filters, so the compositor keeps it on its own layer. */
.fx-gobo {
  position: fixed; z-index: 0; top: 50%; left: 50%;
  width: 132vmax; height: 132vmax; margin: -66vmax 0 0 -66vmax;
  background: var(--fx-gobo-image) center / contain no-repeat;
  mix-blend-mode: screen; opacity: 0.14;
  animation: fx-turn 150s linear infinite;
  -webkit-mask-image: radial-gradient(circle at 50% 50%, #000 0 14%, transparent 54%);
          mask-image: radial-gradient(circle at 50% 50%, #000 0 14%, transparent 54%);
  will-change: transform; pointer-events: none;
}
.fx-gobo.is-slow { animation-duration: 240s; opacity: 0.11; }
@keyframes fx-turn { to { transform: rotate(360deg); } }

/* The gobo is fixed behind everything, so sections with their own background
   simply cover it — which is what keeps it out of the pinned stages and the
   daylight band, and leaves it visible in the hero and the buy band. */
.wp-site-blocks { position: relative; z-index: 1; }

/* ── Block style: Feathered ─────────────────────────────────────────────
   Registered against core/image. Every product shot is a dark studio render on
   a dark page; without this you see the rectangle it was cropped to. */
.wp-block-image.is-style-feathered img,
.fx-feather {
  -webkit-mask-image: radial-gradient(ellipse 66% 64% at 50% 47%, #000 34%, transparent 82%);
          mask-image: radial-gradient(ellipse 66% 64% at 50% 47%, #000 34%, transparent 82%);
}

/* ── Block style: Daylight ──────────────────────────────────────────────
   Registered against core/group. The hard tonal cut from dark room to studio
   grey, matched to the backdrop the daylight renders were shot against. */
.wp-block-group.is-style-daylight {
  background: var(--wp--preset--color--day);
  color: var(--wp--preset--color--day-ink);
}
.wp-block-group.is-style-daylight :where(h1, h2, h3, p, dt, dd) { color: inherit; }

/* ── Pinned stages, shared by both product blocks ───────────────────────── */
.fx-pin { position: relative; background: var(--wp--preset--color--void); }
.fx-pin__stage { position: sticky; top: 0; height: 100svh; overflow: hidden; }
.fx-pin__inner {
  position: relative; height: 100%;
  display: grid; place-items: center;
  padding: 5rem var(--wp--custom--gutter, 2rem) 3rem;
}

/* ── Tier A: the scrubbed assembly ──────────────────────────────────────── */
.fx-scrub__media { position: relative; height: 100%; display: grid; place-items: center; }
.fx-scrub__canvas, .fx-scrub__poster {
  height: min(76svh, 46rem); width: auto; max-width: 92vw;
  -webkit-mask-image: radial-gradient(ellipse 68% 66% at 50% 48%, #000 36%, transparent 84%);
          mask-image: radial-gradient(ellipse 68% 66% at 50% 48%, #000 36%, transparent 84%);
}
.fx-scrub__canvas { opacity: 0; transition: opacity 0.5s ease; }
.fx-scrub__canvas.is-ready { opacity: 1; }
.fx-scrub__poster { position: absolute; inset: 0; margin: auto; transition: opacity 0.5s ease; }
.fx-scrub__poster.is-gone { opacity: 0; }

.fx-scrub__loader {
  position: absolute; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  width: 8rem; height: 1px; background: rgb(244 239 232 / 0.15);
  transition: opacity 0.4s ease;
}
.fx-scrub__loader i { display: block; height: 100%; width: 0; background: var(--wp--preset--color--ember); }
.fx-scrub__loader.is-gone { opacity: 0; }

.fx-scrub__readout {
  position: absolute; z-index: 3; top: 5.5rem; left: var(--wp--custom--gutter, 2rem);
  font-family: var(--wp--preset--font-family--mono);
}
.fx-scrub__count {
  font-size: clamp(2.4rem, 6vw, 4.6rem); line-height: 1; margin: 0;
  letter-spacing: -0.04em; font-variant-numeric: tabular-nums;
}
.fx-scrub__of { color: var(--wp--preset--color--dust); font-size: 0.4em; letter-spacing: 0.1em; }
.fx-scrub__caption {
  font-size: 0.66rem; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--wp--preset--color--ember); margin: 0.6rem 0 0;
}

.fx-scrub__stages {
  position: absolute; z-index: 3; right: var(--wp--custom--gutter, 2rem); top: 50%;
  transform: translateY(-50%); list-style: none; margin: 0; padding: 0; text-align: right;
  font-family: var(--wp--preset--font-family--mono); font-size: 0.64rem;
  letter-spacing: 0.2em; text-transform: uppercase;
}
.fx-scrub__stages li {
  color: var(--wp--preset--color--dust); opacity: 0.35; padding: 0.55rem 0;
  transition: opacity 0.4s ease, color 0.4s ease;
}
.fx-scrub__stages li.is-on { opacity: 1; color: var(--wp--preset--color--ember); }
.fx-scrub__stages li.is-on::before { content: "— "; }

/* ── Tier B: the held image ─────────────────────────────────────────────
   Same pin, same mask, same room. The image is held and the words move, which
   is what a photographed object gets instead of 72 rendered frames. */
.fx-held .fx-pin__inner {
  display: grid; grid-template-columns: 1fr 1fr; align-items: center;
  gap: var(--wp--custom--gutter, 2rem); max-width: 78rem; margin: 0 auto;
  place-items: stretch;
}
.fx-held__shot { margin: 0; justify-self: center; align-self: center; }
.fx-held__shot img {
  height: min(72svh, 36rem); width: auto;
  -webkit-mask-image: radial-gradient(ellipse 66% 64% at 50% 47%, #000 34%, transparent 82%);
          mask-image: radial-gradient(ellipse 66% 64% at 50% 47%, #000 34%, transparent 82%);
  transform: scale(var(--fx-push, 1));
  transition: transform 0.25s linear; will-change: transform;
}

.fx-held__beats { position: relative; list-style: none; margin: 0; padding: 0; min-height: 14rem; }
.fx-held__beats > * {
  position: absolute; inset: 0; opacity: 0; transform: translateY(1.2rem);
  transition: opacity 0.55s ease, transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
}
.fx-held__beats > .is-on { opacity: 1; transform: none; }

/* ── Odds and ends the patterns lean on ─────────────────────────────────── */
.fx-eyebrow {
  font-family: var(--wp--preset--font-family--mono); font-size: 0.66rem;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--wp--preset--color--ember);
}
.fx-rail {
  position: absolute; left: 1rem; top: 50%;
  transform: rotate(180deg) translateY(50%); writing-mode: vertical-rl;
  font-family: var(--wp--preset--font-family--mono); font-size: 0.6rem;
  letter-spacing: 0.34em; text-transform: uppercase;
  color: var(--wp--preset--color--dust); opacity: 0.55;
}
.fx-specs dl { margin: 0; }
.fx-specs dl > div {
  display: grid; grid-template-columns: 15rem 1fr; gap: var(--wp--custom--gutter, 2rem);
  padding: 1.1rem 0; border-top: 1px solid rgb(244 239 232 / 0.1);
}
.fx-specs dt {
  font-family: var(--wp--preset--font-family--mono); font-size: 0.66rem;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--wp--preset--color--dust);
}
.fx-specs dd { margin: 0; }

/* ── Mobile ─────────────────────────────────────────────────────────────
   The pin rides native scroll, so it is fine on touch. What changes is
   density, and fractus.js loads half as many frames. */
@media (max-width: 860px) {
  .fx-pin__inner { padding: 4.5rem 1rem 2rem; }
  .fx-scrub__canvas, .fx-scrub__poster { height: min(60svh, 34rem); }
  .fx-scrub__readout { top: 4.2rem; left: 1.25rem; }
  .fx-scrub__count { font-size: 2.2rem; }
  .fx-scrub__stages { right: 1.25rem; top: auto; bottom: 1.5rem; transform: none; }
  .fx-rail { display: none; }

  .fx-held .fx-pin__inner { grid-template-columns: 1fr; align-content: center; }
  .fx-held__shot { order: 1; }
  .fx-held__shot img { height: auto; width: min(66vw, 17rem); }
  .fx-held__beats { order: 2; min-height: 12rem; }
}

@media (prefers-reduced-motion: reduce) {
  .fx-gobo { animation: none; }
  .fx-pin { height: auto !important; }
  .fx-pin__stage { position: static; height: auto; }
  .fx-pin__inner { padding: 4rem var(--wp--custom--gutter, 2rem); }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── WooCommerce ────────────────────────────────────────────────────────
   Woo ships light-theme defaults for these, and they are the only places its
   markup shows through the design. The gallery is a plain image because the
   theme does not declare the gallery JS supports. */
.woocommerce-product-gallery img { width: 100%; height: auto; }
.woocommerce-product-gallery__trigger { display: none; }
.is-style-feathered .woocommerce-product-gallery img,
.wp-block-woocommerce-product-image-gallery.is-style-feathered img {
  -webkit-mask-image: radial-gradient(ellipse 66% 64% at 50% 47%, #000 34%, transparent 82%);
          mask-image: radial-gradient(ellipse 66% 64% at 50% 47%, #000 34%, transparent 82%);
}

.quantity input.qty {
  background: transparent; color: var(--wp--preset--color--bone);
  border: 1px solid rgb(244 239 232 / 0.25); border-radius: 0;
  font-family: var(--wp--preset--font-family--mono); font-size: 0.8rem;
  padding: 0.9rem 0.5rem; width: 4rem; text-align: center;
}
.quantity input.qty:focus { outline: 1px solid var(--wp--preset--color--ember); }

form.cart { display: flex; align-items: stretch; gap: 0.6rem; flex-wrap: wrap; }
.woocommerce-variation-add-to-cart { align-items: stretch; }

/* Woo's own price colour would override the theme.json preset. */
.wp-block-woocommerce-product-price .woocommerce-Price-amount { color: inherit; }
