/* ==========================================================================
   Company pages — styles for thingtesting.html and airtame.html, and
   their case studies (thingtesting-try-it.html, airtame-homescreen.html
   and airtame-desktop-app.html), loaded after site.css.

   Laid out like an exhibition. At the top, the wall text: the company or
   the project and its years, a few sentences on what I did, and a few
   facts beside it, much like the About row. Then one exhibit per project,
   or per chapter of a case study: on the left (columns 1–4, as on the Work
   page) a grey heading with a few sentences below, which stay in view while
   its images pass by in one block on the right (columns 6–12). Each image
   is a numbered plate: pointing at one shows its number, and its caption
   at the foot of the column, which floats at the bottom of the window as
   the label floats at the top. The full story of a project, where there is
   one, is a link away.
   ========================================================================== */

.company {
  --peek: clamp(200px, 30vh, 360px); /* how much of the first exhibit shows */
  flex: 1 0 auto;
  padding: 0 var(--margin) 120px; /* the wall text sets its own room above */
}

/* Smooth jumps from the list of projects to each exhibit. */
@media (prefers-reduced-motion: no-preference) {
  html:has(.company) {
    scroll-behavior: smooth;
  }
}

/* --------------------------------------------------------------------------
   The wall text: name and years, a few sentences and a link on the left;
   the facts on the right, in columns 9 and 11, so the row spans the page
   and reads as two parts, like the About row.

   Like the About row, it has the window to itself, at the optical centre
   (7% of the window's height more room below it than above), all but a
   strip along the bottom where the first exhibit peeks in, so it's clear
   the page goes on. However short the window, it keeps at least 120px
   above and below.
   -------------------------------------------------------------------------- */

.company-intro {
  align-content: center;
  align-items: start;
  row-gap: 32px;
  /* The window, less the header (52px) and the peek. */
  min-height: calc(100vh - 52px - var(--peek));
  min-height: calc(100svh - 52px - var(--peek));
  padding: 120px 0 calc(120px + 7vh);
}

.company-summary {
  display: flex;
  flex-direction: column;
  grid-column: 1 / span 4;
  gap: 12px;
}

.company-fact {
  display: flex;
  flex-direction: column;
  grid-column: 9 / span 2;
  gap: 12px;
  --enter-delay: 0.06s;
}

.company-fact + .company-fact {
  grid-column: 11 / -1;
}

/* Two columns are narrow at 1024px, so a fact's links wrap rather than
   being cut short. */
.company-fact .item-title {
  overflow: visible;
  white-space: normal;
}

/* Like the Work page: the name in grey, then the years lighter still. */
.company-heading,
.exhibit-heading {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.company-years,
.exhibit-years {
  color: var(--color-text-muted);
}

.company-text,
.company-fact p,
.exhibit-text,
.exhibit-note dd {
  max-width: 33em; /* the About bio's measure */
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--text-label-size);
  font-weight: 500;
  line-height: var(--text-label-line-height);
}

/* A second paragraph starts a line below the first (with the label's 12px
   gap, 20px: one line). */
.exhibit-text + .exhibit-text {
  margin-top: 8px;
}

/* A link in running text is underlined, so it can be found. Like every
   link, it turns grey when you point at it. */
.exhibit-text a {
  text-decoration: underline;
  text-decoration-color: var(--color-text-muted);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color 0.125s ease-out, text-decoration-color 0.125s ease-out;
}

@media (hover: hover) {
  .exhibit-text a:hover {
    color: var(--color-text-secondary);
    text-decoration-color: currentColor;
  }
}

.exhibit-text a:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

/* A case-study link (the circle after it is in site.css) sits 20px under
   the text, not a list's usual 12px, so it stands apart as the one thing to
   do next. */
.exhibit-label > .item-list:has(.item-icon--next) {
  margin-top: 8px;
}

/* --------------------------------------------------------------------------
   Exhibits: one per project, or per chapter of a case study.
   -------------------------------------------------------------------------- */

.exhibits {
  display: flex;
  flex-direction: column;
  gap: 120px;
}

.exhibit {
  align-items: start;
  scroll-margin-top: 100px; /* lands with its label where it stays */
}

.exhibit:first-child {
  --enter-delay: 0.12s;
}

/* On the left, a column as tall as the images: the label at its top, the
   captions at its foot. */
