/* ==========================================================================
   Base: reset, type defaults, the film-grain background, page shell,
   header and navigation. Values come from tokens.css only.
   ========================================================================== */

@view-transition { navigation: auto; }

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--color-bg);
  scrollbar-gutter: stable;
}

html:has(dialog[open]) { overflow: hidden; }

body {
  min-height: 100svh;
  font-family: var(--font-sans);
  font-size: var(--step-0);
  font-weight: var(--weight-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
  color: var(--color-text-body);
  position: relative;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, video, iframe { display: block; max-width: 100%; }
img { height: auto; }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }

h1, h2, h3 {
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--color-text);
  text-wrap: balance;
  overflow-wrap: break-word; /* long single words at 200% text size */
  hyphens: auto;
}
p { text-wrap: pretty; max-width: var(--measure); }

a {
  color: inherit;
  text-decoration-thickness: var(--border);
  text-underline-offset: 0.22em;
}
/* Plain inline links (no component class) are tan, like the email on the card. */
a:not([class]) { color: var(--color-link); }
@media (hover: hover) { a:not([class]):hover { text-decoration-color: var(--color-accent); } }

:focus-visible {
  outline: var(--border-thick) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}

/* The rose band: page titles and [data-highlight] text wear it like a
   permanent selection (site.js registers them with the CSS Custom Highlight
   API). Ordinary selections are rose too; on banded text they invert to a
   black strip so selecting still shows. */
::highlight(band) { background-color: var(--color-highlight); color: var(--color-text); }
::selection { background: var(--color-highlight); color: var(--color-text-on-accent); }
.page-title::selection,
[data-highlight]::selection,
[data-highlight] *::selection { background: var(--color-strip); color: var(--color-text-on-strip); }

/* ---- Film grain -------------------------------------------------------
   The navy is a frame of 8mm film. assets/img/film-grain.jpg is a seamless
   512px tile of real 8mm grain laid onto brand navy (its average is exactly
   #1C497B). It fills the screen behind everything and jumps to a fresh patch
   of grain twelve times a second, like film running through a projector.
   The html element carries flat navy underneath, so the page looks right
   before the tile arrives; body has no background so this layer shows.
   Above everything, a second, finer grain keeps the arch video from looking
   digital-clean. */

body::before {
  content: "";
  position: fixed;
  inset: -2rem; /* room for the jumps in film-grain below */
  z-index: -1;
  pointer-events: none;
  background: url("../assets/img/film-grain.jpg") 0 0 / 512px 512px; /* 1 image pixel per CSS pixel */
  opacity: var(--film-grain-opacity);
  animation: film-grain 1s steps(1, end) infinite;
}

/* Twelve frames a second, each a different patch of the tile. */
@keyframes film-grain {
  0%     { transform: translate(0, 0); }
  8.33%  { transform: translate(-1.2rem, 0.7rem); }
  16.67% { transform: translate(0.8rem, -1.4rem); }
  25%    { transform: translate(-1.7rem, -0.4rem); }
  33.33% { transform: translate(1.4rem, 1.1rem); }
  41.67% { transform: translate(-0.3rem, 1.8rem); }
  50%    { transform: translate(1.8rem, -0.8rem); }
  58.33% { transform: translate(-0.8rem, -1.8rem); }
  66.67% { transform: translate(0.4rem, 1.4rem); }
  75%    { transform: translate(-1.8rem, 0.2rem); }
  83.33% { transform: translate(1.1rem, -0.2rem); }
  91.67% { transform: translate(-0.5rem, -1rem); }
  100%   { transform: translate(0, 0); }
}

body::after {
  content: "";
  position: fixed;
  inset: -50%;
  z-index: var(--z-grain);
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  opacity: var(--grain-opacity);
  mix-blend-mode: overlay;
  animation: grain 1s steps(6) infinite;
}

