/* Mad Cow — shared base. Reset, header and footer shell, nav, buttons, cards.
   Used by all three sites. Depends on tokens.css being loaded first.
   Site-specific layout stays in each site's own CSS; only what the sites
   share belongs here. */

/* ---- Reset ---- */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--hull);
  color: var(--deep);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
}

img,
svg,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

/* The hidden attribute is a user-agent rule, so any author rule that sets
   display beats it, the reset above included. gallery.js hides the
   lightbox's <video> and <img> with it, and on the sailing site the hidden
   video was laid out beside the photo anyway, an empty player that pushed
   the photo 150 px off a phone's screen (#203). The photo site restated this
   rule in its own site.css first, for share.js's hidden "Try again", which
   .button's inline-block showed; it lives here for all three sites since
   #203. */
[hidden] { display: none !important; }

/* ---- Type ---- */

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-stretch: var(--display-stretch);
  font-weight: var(--display-weight);
  line-height: var(--leading-tight);
  text-wrap: balance;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-lg); }

p,
li {
  max-width: var(--measure);
}

a {
  color: var(--blue);
  text-underline-offset: 0.15em;
}

/* Every :hover rule on the three sites sits inside @media (hover: hover),
   which matches only where the main pointer can hover (#200). A touch
   screen keeps :hover on the last element tapped until something else is
   tapped, so a tapped button stayed in its hover colour and read as pressed
   or disabled (the share page's Send, on Android Chrome). The query is
   placed where the rule was, so the cascade's order is unchanged, and
   photos/test/hover.test.js fails on a :hover rule outside one. */
@media (hover: hover) {
  a:hover {
    color: var(--blue-deep);
  }
}

/* Inverted fields — the navy strips. Links and accents flip to the
   values that clear contrast on --deep; never use --ensign here. */
.field-deep {
  background: var(--deep);
  color: var(--chalk);
}

.field-deep a {
  color: var(--chalk);
}

.field-deep .accent,
.field-deep .sail-number {
  color: var(--ensign-lt);
}

/* The eyebrow and a table's caption and headers are --blue on light, which
   reads 2.5:1 on --deep; --spray reads 8.2:1 (#119). The table half names
   the element because each site.css sets `.parties th` and its siblings
   after this file loads, and a specificity tie would go to them. */
.field-deep .eyebrow,
.field-deep table caption,
.field-deep table th {
  color: var(--spray);
}

/* Small structural text — eyebrows, dates, stack tags, nav, the sail
   number. The mono doing this job is what keeps the page from feeling
   like a template. */
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--blue);
}

.sail-number {
  font-family: var(--font-mono);
  color: var(--ensign);
}

/* ---- Focus ----
   Visible everywhere. Never remove without a replacement. */

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* The lightbox sits on --deep too, but gallery.js appends it to <body>, not
   inside a .field-deep, so it is named here: its ring falls on the ::backdrop,
   where --blue reads 2.2:1 and --chalk 12.7:1 (#56). */
.field-deep :focus-visible,
.lightbox :focus-visible {
  outline-color: var(--chalk);
}

/* ---- Layout shell ---- */

.wrap {
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

main > section {
  padding-block: var(--space-7);
}

/* Hand-drawn section divider. The wobble lives in an inline SVG path in
   the markup (stroke: currentColor); this only sizes and colours it.
   Between major sections, nowhere else. */
.divider {
  color: var(--spray);
  height: var(--space-3);
  margin-block: var(--space-2);
}

/* ---- Header shell ----
   The lockup on the left and the nav on the right, wrapping under the
   lockup when the row runs out of room. Each site's site.css carried its own
   copy of these rules until #169.

   The mark's height is read from --lockup-mark-height, which defaults to
   the 3rem sailing and photos use - 48px, the logo pack's floor for the full
   sailboat mark, below which it says to use the favicon cut instead. hq set
   it to 1.5rem in its own :root for the cow-face mark until #371 removed
   hq/; the variable stays so a site can still set its own. */

.site-header {
  border-bottom: var(--border-hair);
  padding-block: var(--space-3);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.lockup {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--blue);
  text-decoration: none;
}

/* Inlined rather than <img>: an <img>-loaded SVG has no parent to inherit
   currentColor from and renders black. */
.lockup-mark { height: var(--lockup-mark-height, var(--space-6)); width: auto; }
.lockup-word { height: var(--space-3); width: auto; }

/* ---- Nav ---- */

.site-nav ul {
  display: flex;
  gap: var(--space-4);
  list-style: none;
  padding: 0;
}

.site-nav a {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--deep);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  color: var(--blue-deep);
  text-decoration: underline;
  text-underline-offset: 0.3em;
}

@media (hover: hover) {
  .site-nav a:hover {
    color: var(--blue-deep);
    text-decoration: underline;
    text-underline-offset: 0.3em;
  }
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: var(--space-2);
  background: var(--chalk);
  padding: var(--space-2) var(--space-3);
  transform: translateY(-300%);
}

.skip-link:focus {
  transform: none;
}

/* ---- Buttons ----
   .button is the everyday action. .button-accent is the red one — one
   per viewport, it is the only warm thing on the page including the
   photography. */

.button {
  display: inline-block;
  background: var(--blue);
  color: var(--chalk);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-4);
  border: none;
  text-decoration: none;
  cursor: pointer;
}

@media (hover: hover) {
  .button:hover {
    background: var(--blue-deep);
    color: var(--chalk);
  }
}

.button-accent {
  background: var(--ensign);
}

@media (hover: hover) {
  .button-accent:hover {
    background: var(--deep);
  }
}

