/* ============================================================================
 *  Matthew Jordan — personal site styles
 *
 *  A static recreation of the Cargo site at matthewjordan.ca. Sizes, spacing,
 *  colours and the grid/gallery rules follow Cargo's own stylesheet so pages
 *  lay out the same way. Everything is sized in rem, and the root font size
 *  scales with the window exactly as Cargo's "base unit" script does.
 * ==========================================================================*/

/* ---- Fonts ---------------------------------------------------------------
 * Served by Adobe Fonts (web project lyg2whe), linked in each page's <head>.
 * They replace the Cargo-licensed typefaces on the original site:
 *   Williams Caslon Text      -> Adobe Caslon Pro (body text, headings)
 *   Social Condensed Variable -> DIN 2014 Narrow  (h1 subheads)
 *   Interstate                -> DIN 2014         (small captions)
 */
:root {
  --serif: "adobe-caslon-pro", Georgia, serif;
  --condensed: "din-2014-narrow", "Arial Narrow", sans-serif;
  --caption: "din-2014", "Helvetica Neue", sans-serif;
  --system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  --link: rgb(105, 143, 255);
}

/* ---- Base unit -------------------------------------------------------------
 * Cargo sets <html> font-size to min(width, height) × weight / 100 percent,
 * where weight is 9 in landscape and rises to 14 as the window gets taller
 * than it is wide (fully at height ≥ 1.78 × width), with a floor of 20%.
 * In px: 1.44vmin + 0.8vw × clamp(0, (h/w − 1) / 0.7778, 1).
 */
html {
  font-size: max(3.2px, calc(1.44vmin + clamp(0px, (100vh - 100vw) * 0.0102857, 0.8vw)));
  -webkit-text-size-adjust: 100%;
  background: #fff;
}

body {
  /* Cargo renders text with greyscale smoothing, which draws strokes
   * thinner on macOS than the default. */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
  min-height: 100vh;
  background-color: rgb(245, 250, 255);
  color: #000;
}

/* ---- Page containers ---------------------------------------------------- */
.container {
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  overflow-wrap: break-word;
}
.container_width { width: 70%; }
.content_padding { padding: 4rem; }

/* ---- Text ---------------------------------------------------------------- */
/* Font metrics. font-size-adjust scales each font so its text runs the same
 * width as the Cargo original (so lines break in the same places) while line
 * spacing stays exactly as on the live site. Measured against the live site:
 * Adobe Caslon Pro is ~4.5% wider than Williams Caslon Text (its semibold,
 * used for bold, is close enough to share the regular size); DIN 2014 and
 * DIN 2014 Narrow are ~8% narrower than Interstate and Social Condensed. */
.bodycopy, .bodycopy b, .bodycopy strong { font-size-adjust: 0.4026; }
/* Homepage tile labels sit in narrow columns; 2% smaller keeps "Math &" on
 * one line as on the live site. */
.thumbnail .title { font-size-adjust: 0.394; }
.bodycopy i, .bodycopy em { font-size-adjust: 0.3893; }
/* Adobe Caslon's Bold is much heavier than Williams Caslon's; Semibold is
 * the closer match. */
.bodycopy b, .bodycopy strong { font-weight: 600; }
/* Italic and bold render at a slightly different size, which would push any
 * line containing them a pixel or two taller. Zero-height inline boxes keep
 * line spacing set by the paragraph alone, as on the live site. */
.bodycopy i, .bodycopy em, .bodycopy b, .bodycopy strong { line-height: 0; }
.bodycopy h1, .bodycopy font[face*="Bureau Grot"],
.bodycopy small { font-size-adjust: 0.541; }

.bodycopy {
  font-family: var(--serif);
  font-size: 2.3rem;
  font-weight: 400;
  font-style: normal;
  line-height: 1.2;
  color: rgba(0, 0, 0, 0.8);
}

.bodycopy a {
  color: var(--link);
  padding-bottom: 0.1em;
  border-bottom: 0 solid rgba(127, 127, 127, 0.3);
  text-decoration: none;
}
a:active { opacity: 0.7; }
.bodycopy a.image-link,
.bodycopy a.gallery_card_link { border-bottom: 0; padding-bottom: 0; }