@keyframes grain {
  0%   { transform: translate(0, 0); }
  17%  { transform: translate(-3%, 2%); }
  33%  { transform: translate(2%, -4%); }
  50%  { transform: translate(-4%, -1%); }
  67%  { transform: translate(3%, 3%); }
  83%  { transform: translate(-1%, 4%); }
  100% { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after { animation: none; }
}

/* ---- Utilities --------------------------------------------------------*/

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: var(--space-s);
  left: var(--space-s);
  z-index: calc(var(--z-grain) + 1);
  padding: var(--space-xs) var(--space-s);
  background: var(--color-paper);
  color: var(--color-text-on-light);
  font-weight: var(--weight-bold);
  border-radius: var(--radius-s);
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease-out);
}
.skip-link:focus { transform: none; }

.label {
  font-size: var(--step--1);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  line-height: var(--leading-snug);
}

/* Page titles: Indivisible bold capitals, the size of the contact page's
   opening line.
   (Amador is reserved for the SF monogram.) --title-nudge, set by site.js
   from the loaded font's real glyph metrics, pulls the title up so the top
   of its capitals lines up with the top of the monogram. */
.page-title {
  overflow-wrap: anywhere; /* capitals at 200% text can outgrow a phone; break rather than overflow */
  font-family: var(--font-sans);
  font-weight: var(--weight-bold);
  font-size: var(--step-2);
  line-height: var(--leading-display);
  letter-spacing: var(--tracking-title);
  text-transform: uppercase;
  color: var(--color-text);
  margin-top: var(--title-nudge, 0);
}

.lead { font-size: var(--step-1); line-height: var(--leading-snug); color: var(--color-text); }

/* ---- Rebrand notice ---------------------------------------------------
   Only shown when the URL carries ?nooffswitch (the old domain redirects
   there). The inline script in each page's <head> adds .has-rebrand-notice
   before first paint, so nothing shifts. */

html:not(.has-rebrand-notice) .rebrand-notice { display: none; }
.rebrand-notice {
  justify-content: center;
  min-height: 0;
  padding: var(--space-3xs) var(--gutter);
  text-align: center;
}

/* ---- Page shell -------------------------------------------------------
   Phones: header bar on top. From 48em: the header becomes a left rail with
   the monogram and stacked nav, content fills the rest. */

.shell {
  min-height: calc(100svh - var(--notice-h, 0px));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
}

main { min-width: 0; }
main:focus { outline: none; }

.site-header {
  position: relative;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-s);
  padding: var(--space-s) var(--gutter);
  view-transition-name: site-header;
}

.logo {
  display: block;
  width: 3.25rem;
  color: var(--color-accent);
  border-radius: var(--radius-s);
  transition: transform var(--dur-base) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.logo svg { width: 100%; height: auto; overflow: visible; }
@media (hover: hover) {
  .logo:hover { color: var(--color-accent-hover); transform: rotate(-3deg); }
}
.logo:active { transform: scale(0.96); transition-duration: var(--dur-instant); }

/* Nav links: stacked lines under the monogram. */
.site-nav ul { list-style: none; padding: 0; }

.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2xs);
  min-height: var(--tap);
  font-size: var(--step--1);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  text-decoration: none;
  color: var(--color-text);
  transition: color var(--dur-fast) var(--ease-out);
}

/* Underline drawn in rose (decorative, so contrast rules for text don't apply). */
.nav-link__text {
  background: linear-gradient(var(--color-accent), var(--color-accent)) 0 100% / 0 var(--border-thick) no-repeat;
  padding-bottom: 0.2em;
  transition: background-size var(--dur-base) var(--ease-out);
}

@media (hover: hover) {
  .nav-link:hover .nav-link__text { background-size: 100% var(--border-thick); }
}
.nav-link:active { transform: translateY(var(--press-shift)); }
.nav-link:active .nav-link__text { background-size: 100% var(--border-thick); }

.nav-link[aria-current="page"]::before {
  content: "";
  width: 0.55em;
  aspect-ratio: 1;
  background: var(--color-accent);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  flex: none;
}

