/* ==========================================================================
   Home page — hero, intro, work grid, biography, lightbox, footer.
   Depends on: tokens.css, base.css
   ========================================================================== */

/* --------------------------------------------------------------------------
   Page atmosphere: a fixed film-grain layer plus soft colour blooms.
   Both are decorative and never intercept pointer events.
   -------------------------------------------------------------------------- */

.grain {
  position: fixed;
  inset: 0;
  z-index: var(--z-grain);
  pointer-events: none;
  /* Deliberately not `mix-blend-mode: overlay`. Blending a full-viewport layer
     forces everything beneath it to be composited into one buffer before the
     blend, which doubled the dropped frames while the hero animates. A flat
     low-opacity veil measures within ~1.3/255 of the blended version over both
     the dark ground and the light cards, so the look is unchanged. */
  opacity: 0.05;
  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='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

.bloom {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.bloom::before,
.bloom::after {
  content: "";
  position: absolute;
  width: 60vmax;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
}

.bloom::before {
  top: -25vmax;
  left: -20vmax;
  background: radial-gradient(circle, var(--brand-b), transparent 65%);
}

.bloom::after {
  right: -25vmax;
  bottom: -30vmax;
  background: radial-gradient(circle, var(--brand-o), transparent 65%);
}

/* --------------------------------------------------------------------------
   Header — hidden over the hero, revealed once the intro comes into view.
   Visibility is toggled by a single [data-visible] attribute from JS.
   -------------------------------------------------------------------------- */

.site-header {
  position: fixed;
  inset-inline: 0;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) var(--gutter);
  background: color-mix(in oklab, var(--surface-base) 72%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-subtle);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-100%);
  transition: opacity var(--duration-base) var(--ease-out),
    transform var(--duration-base) var(--ease-out),
    visibility var(--duration-base);
}

.site-header[data-visible="true"] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.site-header__mark {
  font-family: var(--font-display);
  /* Uppercase Squada One reads much larger than its lowercase, so this sits a
     step below the display size the mark would otherwise take. */
  font-size: var(--step-1);
  text-transform: uppercase;
  letter-spacing: -0.02em;
  text-decoration: none;
  line-height: 1;
}

.site-header__nav {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.nav-link {
  padding: var(--space-2xs) var(--space-sm);
  border-radius: var(--radius-pill);
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
}

.nav-link:hover {
  color: var(--text-primary);
  background: var(--surface-glass);
}

/* --------------------------------------------------------------------------
   Hero — the wordmark. Letters drift apart as the page scrolls; the amount is
   driven by --scroll-progress (0 → 1), written by motion.js on each frame.
   -------------------------------------------------------------------------- */

.hero {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100svh;
  overflow: hidden;
  background: var(--surface-sunken);
}

.wordmark {
  display: flex;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 40vw;
  line-height: 1;
  text-transform: uppercase;
}

.wordmark__letter {
  display: block;
  color: var(--letter-color);
  /* Give each glyph its own layer. Without it the doodle-filled, text-clipped
     background is re-rasterised on every frame the letter moves. */
  will-change: transform, opacity;
}

/*
 * Doodle texture inside the glyphs.
 *
 * Two background layers clipped to the letterforms: the pattern on top, a flat
 * sheet of the letter's colour beneath. The tile is drawn in translucent black,
 * so it darkens whichever colour it lands on and one file serves all four
 * letters. Sized in vw so the doodle keeps the same density relative to the
 * glyphs at every viewport.
 *
 * Guarded, because `color: transparent` would erase the wordmark entirely in a
 * browser that cannot clip a background to text.
 */
@supports (background-clip: text) or (-webkit-background-clip: text) {
  .wordmark__letter {
    color: transparent;
    background-image: url("../img/wordmark-pattern.svg"),
      linear-gradient(var(--letter-color) 0 100%);
    /* Sized so an individual doodle lands at roughly 24px on a desktop
       viewport. Because the tile itself is large, that scale only repeats
       about one and a half times inside a letter. */
    background-size: 27vw 27vw, auto;
    -webkit-background-clip: text;
    background-clip: text;
  }

  /* Start each letter at a different point in the tile, so the four glyphs
     never show the same arrangement. */
  .wordmark__letter:nth-child(2) {
    background-position: 13vw 7vw, 0 0;
  }
  .wordmark__letter:nth-child(3) {
    background-position: 5vw 17vw, 0 0;
  }
  .wordmark__letter:nth-child(4) {
    background-position: 20vw 3vw, 0 0;
  }
}

/* Glyphs are nested tighter as the viewport grows, as in the original mark. */
.wordmark__letter + .wordmark__letter {
  margin-left: -0.5rem;
}

@media (min-width: 40em) {
  .wordmark__letter + .wordmark__letter {
    margin-left: -1rem;
  }
}

@media (min-width: 48em) {
  .wordmark__letter + .wordmark__letter {
    margin-left: -2rem;
  }
}

.wordmark__letter:nth-child(1) { --letter-color: var(--brand-b); }
.wordmark__letter:nth-child(2) { --letter-color: var(--brand-t); }
.wordmark__letter:nth-child(3) { --letter-color: var(--brand-m); }
.wordmark__letter:nth-child(4) { --letter-color: var(--brand-o); }

.hero__tagline {
  position: absolute;
  bottom: clamp(5rem, 12svh, 8rem);
  font-size: var(--step--1);
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.scroll-cue {
  position: absolute;
  bottom: var(--space-xl);
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-2xs) var(--space-sm);
  font-size: var(--step--1);
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.scroll-cue:hover {
  color: var(--text-primary);
}

.scroll-cue__arrow {
  animation: nudge 1.8s var(--ease-in-out) infinite;
}

@keyframes nudge {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(0.3em);
  }
}

/* --------------------------------------------------------------------------
   Intro — the sentences arrive one at a time while ScrollTrigger pins the
   section. All lines share one grid cell so they can pass over each other;
   GSAP positions and fades them. The section is a plain viewport-tall block:
   ScrollTrigger adds the pin spacing itself.
   -------------------------------------------------------------------------- */

.intro {
  position: relative;
  background: var(--surface-sunken);
}

.intro__sticky {
  display: grid;
  place-items: center;
  place-content: center;
  min-height: 100svh;
  padding-inline: var(--gutter);
  overflow: hidden;
  text-align: center;
}

.intro__line {
  grid-area: 1 / 1;
  max-width: min(40ch, 88vw);
  font-size: var(--step-1);
  color: var(--text-secondary);
}

/* Before GSAP takes over, show only the first line. */
html.js .intro__line + .intro__line {
  visibility: hidden;
}

/* --------------------------------------------------------------------------
   Section headers
   -------------------------------------------------------------------------- */

.section-head {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-2xl);
}

