/* Dave Cavalier — portfolio */

:root {
  --bg: #0b0b0c;
  --text: #ececec;
  --text-dim: #9a9a9a;
  --header-h: 64px;
  /* Nav typography traced from davecavalier.com (brandon-grotesque 400,
     12px, uppercase, .18em). Montserrat is the Google-font stand-in. */
  --sans: "Montserrat", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(11, 11, 12, 0.55);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.site-header a {
  color: var(--text);
  text-decoration: none;
  text-transform: uppercase;
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0.18em;
}

.site-header .brand {
  font-size: 14px;
  letter-spacing: 0.32em;
}

.site-header nav {
  display: flex;
  gap: 28px;
}

.site-header nav a {
  opacity: 0.85;
  transition: opacity 0.2s ease;
  padding: 6px 0;
}

.site-header nav a:hover,
.site-header nav a:focus-visible {
  opacity: 1;
}

/* ---------- Stage: field -> black -> bio, on one pinned timeline ---------- */

.stage {
  position: relative;
  background: var(--bg);
  /* height is set by script.js from the beat lengths (URL-tunable) */
}

.stage-pin {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.stage-anchor {
  position: absolute;
  left: 0;
  width: 1px;
  height: 1px;
  /* top set by script.js: the scroll offset where the bio is resolved */
}

#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.9s ease;
}

#field.is-ready { opacity: 1; }

/* Field unavailable (no WebGL2, failed load, or any runtime error): the canvas
   is removed and script.js opens the page on the bio. Content never depends
   on the field. */
.stage.no-field #field { display: none !important; }

/* ---------- Bio (figure / ground) ---------- */

.bio {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;   /* long copy must not overflow off the top */
  justify-content: center;
  overflow: hidden;
  padding: calc(var(--header-h) + 4vh) 6vw 6vh;
  pointer-events: none;
}

.bio-stack {
  position: relative;
  width: 100%;
  max-width: 58ch;
}

/* figure: the real text. Sharp at every point on the timeline. */
.bio-copy {
  position: relative;
  z-index: 2;
  opacity: 0;
  will-change: opacity;
}

.bio-copy p {
  margin: 0 0 0.85em;
  font-size: clamp(11.5px, 0.95vw, 14px);
  line-height: 1.78;
  font-weight: 400;
  letter-spacing: 0.16em;
  color: #cfcfcf;
}

.bio-copy p:last-child { margin-bottom: 0; }

/* 2) The copy lives in a fixed-height window about two paragraphs tall and
   scrolls inside it; gradient masks fade the overflow at both edges. */
.bio-window.is-transit,
.bio.is-transit { overflow: visible; }

.bio-window.is-transit {
  -webkit-mask-image: none;
  mask-image: none;
}

.bio-window {
  overflow: hidden;
  padding: 26px 0;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
}

.bio-scroll { will-change: transform; }

.bio .section-title { margin-bottom: 20px; }

@media (max-width: 640px) {
  .bio { padding: calc(var(--header-h) + 1.5vh) 6vw 3vh; }
  .bio-copy p {
    font-size: 11.5px; line-height: 1.8; letter-spacing: 0.08em; margin-bottom: 0.9em;
  }
  .bio .section-title { margin-bottom: 12px; font-size: 10px; }
}

/* ---------- Contact, revealed from the centre of the black ---------- */

.contact-reveal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 0;
  pointer-events: none;
}

.contact-reveal .contact-email { margin-top: 6px; pointer-events: auto; }
.contact-reveal .fine-print { margin-top: 34px; }

/* per-character dissipation / assembly, driven directly by script.js.
   Words are inline-block so text wraps on word boundaries; the characters
   inside carry the motion. No calc() cascade: 2.3k glyphs made style recalc
   cost ~25ms/frame, so transforms are written per-glyph in JS instead. */
.w { display: inline-block; }
.ch { display: inline-block; }

/* ---------- Section label ---------- */

.section-title {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 28px;
}

/* ---------- Reduced motion: no timeline, no echo, nothing moves ---------- */

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

html.rm .stage { height: auto !important; }
html.rm .stage-pin { position: static; height: auto; }
html.rm #field { position: relative; height: 100vh; opacity: 1; }
html.rm .bio {
  position: relative;
  inset: auto;
  min-height: 62vh;           /* the black gap, held statically */
  padding-top: 22vh;
  padding-bottom: 14vh;
}
html.rm .bio-copy { opacity: 1 !important; }
html.rm .bio-window { height: auto !important; -webkit-mask-image: none; mask-image: none; }
html.rm .bio-scroll { transform: none !important; }
html.rm .contact-reveal {
  position: relative; inset: auto; opacity: 1 !important;
  padding: 14vh 24px 16vh; min-height: 0;
}
html.rm .ch { transform: none !important; opacity: 1 !important; }

/* ---------- No JavaScript: a plain static page ----------
   Applies whenever <html> lacks .js: scripts disabled, or script.js never took
   over (see the marker script in index.html). Title, full bio and contact read
   top to bottom. The field needs JavaScript, so it is removed. */
html:not(.js) .stage { height: auto !important; }
html:not(.js) .stage-pin { position: static; height: auto; overflow: visible; }
html:not(.js) #field { display: none; }
html:not(.js) .bio {
  position: relative;
  inset: auto;
  overflow: visible;
  pointer-events: auto;
  padding-top: calc(var(--header-h) + 8vh);
  padding-bottom: 6vh;
}
html:not(.js) .bio-copy { opacity: 1; }
html:not(.js) .bio-window {
  overflow: visible;
  padding: 0;
  -webkit-mask-image: none;
  mask-image: none;
}
html:not(.js) .contact-reveal {
  position: relative;
  inset: auto;
  opacity: 1;
  pointer-events: auto;
  padding: 8vh 24px 14vh;
}
html:not(.js) #about { top: 0; }

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

.site-footer {
  padding: 40px 24px 90px;
  text-align: center;
  scroll-margin-top: var(--header-h);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.contact-email {
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 400;
  border-bottom: 1px solid rgba(255, 255, 255, 0.25);
  padding-bottom: 3px;
  transition: border-color 0.2s ease;
}

.contact-email:hover,
.contact-email:focus-visible {
  border-color: #fff;
}

.fine-print {
  margin-top: 48px;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(5, 5, 6, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox[hidden] { display: none; }

.lightbox-figure {
  margin: 0;
  max-width: min(1100px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
}

.lightbox-media {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.lightbox-media img,
.lightbox-media video {
  max-width: 100%;
  max-height: calc(100vh - 180px);
  display: block;
}

.lightbox-figure figcaption {
  padding: 18px 4px 0;
  text-align: center;
}

.lightbox-figure h3 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.lightbox-figure p {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}

.lightbox-link {
  display: inline-block;
  margin-top: 12px;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(255, 255, 255, 0.25);
  padding-bottom: 2px;
  transition: border-color 0.2s ease;
}

.lightbox-link:hover,
.lightbox-link:focus-visible {
  border-color: #fff;
}

/* `display` on the class above outranks the UA rule for [hidden], so setting
   the attribute alone left the previous item's URL on screen -- attributing
   the wrong destination to the next piece of work. Same guard as .lightbox. */
.lightbox-link[hidden] { display: none; }

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  z-index: 201;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease;
}

.lightbox-close:hover,
.lightbox-close:focus-visible {
  background: rgba(255, 255, 255, 0.22);
}

.lightbox-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

body.lightbox-open { overflow: hidden; }