/* Forced colours (Windows contrast themes) paint every background in the
   page's own colour, so a button drawn by its background alone lost its
   edge there and read as a line of text (#186, WCAG 1.4.11). A native
   <button> gets a 2 px border in that mode; every .button gets the same,
   in the theme's button-border colour. Only in that mode, so the normal
   rendering keeps every button's size. .button-quiet's own 1 px border
   (photos/public/css/site.css) loads later and stays. */
@media (forced-colors: active) {
  .button {
    border: calc(var(--space-1) / 2) solid ButtonBorder;
  }
}

/* ---- Cards ----
   Hard edges, offset hover into a hard blue shadow. Cut vinyl, not
   Material Design. */

.card {
  background: var(--chalk);
  border: var(--border-hair);
  padding: var(--space-4);
  transition: transform var(--ease-quick), box-shadow var(--ease-quick);
}

@media (hover: hover) {
  .card:hover {
    transform: translate(-0.25rem, -0.25rem);
    box-shadow: var(--shadow-card);
  }
}

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

.site-footer {
  padding-block: var(--space-6);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* Left-aligned by default: sailing's footer is one item, and space-between
   would push a lone item to the right edge. hq spread its name and its list
   of links to the two edges, setting --footer-justify to space-between in its
   own :root, until #371 removed hq/. Each site's site.css carried its own
   copy until #169. */
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  justify-content: var(--footer-justify, flex-start);
  align-items: baseline;
}

/* ---- Gallery lightbox ----
   The dialog is built by shared/js/gallery.js (story #12), not written into
   any page, so this styles markup no HTML file in the repo contains. It lives
   here rather than in a site stylesheet because the script is shared: a
   gallery on either site gets the lightbox and its styling from the same copy
   step, and there is only one place to change it.

   The <dialog> element supplies the behaviour - focus trap, ::backdrop,
   Escape. What is below is only the look. */

.lightbox {
  /* The dialog's own box IS the viewport. That is what makes the backdrop
     hit-test in gallery.js meaningful: a click landing on the dialog but
     outside this box is a backdrop click. */
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
}

.lightbox::backdrop {
  background: var(--deep);
  opacity: 0.94;
}

.lightbox-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: var(--space-5) var(--space-7) var(--space-8);
}

/* The photo is capped by the stage in BOTH axes, so a portrait shot is bounded
   by the height and a landscape one by the width, and neither is cropped - the
   gallery grid does not crop and neither does this. width/height attributes are
   set by the script from the real file, so the box is reserved before the bytes
   land and opening the lightbox shifts nothing. */
.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: var(--deep);
}

.lightbox-bar {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: var(--hull);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.lightbox-caption {
  margin: 0;
  max-width: var(--measure);
}

/* The counter never wraps and never moves as the number of digits changes:
   it is the one thing a reader tracks while arrowing through, and a counter
   that shifts between 9 / 24 and 10 / 24 reads as the page jumping. */
.lightbox-counter {
  margin: 0;
  margin-inline-start: auto;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.lightbox-close,
.lightbox-nav {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  border: var(--border-hair);
  background: var(--deep);
  color: var(--hull);
  cursor: pointer;
  transition: background-color var(--lightbox-motion), color var(--lightbox-motion);
}

.lightbox-close svg,
.lightbox-nav svg {
  width: var(--space-4);
  height: var(--space-4);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: square;
}

@media (hover: hover) {
  .lightbox-close:hover,
  .lightbox-nav:hover {
    background: var(--blue);
  }
}

.lightbox-close {
  inset-block-start: var(--space-3);
  inset-inline-end: var(--space-3);
}

.lightbox-nav {
  inset-block-start: 50%;
  transform: translateY(-50%);
}

.lightbox-prev { inset-inline-start: var(--space-3); }
.lightbox-next { inset-inline-end: var(--space-3); }

/* At phone width the side arrows would sit on top of the photo, which is the
   surface the swipe is for. So they move down beside the counter instead, and
   the bar makes room for them. */
@media (max-width: 46rem) {
  .lightbox-stage {
    padding: var(--space-4) var(--space-2) var(--space-8);
  }

  .lightbox-nav {
    inset-block-start: auto;
    inset-block-end: var(--space-3);
    transform: none;
  }

  .lightbox-bar {
    justify-content: center;
    padding-inline: var(--space-8);
  }
}

/* ---- Reduced motion ----
   Disabled entirely, not shortened. The eye tracking honours this via
   its own script check as well. */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  @media (hover: hover) {
    .card:hover {
      transform: none;
    }
  }

  /* A true zero for the lightbox, not the 0.01ms above. Story #12 AC 5
     measures the computed transition-duration of the lightbox controls under
     this media query and requires 0 - and 0.01ms, while imperceptible, is not
     0 and reads as 1e-05s (measured 2026-09-04, which is how this rule came
     to exist: the token alone was not enough).

     Retargeting the token is NOT enough on its own, and that is the whole
     point of this block. `transition-duration: 0.01ms !important` on `*` beats
     an ordinary declaration whatever value the token holds, so the shorthand
     in .lightbox-close never gets to lose on value - it loses on !important
     first. The token is still set, so nothing anywhere reads a stale 90ms, and
     the duration is then restated !important at a specificity the star
     selector cannot reach.

     The blanket rule above stays exactly as it is: shortening to a hair rather
     than to zero is deliberate everywhere else, because a transitionend
     listener that never fires is its own bug. gallery.js listens for no such
     event, which is what makes a true zero safe here and only here. */
  :root {
    --lightbox-motion: 0s;
  }

  .lightbox,
  .lightbox-close,
  .lightbox-nav {
    transition-duration: 0s !important;
    animation-duration: 0s !important;
  }
}
