/* ==========================================================================
   Typography
   Two text styles, used across the whole site:
   .type-body – Suisse Works, for all regular text (the default, set on <body>)
   .type-caps – Suisse Intl in capitals, for the name, project and section titles and the footer
   ========================================================================== */

@font-face {
  font-family: "Suisse Works";
  src: url("../Font/SuisseWorks-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Suisse Intl";
  src: url("../Font/SuisseIntl-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-body: "Suisse Works", serif;
  --font-caps: "Suisse Intl", sans-serif;
  --font-size: 14px;
  --line-height: 18px;
  --letter-spacing: -0.018em; /* Suisse Works, slightly tighter than the font's default spacing */
  --letter-spacing-caps: -0.01em; /* Suisse Intl */
}

body,
.type-body {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  /* Thinner, grayscale anti-aliasing on Mac */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.type-caps {
  font-family: var(--font-caps);
  letter-spacing: var(--letter-spacing-caps);
  text-transform: uppercase;
  color: var(--caps-color);
}

/* Headings and paragraphs take the text style they are given, without browser defaults */
h2,
p {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

/* ==========================================================================
   Layout and components
   ========================================================================== */

:root {
  --gutter: 4px; /* the grid's margins and the space between its columns */
  --header-button-height: 74px;
  --background-color: #ffffff;
  --caps-color: #121212; /* text in capitals: the name, About, titles, labels and the footer */
  --text-color: #757575;
  --link-color: #757575;
  --link-hover-color: #121212;
  --divider-color: #e3e3e3;
  --media-height: 480px;
  --media-height-list: 280px; /* the smaller images in the list projects */
  --hover-preview-height: 160px; /* the image that follows the pointer over the list projects */
  --media-radius: 8px;
  --media-gap: 4px;
  --cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Ccircle cx='4' cy='4' r='4' fill='black'/%3E%3C/svg%3E") 4 4, auto;
  --cursor-clickable: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Ccircle cx='4' cy='4' r='4' fill='%23FF0000'/%3E%3C/svg%3E") 4 4, pointer;
  --project-padding: 16px; /* above and below each project */
  --space-after-header: 76px; /* + the header's 4px and the project's 16px = 96px to the first project */
  --space-between-projects: 32px; /* + 16px + 16px project padding = 64px in total */
  --space-above-media: 8px; /* between a project's text and its images */
}

* {
  box-sizing: border-box;
}

/* Custom cursor: a small black circle, 8×8px, centred on the pointer – used everywhere */
html {
  cursor: var(--cursor);
}

*,
*::before,
*::after {
  cursor: inherit;
}

/* Red circle over anything clickable, and over the image rows you can scroll.
   The menu item for the page you are on has no href, so it isn't a button */
a[href],
button,
[role="button"],
.project-media {
  cursor: var(--cursor-clickable);
}

body {
  margin: 0;
  padding-top: calc(var(--header-button-height) + 2 * var(--gutter)); /* room for the fixed header */
  color: var(--text-color);
  background: var(--background-color);
}

a {
  color: var(--link-color);
  text-decoration: none;
}

/* Hover styles only on devices with a real pointer – on touch screens they would stick after a tap */
@media (hover: hover) {
  a[href]:hover,
  .is-collapsible .project-summary a[href]:hover {
    color: var(--link-hover-color);
  }

  /* The name and About buttons go light grey on hover */
  .header-button[href]:hover {
    color: #d7d7d7;
  }

  /* A list project's text turns dark while hovered */
  .is-collapsible .project-summary:hover,
  .is-collapsible .project-summary:hover a:not(:hover) {
    color: var(--caps-color);
  }
}

/* 12-column grid (4 on phones), with 4px gutters and outer margins */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--gutter);
  padding: var(--gutter);
}

/* Header – fixed to the top of the window, also on phones (where a sticky header would bounce
   along with the page). The page keeps the same room for it at the top. The name and About are frosted
   buttons side by side; each is as wide as its text, so the name's button shrinks along with P.T.M. */
.header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
}

/* The menu fades in on the first page of a visit only (the "first-visit" class is set in <head>) */
.first-visit .header-button {
  animation: menu-in 0.5s ease both;
}

.first-visit .nav .header-button {
  animation-delay: 40ms;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .first-visit .header-button {
    animation-name: menu-fade-in;
  }
}

@keyframes menu-fade-in {
  from {
    opacity: 0;
  }
}

.nav {
  display: flex;
  gap: var(--gutter);
}

.header-button {
  display: flex;
  align-items: flex-end; /* text sits at the bottom left */
  height: var(--header-button-height);
  padding: 16px 64px 16px 16px;
  border-radius: 8px;
  background: rgb(246 246 246 / 60%);
  box-shadow: inset 0 0 0 1px rgb(213 213 213 / 80%); /* a 1px border drawn inside */
  -webkit-backdrop-filter: blur(20px); /* "40" in Figma – Figma's blur value is twice the CSS one */
  backdrop-filter: blur(20px);
  white-space: nowrap;
}

/* Projects */
.projects {
  padding-top: var(--space-after-header);
}

/* Vertical spacing in a project doesn't follow the grid's 4px – it has its own values (see :root) */
.project {
  padding-block: var(--project-padding);
  row-gap: var(--project-padding);
}

.project + .project {
  margin-top: var(--space-between-projects);
}

/* Title and text sit on the same columns as the rest of the page */
.project-summary {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  position: relative;
}

/* Each text field is three columns wide */
.project-heading {
  grid-column: 1 / 4;
}

.project-info {
  grid-column: 4 / 7;
}

/* Values and links in caps (SNØHETTA, PIA FALK LIND …) keep the grey of the text */
.field-value {
  color: var(--text-color);
}

/* One line per field – links too */
.project-heading > *,
.project-info > *,
.about-section > * {
  display: block;
}

/* Images and videos in one horizontal row – scroll sideways to see them all */
.project-media {
  grid-column: 1 / -1;
  margin-top: calc(var(--space-above-media) - var(--project-padding));
  display: flex;
  gap: var(--media-gap);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  /* Extend the row to the screen edges, but keep the first and last image on the grid margin */
  margin-inline: calc(-1 * var(--gutter));
  padding-inline: var(--gutter);
  /* Hide the scrollbar – the row still scrolls */
  scrollbar-width: none;
  /* Click and drag */
  user-select: none;
}

.project-media::-webkit-scrollbar {
  display: none;
}

/* Fixed height, width follows each file's own format (aspect-ratio is set from build.js) */
.media {
  position: relative;
  flex-shrink: 0;
  height: var(--media-height);
  aspect-ratio: 1;
  border-radius: var(--media-radius);
  overflow: hidden;
}

/* The pixelated preview and the real file sit on top of each other */
.media-preview,
.media-file {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-preview {
  image-rendering: pixelated;
}

/* No "Save image" on long-press (iOS) and no dragging images out of the page */
.media,
.about-image {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  user-select: none;
}

.media-file {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.media.is-loaded .media-file {
  opacity: 1;
}

/* Content fades in as it scrolls into view. Text comes in one line at a time: reveal.js marks each
   heading, paragraph and link as a .reveal-line and gives it its own delay */
.reveal,
.reveal-line {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.reveal.has-lines,
.reveal.is-visible,
.is-visible .reveal-line {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .reveal,
  .reveal-line {
    transform: none;
  }
}

/* Secondary projects, shown as a list: a 1px line on the grid margins above each,
   and the whole text area opens and closes the images */
.project-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: var(--divider-color);
}

.project.is-collapsible + .project.is-collapsible {
  margin-top: 0;
  padding-top: 0;
}

.project.is-collapsible {
  --media-height: var(--media-height-list);
}

.project.is-collapsible:not(.is-open) .project-media {
  display: none;
}

/* Plus, turning into a minus when open – drawn with two 1px lines */
.project-toggle {
  position: absolute;
  top: 2px; /* centred on the first 18px text line */
  right: 0;
  width: 14px;
  height: 14px;
  color: var(--link-color);
}

.project-toggle::before,
.project-toggle::after {
  content: "";
  position: absolute;
  background: currentColor;
}

/* Both lines sit 6px in, so they cross on whole pixels and stay sharp */
.project-toggle::before {
  top: 6px;
  left: 0;
  width: 14px;
  height: 1px;
}

/* The vertical line turns flat when the project opens, so the plus becomes a minus */
.project-toggle::after {
  top: 0;
  left: 6px;
  width: 1px;
  height: 14px;
  transition: transform 0.4s ease;
}

.is-open .project-toggle::after {
  transform: rotate(90deg);
}

/* Small image following the pointer over the list projects (see showPreview in main.js) */
.hover-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.hover-preview .media {
  height: var(--hover-preview-height);
}

.hover-preview.is-shown {
  opacity: 1;
}

/* About page: two columns on the same grid as the projects */
.about {
  padding-top: var(--space-after-header);
}

.about-left {
  grid-column: 1 / 6;
}

.about-right {
  grid-column: 6 / 13;
}

/* One empty line between sections, like in the text file */
.about-section + .about-section {
  margin-top: 18px;
}

/* The About footer stays at the bottom of the window. The page keeps room for it underneath,
   and it has the page colour, so it never covers the text */
.page-about {
  --about-image-height: max(160px, 100vw * 250 / 1440); /* 250px on a 1440px window, never below 160px */
  padding-bottom: var(--footer-height, calc(var(--about-image-height) + 2 * var(--gutter))); /* measured in about.js */
}

.page-about .footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  align-items: end;
  margin-top: 0;
  background: var(--background-color);
}

.page-about .footer-text {
  grid-column: 7 / 13;
  justify-self: end;
}

/* The illustration, bottom left in the About footer */
.about-image {
  grid-column: 1 / 7;
  display: block;
  height: var(--about-image-height);
  width: auto;
}

/* The figure shakes every now and then (started from about.js), and keeps shaking while hovered */
.about-image.is-shaking {
  animation: shake 0.5s ease-in-out;
}

@media (hover: hover) {
  .about-image:hover {
    animation: shake 0.5s ease-in-out infinite;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: none;
  }
  15% {
    transform: translate(-2px, 1px) rotate(-2deg);
  }
  30% {
    transform: translate(2px, -1px) rotate(2deg);
  }
  45% {
    transform: translate(-2px, 0) rotate(-1.5deg);
  }
  60% {
    transform: translate(2px, 1px) rotate(1.5deg);
  }
  75% {
    transform: translate(-1px, 0) rotate(-1deg);
  }
}

/* Over the About image the pointer becomes a speech bubble – its tail tip is the pointer */
@media (hover: hover) {
  .about-image {
    cursor: none;
  }
}

.speech-bubble {
  --bubble-color: #000000;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  padding: 4px 8px;
  border-radius: 10px;
  background: var(--bubble-color);
  color: #ffffff;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(var(--x, 0), var(--y, 0)) translate(-6px, calc(-100% - 8px));
  transition: opacity 0.15s ease;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 6px;
  border-style: solid;
  border-width: 8px 8px 0 0;
  border-color: var(--bubble-color) transparent transparent transparent;
}

/* Near the right edge the bubble opens to the left, with its tail on the right */
.speech-bubble.is-flipped {
  transform: translate(var(--x, 0), var(--y, 0)) translate(calc(-100% + 6px), calc(-100% - 8px));
}

.speech-bubble.is-flipped::after {
  right: 6px;
  left: auto;
  border-width: 8px 0 0 8px;
}

.speech-bubble.is-shown {
  opacity: 1;
}

/* Footer at the bottom of every page */
.footer {
  margin-top: var(--space-after-header);
}

.footer-text {
  grid-column: 1 / -1;
}

/* ==========================================================================
   Mobile – phones and narrow windows (up to 700px wide)
   Everything specific to mobile goes here. The values below are the knobs for
   scaling: change them to resize text, spacing and images on phones only
   ========================================================================== */

@media (max-width: 700px) {
  :root {
    /* Text */
    --font-size: 14px;
    --line-height: 16px;

    /* Spacing */
    --gutter: 4px;
    --project-padding: 16px;
    --space-after-header: 172px; /* about 190px from the buttons to the first project */
    --space-between-projects: 8px; /* + 16px + 16px project padding = 40px in total */
    --space-above-media: 12px;

    /* Images */
    --media-height: 260px;
    --media-height-list: 200px;
    --media-gap: 4px;
  }

  /* A 4-column grid on phones */
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Header: the name in columns 1–2, About in columns 3–4 */
  .header {
    display: grid;
  }

  .name {
    grid-column: 1 / 3;
  }

  .nav {
    grid-column: 3 / 5;
  }

  .nav .header-button {
    flex: 1;
  }

  /* Project text: title block in columns 1–2, info in columns 3–4 */
  .project-heading {
    grid-column: 1 / 3;
  }

  .project-info {
    grid-column: 3 / 5;
  }

  .is-collapsible .project-info {
    padding-right: 30px; /* keeps the text clear of the plus */
  }

  /* About text: one column */
  .about-left,
  .about-right {
    grid-column: 1 / -1;
  }

  .about-right {
    margin-top: 18px;
  }

  /* About footer: not fixed on phones – it comes at the end of the page, so the text gets the whole screen */
  .page-about {
    padding-bottom: 0;
  }

  .page-about .footer {
    position: static;
    margin-top: calc(2 * var(--project-padding) + var(--space-between-projects)); /* 40px, as between projects */
  }

  /* The illustration across the whole screen, the copyright line below it on the left */
  .about-image {
    grid-column: 1 / -1;
    width: calc(100% + 2 * var(--gutter));
    height: auto;
    margin-inline: calc(-1 * var(--gutter));
  }

  .page-about .footer-text {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
