/* ---------- Tokens ---------- */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/assets/fonts/inter.woff2') format('woff2');
}

:root {
  --bg: #ffffff;
  /* Faint surfaces and lines are a tint of the text colour on the background.
     In both themes, and while the theme fades, they keep the same relative
     contrast as the text instead of crossing the background on their own. */
  --bg-subtle: color-mix(in srgb, var(--text) 4%, var(--bg));
  --text: #111316;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --border: color-mix(in srgb, var(--text) 8%, var(--bg));
  --border-strong: color-mix(in srgb, var(--text) 16%, var(--bg));
  --keyline: color-mix(in srgb, var(--text) 15%, var(--bg));
  --accent: #268fff;
  --spiro: #374151;

  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto,
    Helvetica, Arial, sans-serif;
  --column: 640px;
  --wide: 960px;
  --gutter: 20px;
  --radius: 8px;

  color-scheme: light dark;
}

/* Dark theme. theme.js sets data-theme (system setting, or the visitor's
   choice); the media query below only covers browsers without JavaScript. */
:root[data-theme='dark'] {
  --bg: #15171a;
  --text: #ededef;
  --text-secondary: #9a9ca3;
  --text-tertiary: #6b6e76;
  --accent: #5aa9ff;
  --spiro: #b4b8c0;
  color-scheme: dark;
}

:root[data-theme='light'] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #15171a;
    --text: #ededef;
    --text-secondary: #9a9ca3;
    --text-tertiary: #6b6e76;
    --accent: #5aa9ff;
    --spiro: #b4b8c0;
  }
}

/* Switching the theme by hand cross-fades the whole page (see theme.js) */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 350ms;
}

/* The spinning logo and the moving spirograph switch at once: fading their
   frozen old picture over the live one would show them twice */
.logo-button {
  view-transition-name: logo;
}

.spiro {
  view-transition-name: spiro;
}

::view-transition-old(logo),
::view-transition-old(spiro) {
  display: none;
}

::view-transition-new(logo),
::view-transition-new(spiro) {
  animation: none;
}

/* clicks still reach the page during the fade, so the logo can be clicked
   again straight away */
::view-transition {
  pointer-events: none;
}

/* ---------- Base ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.6;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img,
svg,
canvas {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
}

p {
  margin: 0 0 1em;
}

/* Avoid single-word last lines (orphans) */
p,
li,
dd,
figcaption {
  text-wrap: pretty;
}

h1,
h2,
h3 {
  text-wrap: balance;
}

h1,
h2,
h3 {
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 18px;
  margin: 1.25em 0 0.25em;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: text-decoration-color 150ms ease, color 150ms ease;
}

a:hover {
  text-decoration-color: currentColor;
}

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

ul {
  padding-left: 1.25em;
  margin: 0 0 1em;
}

li {
  margin-bottom: 0.4em;
}

.muted {
  color: var(--text-secondary);
}

/* ---------- Layout ---------- */

