/* Self-hosted Google Fonts (latin subset, SIL Open Font License) */
@font-face {
  font-family: Hind;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/hind-400.woff2") format("woff2");
}

@font-face {
  font-family: Hind;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/hind-600.woff2") format("woff2");
}

@font-face {
  font-family: Montserrat;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/montserrat-700.woff2") format("woff2");
}

* {
  box-sizing: border-box;
}

:root {
  --gutter: 1.5rem;
  --bg: #f3f7fc;
  --tint: #e4edf8; /* mobile nav */
  --text: #13294b;
  --accent: #3a6aa8; /* lighter blue that still meets WCAG AA */
}

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  max-width: 66rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
  font: 1.0625rem/1.6 Hind, sans-serif;
  color: var(--text);
  background: var(--bg);
  /* Fade in on load, fade out before switching language (script.js) */
  animation: fade-in 0.6s ease-out;
  transition: opacity 0.2s;
}

body.leaving {
  opacity: 0;
}

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

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  body,
  nav,
  section *,
  section::before {
    animation: none !important;
    transition: none;
  }
}

h1,
h2,
h3 {
  font-family: Montserrat, sans-serif;
  line-height: 1.3;
}

h1,
h2 {
  margin: 0 0 2rem;
  font-size: 2.5rem;
}

h3 {
  margin: 1rem 0 0.25rem;
  font-size: 1.375rem;
}

p {
  max-width: 40em;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
  transition: color 0.2s;
}

/* Hover and keyboard focus */
a:hover,
a:focus-visible {
  color: var(--accent);
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 2px;
}

img {
  display: block;
  width: 100%;
  height: auto;
}

/* Rounded corners in step with the wave curve */
img,
.placeholder {
  border-radius: 8px;
}

/* Images, placeholders and the mobile nav get a wavy bottom edge */
img,
.placeholder,
nav {
  --wave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 14'%3E%3Cpath d='M0 0H40V7Q30 14 20 7T0 7Z'/%3E%3C/svg%3E");
  mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - 13px) no-repeat,
    var(--wave) bottom / 40px 14px repeat-x;
}

/* Stands in for a missing image */
.placeholder {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  font-family: Montserrat, sans-serif;
  font-weight: 700;
  color: var(--bg);
  background: var(--text);
}

/* Mobile: sticky bar at the top */
nav {
  position: sticky;
  top: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between; /* first and last link sit on the margins */
  gap: 0.5rem 0.6em;
  z-index: 1; /* above the masked images */
  margin: 0 calc(-1 * var(--gutter));
  padding: 1rem var(--gutter) 1.5rem;
  font-family: Montserrat, sans-serif;
  font-weight: 700;
  font-size: min(3.4vw, 1.25rem); /* fits one line on a phone */
  background: var(--tint);
}

nav a {
  text-decoration: none;
}

/* Section in view (set by script.js) */
nav a[aria-current] {
  color: var(--accent);
}

section {
  position: relative;
  padding: 4rem 0;
  scroll-margin-top: 2rem;
}

/* Wavy line between sections */

section + section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 14px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 14'%3E%3Cpath d='M0 7Q10 0 20 7T40 7' fill='none' stroke='%23dce6f4' stroke-width='3'/%3E%3C/svg%3E") left top / 40px 14px repeat-x;
}

/* First load: sections appear one by one, each as the wave above it draws in.
   Mobile keeps it short and shows everything below Kirjat at once, so scrolling never waits. */
section > *,
#johanna > div > *,
#johanna h1 span {
  animation: rise 0.4s ease-out backwards;
}

section::before {
  animation: draw 0.6s ease-in-out backwards;
}

#johanna > div {
  animation: none;
}

#johanna h1 { animation-delay: 0.1s; }
#johanna h1 span { animation-delay: 0.2s; }
#johanna p { animation-delay: 0.3s; }
#books::before { animation-delay: 0.4s; }
#books > * { animation-delay: 0.6s; }