.exhibit-side {
  display: flex;
  flex-direction: column;
  grid-column: 1 / span 4;
  align-self: stretch;
}

/* The label stays in view, just below the header, while its images pass. */
.exhibit-label {
  position: sticky;
  top: 100px;
  display: flex;
  flex-direction: column;
  grid-column: 1 / span 4;
  gap: 12px;
}

/* Beside its pictures, the heading hangs from the tops of its capitals, not
   from the top of its line (which left them about 6px below the pictures'
   top edge, and the text looking dropped), as on Work. Only beside pictures:
   beside a list of findings, text lines up with text as it is. Where the
   browser can't trim the line (text-box), the label is raised by hand. */
@media (min-width: 1024px) {
  .exhibit:has(> .exhibit-media) .exhibit-label > .label:not(.exhibit-heading),
  .exhibit:has(> .exhibit-media) .exhibit-heading > span {
    text-box: trim-start cap alphabetic;
  }

  @supports not (text-box: trim-start cap alphabetic) {
    .exhibit:has(> .exhibit-media) .exhibit-label {
      margin-top: -6px;
    }
  }
}

/* Beside plates, it stops 64px short of the column's foot (24px, then room
   for a caption of two lines), so it never meets the caption below. */
.exhibit-side .exhibit-label {
  margin-bottom: 64px;
}

/* On the first screen only the first exhibit's pictures peek in, so the
   wall text is the one thing to read. Its label fades in over the first
   160px of scrolling, and back out on the way up. It follows the scroll,
   not a timer, so nothing moves on its own, and tabbed to, it shows at
   once. From 1024px up only: where the label sits above its pictures,
   hiding it would leave a gap. Browsers that can't tie an animation to
   scrolling show it as before. */
@media (min-width: 1024px) {
  @supports (animation-timeline: view()) {
    .exhibit:first-child {
      view-timeline: --first-exhibit block;
    }

    .exhibit:first-child .exhibit-label {
      animation: label-in linear both;
      animation-timeline: --first-exhibit;
      /* From where the exhibit sits as the page opens (the peek), 160px on. */
      animation-range: entry var(--peek) entry calc(var(--peek) + 160px);
    }

    .exhibit:first-child .exhibit-label:focus-within {
      animation: none;
    }
  }
}

@keyframes label-in {
  from { opacity: 0; }
}

/* The images, in one block: a wide one across the top, then a pair. They
   sit close together, so a project's images read as one set. */
.exhibit-media {
  display: grid;
  grid-column: 6 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.exhibit-media img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--color-background-hover);
}

.exhibit-media .is-wide {
  grid-column: 1 / -1;
}

/* Where an exhibit has a case study, its pictures are the way in to it:
   each is a link there rather than opening larger (the plate itself, or for
   bare graphics an a around the img). Pointing at one zooms it in 2%, as on
   the Work page. The "Read the case study" link keeps its own hover for
   itself (it greys and its circle eases on only when it's the thing pointed
   at), so that small move is always there to see on reaching it. */
.exhibit-media a {
  display: block;
  overflow: hidden;
}

.exhibit-media a img {
  transition: transform 0.8s cubic-bezier(0.33, 1, 0.68, 1); /* as on Work */
}

@media (hover: hover) {
  .exhibit-media a:hover img {
    transform: scale(1.02);
  }
}

@media (prefers-reduced-motion: reduce) {
  .exhibit-media a:hover img {
    transform: none;
  }
}

/* Mounts, for pictures with no ground of their own (a photo, a bare screen,
   a thin strip), or that need a pair's 16:9 shape. Like a print on a mount,
   the plate is the plates' light grey, 16:9 like the others, and the picture
   sits on it at its own shape: with a margin all round (is-mounted), or none
   where it's on the grey already (is-fitted). So a set of plates reads as
   one, and a mounted plate's number sits on the grey. Like the pictures,
   the grey stays light in dark mode. */
.plate.is-mounted,
.plate.is-fitted {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  aspect-ratio: 16 / 9;
  background: #f3f3f3;
}

.plate.is-mounted {
  padding: 7%;
}

.plate.is-mounted img,
.plate.is-fitted img {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 100%;
  background: none;
}