.page {
  max-width: calc(var(--column) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

main {
  padding: 72px 0 48px;
}

@media (max-width: 640px) {
  main {
    padding-top: 40px;
  }
}

.section {
  margin-top: 48px;
}

.section-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
  letter-spacing: 0;
}

/* Wider media block that breaks out of the text column */
.wide {
  --w: min(var(--wide), calc(100vw - var(--gutter) * 2));
  width: var(--w);
  margin-left: calc((100% - var(--w)) / 2);
}

/* ---------- Home ---------- */

.intro {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 48px;
  height: 48px;
  flex: none;
  transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.logo:hover {
  transform: rotate(-15deg);
}

:root[data-theme='dark'] .logo {
  filter: invert(1);
}

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

/* The logo is the light / dark switch */
.logo-button {
  display: block;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.intro h1 {
  font-size: 18px;
  line-height: 1.45;
}

.intro p {
  margin: 0;
  line-height: 1.45;
  color: var(--text-secondary);
  text-wrap: balance;
}

.spiro {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Spirograph figure: boxed with keylines */

.spiro-figure {
  margin: 56px 0;
  border: 1px solid var(--keyline);
  border-radius: var(--radius);
}

.spiro-stage {
  display: grid;
  place-items: center;
  padding: 32px 0;
}

.spiro-stage .spiro {
  width: min(240px, 60%);
}

@media (max-width: 640px) {
  .spiro-figure {
    margin: 40px 0;
  }
}

.spiro canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Slow counter-clockwise rotation, as in the original */
@media (prefers-reduced-motion: no-preference) {
  .spiro canvas {
    animation: spiro-rotate 60s linear infinite;
  }
}

@keyframes spiro-rotate {
  from {
    transform: rotate(360deg);
  }
  to {
    transform: rotate(0deg);
  }
}

/* List rows (projects, links) */

.list {
  list-style: none;
  padding: 0;
  margin: 0 -10px;
}

.list li {
  margin: 0;
}

.row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  transition: background-color 150ms ease;
}

a.row:hover {
  background: var(--bg-subtle);
}

.row-title {
  font-weight: 500;
  white-space: nowrap;
}

.row-desc {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.row-meta {
  margin-left: auto;
  padding-left: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 18px;
}

@media (max-width: 480px) {
  .row {
    flex-wrap: wrap;
    gap: 0 10px;
  }
  .row-desc {
    order: 3;
    flex-basis: 100%;
    white-space: normal;
  }
}

/* ---------- Article ---------- */

.back {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: 40px;
  font-size: 18px;
}

/* The arrow hangs in the left margin so the name lines up with the text
   edge below; where the margin has no room for it, it sits in front of the
   name instead. */
.back span {
  position: absolute;
  right: 100%;
  margin-right: 8px;
  transition: transform 200ms ease;
}

@media (max-width: 740px) {
  .back span {
    position: static;
  }
}

@media (min-width: 1000px) and (max-width: 1060px) {
  main:has(.article-meta) > .back span {
    position: static;
  }
}

.back:hover {
  color: var(--text);
}

.back:hover span {
  transform: translateX(-3px);
}

.article-header {
  margin-bottom: 28px;
}

.article-header h1 {
  font-size: 18px;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.article-header .subtitle {
  color: var(--text-secondary);
  margin: 0;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 24px;
  margin: 0 0 32px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 18px;
}

.facts dt {
  color: var(--text-tertiary);
}

.facts dd {
  margin: 0;
}

/* Gallery: a six-column grid of framed tiles. Each tile is a soft card with
   the image inset; spans (2/3/4/6) give each row its own rhythm while
   3 + 3 rows line up with the two text columns. */
.gallery {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 24px;
  margin-top: 48px;
  margin-bottom: 48px;
}

.tile {
  --inset: 28px;
  margin: 0;
  height: var(--h, 360px);
  padding: var(--inset);
  /* always a light surface, in dark mode too: the cut-outs and logos on
     these tiles are made for a light background */
  background: var(--tile, #f5f6f7);
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
}

/* hairline on top of the image, so it also survives the hover zoom */
.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.06);
  pointer-events: none;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Photos and screenshots: fill the tile edge to edge */
.tile[data-photo] {
  --inset: 0px;
}

.tile[data-photo] img {
  display: block;
  object-fit: cover;
}

/* A tall white screenshot: a sheet on the grey tile, top-aligned and
   running off the bottom edge so it stays large enough to read */
.tile[data-screen] {
  padding-bottom: 0;
}

.tile[data-screen] img {
  display: block;
  height: auto;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.06);
}

/* Tiles that take their height from the image */
.tile[data-natural] {
  height: auto;
}

.tile[data-natural] img {
  height: auto;
}

/* A tile on its own inside running text */
:not(.gallery) > .tile {
  margin: 32px 0;
}

.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }

@media (max-width: 640px) {
  .gallery {
    gap: 12px;
  }
  .gallery > .tile {
    --inset: 16px;
    grid-column: 1 / -1;
    height: auto;
  }
  .gallery > .tile[data-photo] {
    --inset: 0px;
  }
  .gallery > .tile img {
    height: auto;
  }
}

/* ---------- Contact ---------- */

.profile {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin-bottom: 24px;
  background: var(--bg-subtle);
}

.form {
  margin-top: 28px;
  display: grid;
  gap: 16px;
}

.field label {
  display: block;
  font-size: 18px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input,
.field textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.field textarea {
  min-height: 180px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.button {
  justify-self: start;
  font: inherit;
  font-weight: 500;
  color: var(--bg);
  background: var(--text);
  border: 0;
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
  transition: opacity 150ms ease;
}

.button:hover {
  opacity: 0.85;
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

.form-status {
  font-size: 18px;
  color: var(--text-secondary);
  min-height: 1.6em;
  margin: 0;
}

.form-note {
  font-size: 16px;
  color: var(--text-tertiary);
  margin: 0;
}

.form-status[data-state='success'] {
  color: #16a34a;
}

.form-status[data-state='error'] {
  color: #dc2626;
}

/* ---------- Footer ---------- */

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  white-space: nowrap;
  padding: 24px 0 40px;
  border-top: 1px solid var(--border);
  font-size: 16px;
  color: var(--text-tertiary);
}

.footer a {
  color: inherit;
  text-decoration: none;
}

.footer a:hover {
  color: var(--text);
}

.footer nav {
  display: flex;
  gap: 16px;
}

/* ---------- Page entrance ---------- */

@media (prefers-reduced-motion: no-preference) {
  .reveal > * {
    animation: reveal 600ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .reveal > *:nth-child(2) { animation-delay: 60ms; }
  .reveal > *:nth-child(3) { animation-delay: 120ms; }
  .reveal > *:nth-child(4) { animation-delay: 180ms; }
  .reveal > *:nth-child(5) { animation-delay: 240ms; }
  .reveal > *:nth-child(n + 6) { animation-delay: 300ms; }

  @keyframes reveal {
    from {
      opacity: 0;
      transform: translateY(6px);
      filter: blur(2px);
    }
    to {
      opacity: 1;
      transform: none;
      filter: none;
    }
  }
}

/* ---------- Article pages, two columns (desktop) ----------
   Title + facts left, text right. The two columns are the same two columns
   the image grid uses, so text and images share every edge. */

@media (min-width: 1000px) {
  .page:has(.article-meta) {
    max-width: calc(var(--wide) + var(--gutter) * 2);
  }

  main:has(.article-meta) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 24px;
    align-items: start;
  }

  /* running content lives in the right column */
  main:has(.article-meta) > * {
    grid-column: 2;
  }

  main > .article-meta {
    grid-column: 1;
  }

  main > .back,
  main > .wide {
    grid-column: 1 / -1;
  }

  /* keyline 1: full width, under the back link */
  main:has(.article-meta) > .back {
    display: flex;
    padding-bottom: 20px;
    margin-bottom: 28px;
    border-bottom: 1px solid var(--keyline);
  }

  /* keyline 2: full width, between the intro and the images */
  main > .article-body + .wide {
    margin-top: 40px;
    padding-top: 40px;
    border-top: 1px solid var(--keyline);
  }

  /* no partial-width rules inside the columns */
  .article-meta .article-header {
    margin-bottom: 0;
  }

  .article-meta h1 {
    line-height: 1.6; /* same first baseline as the text column */
    margin-bottom: 0;
  }

  .article-meta .facts {
    margin: 24px 0 0;
    padding: 0;
    border: 0;
  }

  .article-body > :last-child {
    margin-bottom: 0;
  }

  /* Long articles: after the intro, the running text is one centred
     column; screenshots inside it span the full width */
  main:has(.article-meta) > :not(.back, .article-meta, .article-body, .wide, .tile) {
    grid-column: 1 / -1;
    justify-self: center;
    width: 100%;
    max-width: var(--column);
  }

  /* 72px above and below every in-article image – clearly more than the
     gap between paragraphs (17px) or above a heading (38px) */
  main:has(.article-meta) > .tile {
    grid-column: 1 / -1;
    margin: 72px 0;
  }

  main:has(.article-meta) > :has(+ .tile) {
    margin-bottom: 0;
  }

  main:has(.article-meta) > .gallery + h3 {
    margin-top: 24px;
  }
}

/* ---------- Home, two columns (desktop) ----------
   Identity (logo, name, spirograph) left and fixed while scrolling,
   content right, with generous space around both. */

@media (min-width: 1000px) {
  .page:has(.home-side) {
    max-width: calc(var(--wide) + var(--gutter) * 2);
  }

  main:has(> .home-side) {
    display: grid;
    /* left column just wide enough for logo + one-line subtitle */
    grid-template-columns: 352px minmax(0, 1fr);
    column-gap: 72px;
    align-items: start;
    padding-top: 144px;
    padding-bottom: 120px;
  }

  .home-side {
    position: sticky;
    top: 144px;
  }

  .home-side .intro p {
    white-space: nowrap;
  }

  /* first text line on the same baseline as the name */
  .home-main {
    padding-top: 2px;
  }

  /* spirograph without its frame, left-aligned under the name */
  .home-side .spiro-figure {
    margin: 72px 0 0;
    border: 0;
    border-radius: 0;
  }

  .home-side .spiro-stage {
    padding: 0;
    place-items: start;
  }

  .home-side .spiro-stage .spiro {
    width: 220px;
  }

  .home-main .section {
    margin-top: 96px;
  }
}

/* ---------- Image hover and lightbox ---------- */

.tile {
  cursor: zoom-in;
}

.tile img {
  transition: transform 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .tile:hover img {
    transform: scale(1.015);
  }
}

.lightbox {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 24px 72px;
  box-sizing: border-box;
  overflow: hidden;
  border: 0;
  background: var(--bg);
  cursor: zoom-out;
  outline: none; /* the dialog holds the focus while open */
  touch-action: pan-y pinch-zoom; /* sideways swipes belong to the gallery */
}

.lightbox[open] {
  display: grid;
  place-items: center;
}

.lightbox::backdrop {
  background: var(--bg);
}

.lightbox img {
  max-width: 100%;
  max-height: calc(100dvh - 48px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius);
  outline: 1px solid rgb(0 0 0 / 0.06);
  outline-offset: -1px;
}

.lightbox img.lightbox-framed {
  padding: 4vmin;
  box-sizing: border-box;
}

.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  font: inherit;
  font-size: 16px;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--keyline);
  border-radius: 50%;
  cursor: pointer;
}

.lightbox-close:hover {
  color: var(--text);
}

@media (prefers-reduced-motion: no-preference) {
  .lightbox[open] img {
    animation: lightbox-in 250ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  @keyframes lightbox-in {
    from {
      opacity: 0;
      transform: scale(0.97);
    }
  }
}

@media (max-width: 640px) {
  .lightbox {
    padding: 64px 12px 24px;
  }
}

/* no page scrolling behind the open lightbox */
html:has(.lightbox[open]) {
  overflow: hidden;
}
