@font-face {
  font-family: "Schibsted Grotesk";
  src: url("/fonts/schibsted-grotesk-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Schibsted Grotesk";
  src: url("/fonts/schibsted-grotesk-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Schibsted Grotesk";
  src: url("/fonts/schibsted-grotesk-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("/fonts/source-sans-3-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Sans 3";
  src: url("/fonts/source-sans-3-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* Light (day) mode. --ink is the text colour, --paper the background, as RGB channels. */
:root {
  color-scheme: light;
  --ink: 0 0 0;
  --paper: 255 255 255;
  --logo-filter: invert(0); /* a real filter, not "none", so blur() can be added to it */

  --swatch-1: rgb(var(--ink) / 0.85);
  --swatch-2: rgb(var(--ink) / 0.75);
  --swatch-3: rgb(var(--ink) / 0.6);
  --swatch-4: rgb(var(--ink) / 0.4);
  --swatch-5: rgb(var(--ink) / 0.25);

  --font-display: "Schibsted Grotesk", system-ui, sans-serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;

  --side: 10rem;
  --gallery-gap: 5rem;
  --wide-gap: 2rem;
  --narrow-gap: 1rem;
  --body-size: 1.08rem;

  /* logo drawing height; the header is 2rem padding above and below it */
  --logo-h: 4rem;
  --header-h: calc(4rem + var(--logo-h));
  /* 2rem + 2rem padding + one 1.4rem line at 1.1 line-height */
  --footer-h: 5.54rem;
}

/* Dark (night) mode: chosen with the toggle, or following the system when nothing is saved. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: 255 255 255;
  --paper: 17 17 17;
  --logo-filter: invert(1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --ink: 255 255 255;
    --paper: 17 17 17;
    --logo-filter: invert(1);
  }
}

/* 1rem = 13.12px at 1920 */
html {
  font-size: clamp(11px, 0.683vw, 16px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

body {
  background: rgb(var(--paper));
  color: var(--swatch-1);
  font-family: var(--font-body);
  font-size: var(--body-size);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

h1,
h2 {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

/* The only interactive feedback on the site. No hover states. */
a:active,
a:active img,
.pf-pages.is-viewer:not(.is-zoomed):active img {
  opacity: 0.7;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 0;
}

p + p {
  margin-top: 1.3em;
}

em {
  font-style: italic;
}

/* ---------- header ---------- */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: var(--header-h);
  padding: 2rem var(--side);
  /* fully opaque at the top, fading evenly to 80% at the bottom edge */
  background: linear-gradient(to bottom, rgb(var(--paper) / 1), rgb(var(--paper) / 0.8));
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--wide-gap);
  align-items: center;
  font-family: var(--font-display);
  color: var(--swatch-2);
  line-height: 1.1;
}

.logo {
  grid-column: span 8;
  justify-self: start;
  line-height: 0;
}

.logo img {
  height: var(--logo-h);
  width: auto;
  filter: var(--logo-filter);
}

/* One quick turn with a motion blur that peaks mid-spin. */
.logo img.is-spinning {
  animation: logo-spin 350ms ease-in-out;
}

/* the page reached by a logo click picks the spin up mid-turn */
.logo-spin-resume .logo img {
  animation: logo-spin 350ms ease-in-out var(--spin-delay, 0ms);
}

@media (prefers-reduced-motion: reduce) {
  .logo-spin-resume .logo img {
    animation: none;
  }
}

@keyframes logo-spin {
  0% {
    transform: rotate(0deg);
    filter: var(--logo-filter) blur(0);
  }
  50% {
    filter: var(--logo-filter) blur(2px);
  }
  100% {
    transform: rotate(360deg);
    filter: var(--logo-filter) blur(0);
  }
}

.nav {
  grid-column: span 4;
  justify-self: end;
  display: flex;
  /* centre everything on the middle of the capital letters (at line-height 1.1 the text box
     is centred on the caps), so the icons line up with PORTFOLIO and INFO */
  align-items: center;
  gap: 1.3em;
  font-size: 1rem;
  white-space: nowrap;
}

.nav a[aria-current="page"] {
  font-weight: 700;
}

.nav-ig {
  font-size: 1.4rem;
  line-height: 0;
}

/* overflow: visible so shapes that touch the edge of their drawing (the moon's points) are not trimmed */
.ig,
.theme-toggle svg {
  display: block;
  width: 1em;
  height: 1em;
  overflow: visible;
}

/* Slight enlargement on hover, only where there is a real mouse pointer. */
@media (hover: hover) and (pointer: fine) {
  .nav a,
  .theme-toggle,
  .site-footer a {
    transition: transform 150ms ease;
  }

  .nav a:hover,
  .theme-toggle:hover,
  .site-footer a:hover {
    transform: scale(1.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav a,
  .theme-toggle,
  .site-footer a {
    transition: none;
  }
}

/* Day mode shows the moon (switch to night), night mode shows the sun. */
.theme-toggle {
  display: none;
  font-size: 1.4rem;
  line-height: 0;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.js .theme-toggle {
  display: block;
}

.theme-toggle:active {
  opacity: 0.7;
}

.theme-toggle .icon-moon {
  width: 0.86em; /* the moon drawing is narrower than it is tall */
}

.theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

main {
  flex: 1 0 auto;
  padding: var(--header-h) var(--side) 0;
}

/* ---------- footer ---------- */

.site-footer {
  padding: 2rem var(--side);
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.4rem;
  line-height: 1.1;
  color: var(--swatch-2);
}

.site-footer a {
  display: inline-block;
}

/* ---------- home ---------- */

.page-home main {
  padding: calc(var(--header-h) + 10rem) var(--side) 10rem;
}

/* Without JS: CSS columns (top-to-bottom order). With JS: shortest-column placement. */
.masonry {
  columns: 3;
  column-gap: var(--gallery-gap);
}

.masonry > .tile {
  display: block;
  break-inside: avoid;
  margin-bottom: var(--gallery-gap);
}

.masonry.is-built {
  columns: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--gallery-gap);
}

.masonry-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gallery-gap);
}

.masonry-col .tile {
  display: block;
  margin: 0;
}

.tile img {
  width: 100%;
}

/* ---------- project ---------- */

.project-head {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--wide-gap);
  margin-bottom: 1.3em;
}

.project-title {
  grid-column: 1 / span 4;
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.3;
  color: var(--swatch-1);
}

.project-title h1 {
  font-weight: 700;
}

.project-title p {
  font-style: italic;
}

.project-body {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--narrow-gap);
  align-items: start;
  padding-bottom: 5rem;
}

.project-text {
  grid-column: 1 / span 3;
}

.project-text .notes {
  margin-top: 1.3em;
}

.project-images {
  grid-column: 4 / span 6;
  display: flex;
  flex-direction: column;
  gap: var(--gallery-gap);
}

.project-images img {
  width: 100%;
}

/* ---------- info ---------- */

.info {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: var(--wide-gap);
  align-items: start;
  padding-bottom: 2rem;
}

.info-photo img {
  width: 100%;
}

/* ---------- portfolio ---------- */

.page-portfolio main {
  display: flex;
  flex-direction: column;
}

.pf {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 2rem;
}

/* Without JS: every page stacked, download link on top. */
.pf-pages {
  width: 100%;
  max-width: 60rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.pf-pages img {
  width: 100%;
}

.pf-download-top {
  margin-bottom: 2rem;
}

.pf-count,
.pf-download-bottom {
  display: none;
}

/* With JS: a flip-through viewer that fits the viewport. */
.js .pf-download-top {
  display: none;
}

.js .pf-count,
.js .pf-download-bottom {
  display: block;
}

.pf-count {
  margin-top: 1.3em;
  color: var(--swatch-3);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.pf-download {
  color: var(--swatch-1);
}

.pf-pages.is-viewer {
  --avail-h: calc(100svh - var(--header-h) - var(--footer-h) - 4rem - 5.4rem);
  --spread-h: calc((100vw - 2 * var(--side)) / 2 * var(--page-ratio));
  max-width: none;
  height: min(var(--avail-h), var(--spread-h));
  display: block;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  scrollbar-width: none;
}

.pf-pages.is-viewer::-webkit-scrollbar {
  display: none;
}

.pf-pages.is-zoomed {
  overflow: auto;
  cursor: grab;
}

.pf-pages.is-panning {
  cursor: grabbing;
}

.pf-spread {
  display: flex;
  justify-content: center;
  width: 100%;
  height: 100%;
  margin: 0 auto;
}

.pf-pages.is-viewer img {
  display: none;
  width: auto;
  height: 100%;
  max-width: 50%;
  -webkit-user-drag: none;
}

.pf-pages.is-viewer img.on {
  display: block;
  animation: pf-fade 120ms linear;
}

@keyframes pf-fade {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pf-pages.is-viewer img.on {
    animation: none;
  }
}

/* ---------- mobile ---------- */

@media (max-width: 767px) {
  :root {
    --side: 3.5rem;
  }

  .site-header {
    display: flex;
    justify-content: space-between;
  }

  .page-home main {
    padding: calc(var(--header-h) + 3.5rem) var(--side) 5rem;
  }

  .masonry {
    columns: 2;
    --gallery-gap: 3.5rem; /* narrower than desktop's 5rem */
  }

  .project-head,
  .project-body {
    display: block;
  }

  .project-text {
    margin-bottom: 3.5rem;
  }

  .info {
    display: flex;
    flex-direction: column;
    gap: 2.6rem;
  }

  .pf-pages.is-viewer {
    --spread-h: calc((100vw - 2 * var(--side)) * var(--page-ratio));
  }

  .pf-pages.is-viewer img {
    max-width: 100%;
  }

  :root {
    --logo-h: 3.4rem;
  }
}