/* A bare screen (a TV screenshot) has a thin dark bezel, so on its mount it
   reads as a screen on the wall, like the photographed ones. */
.exhibit-media .is-screen {
  border: 3px solid var(--color-bezel);
}

/* --------------------------------------------------------------------------
   Plates and captions, as in a gallery. Each image is a plate (div.plate),
   numbered like a plate in a catalogue, and the side column holds their
   captions (ol.exhibit-captions). At rest neither shows, so the wall stays
   calm. Pointing at a plate shows its number, on the grey margin in its
   top corner, and its caption at the foot of the column, which floats at
   the bottom of the window while the exhibit runs past, as the label floats
   at the top: what the project is stays up top, what you're looking at
   sits below. A chapter with only one plate needs no number.
   -------------------------------------------------------------------------- */

.exhibit-media {
  counter-reset: plate;
}

.plate {
  position: relative;
  counter-increment: plate;
}

/* The number sits 12px in, as far as the plates are apart. */
.plate::before {
  content: counter(plate) / ""; /* screen readers have the captions */
  position: absolute;
  top: 6px; /* the figure's top 12px down, with the line's own space */
  left: 12px;
  /* The pictures stay light in dark mode, so the number on them keeps the
     light theme's muted grey in both. */
  color: #a6a5b5;
  font-size: var(--text-label-size);
  font-weight: 500;
  line-height: var(--text-label-line-height);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease-in-out;
}

/* A chapter with only one plate needs no number, and nor does a plate
   that's a link: it leads on to a case study, which has the captions, so
   its exhibit has none. */
.plate:only-child::before,
a.plate::before {
  content: none;
}

/* A picture on a colour of its own (Airtame's blue) fills its plate, as the
   pictures on grey do. Its number is white (is-coloured), as quiet on the
   colour as the grey one is on the grey. */
.plate.is-coloured::before {
  color: #fff;
}

/* The captions take the rest of the column below the label, and all wait
   in one spot at its foot, so a caption can float up as far as the label
   but never over it. */
.exhibit-captions {
  display: grid;
  flex: 1 0 auto;
  max-width: 33em;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: caption;
  color: var(--color-text-secondary);
  font-size: var(--text-label-size);
  font-weight: 500;
  line-height: var(--text-label-line-height);
}

/* A caption, in grey, lined up with the label's text, its number in light
   grey hanging in the margin before it. While its exhibit runs on below
   the window, it waits 16px up from the bottom, where the lightbox shows
   it, so opening the picture leaves the caption's words where they are
   and only the number fades. Going, it fades out, then drops back out of
   sight. */
.exhibit-captions li {
  position: sticky;
  bottom: 16px;
  grid-area: 1 / 1;
  align-self: end;
  counter-increment: caption;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.28s ease-in-out, transform 0s 0.28s;
}

.exhibit-captions li::before {
  content: counter(caption);
  position: absolute;
  right: 100%;
  width: 20px; /* as far before the words as the lists' numbers are */
  color: var(--color-text-muted);
}

.exhibit-captions li:only-child::before {
  content: none;
}

/* Pointing at a plate shows its number, and its caption rises 6px into
   place as it fades in, a small version of the pages' entrance. Both wait
   200ms, so sweeping across the pictures shows nothing, and the last
   caption has gone before the next one comes. Tabbing to a plate does the
   same, unless the pointer is on another. Up to four plates an exhibit. */
.plate:hover::before,
.exhibit:not(:has(.plate:hover)) .plate:has(:focus-visible)::before {
  opacity: 1;
  transition: opacity 0.45s ease-in-out 0.2s;
}

.exhibit:has(.plate:nth-child(1):hover) .exhibit-captions li:nth-child(1),
.exhibit:has(.plate:nth-child(2):hover) .exhibit-captions li:nth-child(2),
.exhibit:has(.plate:nth-child(3):hover) .exhibit-captions li:nth-child(3),
.exhibit:has(.plate:nth-child(4):hover) .exhibit-captions li:nth-child(4),
.exhibit:not(:has(.plate:hover)):has(.plate:nth-child(1) :focus-visible) .exhibit-captions li:nth-child(1),
.exhibit:not(:has(.plate:hover)):has(.plate:nth-child(2) :focus-visible) .exhibit-captions li:nth-child(2),
.exhibit:not(:has(.plate:hover)):has(.plate:nth-child(3) :focus-visible) .exhibit-captions li:nth-child(3),
.exhibit:not(:has(.plate:hover)):has(.plate:nth-child(4) :focus-visible) .exhibit-captions li:nth-child(4) {
  opacity: 1;
  transform: none;
  transition:
    opacity 0.45s ease-in-out 0.2s,
    transform 0.6s cubic-bezier(0.22, 1, 0.36, 1) 0.2s;
}