.section-head__title {
  font-size: var(--step-4);
}

.section-head__lede {
  max-width: var(--measure);
  color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   Work grid + cards
   -------------------------------------------------------------------------- */

.work {
  position: relative;
  background: var(--surface-base);
  border-top: 1px solid var(--line-subtle);
}

.work__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
  /* Wider than the visual gap: the tape overhangs each card's top edge. */
  gap: var(--space-xl);
  align-items: start;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  height: 100%;
  padding: var(--space-lg);
  background: var(--paper);
  color: var(--ink);
  border-radius: 2px;
  box-shadow: 0 18px 30px -20px rgba(0, 0, 0, 0.9);
  transition: rotate var(--duration-base) var(--ease-out),
    transform var(--duration-base) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out);
}

/* A strip of tape over the top edge, holding the print to the page. */
.card::before {
  content: "";
  position: absolute;
  top: -0.7rem;
  left: 50%;
  width: 5.5rem;
  height: 1.5rem;
  transform: translateX(-50%) rotate(-2.5deg);
  background: rgba(232, 226, 205, 0.75);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* Pinned up by hand, so nothing hangs perfectly straight.
   The tilt lives on the list item, not the card: GSAP animates the card and
   neutralises the individual `rotate` property on anything it drives. */
.work__grid > li {
  transition: rotate var(--duration-base) var(--ease-out);
}

.work__grid > li:nth-child(odd) {
  rotate: -1deg;
}

.work__grid > li:nth-child(even) {
  rotate: 0.8deg;
}

.work__grid > li:hover {
  rotate: 0deg;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 26px 40px -22px rgba(0, 0, 0, 0.95);
}

/* Amber on off-white is too faint; focus rings inside a card use ink. */
.card :focus-visible {
  outline-color: var(--ink);
}

.card__tag {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  font-family: var(--font-hand);
  font-size: var(--step-1);
  color: color-mix(in oklab, var(--accent) 72%, #000);
}

.card__title {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 400;
  letter-spacing: 0.01em;
}

.card__body {
  font-size: var(--step--1);
  color: color-mix(in oklab, var(--ink) 76%, transparent);
}

.card__media {
  margin-top: auto;
  padding-top: var(--space-xs);
}

.card__embed {
  width: 100%;
  /* Playlists need more room than single tracks; the card sets the value. */
  height: var(--embed-height, 300px);
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: var(--paper-shade);
}

/* Story list inside the writing card. */
.card__links {
  display: flex;
  flex-direction: column;
  margin-top: auto;
  padding-top: var(--space-xs);
}

.card__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding-block: var(--space-sm);
  border-bottom: 1px dashed rgba(0, 0, 0, 0.35);
  font-size: var(--step--1);
  font-weight: 500;
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.card__link:hover {
  color: color-mix(in oklab, var(--accent) 72%, #000);
}

.card__link::after {
  content: "→";
  transition: transform var(--duration-fast) var(--ease-out);
}

.card__link:hover::after {
  transform: translateX(0.2em);
}

/*
 * Thumbnail block, shared by the gallery card (a <button> that opens the
 * lightbox) and the external card (an <a> to another site).
 */
.card__thumb {
  position: relative;
  display: block;
  width: 100%;
  margin-top: auto;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.18);
  overflow: hidden;
  text-align: left;
  text-decoration: none;
}

.card__thumb img {
  width: 100%;
  transition: transform var(--duration-slow) var(--ease-out);
}

.card__thumb:hover img {
  transform: scale(1.05);
}

.card__thumb-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--space-md);
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.75),
    rgba(0, 0, 0, 0.15)
  );
  color: #fff;
  font-family: var(--font-hand);
  font-size: var(--step-1);
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-out);
}

