/* ==========================================================================
   HOW SPACING WORKS

   Everything is measured in lines. One line (--lh) is the leading: 34px on
   desktop, 23px on phones (type 24/34 and 16/23). Every space below is a
   whole number of lines, written as  calc(N * var(--lh)).

   To adjust spacing, change the numbers in SETTINGS below. Each setting
   says where it is used. Phones use the same numbers of lines, at their
   smaller line height, unless a setting is overridden in the phone block.

   To see the line grid and columns while working locally, press G on any
   page (only when the site runs locally, see site/config/).

   The first screen (homepage, and the top of project pages) is built
   from the top down:

      ┌───────────────────────────────────┐
      │ top margin            3 lines     │  project page: caption on line 2
      ├───────────────────────────────────┤
      │                                   │
      │ image area   = whatever is left,  │
      │              rounded down to      │
      │              whole lines          │
      │                                   │
      ├───────────────────────────────────┤
      │ image gap             1 line      │
      │ bottom line           1 line      │  "1 of N" / project title
      │ bottom margin   2 lines (+ the    │
      │                 leftover fraction │
      │                 of a line)        │
      └───────────────────────────────────┘  ← bottom of the screen
                                               footer starts here
   ========================================================================== */

@font-face {
  font-family: "Univers";
  src: url("../fonts/UniversLTStd.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "AX28 Script";
  src: url("../fonts/AX28ScriptSpiro.otf") format("opentype");
  font-display: swap;
}


/* ==========================================================================
   SETTINGS
   ========================================================================== */

:root {
  /* Type */
  --fs: 24px;                                  /* font size */
  --lh: 34px;                                  /* line height = 1 line */

  /* Colours */
  --bg: #ffff00;
  --text: #000;
  --muted: #808080;

  /* Page margins and grid */
  --columns: 6;
  --margin-top: calc(3 * var(--lh));           /* above the first content on every page */
  --margin-side: calc(2 * var(--lh));          /* left and right */
  --margin-bottom: calc(2 * var(--lh));        /* below the last content (and below the first screen's bottom line) */
  --gutter: calc(1 * var(--lh));               /* between columns */

  /* Text */
  --paragraph-space: calc(1 * var(--lh));      /* after paragraphs, year headings, project details */

  /* First screen (homepage + top of project pages) */
  --image-gap: calc(1 * var(--lh));            /* between the image and the bottom line ("1 of N" / project title) */
  --caption-gap: calc(1 * var(--lh));          /* project page: between the caption and the image above it */

  /* Project page, below the first screen */
  --description-gap: calc(2 * var(--lh));      /* phones: between the project title and the description */
  --close-gap: calc(1 * var(--lh));            /* between the project details and "Close" */

  /* Footer */
  --footer-padding: calc(1 * var(--lh));       /* above and below the footer text */

  /* Touch screens (homepage): extra room above the image for the project
     title, which is always shown there and can wrap onto several lines */
  --touch-title-room: calc(2 * var(--lh));

  /* Website screenshots ("Website" switched on for an image in the Panel) */
  --website-radius: 8px;
  --website-shadow: 0 2px 16px rgb(0 0 0 / 0.18);
}

/* Phones: smaller type, two columns. Every setting above scales with --lh
   automatically; override any of them here to use a different number of
   lines on phones. */
@media (max-width: 600px) {
  :root {
    --fs: 16px;
    --lh: 23px;
    --columns: 2;
  }
}

/* Calculated from the settings (no need to edit) */
:root {
  /* The image area: the screen height minus everything around it */
  --stage-height: calc(100svh - var(--margin-top) - var(--image-gap) - var(--lh) - var(--margin-bottom));
  /* Where the bottom line sits, measured from the top of the screen */
  --bottom-line: calc(var(--margin-top) + var(--stage-height) + var(--image-gap));
}
/* Round the image area down to whole lines, so everything below it stays
   on the line grid (browsers without round() skip this) */
@supports (height: round(down, 1px, 1px)) {
  :root { --stage-height: round(down, calc(100svh - var(--margin-top) - var(--image-gap) - var(--lh) - var(--margin-bottom)), var(--lh)); }
}


/* ==========================================================================
   BASE
   ========================================================================== */

* { box-sizing: border-box; }

html {
  font-family: "Univers", "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* Univers word spacing at 110%: its space is 0.278em wide, so add 10%
     of that (written in em so every browser supports it) */
  word-spacing: 0.0278em;
  /* Univers tracking +10 (10/1000 em) */
  letter-spacing: 0.01em;
  /* Kerning from the font's own pair metrics (browsers have no optical
     kerning) */
  font-kerning: normal;
}

body { margin: 0; }
p, figure { margin: 0 0 var(--paragraph-space); }
a { color: inherit; text-decoration: none; }
img, video { display: block; max-width: 100%; }

.script { font-family: "AX28 Script", cursive; word-spacing: normal; letter-spacing: normal; }
.muted { color: var(--muted); }


/* ==========================================================================
   PAGE GRID
   About, All Projects, and the project description use .grid: columns
   with gutters, inside the page margins. Text (.text) runs through the
   four central columns (both columns on phones).
   ========================================================================== */

.grid {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  column-gap: var(--gutter);
  padding: var(--margin-top) var(--margin-side) var(--margin-bottom);
}

.text { grid-column: 2 / span 4; }
@media (max-width: 600px) {
  .text { grid-column: 1 / -1; }
}

/* Pages fill at least the first screen, so the footer sits below it */
.page { min-height: 100svh; align-content: start; }


/* ==========================================================================
   IMAGES
   Desktop: every image and video is as tall as the image area, its width
   following its proportions (--ratio, width / height, is set on each
   image). An image too wide for the page is scaled down to fit.
   ========================================================================== */

img.media {
  width: min(100%, calc(var(--stage-height) * var(--ratio)));
  height: auto;
}
video.media {
  height: var(--stage-height);
  width: auto;
  max-width: 100%;
}

/* Website screenshots ("Website" switched on in the Panel): rounded
   corners and a slight shadow (see SETTINGS) */
.media.is-website {
  border-radius: var(--website-radius);
  box-shadow: var(--website-shadow);
}

/* Each image (or video) in a carousel sits in .slide-media */
.slide-media {
  position: relative;
  width: min(100%, calc(var(--stage-height) * var(--ratio)));
}
.slide-media .media { width: 100%; }
.slide-media:not([style]) { width: fit-content; max-width: 100%; }
.slide-media:not([style]) .media { width: auto; }

/* Phones and portrait screens: project images and videos all fill the
   page width instead, their height following their proportions */
@media (max-width: 600px), (orientation: portrait) {
  .project-carousel .slide-media { width: 100%; }
  .project-carousel .media { width: 100%; height: auto; }
}


/* ==========================================================================
   CAROUSEL MECHANICS (homepage and project pages; no spacing here)
   Without JavaScript the slides are a horizontally scrolling row. With it,
   they are stacked in one place and cross-fade.
   ========================================================================== */

.carousel {
  display: flex;
  height: 100svh;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.carousel::-webkit-scrollbar { display: none; }

.carousel.is-fading {
  display: grid;
  overflow: visible;
  scroll-snap-type: none;
}
.carousel.is-fading > .slide {
  grid-area: 1 / 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.carousel.is-fading > .slide.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.carousel.is-ready > .slide { transition: opacity 0.3s ease, visibility 0s linear 0.3s; }
.carousel.is-ready > .slide.is-active { transition: opacity 0.3s ease, visibility 0s; }

.slide {
  position: relative;
  flex: 0 0 100%;
  scroll-snap-align: start;
  grid-template-rows: var(--stage-height);   /* one row: the image area */
  align-content: start;
}


/* ==========================================================================
   HOMEPAGE
   Each slide is a full screen (.slide.grid, so it has the page margins):
   image at the top margin, "1 of N" on the bottom line.
   ========================================================================== */

.slide .slide-media {
  grid-row: 1;
  grid-column: 1 / -1;
  justify-self: center;
  align-self: start;                         /* image at the top of the image area */
}
/* Phones and portrait screens: images fit the width, so centre them
   vertically in the image area */
@media (max-width: 600px), (orientation: portrait) {
  .template-projects .slide .slide-media { align-self: center; }
}

/* "1 of 12", centred on the bottom line */
.count {
  position: absolute;
  top: var(--bottom-line);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  white-space: nowrap;
}

/* "Title for Client with Collaborator": links to the project. While the
   image is hovered it replaces "1 of N" on the bottom line. Its top
   padding (the image gap) bridges the space up to the image, so the
   mouse can move onto it without it disappearing. */
.slide-title {
  position: absolute;
  top: calc(var(--bottom-line) - var(--image-gap));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2 * var(--margin-side));
  padding-top: var(--image-gap);
  text-align: center;
  visibility: hidden;
  z-index: 3;
}
@media (hover: hover) {
  /* The script sets .show-title on the carousel while the mouse is over
     the image; it stays set while clicking through slides, so the
     outgoing and incoming titles cross-fade with no "1 of N" between */
  .carousel.show-title .slide-title { visibility: visible; }
  .carousel.show-title .count { visibility: hidden; }
  /* Keyboard focus, and plain :hover as a fallback without JavaScript */
  .slide:has(.slide-media:hover, .slide-title:focus-visible) .slide-title { visibility: visible; }
  .slide:has(.slide-media:hover, .slide-title:focus-visible) .count { visibility: hidden; }
}

/* Touch screens have no hover, so the title is always shown, above the
   image. The image area starts lower by --touch-title-room (and is that
   much shorter); the title sits one image gap above the image and grows
   upward if it wraps. */
@media (hover: none) {
  .template-projects { --stage-height: calc(100svh - var(--margin-top) - var(--touch-title-room) - var(--image-gap) - var(--lh) - var(--margin-bottom)); }
  @supports (height: round(down, 1px, 1px)) {
    .template-projects { --stage-height: round(down, calc(100svh - var(--margin-top) - var(--touch-title-room) - var(--image-gap) - var(--lh) - var(--margin-bottom)), var(--lh)); }
  }
  .template-projects .slide { padding-top: calc(var(--margin-top) + var(--touch-title-room)); }
  .slide-title {
    visibility: visible;
    top: auto;
    bottom: calc(100% - var(--margin-top) - var(--touch-title-room) + var(--image-gap));
    padding-top: 0;
  }
}


/* ==========================================================================
   PROJECT PAGE
   Yellow on black. The first screen mirrors the homepage: caption one
   line above the image, image at the top margin, project title on the
   bottom line. Then the description (from the first line below the first
   screen), the details, "Close", and the footer.
   ========================================================================== */

:root:has(.template-project) { --bg: #000; --text: #ffff00; }

.project { min-height: 100svh; padding-bottom: var(--margin-bottom); }

/* First screen: exactly as tall as the homepage's content (down to and
   including the bottom line) */
.project-hero {
  position: relative;
  height: calc(var(--bottom-line) + var(--lh));
  padding: var(--margin-top) var(--margin-side) 0;
}
.project-carousel { height: auto; }
.project-carousel .slide { display: grid; justify-items: center; align-content: start; }

/* "1 of 12: Caption  Photo: …", centred, one caption gap above the image
   (grows upward if it wraps) */
.slide-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + var(--caption-gap));
  text-align: center;
}
.slide-caption .muted { margin-left: var(--lh); }   /* space before "Photo:" */

/* Project title, on the bottom line */
.project-title {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2 * var(--margin-side));
  margin: 0;
  font: inherit;
  text-align: center;
}