@media (prefers-reduced-motion: reduce) {
  .exhibit-captions li {
    transform: none; /* it only fades */
  }
}

/* Where you can't point (phones and tablets), or the label sits above the
   images (below 1024px), the plates have no numbers and the captions are
   kept for screen readers only: the lightbox shows each picture's caption
   instead. */
@media (hover: none), (max-width: 1023px) {
  .plate::before {
    content: none;
  }

  .exhibit-side .exhibit-label {
    margin-bottom: 0;
  }

  .exhibit-captions {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* Where a chapter has findings rather than pictures, they take the images'
   place as a list, one below another, so their order is plain. Each is a
   numbered name in grey with its point directly beneath, as close as two
   lines of one paragraph. The number hangs in the gutter, in the light grey
   of a caption's. */
.exhibit-notes {
  display: flex;
  flex-direction: column;
  grid-column: 6 / -1;
  gap: 24px;
  margin: 0;
  counter-reset: note;
}

.exhibit-note {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  counter-increment: note;
}

.exhibit-note::before {
  content: counter(note) / ""; /* the list's order says as much */
  position: absolute;
  top: 0;
  right: 100%;
  width: 20px; /* as far before the words as a caption's number */
  color: var(--color-text-muted);
  font-size: var(--text-label-size);
  font-weight: 500;
  line-height: var(--text-label-line-height);
}

/* At the end, links to more: the first list in the first column, a second
   where the images start. */
.company-end {
  row-gap: 32px;
  margin-top: 120px;
}

.company-end .group {
  grid-column: 1 / span 4;
}

.company-end .group + .group {
  grid-column: 6 / span 3;
}

/* --------------------------------------------------------------------------
   Below 1024px everything stacks, from the top: the wall text, then each
   exhibit's label above its images. Labels stop following the scroll. The
   facts, and the lists at the end, sit side by side, half the width each.
   -------------------------------------------------------------------------- */

@media (max-width: 1023px) {
  .company {
    padding: 64px var(--margin) 96px;
  }

  /* From the top, as About is below 1024px, with a little more room under
     it than between the exhibits. */
  .company-intro {
    min-height: 0;
    padding: 0;
  }

  .company-summary {
    grid-column: 1 / -1;
  }

  .company-fact,
  .company-end .group {
    grid-column: 1 / span 6;
  }

  .company-fact + .company-fact,
  .company-end .group + .group {
    grid-column: 7 / span 6;
  }

  /* A list on its own has the whole width, so a name and its years stay on
     one line. (Beside another list, on a narrow phone, the years go on a
     line below rather than off the edge: site.css lets a row wrap there.) */
  .company-end .group:only-child {
    grid-column: 1 / -1;
  }

  .company-text,
  .exhibit-text {
    max-width: 36em;
  }

  .exhibits {
    gap: 64px;
    margin-top: 96px;
  }

  .exhibit {
    row-gap: 16px;
  }

  .exhibit-label {
    position: static;
    grid-column: 1 / -1;
  }

  .exhibit-side,
  .exhibit-media,
  .exhibit-notes {
    grid-column: 1 / -1;
  }

  /* Notes are text too, so a little more space sets them apart from the
     text above (32px in all). */
  .exhibit-notes {
    margin-top: 16px;
  }

  .company-end {
    margin-top: 64px;
  }
}

/* On phones a pair would be too small to read, so every image takes the
   full width. There's no room to hang a finding's number in the margin, so
   it leads the name, and the point lines up beneath the name. */
@media (max-width: 640px) {
  .exhibit-media {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .exhibit-note::before {
    content: none;
  }

  .exhibit-note dt::before {
    content: counter(note) / "";
    display: inline-block;
    width: 20px;
    color: var(--color-text-muted);
  }

  .exhibit-note dd {
    padding-left: 20px;
  }
}