/* Mobile menu toggle */
.menu-toggle {
  display: none;
  align-items: center;
  gap: var(--space-2xs);
  min-height: var(--tap);
  min-width: var(--tap);
  padding-inline: var(--space-xs);
  margin-right: calc(var(--space-xs) * -1);
  font-size: var(--step--1);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-text);
  border-radius: var(--radius-s);
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out);
}
@media (hover: hover) { .menu-toggle:hover { background: var(--color-hover-wash); } }
.menu-toggle:active { transform: scale(0.96); }

.menu-toggle__icon {
  position: relative;
  width: 1.25rem;
  height: 0.75rem;
}
.menu-toggle__icon::before,
.menu-toggle__icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: var(--border-thick);
  background: currentColor;
  transition: transform var(--dur-base) var(--ease-out-expo), top var(--dur-base) var(--ease-out-expo);
}
.menu-toggle__icon::before { top: 0; }
.menu-toggle__icon::after { top: calc(100% - var(--border-thick)); }
.menu-toggle[aria-expanded="true"] .menu-toggle__icon::before { top: calc(50% - 1px); transform: rotate(45deg); }
.menu-toggle[aria-expanded="true"] .menu-toggle__icon::after { top: calc(50% - 1px); transform: rotate(-45deg); }

/* Phones with JS: nav collapses into a dropdown panel. Without JS it stays visible. */
@media (max-width: 47.99em) {
  .js .menu-toggle { display: inline-flex; }

  .site-nav ul { display: flex; gap: var(--space-m); }

  .js .site-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: var(--z-menu);
    padding: var(--space-2xs) var(--gutter) var(--space-m);
    background: var(--color-strip);
    box-shadow: var(--shadow-lift);
    visibility: hidden;
    opacity: 0;
    transform: translateY(calc(var(--rise-s) * -1));
    transition:
      opacity var(--dur-base) var(--ease-out),
      transform var(--dur-base) var(--ease-out-expo),
      visibility 0s linear var(--dur-base);
  }
  .js .site-header[data-menu-open] .site-nav {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition-delay: 0s;
  }

  .js .site-nav ul { display: block; }
  .js .site-nav li {
    border-bottom: var(--border) solid var(--color-line-on-strip);
    opacity: 0;
    transform: translateY(calc(var(--rise-s) * -1));
    transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-slow) var(--ease-out-expo);
  }
  .js .site-header[data-menu-open] .site-nav li {
    opacity: 1;
    transform: none;
    transition-delay: calc(var(--i, 0) * var(--stagger) + 40ms);
  }
  .js .site-nav li:last-child { border-bottom: 0; }

  .js .site-nav .nav-link {
    display: flex;
    width: 100%;
    min-height: 3.5rem;
    font-size: var(--step-1);
    letter-spacing: var(--tracking-wordmark);
    color: var(--color-text-on-strip);
  }
  .js .site-nav .nav-link[aria-current="page"] { color: var(--color-text-on-strip-strong); }
}

@media (min-width: 48em) {
  .shell {
    grid-template-columns: var(--rail) minmax(0, 1fr);
    grid-template-rows: 1fr;
  }

  .site-header {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: 0;
    align-self: start;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: var(--space-m);
    padding: var(--gutter);
  }

  .logo { width: clamp(4.5rem, 3rem + 3vw, 6.25rem); }

  main { grid-column: 2; grid-row: 1; }

  .site-nav li + li { margin-top: calc(var(--space-2xs) * -1); }
}

/* Entrance: one orchestrated reveal on load, nothing scattered. */
.reveal {
  animation: reveal var(--dur-slower) var(--ease-out-expo) both;
  animation-delay: calc(var(--d, 0) * 90ms);
}
@keyframes reveal {
  from { opacity: 0; transform: translateY(var(--rise)); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; }
}

::view-transition-old(root),
::view-transition-new(root) { animation-duration: var(--dur-base); }