/* Description: on the page grid, starting on the first whole line below
   the first screen (browsers without round() use the description gap) */
.project-body { padding-top: var(--description-gap); padding-bottom: 0; }
@supports (height: round(up, 1px, 1px)) {
  .project-body { padding-top: calc(round(up, 100svh, var(--lh)) - var(--bottom-line) - var(--lh)); }
}

/* Date / Client / Format, then the close gap */
.project-details { margin: 0 0 var(--close-gap); display: grid; grid-template-columns: auto 1fr; gap: 0 1em; }
.project-details dt { color: var(--muted); }
.project-details dd { margin: 0; }

/* "Close", centred below the details */
.project-close {
  display: block;
  width: max-content;
  margin: 0 auto;
}

/* Phones and portrait screens: images fill the width, so the project
   title follows the carousel (one image gap below it) instead of sitting
   on the bottom line. The top margin gets one extra line so a caption
   that wraps onto two lines still fits above the image. */
@media (max-width: 600px), (orientation: portrait) {
  .project-hero { height: auto; padding-top: calc(var(--margin-top) + var(--lh)); }
  .project-title { position: static; transform: none; width: auto; max-width: none; margin-top: var(--image-gap); }
  .project-body { padding-top: var(--description-gap); }
}


/* ==========================================================================
   ALL PROJECTS AND ABOUT
   Both use .page.grid with .text (see PAGE GRID).
   ========================================================================== */

/* Year headings, centred, followed by a paragraph space */
.all-projects h2 { font: inherit; margin: 0 0 var(--paragraph-space); text-align: center; }

/* About: hyphenated bio */
.about { hyphens: auto; }


/* ==========================================================================
   FOOTER
   White, right below the first full screen of every page (pages are at
   least one screen tall).
   ========================================================================== */

.site-footer {
  background: #fff;
  color: #000;
  padding: var(--footer-padding) var(--margin-side);
}
.site-footer p { margin: 0; }


/* ==========================================================================
   GRID OVERLAY (local development only)
   Press G to show the line grid (magenta lines every line height, from
   the top of the page) and the columns (blue). See assets/js/grid.js.
   ========================================================================== */

.show-grid body { position: relative; }
.show-grid body::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgb(255 0 255 / 0.5) 0 1px, transparent 1px var(--lh));
}
.show-grid body::after {
  --column: calc((100% - (var(--columns) - 1) * var(--gutter)) / var(--columns));
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  left: var(--margin-side);
  right: var(--margin-side);
  z-index: 1000;
  pointer-events: none;
  background: repeating-linear-gradient(to right, rgb(0 150 255 / 0.15) 0 var(--column), transparent var(--column) calc(var(--column) + var(--gutter)));
}

