/* =======================================================================
   BASE STYLES
   Order: reset → element defaults → display type → utilities → layout
   primitives → sky → nav → components (cv, photo grids, cover stacks,
   spotlight, viewer) → breakpoints → reduced motion.

   Tokens live in tokens.css. Newly proposed tokens are written as
   var(--token, fallback) so this file works before tokens.css is updated;
   once the tokens exist, the fallbacks can be dropped.
   ======================================================================= */


/* ---- RESET -----------------------------------------------------------
   Strip browser defaults. Note: this also removes defaults 
   some native elements rely on (e.g. <dialog> centering),
   so components restore what they need. */
*,
*::before,
*::after {
  box-sizing: border-box;
  /* width includes padding + border */
  margin: 0;
  padding: 0;
}

img,
picture,
video,
iframe {
  display: block;
  max-width: 100%;
  /* media never overflows its container */
}

img {
  height: auto;
  /* width/height attributes reserve space without distorting */
}

[hidden] {
  display: none !important;   /* the hidden attribute always hides, whatever display a class sets */
}


/* ---- ELEMENT DEFAULTS ------------------------------------------------*/
html {
  /* No pixel font-size: leaving the root at the browser default keeps
     rem units honoring user zoom / text-size settings. */
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--step-body);
  font-weight: 300;
  line-height: var(--leading-body);
  color: var(--color-type);
  background-color: var(--color-sky-fallback, #6b6480);
  /* shows if the sky image is slow or missing */
}

a {
  color: inherit;
  /* no browser blue/purple anywhere */
  text-decoration: none;
}

p {
  letter-spacing: var(--tracking-normal);
  max-width: var(--measure-prose, 60ch);
  /* readable line length */
}

/* One visible focus ring for every focusable element, legible on the sky. */
:focus-visible {
  outline: 2px solid var(--color-type);
  outline-offset: 4px;
}


/* ---- DISPLAY TYPE ----------------------------------------------------
   Two display styles, each defined once. Individual rules below only add
   what's unique to them (mostly spacing). */
h1,
h2,
.nav-links a,
.nav-mono,
.nav-label,
.cv-download,
.album-title,
.item-title,
.tile-title {
  font-family: var(--font-display);
  font-weight: bold;
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

/* hero: the big assertive words */
h1,
.nav-links a {
  font-size: var(--step-hero);
}

/* mono: monogram, labels, section heads. .album-title is an h1, but its
   class outranks the h1 selector, so it correctly gets mono size. */
h2,
.nav-mono,
.nav-label,
.cv-download,
.album-title,
.item-title,
.tile-title {
  font-size: var(--step-mono);
}

main p a,
.item-links a {
  text-shadow: 0 0 0.6em rgb(255 255 255 / 1);
  text-shadow: 0 0 0.6em rgb(255 255 255 / 1);
  text-shadow: 0 0 0.6em rgb(255 255 255 / 1);
}


/* ---- UTILITIES -------------------------------------------------------*/
/* Visually hidden, still announced by screen readers. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Shared button reset: looks like text, keeps the focus ring. */
.viewer-open,
.viewer-button,
.filter {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}


/* ---- LAYOUT PRIMITIVES -----------------------------------------------*/
.page {
  padding: var(--page-margin);
}

/* Vertical rhythm: children spaced by a gap token. Override per use. */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}


/* ---- SKY -------------------------------------------------------------
   A dedicated fixed element (not a body background) so swup can leave it
   untouched between pages and the drift never resets. */
.sky {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100lvh;
  z-index: -1;
  background-image: url("/images/sky-4000-q90.avif");
  background-repeat: no-repeat;
  /* Width is 450% of the screen, or enough for the height to reach 300%,
     whichever is larger, so the image always overflows in both directions
     and the drift has room on any screen shape.
     666 = 300 × (image width ÷ height) = 300 × (9654 ÷ 4343).
     If you swap the sky photo, recompute it. */
  background-size: max(400vw, 592vh) auto;
  animation: sky-drift 420s linear infinite alternate;
}