.card__thumb:hover .card__thumb-overlay,
.card__thumb:focus-visible .card__thumb-overlay {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   Biography
   -------------------------------------------------------------------------- */

.bio {
  position: relative;
  background: var(--surface-sunken);
  border-top: 1px solid var(--line-subtle);
}

.bio__text {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  max-width: var(--measure);
  font-size: var(--step-1);
  line-height: 1.65;
  color: var(--text-secondary);
}

/* First line gets the display treatment. */
.bio__text > p:first-child::first-line {
  color: var(--text-primary);
}

/* Blinking caret, drawn on whichever paragraph is currently being typed. */
.bio__text p[data-active]::after {
  content: "";
  display: inline-block;
  width: 0.08em;
  height: 1em;
  margin-left: 0.08em;
  translate: 0 0.12em;
  background: var(--brand-t);
  animation: caret 1s steps(2, start) infinite;
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   Lightbox — a native <dialog>, so Esc-to-close and the top layer come free.
   -------------------------------------------------------------------------- */

.lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100svh;
  max-height: 100svh;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  overflow: hidden;
}

.lightbox::backdrop {
  background: rgba(3, 3, 5, 0.94);
  backdrop-filter: blur(6px);
}

.lightbox__inner {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  padding: var(--space-md) var(--gutter) var(--space-xl);
}

.lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.lightbox__counter {
  font-size: var(--step--1);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.lightbox__stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  margin-block: var(--space-md);
}

/*
 * The image fills the stage box exactly and `object-fit: contain` letterboxes
 * it inside. Sizing it with `max-height: 100%` instead means the browser has
 * to resolve a percentage against a `1fr` grid track, which not every engine
 * does reliably — where it fails the photo renders at its natural size and
 * runs off the bottom of the window. Absolute positioning takes the box from
 * the laid-out stage instead of a percentage, so the whole image is always
 * visible.
 */
.lightbox__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-out);
}

.lightbox__image[data-loaded="true"] {
  opacity: 1;
}

.lightbox__spinner {
  width: 2.5rem;
  aspect-ratio: 1;
  border: 3px solid var(--line-strong);
  border-top-color: var(--brand-t);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.lightbox__spinner[hidden] {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

.lightbox__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  /* Its own row in the grid, so the image can never grow over it. */
  position: relative;
  z-index: 1;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-lg);
  /* Opaque, not glass: these sit over photographs, and a 4%-white pill
     disappears completely against a light part of an image. */
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-size: var(--step--1);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.55);
}

/* Dimming to 35% made a disabled button read as absent. Keep it legible and
   let the muted colour say it is inactive. */
.button:disabled {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text-muted);
  cursor: not-allowed;
}

.button i {
  flex: none;
}

.button i {
  font-size: 1em;
  line-height: 1;
}

.button--icon {
  padding: var(--space-xs);
  aspect-ratio: 1;
  justify-content: center;
  font-size: var(--step-1);
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.site-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  padding-block: var(--space-2xl);
  background: var(--surface-base);
  border-top: 1px solid var(--line-subtle);
  text-align: center;
}

.social {
  display: flex;
  gap: var(--space-xs);
}

.social__link {
  display: grid;
  place-items: center;
  width: 2.75rem;
  aspect-ratio: 1;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  transition: color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.social__link:hover {
  color: var(--text-primary);
  border-color: var(--line-strong);
  transform: translateY(-2px);
}

.social__link i {
  font-size: 1.25rem;
  line-height: 1;
}

.site-footer__note {
  font-size: var(--step--1);
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Scroll reveal — elements opt in with [data-reveal]; GSAP animates them in.
   The hidden start state only applies once JS has confirmed it can run it.
   -------------------------------------------------------------------------- */

html.js [data-reveal] {
  opacity: 0;
}

/* --------------------------------------------------------------------------
   Static fallback — reduced motion, or GSAP unavailable (motion.js adds
   .no-motion). The page must read correctly with nothing animating.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

html.no-motion [data-reveal],
html.no-motion.js [data-reveal] {
  opacity: 1;
  transform: none;
}

/* Without the pin, the greeting becomes an ordinary block of text. */
html.no-motion .intro__sticky {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-height: 0;
  padding-block: var(--space-4xl);
}

html.no-motion .intro__line,
html.no-motion.js .intro__line + .intro__line {
  visibility: visible;
  opacity: 1;
  transform: none;
}

html.no-motion .work__grid > li:nth-child(odd),
html.no-motion .work__grid > li:nth-child(even) {
  rotate: none;
}