#articles > *,
#articles::before,
#projects > *,
#projects::before {
  animation: none;
}

nav {
  animation: fade-in 0.3s ease-out backwards;
}

/* Desktop: the full, slower sequence */
@media (min-width: 60rem) {
  section > *,
  #johanna > div > *,
  #johanna h1 span {
    animation: rise 0.5s ease-out backwards;
  }

  section::before {
    animation: draw 1s ease-in-out backwards;
  }

  #johanna h1 { animation-delay: 0.2s; }
  #johanna h1 span { animation-delay: 0.4s; }
  #johanna p { animation-delay: 0.6s; }
  #books::before { animation-delay: 1s; }
  #books > * { animation-delay: 1.5s; }
  #articles::before { animation: draw 1s ease-in-out 1.9s backwards; }
  #articles > * { animation: rise 0.5s ease-out 2.4s backwards; }
  #projects::before { animation: draw 1s ease-in-out 2.8s backwards; }
  #projects > * { animation: rise 0.5s ease-out 3.3s backwards; }

  nav {
    animation: fade-in 0.5s ease-out 1.9s backwards;
  }
}

/* Switching language opens mid-page, so skip the sequence (script.js) */
.switched nav,
.switched section *,
.switched section::before {
  animation: none !important;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(1rem);
  }
}

@keyframes draw {
  from {
    width: 0;
  }
}

article p {
  margin: 0.25rem 0;
}

/* First line under a book or project title: publisher or role */
#books h3 + p,
#projects h3 + p {
  margin: 0.75rem 0;
  font-weight: 600;
}

/* One column on mobile, two on desktop */
.grid,
.intro {
  display: grid;
  gap: 4rem 3.5rem;
}

.intro {
  row-gap: 1.5rem;
}

.grid {
  margin-top: 4rem;
}

.grid img {
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

/* Below desktop the name scales with the screen so it always fits on one line */
.intro h1 {
  font-size: min(3rem, calc((100vw - 2 * var(--gutter)) / 14));
  line-height: 1.1;
}

/* Tagline under the name */
.intro h1 span {
  display: block;
  margin-top: 0.3em;
  font-size: 1.25rem;
  color: var(--accent);
}

figure {
  margin: 0;
}

/* Low portrait crop on mobile; on desktop it stretches to the text height */
.intro img {
  aspect-ratio: 8 / 5;
  object-fit: cover;
  object-position: 50% 30%;
}

figcaption,
.credit {
  font-size: 0.75rem;
  color: #4a73a6; /* palest blue that passes WCAG AA (4.55:1) */
}

figcaption {
  padding-top: 0.5rem;
  text-align: center;
}

/* Photo credit under a card image */
.credit {
  margin: 0.5rem 0 0;
}

/* Tablet and up: two columns of cards */
@media (min-width: 40rem) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }

  .grid img,
  .placeholder {
    aspect-ratio: 1;
  }
}

/* Desktop: sticky column on the left */
@media (min-width: 60rem) {
  :root {
    --gutter: 3rem;
  }

  body {
    display: grid;
    grid-template-columns: 8rem 1fr;
    gap: 3rem;
    font-size: 1rem;
  }

  main {
    grid-column: 2;
  }

  nav {
    flex-direction: column;
    align-self: start;
    margin: 0;
    padding: 4rem 0 0;
    background: none;
    mask: none;
  }

  section {
    scroll-margin-top: 0;
  }

  h3 {
    font-size: 1.5rem;
  }

  /* Smaller portrait, wider text */
  .intro {
    grid-template-columns: 1fr 2fr;
  }

  .intro h1 {
    font-size: clamp(2.5rem, 4vw, 3rem);
  }

  /* Portrait as tall as the text next to it */
  .intro figure {
    display: flex;
    flex-direction: column;
  }

  .intro img {
    flex: 1 1 0;
    min-height: 0;
  }
}

/* Large desktop: everything a bit bigger */
@media (min-width: 80rem) {
  html {
    font-size: 118.75%;
  }
}