@keyframes sky-drift {
  from {
    background-position: 0% 0%;
  }

  to {
    background-position: 100% 100%;
  }
}


/* ---- NAV -------------------------------------------------------------
   cf (home link) + life / work / cv + external exits. Mobile-first: a
   vertical stack here; the desktop column and the collapsed mobile
   content-page header live in the breakpoint queries below. */
.nav {
  display: flex;
  flex-direction: column;
  padding: var(--page-margin);
}

.nav-mono {
  display: inline-block;
  margin-bottom: var(--space-4);
  /* gap between cf and the nav words */
}

.nav-label {
  display: none;
  /* shown only in the collapsed mobile header */
}

.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

/* Blur encodes focus: clouded at rest, sharp when active or pointed at. */
.nav-links a {
  filter: blur(var(--blur-rest, 2px));
  transition: filter var(--duration-focus, 0.25s) ease;
}

.nav-links a:hover,
.nav-links a:focus-visible,
.nav-links a.is-active {
  filter: blur(0);
}

/* Hovering the monogram previews "home": all nav links sharpen. */
.nav-mono:hover~.nav-links a,
.nav-mono:focus-visible~.nav-links a {
  filter: blur(0);
  transition-duration: 0.4s;
  /* deliberately slower: the whole menu waking up */
}

/* Homepage: everything sharp at rest; pointing at one link blurs the rest.
   :has() means nothing blurs while the cursor is in a gap between links. */
.is-home .nav-links a {
  filter: blur(0);
}

@media (hover: hover) and (pointer: fine) {
  .is-home .nav-links:has(a:hover) a:not(:hover) {
    filter: blur(var(--blur-rest, 2px));
  }
}

.is-home .nav-links:has(a:focus-visible) a:not(:focus-visible) {
  filter: blur(var(--blur-rest, 2px));
}

/* Exits: doors OUT. Quiet body text, static, like the monogram. */
.nav-exits {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-0);
  margin-top: var(--space-4);
  /* mobile gap; desktop pins exits to the bottom instead */
}


/* ---- CV --------------------------------------------------------------*/
.cv-heading {
  margin-bottom: var(--space-1);
}

/* .cv-overview sits on the same element as .stack and must come after it
   in this file so its gap wins. */
.cv-overview {
  gap: var(--space-0);
}

.cv-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-0);
}

/* Now playing: blurred until the data arrives, then reveals. */
.cv-nowplaying {
  filter: blur(6px);
  /* heavy enough to hide the placeholder → track swap */
  transition: filter 1.2s ease;
}

.cv-nowplaying.is-loaded {
  filter: blur(0);
}

/* Live: breathe twice after the reveal, then rest. */
.cv-nowplaying.is-live.is-loaded a {
  animation: np-breathe 2.4s ease-in-out 1.2s 2;
  /* delay matches the reveal duration */
}

.cv-nowplaying a:hover,
.cv-nowplaying a:focus-visible {
  animation: none;
}

@keyframes np-breathe {

  0%,
  100% {
    filter: blur(0);
  }

  50% {
    filter: blur(1.5px);
  }
}


/* ---- PHOTO GRIDS -----------------------------------------------------
   One grid, two uses: album covers on /life/, photos on album pages. */
.album-title {
  margin-bottom: var(--space-2);
}

.photo-grid {
  --tile-min: 16rem;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--tile-min)), 1fr));
  gap: var(--space-2);
}

.photo-grid a {
  display: block;
}

.photo-grid picture,
.photo-grid img {
  display: block;
  width: 100%;
}

.photo-grid figcaption {
  margin-top: var(--space-1);
}

.photo-grid time {
  display: block;
}