h1 {
  font-family: var(--condensed);
  font-style: normal;
  font-weight: 400;
  padding: 0;
  margin: 0;
  font-size: 3.3rem;
  line-height: 0.9;
  color: #000;
}
h1 a { color: #000; }

h2 {
  font-family: var(--serif);
  font-style: normal;
  font-weight: 400;
  padding: 0;
  margin: 0;
  color: rgba(0, 0, 0, 0.85);
  font-size: 6rem;
  line-height: 1.2;
}
h2 a { color: rgba(0, 0, 0, 0.85); }
/* Adobe Caslon sits higher in its line box than Williams Caslon; nudge page
 * titles down to where Cargo draws them, without moving anything else. */
.bodycopy h2 { position: relative; top: 0.14em; }
.page-home h2 { line-height: 1; }
.page-university-courses h2 { font-size: 5.8rem; }

small {
  display: inline-block;
  font-size: 1.5rem;
  line-height: 1.4;
  font-family: var(--caption);
  font-style: normal;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.3);
}
.bodycopy small a { color: rgba(0, 0, 0, 0.3); border-bottom-width: 1px; }

/* "Calculus Textbook" on University Courses uses a <font face> Cargo font */
font[face*="Bureau Grot"] { font-family: var(--condensed); }

i, em { font-style: italic; }
b, strong { font-weight: bolder; }
s { text-decoration: line-through; }
sub, sup { position: relative; vertical-align: baseline; }
sub { top: 0.3em; }
sup { top: -0.4em; }

ul, ol { margin: 0; padding: 0 0 0 2em; }
blockquote { margin: 0; padding: 0 0 0 2em; }

hr {
  background: rgba(127, 127, 127, 0.2);
  border: 0;
  height: 1px;
  display: block;
}

img { border: 0; padding: 0; }
.content-img { height: auto; margin-bottom: 0.5em; vertical-align: baseline; }
.content-img:active { opacity: 0.7; }

iframe { max-width: 100%; }
/* Cargo stretches embeds marked width="100%" (the Spotify players) to the
 * full column, overriding the fixed width in their inline style. */
iframe[width="100%"] { width: 100% !important; }

/* ---- Cargo layout grid --------------------------------------------------
 * Page content uses Cargo's grid attributes verbatim: a row's gutter is a
 * negative margin, and padding on rows and columns adds the space back.
 */
[grid-row] {
  align-items: flex-start;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
}
[grid-col] { box-sizing: border-box; }
[grid-col="auto"] { flex: 1 1 0%; }
[grid-col="x12"] { width: 100%; }
[grid-col="x11"] { width: 50%; }
[grid-col="x10"] { width: 33.33%; }
[grid-col="x9"]  { width: 25%; }
[grid-col="x8"]  { width: 20%; }
[grid-col="x7"]  { width: 16.6667%; }
[grid-col="x6"]  { width: 14.2857%; }
[grid-col="x5"]  { width: 12.5%; }
[grid-col="x4"]  { width: 11.1111%; }
[grid-col="x3"]  { width: 10%; }
[grid-col="x2"]  { width: 9.09091%; }
[grid-col="x1"]  { width: 8.33333%; }
[grid-col="1"]  { width: 8.33333%; }
[grid-col="2"]  { width: 16.6667%; }
[grid-col="3"]  { width: 25%; }
[grid-col="4"]  { width: 33.3333%; }
[grid-col="5"]  { width: 41.6667%; }
[grid-col="6"]  { width: 50%; }
[grid-col="7"]  { width: 58.3333%; }
[grid-col="8"]  { width: 66.6667%; }
[grid-col="9"]  { width: 75%; }
[grid-col="10"] { width: 83.3333%; }
[grid-col="11"] { width: 91.6667%; }
[grid-col="12"] { width: 100%; }
[grid-pad="0"] { padding: 0; }
[grid-pad="1"] { padding: 0.5rem; }
[grid-pad="2"] { padding: 1rem; }
[grid-pad="3"] { padding: 1.5rem; }
[grid-pad="4"] { padding: 2rem; }
[grid-gutter="0"] { margin: 0; }
[grid-gutter="2"] { margin: -1rem; }
[grid-gutter="4"] { margin: -2rem; }
[grid-gutter="6"] { margin: -3rem; }
[grid-gutter="8"] { margin: -4rem; }