.photo-grid--covers img {
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.photo-grid--album {
  --tile-min: 20rem;
  /* bigger tiles: browse without opening anything */
}

.photo-grid--work {
  --tile-min: 12rem;
  /* narrower columns than the album grid */
  display: block;
  columns: var(--tile-min);
  column-gap: var(--space-2);
}

.photo-grid--work li {
  break-inside: avoid;
  /* never split a tile across two columns */
  margin-bottom: var(--space-2);
  /* vertical spacing, since columns have no row gap */
}

.tile-title {
  display: block;
  /* its own line, so the tight leading applies cleanly to multi-line titles */
}

/* ---- FILTERS ---------------------------------------------------------
   Nothing selected: all sharp. Something selected: unselected words cloud.
   State comes from aria-pressed, so what's styled is what's announced. */
.filters {
  margin-bottom: var(--space-2);
}

.filter-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-0) var(--space-1);
}

.filter {
  transition: filter var(--duration-focus) ease;
}

.has-selection .filter[aria-pressed="false"] {
  filter: blur(var(--blur-rest));
}

.filter-empty,
.ideas {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.ideas-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-0);
}

@media (hover: hover) and (pointer: fine) {
  .has-selection .filter[aria-pressed="false"]:hover {
    filter: blur(0);
  }
}

.has-selection .filter[aria-pressed="false"]:focus-visible {
  filter: blur(0);
}

/* ---- COVER STACKS ----------------------------------------------------
   Blurred layers behind each cover. Direction and tilt come from
   albums.js (seeded by slug) as inline --x/--y/--r variables. */
.cover-stack {
  --stack-offset: calc(var(--space-1) / 2);
  position: relative;
  isolation: isolate;
  /* keeps the layers' z-index contained to this tile */
}

.cover-stack>picture {
  /* the cover itself */
  position: relative;
  z-index: 2;
}

.cover-stack-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  filter: blur(3px);
}

.cover-stack-layer picture,
.cover-stack-layer img {
  width: 100%;
  height: 100%;
}

.cover-stack-layer--1 {
  transform:
    translate(calc(var(--x1) * var(--stack-offset)), calc(var(--y1) * var(--stack-offset))) rotate(calc(var(--r1) * 1deg));
}

.cover-stack-layer--2 {
  z-index: 0;
  transform:
    translate(calc(var(--x2) * 2 * var(--stack-offset)), calc(var(--y2) * 2 * var(--stack-offset))) rotate(calc(var(--r2) * 1deg));
}


/* ---- GRID SPOTLIGHT --------------------------------------------------
   Point at (or keyboard-focus) one tile; the rest recede. */
.photo-grid li {
  transition: filter var(--duration-focus, 0.25s) ease;
}

@media (hover: hover) and (pointer: fine) {
  .photo-grid:has(li:hover) li:not(:hover) {
    filter: blur(var(--blur-rest, 2px));
  }
}

.photo-grid:has(:focus-visible) li:not(:has(:focus-visible)) {
  filter: blur(var(--blur-rest, 2px));
}


/* ---- PHOTO VIEWER ----------------------------------------------------
   Native <dialog> + a canvas for temporary drawing. */
.viewer-open {
  display: block;
  width: 100%;
  cursor: zoom-in;
}

.viewer {
  margin: auto;
  /* restores the native centering the reset removed */
  border: 0;
  padding: 0;
  /* so any click on the dialog itself is a backdrop click */
  background: transparent;
  color: var(--color-type);
}

.viewer::backdrop {
  background: var(--color-scrim);
  backdrop-filter: blur(var(--blur-backdrop));
}

.viewer {
  max-width: 90vw;
  max-height: 90dvh;
}

.viewer-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.viewer-stage {
  position: relative;
  width: fit-content;
  margin-inline: auto;
}

.viewer-stage picture {
  display: block;
}

.viewer img {
  max-width: 90vw;
  max-height: 75dvh;
  /* leaves room for the caption and controls */
  width: auto;
  object-fit: contain;
}

/* A canvas keeps its attribute size unless told otherwise, so width/height
   are set explicitly to match the photo. */
.viewer-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  /* a finger on the photo draws instead of scrolling */
  cursor: crosshair;
}

.viewer-caption:empty {
  display: none;
}

.viewer-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  width: 0;
  min-width: 100%;
}

.viewer-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.viewer-pen {
  display: flex;
  align-items: center;
  gap: 0.5em;
  cursor: pointer;
}