/* ---- Image galleries ----------------------------------------------------
 * Cargo builds these with JavaScript; here they are plain markup. --pad is
 * the padding around each image (half of Cargo's "image padding" setting).
 */
.gallery {
  --pad: 0rem;
  display: flex;
  flex-wrap: wrap;
  margin: calc(-1 * var(--pad));
  line-height: 0;
}
.gallery .gallery_card { box-sizing: border-box; padding: var(--pad); }
.gallery img { display: block; width: 100%; height: auto; margin: 0; }
.gallery a { display: block; }

.gallery.freeform { justify-content: center; align-items: center; }
.gallery.grid { align-items: baseline; }
.gallery.justify { align-items: flex-start; }
.gallery.columns { align-items: flex-start; }
.gallery.columns .gallery_column { box-sizing: border-box; }

.gallery.montessori {
  display: block;
  position: relative;
  height: 0;
  margin: 0;
}
.gallery.montessori .gallery_card { position: absolute; padding: 0; }

/* Slideshow: every slide is fitted to the height of the shortest slide (set
 * per gallery with aspect-ratio). js/slideshow.js adds autoplay and arrows;
 * without it the first slide simply shows. */
.gallery.slideshow {
  display: block;
  position: relative;
  width: 100%;
  margin: 0;
  overflow: hidden;
}
.slideshow-track {
  display: flex;
  height: 100%;
}
.slideshow .slide {
  flex: 0 0 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.slideshow .slide { overflow: hidden; }
/* Photos fill their slide edge to edge: letterboxing a near-square photo in
 * a slightly wider frame left thin gaps where the next slide peeked through. */
.slideshow .slide img,
.slideshow .slide a { display: block; width: 100%; height: 100%; }
.slideshow .slide img { object-fit: cover; }

.slideshow-arrow {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 25%;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 0;
  background: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2;
}
.slideshow-arrow.prev { left: 0; justify-content: flex-start; }
.slideshow-arrow.next { right: 0; justify-content: flex-end; }
.slideshow:hover .slideshow-arrow,
.slideshow-arrow:focus-visible { opacity: 1; }
.slideshow-arrow svg { width: 36px; height: 36px; fill: none; }
.slideshow-arrow .outer { stroke: rgba(0, 0, 0, 0.6); stroke-width: 2.5px; }
.slideshow-arrow .inner { stroke: #fff; stroke-width: 1.5px; }

/* ---- Homepage thumbnail grid ------------------------------------------- */
.thumbnails_width { width: 60%; }
.thumbnails {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center; /* a short last row sits in the middle */
  box-sizing: border-box;
  margin: -4rem;
  padding: 2rem;
  overflow-wrap: normal; /* long titles overhang rather than break mid-word */
}
.thumbnail {
  display: block;
  box-sizing: border-box;
  width: 25%;   /* four per row */
  padding: 1.25rem 2rem; /* a little less space between rows than across */
  text-decoration: none;
}
.thumb_image {
  display: block;
  position: relative;
  height: 0;
  padding-bottom: 100%;
  overflow: hidden;
}
.thumb_image img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumbnail .title {
  display: block;
  margin-top: 2.2rem;
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 400;
  line-height: 1.1;
  color: rgba(0, 0, 0, 0.85);
}

/* ---- Footer (social icons) ---------------------------------------------- */
.footer { width: 40%; }
.footer .content_padding { padding: 4rem 10rem; }
.footer .bodycopy { font-size: 6.7rem; }

/* ---- Site menu ----------------------------------------------------------
 * A CSS-only toggle: the hidden checkbox opens the panel, and the button and
 * the transparent overlay behind the panel are labels for it.
 */
.site-menu-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.site-menu-button {
  position: fixed;
  top: 3rem;
  left: 3rem;
  z-index: 10;
  display: block;
  width: 28px;
  height: 28px;
  padding: 6px;
  color: rgba(0, 0, 0, 0.75);
  cursor: pointer;
  line-height: 1;
}
.site-menu-button svg {
  display: block;
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}
.site-menu-button:active { opacity: 0.7; }
.site-menu-toggle:checked ~ .site-menu-button { display: none; }

.site-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
}
.site-menu-toggle:checked ~ .site-menu-overlay { display: block; }

.site-menu {
  display: none;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 11;
  box-sizing: border-box;
  min-width: 300px;
  max-width: 400px;
  padding: 20px 30px 90px;
  overflow-y: auto;
  background: rgba(20, 20, 20, 0.95);
  font-family: var(--system);
  font-size: 20px;
  font-weight: 400;
  text-align: left;
}
.site-menu-toggle:checked ~ .site-menu { display: block; }
.site-menu a {
  display: block;
  line-height: 28px;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
}
.site-menu a:active { opacity: 0.7; }
.site-menu a.active { opacity: 0.4; }

/* ---- Refinements (departures from the Cargo original) --------------------
 * Small changes for readability and consistency, in the site's own style.
 */
/* Links: a slightly deeper shade of the same periwinkle, so link text (and
 * the long italic book lists) reads comfortably; underline on hover. */
:root { --link: rgb(76, 112, 235); }
/* A real text underline sits just under the letters; a bottom border would
 * sit under the font's full line box, well below the text. */
.bodycopy a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}
.bodycopy a.image-link:hover,
.bodycopy a.gallery_card_link:hover { text-decoration: none; }