.viewer-pen input[type="color"] {
  inline-size: 1.25em;
  block-size: 1.25em;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

body:has(dialog[open]) {
  overflow: hidden;
  /* stop the page scrolling behind the viewer */
}

/* ---- WORK ITEM -------------------------------------------------------
   One item per page. Mobile: stacked. Desktop: media beside text,
   fitted to one screen so nothing scrolls. */
.item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.item-media picture,
.item-media img {
  display: block;
  width: 100%;
}

.item-caption {
  margin-top: var(--space-1);
}

.item-text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.item-links {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-0) var(--space-1);
  /* no gap between wrapped lines, 20px between items */
}

.item-tags a {
  text-shadow: none;
}

.item-images {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5rem, 1fr));
  gap: var(--space-1);
}

.item-images picture,
.item-images img {
  display: block;
  width: 100%;
}

.item-images img {
  aspect-ratio: 4 / 3;
  /* tidy, matching thumbnails; the viewer shows the full image */
  object-fit: cover;
}

.item-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-0);
  margin-top: var(--space-1);   /* extra room above, setting the trailing block apart */
}

/* ---- DESKTOP (≥ 48rem) -----------------------------------------------
   Keep 48rem in sync with the mobile query below; media queries can't
   read tokens. */
@media (min-width: 48rem) {
  #swap {
    display: grid;
    grid-template-columns: max-content 1fr;
    /* nav sizes to its words; content takes the rest */
    align-items: start;
  }

  .nav {
    position: sticky;
    top: 0;
    height: 100dvh;
    /* exactly one screen tall, so the exits stay reachable */
    overflow-y: auto;
    /* a short window scrolls the nav instead of hiding the exits */
  }

  .nav-exits {
    margin-top: auto;
    /* pin exits to the bottom of the column */
  }

  .cv-columns {
    flex-wrap: wrap;
    height: calc(100dvh - 2 * var(--page-margin));
    /* screen height minus .page padding */
    column-gap: var(--space-4);
    align-content: flex-start;
  }

  .item {
    flex-direction: row;
    align-items: flex-start;
  }

  .item-media {
    flex: 1 1 55%;
  }

  .item-text {
    flex: 1 1 45%;
  }

  .item-media img {
    width: auto;
    max-width: 100%;
    max-height: calc(100dvh - 2 * var(--page-margin));
    /* the cover never makes the page scroll */
  }

  .work-layout {
    display: grid;
    grid-template-columns: 1fr max-content;
    grid-template-areas: "grid filters";
    /* one row: everything starts at the top */
    column-gap: var(--space-4);
    align-items: start;
  }

  .work-layout .photo-grid--work,
  .work-layout .filter-empty {
    grid-area: grid;
    /* same spot: only one of them is ever visible */
  }

  .work-layout .filters {
    grid-area: filters;
    margin-bottom: 0;
    position: sticky;
    top: var(--page-margin);
    /* the row spacing only applies on mobile now */
  }

  .work-layout .filter-list {
    flex-direction: column;
    /* stacked, like the exits */
  }
}


/* ---- MOBILE (< 48rem) ------------------------------------------------
   Content pages collapse the nav to cf + page label. Keep 48rem in sync
   with the desktop query above. */
@media (width < 48rem) {
  #swap:not(.is-home) .nav {
    flex-direction: row;
    align-items: baseline;
    gap: var(--space-1);
    padding-bottom: 0;
    /* .page already has top padding; avoid a double gap */
  }

  #swap:not(.is-home) .nav-mono {
    margin-bottom: 0;
  }

  #swap:not(.is-home) .nav-links,
  #swap:not(.is-home) .nav-exits {
    display: none;
  }

  #swap:not(.is-home) .nav-label {
    display: inline;
  }
}


/* ---- REDUCED MOTION --------------------------------------------------
   Every animation's off-switch, in one place. */
@media (prefers-reduced-motion: reduce) {
  .sky {
    animation: none;
  }

  .cv-nowplaying {
    transition: none;
  }

  .cv-nowplaying a {
    animation: none;
  }
}