/* Captions: darker grey so they stay legible at their small size. */
small, .bodycopy small a { color: rgba(0, 0, 0, 0.5); }

/* Section subheads get a little more room above than below, so each one
 * reads as the start of its section rather than floating between two. */
.bodycopy h1 { padding-top: 0.5em; }

/* Even out ragged headings ("Press Coverage & Academic / CV") and avoid
 * one-word last lines in paragraphs, where browsers support it. */
h1, h2 { text-wrap: balance; }
.bodycopy { text-wrap: pretty; }

/* Social icons: soften from pure black to match the text colour. */
.footer img { opacity: 0.8; transition: opacity 0.15s; }
.footer a:hover img { opacity: 1; }

/* ---- Phones -------------------------------------------------------------
 * Cargo's mobile layout (measured on the live site): every section goes
 * full width with tighter padding, grid columns stack, and the homepage
 * thumbnails become four per row. (On the live site the homepage slideshow
 * collapses to nothing on phones; here it keeps working.)
 */
@media (max-width: 767px) {
  .container_width,
  .thumbnails_width,
  .footer { width: 100%; }
  .content_padding { padding: 2.3rem; }
  .footer .content_padding { padding: 2.3rem 5.8rem; }

  [grid-responsive] [grid-col] { width: 100%; flex: 0 0 auto; }

  .thumbnails { margin: -3.25rem; padding: 1.625rem; }
  .thumbnail { width: 25%; padding: 1.625rem; }

  .site-menu-button {
    top: 1.7rem;
    left: 1.7rem;
    margin: -6px;
    width: 34px;
    height: 34px;
  }
  .site-menu-button svg { width: 34px; height: 34px; }
  .site-menu { width: 100%; max-width: none; }

  /* Start page titles just below the menu button so long ones don't run
   * into it. */
  .bodycopy > h2:first-child,
  .bodycopy > [grid-row]:first-child > [grid-col]:first-child > h2:first-child { padding-top: 3.4rem; }

  /* Loose photos sized for a wide desktop column get too small on a phone. */
  .bodycopy img.content-img { min-width: 80%; }
  .gallery.freeform .gallery_card:only-child { min-width: 70%; }
}
