/*
 * Every colour and font is defined once, in the tokens layer. The canvases read
 * the same custom properties, so changing a colour here changes it everywhere.
 *
 * Nothing moves unless <html> has data-motion="on", which head.js only sets when
 * motion is allowed. Without JavaScript, every page is a still version of itself.
 *
 * Layers are listed lowest priority first.
 */

@layer reset, tokens, base, layout, components, motion, utilities;

@font-face {
  font-family: "TeX Gyre Heros";
  src: url("../fonts/texgyreheros-regular.433835b68901.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "TeX Gyre Heros";
  src: url("../fonts/texgyreheros-bold.10620aebae10.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* The screens' typefaces, on the projects page and the write-ups. Browsers only fetch them on
   the pages that use them. */
@font-face {
  font-family: "VT323";
  src: url("../fonts/vt323-regular.3be46ad2710a.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Michroma";
  src: url("../fonts/michroma-regular.21261707682e.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

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

  * {
    margin: 0;
  }

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

  img,
  picture,
  svg,
  video,
  canvas {
    display: block;
    max-inline-size: 100%;
  }

  input,
  button,
  textarea,
  select {
    font: inherit;
    color: inherit;
  }

  h1,
  h2,
  h3,
  p {
    overflow-wrap: break-word;
  }
}

@layer tokens {
  :root {
    color-scheme: dark;

    /* Page colours. Night is the default; day is below. */
    --page: #0c1824;
    --surface: #13263a;
    --rule: #2e4c66;
    --text: #dfe9f0;
    --muted: #8ea7ba;
    --link: var(--accent);
    --led-off: #5b7178;

    /* Colours used at more than one opacity are kept as channels,
       e.g. rgb(var(--accent-rgb) / 0.5). */
    --accent-rgb: 141 242 189;
    --accent: rgb(var(--accent-rgb));
    --accent-ink: #06171c;
    --glow-rgb: 236 255 246;
    --brand-glow: 0 0 10px rgb(var(--accent-rgb) / 0.6);

    /* The screens (the hero, project screens and panels) stay dark in both themes. */
    --screen-text-rgb: 227 237 244;
    --screen-dim-rgb: 159 182 200;
    --screen-haze-rgb: 56 122 152;
    --screen-text: rgb(var(--screen-text-rgb));
    --screen-dim: rgb(var(--screen-dim-rgb));
    --screen-soft: #b9cbd8;
    --screen-edge: rgb(var(--screen-dim-rgb) / 0.24);
    --screen-deep: #0b1a29;
    --screen-mid: #123049;
    --screen-base: linear-gradient(160deg, var(--screen-deep), var(--screen-mid));
    --hero-top: #08141f;
    --hero-middle: #0d2233;
    --hero-bottom: #102b42;
    --console-glass: rgb(3 10 18 / 0.55);
    --tube-rgb: 4 10 16;
    --tube: rgb(var(--tube-rgb));
    --halo: #06101a;

    /* The VHS name: colour fringes, a soft bloom and two torn slices. */
    --name: #eef5fa;
    --fringe-red-rgb: 255 70 130;
    --fringe-blue-rgb: 80 200 255;
    --bloom-rgb: 143 211 255;
    --slice-upper: #a9f6ff;
    --slice-lower: #ffb8d8;

    --rec-rgb: 255 107 99;
    --sell: #ff9ec4;

    /* Type */
    --font-sans: "TeX Gyre Heros", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
    /* For the katakana in the code rain, which only system fonts have. */
    --font-katakana: "MS Gothic", "Yu Gothic", "Hiragino Sans", "Noto Sans CJK JP", "Noto Sans JP", monospace;

    /* Layout */
    --page-width: 1280px;
    --gutter: clamp(16px, 4vw, 56px);
    --section-gap: clamp(64px, 4rem + 2vw, 96px);
    --radius-screen: 12px;
    --radius-button: 6px;
  }

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

    --page: #e2e9ee;
    --surface: #eef3f6;
    --rule: #b4c3ce;
    --text: #0f1e2b;
    --muted: #4a6072;
    /* The accent at 42% brightness, dark enough for text on the light page. */
    --link: #3b664f;
    --brand-glow: none;
  }
}

@layer base {
  html {
    background-color: var(--page);
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Keeps the layout still when the intro hides the scrollbar. */
    scrollbar-gutter: stable;
    scroll-padding-block-start: 24px;
  }

  body {
    min-block-size: 100vh;
    min-block-size: 100dvh;
    font-size: 1.125rem;
  }

  a {
    color: inherit;
  }

  code {
    font-family: var(--font-mono);
  }

  ::selection {
    background-color: rgb(var(--accent-rgb) / 0.3);
  }
}

@layer layout {
  /* The gutters widen where a phone's notch or rounded corners need them. */
  .page {
    inline-size: min(
      100% - 2 * max(var(--gutter), env(safe-area-inset-left), env(safe-area-inset-right)),
      var(--page-width)
    );
    margin-inline: auto;
  }

  /* Focused by the skip link; no outline needed round the whole page. */
  .site-main:focus {
    outline: none;
  }
}

@layer components {
  /* Off-screen until focused. */
  .skip-link {
    position: absolute;
    inset-block-start: 12px;
    inset-inline-start: 12px;
    z-index: 60;
    padding: 10px 16px;
    border-radius: var(--radius-button);
    background-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    text-decoration: none;
    transform: translateY(-200%);
  }

  .skip-link:focus {
    transform: none;
  }

  /* Header */

  .site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 40px;
    padding-block: 24px 18px;
    border-block-end: 1px solid var(--rule);
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-block-size: 44px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 1.0625rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-decoration: none;
    text-transform: lowercase;
  }

  .brand__prompt {
    color: var(--link);
  }

  /* Wide enough for the full name, so the nav doesn't shift as the readout types. */
  .brand__readout {
    display: inline-block;
    min-inline-size: 18.5ch;
    white-space: pre;
  }

  .brand[data-hot] .brand__text {
    color: var(--link);
    text-shadow: var(--brand-glow);
  }

  .brand__cursor {
    display: inline-block;
    inline-size: 0.6em;
    block-size: 1.1em;
    margin-inline-start: 2px;
    vertical-align: -0.2em;
    background-color: var(--link);
    opacity: 0;
  }

  .brand[data-cursor] .brand__cursor {
    opacity: 1;
  }

  .primary-nav__list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px clamp(20px, 2vw, 28px);
    padding: 0;
    list-style: none;
  }

  .primary-nav__link {
    display: inline-flex;
    align-items: center;
    min-block-size: 44px;
    border-block-end: 2px solid transparent;
    color: var(--muted);
    font-size: 1rem;
    font-weight: 700;
    text-decoration: none;
    text-transform: lowercase;
  }

  .primary-nav__link[aria-current] {
    border-block-end-color: var(--link);
    color: var(--text);
  }

  /* Buttons */

  .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-block-size: 46px;
    padding: 0 22px;
    border: 1px solid transparent;
    border-radius: var(--radius-button);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    text-transform: lowercase;
    cursor: pointer;
  }

  .button--primary {
    background: linear-gradient(to bottom, rgb(var(--accent-rgb) / 0.98), rgb(var(--accent-rgb) / 0.78));
    color: var(--accent-ink);
    box-shadow:
      0 0 26px rgb(var(--accent-rgb) / 0.28),
      inset 0 1px 0 rgb(255 255 255 / 0.5);
  }

  /* For use on screens, which are dark in both themes. */
  .button--secondary {
    border-color: rgb(var(--screen-text-rgb) / 0.38);
    background: linear-gradient(to bottom, rgb(255 255 255 / 0.12), rgb(255 255 255 / 0.02));
    color: var(--screen-text);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.2);
    transition:
      border-color 0.2s ease,
      box-shadow 0.2s ease,
      color 0.2s ease,
      transform 0.2s ease;
  }

  /* Lit up like the project cards when pointed at or tabbed to, so it's clear they lead
     somewhere. */
  .button--secondary:focus-visible {
    border-color: rgb(var(--accent-rgb) / 0.7);
    color: var(--accent);
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 0.2),
      0 8px 20px -10px rgb(0 0 0 / 0.8),
      0 0 18px -4px rgb(var(--accent-rgb) / 0.35);
  }

  [data-motion="on"] .button--secondary:focus-visible {
    transform: translateY(-2px);
  }

  .button--quiet {
    min-block-size: 44px;
    padding: 0 18px;
    border-color: var(--rule);
    background: transparent;
    color: var(--text);
    font-size: 0.9375rem;
  }

  .button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

  @media (hover: hover) {
    .primary-nav__link:hover {
      color: var(--text);
    }

    .button--primary:hover {
      filter: brightness(1.06);
    }

    .button--secondary:hover {
      border-color: rgb(var(--accent-rgb) / 0.7);
      color: var(--accent);
      box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.2),
        0 8px 20px -10px rgb(0 0 0 / 0.8),
        0 0 18px -4px rgb(var(--accent-rgb) / 0.35);
    }

    [data-motion="on"] .button--secondary:hover {
      transform: translateY(-2px);
    }

    .button--quiet:hover:not(:disabled) {
      border-color: var(--muted);
    }
  }

  /* Screens: the dark, textured panels the hero, project cards and panels sit on.
     The grain and scanlines go behind the content but over the background. */

  .screen {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    border: 1px solid var(--screen-edge);
    border-radius: var(--radius-screen);
    background: var(--screen-base);
    box-shadow: inset 0 0 60px rgb(0 0 0 / 0.5);
    color: var(--screen-text);
  }

  .screen::before,
  .screen::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
  }

  .screen::before {
    background: url("../img/grain.1a76619ec888.webp") 0 0 / 192px 192px;
    mix-blend-mode: soft-light;
    opacity: 0.9;
  }

  .screen::after {
    background: repeating-linear-gradient(
      to bottom,
      rgb(255 255 255 / 0.04) 0 1px,
      transparent 1px 3px
    );
  }

  /* Hero */

  .hero {
    margin-block-start: clamp(24px, 3vw, 36px);
    border-radius: 18px;
    background:
      radial-gradient(70% 80% at 76% 46%, rgb(var(--accent-rgb) / 0.13), transparent 60%),
      radial-gradient(110% 85% at 88% 10%, rgb(var(--screen-haze-rgb) / 0.45), transparent 62%),
      linear-gradient(160deg, var(--hero-top) 0%, var(--hero-middle) 55%, var(--hero-bottom) 100%);
    box-shadow: inset 0 0 140px rgb(0 0 0 / 0.6);
  }

  /* A grid floor running off towards the horizon. The grid inside is a cell
     taller than the floor, so sliding it down one cell loops seamlessly. */
  .hero__floor {
    position: absolute;
    inset: auto -25% 0;
    z-index: -1;
    block-size: 50%;
    overflow: hidden;
    pointer-events: none;
    transform-origin: 50% 100%;
    transform: perspective(420px) rotateX(60deg);
    -webkit-mask-image: linear-gradient(to top, #000 15%, transparent 92%);
    mask-image: linear-gradient(to top, #000 15%, transparent 92%);
  }

  .hero__grid {
    position: absolute;
    inset: -56px 0 0;
    background-image:
      linear-gradient(rgb(var(--accent-rgb) / 0.34) 1px, transparent 1px),
      linear-gradient(90deg, rgb(var(--accent-rgb) / 0.34) 1px, transparent 1px);
    background-size: 56px 56px;
  }

  /* The glow along the floor, and a vignette. */
  .hero__glow {
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
      radial-gradient(60% 34% at 50% 100%, rgb(var(--accent-rgb) / 0.16), transparent 100%),
      radial-gradient(ellipse at center, transparent 58%, rgb(0 0 0 / 0.45) 100%);
  }

  /* Viewfinder brackets in each corner, tucked further in on small screens. */
  .hero__frame {
    --bracket: linear-gradient(rgb(var(--screen-text-rgb) / 0.55), rgb(var(--screen-text-rgb) / 0.55));
    --arm: clamp(14px, 1.6vw, 22px);

    position: absolute;
    inset: clamp(12px, 1.4vw, 20px);
    z-index: -1;
    pointer-events: none;
    background:
      var(--bracket) top left / var(--arm) 1.5px,
      var(--bracket) top left / 1.5px var(--arm),
      var(--bracket) top right / var(--arm) 1.5px,
      var(--bracket) top right / 1.5px var(--arm),
      var(--bracket) bottom left / var(--arm) 1.5px,
      var(--bracket) bottom left / 1.5px var(--arm),
      var(--bracket) bottom right / var(--arm) 1.5px,
      var(--bracket) bottom right / 1.5px var(--arm);
    background-repeat: no-repeat;
  }

  .hero__body {
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: clamp(36px, 4vw, 48px) clamp(28px, 4.5vw, 60px);
  }

  .hero__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    font-family: var(--font-mono);
  }

  .hero__meta--top {
    font-size: 0.875rem;
    letter-spacing: 0.14em;
  }

  .hero__meta--bottom {
    font-size: 0.8125rem;
    letter-spacing: 0.08em;
  }

  .hero__rec {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .hero__rec::before {
    content: "";
    inline-size: 10px;
    block-size: 10px;
    border-radius: 50%;
    background-color: rgb(var(--rec-rgb));
    box-shadow: 0 0 10px rgb(var(--rec-rgb) / 0.85);
  }

  .hero__uplink {
    color: var(--screen-dim);
  }

  .hero__date {
    text-transform: uppercase;
  }

  .hero__main {
    display: grid;
    align-items: center;
    gap: 32px 40px;
  }

  .hero__text {
    min-inline-size: 0;
    container-type: inline-size;
  }

  .hero__title {
    position: relative;
    inline-size: fit-content;
  }

  /* min-content puts each word of the name on its own line. The slices are
     copies laid exactly over it, shown for a few frames when it glitches. */
  .hero__name,
  .hero__slice {
    inline-size: min-content;
    padding: 0 0.06em 0.04em 0;
    font-size: clamp(2.5rem, 9vw, 8rem);
    font-size: clamp(2.5rem, 17.5cqi, 8rem);
    font-weight: 700;
    line-height: 0.86;
    letter-spacing: -0.05em;
    text-transform: lowercase;
  }

  .hero__name {
    color: var(--name);
    opacity: 0.94;
    text-shadow:
      -3px 0 rgb(var(--fringe-red-rgb) / 0.38),
      3px 0 rgb(var(--fringe-blue-rgb) / 0.42),
      0 0 36px rgb(var(--bloom-rgb) / 0.28);
    filter: blur(0.3px);
  }

  .hero__slice {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
  }

  .hero__slice--upper {
    color: var(--slice-upper);
    text-shadow: -4px 0 rgb(var(--fringe-red-rgb) / 0.7);
    clip-path: inset(30% 0 52% 0);
  }

  .hero__slice--lower {
    color: var(--slice-lower);
    text-shadow: 4px 0 rgb(var(--fringe-blue-rgb) / 0.7);
    clip-path: inset(66% 0 14% 0);
  }

  .hero__role {
    margin-block-start: 24px;
    color: var(--screen-dim);
    font-size: clamp(1.25rem, 1rem + 1vw, 1.5rem);
    line-height: 1.3;
    letter-spacing: -0.01em;
    text-transform: lowercase;
  }

  .hero__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-block-start: 24px;
  }

  .hero__visual {
    display: grid;
    grid-template-columns: minmax(0, 470px) 56px;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }

  .hero__globe {
    grid-area: 1 / 1;
    inline-size: 100%;
    block-size: auto;
    aspect-ratio: 1;
  }

  /* As tall as the globe allows, up to the 430px it was drawn at. */
  .hero__rain {
    grid-area: 1 / 2;
    inline-size: 56px;
    block-size: min(430px, 91%);
    object-fit: cover;
    object-position: top;
    opacity: 0.9;
  }

  /* A strip of tape noise along the bottom edge. */
  .hero__noise {
    position: absolute;
    inset: auto 0 0;
    block-size: 6px;
    pointer-events: none;
    background: url("../img/noise.c653cea56870.webp") 0 0 / 160px 160px;
    opacity: 0.35;
  }

  /* Console */

  .console {
    position: relative;
    max-inline-size: 560px;
    margin-block-start: 24px;
    border: 1px solid rgb(var(--accent-rgb) / 0.32);
    border-radius: 8px;
    background-color: var(--console-glass);
    box-shadow:
      0 0 30px rgb(var(--accent-rgb) / 0.08),
      inset 0 0 24px rgb(var(--accent-rgb) / 0.05);
    font-family: var(--font-mono);
  }

  .console__bar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 7px 14px;
    border-block-end: 1px solid rgb(var(--accent-rgb) / 0.2);
    color: var(--screen-dim);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
  }

  /* A fixed height, so nothing below moves as lines appear. console.js keeps
     it scrolled to the newest line, as a terminal would. */
  .console__screen {
    block-size: 230px;
    padding: 12px 16px 14px;
    overflow: hidden;
    font-size: 0.875rem;
    line-height: 1.6;
  }

  .console__script {
    padding: 0;
    list-style: none;
  }

  .console__script > li {
    min-block-size: 1.6em;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .console__command {
    color: var(--screen-text);
  }

  .console__command::before {
    content: "> ";
    color: var(--accent);
  }

  .console__output {
    color: var(--screen-soft);
  }

  .console__ok {
    color: var(--accent);
  }

  .console__cursor {
    display: inline-block;
    inline-size: 0.6em;
    block-size: 1.1em;
    margin-inline-start: 2px;
    vertical-align: -0.2em;
    background-color: var(--accent);
    box-shadow: 0 0 8px rgb(var(--accent-rgb) / 0.6);
  }

  .console__cursor[data-off] {
    opacity: 0;
  }

  /* Projects */

  .projects {
    margin-block-start: var(--section-gap);
  }

  .section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px 24px;
    padding-block-end: 18px;
    border-block-end: 1px solid var(--rule);
  }

  .section-head__title {
    font-size: clamp(1.875rem, 1.5rem + 1vw, 2.25rem);
    line-height: 1;
    letter-spacing: -0.035em;
    text-transform: lowercase;
  }

  .project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 28px;
    margin-block-start: 32px;
  }

  .project-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .project-card__link {
    color: inherit;
    text-decoration: none;
  }

  /* Stretched over the whole card, so all of it is the link. */
  .project-card__link::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: var(--radius-screen);
  }

  .project-card__link:focus-visible {
    outline: none;
  }

  .project-card:has(.project-card__link:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 6px;
    border-radius: var(--radius-screen);
  }

  .section-head__link {
    color: var(--link);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    text-decoration: none;
  }

  .project-card__screen {
    aspect-ratio: 16 / 10;
  }

  .project-card__title {
    margin-block-start: 4px;
    font-size: 1.5rem;
    line-height: 1.15;
    letter-spacing: -0.025em;
    text-transform: lowercase;
  }

  .project-card__summary {
    color: var(--muted);
    font-size: 1rem;
  }

  /* Hovered or focused, a card's screen lifts a little and lights up at the edge, to show the
     card leads somewhere. It only moves when motion is on. */
  .project-card__screen {
    transition:
      border-color 0.25s ease,
      box-shadow 0.25s ease,
      transform 0.25s ease;
  }

  .project-card:has(.project-card__link:focus-visible) .project-card__screen {
    border-color: rgb(var(--accent-rgb) / 0.55);
    box-shadow:
      0 16px 34px -14px rgb(0 0 0 / 0.75),
      0 0 26px -6px rgb(var(--accent-rgb) / 0.3);
  }

  [data-motion="on"] .project-card:has(.project-card__link:focus-visible) .project-card__screen {
    transform: translateY(-4px);
  }

  @media (hover: hover) {
    .project-card:hover .project-card__title,
    .section-head__link:hover {
      color: var(--accent);
    }

    .project-card:hover .project-card__screen {
      border-color: rgb(var(--accent-rgb) / 0.55);
      box-shadow:
        0 16px 34px -14px rgb(0 0 0 / 0.75),
        0 0 26px -6px rgb(var(--accent-rgb) / 0.3);
    }

    [data-motion="on"] .project-card:hover .project-card__screen {
      transform: translateY(-4px);
    }
  }

  .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-block-start: 2px;
    padding: 0;
    list-style: none;
    color: var(--muted);
    font-size: 0.8125rem;
  }

  .tag {
    padding: 3px 10px;
    border: 1px solid var(--rule);
    border-radius: 4px;
    text-transform: lowercase;
  }

  /* Each project's screen. The --art insets place the still image, and
     project-screens.js reads them to draw the animation in the same place. */

  .screen--site {
    --art-top: 18%;
    --art-side: 14%;
    --art-bottom: 12%;

    background:
      radial-gradient(80% 70% at 70% 30%, rgb(var(--screen-haze-rgb) / 0.45), transparent 65%),
      var(--screen-base);
  }

  .screen--forecast {
    --art-top: 20%;
    --art-side: 10%;
    --art-bottom: 12%;

    background:
      radial-gradient(80% 70% at 75% 35%, rgb(var(--accent-rgb) / 0.16), transparent 65%),
      var(--screen-base);
  }

  .screen--backtest {
    --art-top: 20%;
    --art-side: 8%;
    --art-bottom: 8%;

    background:
      radial-gradient(80% 70% at 30% 40%, rgb(var(--screen-haze-rgb) / 0.4), transparent 65%),
      var(--screen-base);
  }

  .screen__canvas {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
  }

  .screen__still {
    position: absolute;
    inset-block-start: var(--art-top);
    inset-inline-start: var(--art-side);
    inline-size: calc(100% - 2 * var(--art-side));
    block-size: calc(100% - var(--art-top) - var(--art-bottom));
    overflow: visible;
  }

  .screen__label,
  .screen__status {
    position: absolute;
    inset-block-start: 14px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
  }

  .screen__label {
    inset-inline-start: 16px;
    color: var(--screen-dim);
  }

  .screen__status {
    inset-inline-end: 16px;
    color: var(--accent);
  }

  /* The still images' strokes and fills, matching the animations. */

  .art-outline,
  .art-globe,
  .art-bars,
  .art-grid,
  .art-axis,
  .art-now,
  .art-series,
  .art-forecast,
  .art-price {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .art-outline {
    stroke: rgb(var(--accent-rgb) / 0.65);
  }

  .art-globe {
    stroke: rgb(var(--accent-rgb) / 0.75);
  }

  .art-bars {
    stroke: rgb(var(--accent-rgb) / 0.8);
    stroke-width: 3;
  }

  .art-grid {
    stroke: rgb(var(--screen-dim-rgb) / 0.35);
    stroke-width: 0.8;
    stroke-dasharray: 2 4;
    stroke-linecap: butt;
  }

  .art-axis {
    stroke: rgb(var(--screen-dim-rgb) / 0.6);
  }

  .art-now {
    stroke: rgb(var(--screen-text-rgb) / 0.35);
    stroke-dasharray: 3 3;
    stroke-linecap: butt;
  }

  .art-shade-start {
    stop-color: var(--accent);
    stop-opacity: 0.2;
  }

  .art-shade-end {
    stop-color: var(--accent);
    stop-opacity: 0;
  }

  .art-cone,
  .art-equity-area {
    fill: rgb(var(--accent-rgb) / 0.14);
  }

  .art-series {
    stroke: var(--accent);
    stroke-width: 1.6;
  }

  .art-forecast {
    stroke: var(--accent);
    stroke-width: 2.2;
    stroke-dasharray: 0.1 6;
  }

  .art-point,
  .art-buy {
    fill: var(--accent);
  }

  .art-price {
    stroke: rgb(var(--screen-text-rgb) / 0.5);
    stroke-width: 1.2;
  }

  .art-sell {
    fill: var(--sell);
  }

  /* CV and contact panels */

  .panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 28px;
    margin-block-start: var(--section-gap);
  }

  .panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 24px 28px 28px;
  }

  .panel--cv {
    background:
      radial-gradient(80% 90% at 85% 10%, rgb(var(--screen-haze-rgb) / 0.42), transparent 65%),
      var(--screen-base);
  }

  .panel--contact {
    background:
      radial-gradient(80% 90% at 15% 10%, rgb(var(--accent-rgb) / 0.12), transparent 65%),
      var(--screen-base);
  }

  .panel__label {
    color: var(--screen-dim);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
  }

  .panel__title {
    font-size: 1.75rem;
    line-height: 1.1;
    letter-spacing: -0.03em;
    text-transform: lowercase;
  }

  .panel__text {
    max-inline-size: 44ch;
    color: var(--screen-soft);
    font-size: 1rem;
  }

  .panel__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-block-start: auto;
    padding-block-start: 8px;
  }

  /* Footer */

  .site-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 32px;
    margin-block-start: clamp(80px, 5rem + 2vw, 112px);
    padding-block: 24px 40px;
    border-block-start: 1px solid var(--rule);
    color: var(--muted);
    font-size: 0.9375rem;
    text-transform: lowercase;
  }

  .site-footer a {
    color: var(--link);
    text-underline-offset: 4px;
  }

  .site-footer__build {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
  }

  .site-footer__build a {
    color: inherit;
  }

  .site-footer__controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-inline-start: auto;
  }

  .motion-toggle__led {
    inline-size: 8px;
    block-size: 8px;
    border-radius: 50%;
    background-color: var(--led-off);
  }

  .motion-toggle[aria-pressed="true"] {
    background-color: rgb(var(--accent-rgb) / 0.1);
  }

  .motion-toggle[aria-pressed="true"] .motion-toggle__led {
    background-color: var(--accent);
    box-shadow: 0 0 8px rgb(var(--accent-rgb) / 0.9);
  }

  /* Intro: an old monitor booting up, played once per visit. head.js shows it
     before first paint and home.js takes over. If home.js never arrives, it
     fades out by itself so the page can't be left covered. */

  .intro {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    inline-size: 100%;
    block-size: 100%;
    padding: 0;
    border: 0;
    background-color: var(--tube);
    cursor: pointer;
  }

  .intro:focus-visible {
    outline: none;
  }

  .intro__canvas {
    position: absolute;
    inset: 0;
    inline-size: 100%;
    block-size: 100%;
  }

  /* Scanlines and the darker edges of a curved tube. */
  .intro__tube {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
      repeating-linear-gradient(to bottom, transparent 0 2px, rgb(0 0 0 / 0.3) 2px 3px),
      radial-gradient(ellipse at center, transparent 55%, rgb(0 0 0 / 0.62) 100%);
    transition: opacity 0.3s ease;
  }

  .intro__skip {
    position: absolute;
    inset-block-end: 56px;
    inset-inline-end: 20px;
    padding: 10px 14px;
    border: 1px solid rgb(var(--accent-rgb) / 0.5);
    border-radius: var(--radius-button);
    background-color: rgb(var(--tube-rgb) / 0.75);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    letter-spacing: 0.1em;
    transition: opacity 0.3s ease;
  }

  [data-intro="pending"] .intro,
  [data-intro="playing"] .intro,
  [data-intro="revealing"] .intro {
    display: block;
  }

  [data-intro="pending"] .intro {
    animation: intro-failsafe 0.4s ease 6s forwards;
  }

  /* No scrolling underneath. The space kept for the scrollbar takes the
     intro's colour, so it doesn't show as a stripe down the side. */
  [data-intro="playing"] {
    overflow: hidden;
    background-color: var(--tube);
  }

  /* The scan line wipes the boot screen away, so the page shows through above it. */
  [data-intro="revealing"] .intro {
    background-color: transparent;
    pointer-events: none;
  }

  [data-intro="revealing"] .intro__tube,
  [data-intro="revealing"] .intro__skip {
    opacity: 0;
  }

  /* Error pages */

  .error-page {
    display: grid;
    gap: 16px;
    max-inline-size: 60ch;
    padding-block-start: var(--section-gap);
  }

  .error-page h1 {
    font-size: clamp(2.25rem, 1.5rem + 3vw, 3.5rem);
    line-height: 1;
    letter-spacing: -0.035em;
    text-transform: lowercase;
  }

  .error-page p {
    color: var(--muted);
  }

  .error-page a {
    color: var(--link);
    font-weight: 700;
    text-underline-offset: 4px;
  }

  /* Phones */

  @media (max-width: 30em) {
    .hero__meta--bottom {
      font-size: 0.75rem;
      letter-spacing: 0.04em;
    }

    .console__screen {
      block-size: 250px;
      padding-inline: 12px;
      font-size: 0.75rem;
    }

    /* The footer buttons share the full width, whether they fit on one row or wrap. */
    .site-footer__controls {
      inline-size: 100%;
      margin-inline-start: 0;
    }

    .site-footer__controls .button {
      flex: 1 1 auto;
      padding-inline: 14px;
    }

    .panel {
      padding: 20px 20px 24px;
    }

    .hero__visual {
      grid-template-columns: minmax(0, 470px) 42px;
    }

    .hero__rain {
      inline-size: 42px;
    }

    .intro__skip {
      inset-block-end: 24px;
    }
  }

  /* Phones and small tablets: the page links become a bar along the bottom of the screen,
     where a thumb reaches them. */

  @media (max-width: 40em) {
    .site-header {
      padding-block: 14px 12px;
    }

    .primary-nav {
      position: fixed;
      inset: auto 0 0;
      z-index: 40;
      padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
      border-block-start: 1px solid rgb(var(--accent-rgb) / 0.28);
      background: color-mix(in srgb, var(--page) 88%, transparent);
      backdrop-filter: blur(10px);
    }

    .primary-nav__list {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 6px;
    }

    .primary-nav__link {
      flex-direction: column;
      justify-content: center;
      gap: 6px;
      inline-size: 100%;
      min-block-size: 54px;
      border: 1px solid var(--rule);
      border-radius: 10px;
      background: linear-gradient(to bottom, rgb(255 255 255 / 0.07), rgb(255 255 255 / 0));
      box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.08);
      font-size: 0.8125rem;
    }

    /* Each link has a lamp, lit for the page you're on. */
    .primary-nav__link::before {
      content: "";
      inline-size: 6px;
      block-size: 6px;
      border-radius: 50%;
      background-color: var(--led-off);
    }

    .primary-nav__link[aria-current] {
      border-color: rgb(var(--accent-rgb) / 0.55);
      background: rgb(var(--accent-rgb) / 0.08);
      color: var(--text);
    }

    .primary-nav__link[aria-current]::before {
      background-color: var(--accent);
      box-shadow: 0 0 8px rgb(var(--accent-rgb) / 0.9);
    }

    /* Room at the bottom of the page, so the bar never covers the footer. */
    .page {
      padding-block-end: calc(92px + env(safe-area-inset-bottom));
    }

    /* Under 16px, phones zoom in on a field when it's tapped. */
    input,
    textarea,
    select {
      font-size: max(1rem, 16px);
    }
  }

  /* Laptops and up: the name and console on the left, the globe on the right. */

  @media (min-width: 64em) {
    .hero__main {
      grid-template-columns: minmax(0, 1.07fr) minmax(0, 1fr);
    }
  }

  /* ---------------------------------------------------------------- page headings */

  /* For the pages with a heading of their own, such as the CV and contact pages. */

  .page-head {
    padding-block-start: clamp(40px, 1rem + 4vw, 72px);
  }

  .path {
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    letter-spacing: 0.06em;
  }

  .path a {
    color: var(--link);
    text-underline-offset: 4px;
  }

  .page-head__lede {
    max-inline-size: 40ch;
    margin-block-start: 20px;
    color: var(--muted);
    font-size: clamp(1.125rem, 1rem + 0.6vw, 1.5rem);
    line-height: 1.35;
    letter-spacing: -0.01em;
  }

  .tt-glitch {
    position: relative;
    inline-size: fit-content;
    color: var(--text);
    font-size: clamp(2.75rem, 1.6rem + 4.5vw, 5.5rem);
    font-weight: 700;
    line-height: 0.92;
    letter-spacing: -0.045em;
    text-shadow:
    -3px 0 rgb(var(--fringe-red-rgb) / 0.45),
    3px 0 rgb(var(--fringe-blue-rgb) / 0.5);
    text-transform: lowercase;
  }

  .tt-glitch::before,
  .tt-glitch::after {
    content: attr(data-text);
    content: attr(data-text) / "";
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
  }

  .tt-glitch::before {
    color: var(--slice-upper);
    clip-path: inset(16% 0 60% 0);
  }

  .tt-glitch::after {
    color: var(--slice-lower);
    clip-path: inset(62% 0 10% 0);
  }
}

@layer motion {
  /* Canvases only show while they're animating; their still images take over otherwise. */
  .live {
    display: none;
  }

  [data-motion="on"] .live {
    display: block;
  }

  [data-motion="on"] .still {
    display: none;
  }

  html[data-motion="on"] {
    scroll-behavior: smooth;
  }

  [data-motion="on"] .hero__grid {
    animation: grid-scroll 3.2s linear infinite;
  }

  [data-motion="on"] .hero__rec::before {
    animation: rec-blink 1.2s steps(1, end) infinite;
  }

  [data-motion="on"] .hero__noise {
    animation: tape-noise 0.32s steps(1, end) infinite;
  }

  [data-motion="on"] .hero__name {
    animation: vhs-stutter 6.5s steps(1, end) infinite;
  }

  [data-motion="on"] .hero__slice--upper {
    animation: vhs-slice-upper 6.5s steps(1, end) infinite;
  }

  [data-motion="on"] .hero__slice--lower {
    animation: vhs-slice-lower 6.5s steps(1, end) infinite;
  }

  /* The page coming in as the intro's scan line passes. intro.js sets
     data-entrance for a couple of seconds. */

  [data-motion="on"][data-entrance] .site-header {
    animation: fade-in 0.5s ease-out 0.05s both;
  }

  [data-motion="on"][data-entrance] .hero__meta {
    animation: fade-in 0.6s ease-out 0.3s both;
  }

  [data-motion="on"][data-entrance] .hero__name {
    animation:
      tune-in 0.9s steps(10, end) 0.15s both,
      vhs-stutter 6.5s steps(1, end) 1.2s infinite;
  }

  [data-motion="on"][data-entrance] .hero__slice {
    animation-delay: 1.2s;
  }

  [data-motion="on"][data-entrance] .hero__role {
    animation: fade-up 0.5s ease-out 0.55s both;
  }

  [data-motion="on"][data-entrance] .console {
    animation: window-open 0.5s ease-out 0.6s both;
  }

  [data-motion="on"][data-entrance] .hero__actions {
    animation: fade-up 0.5s ease-out 0.95s both;
  }

  [data-motion="on"][data-entrance] .hero__visual {
    animation: crt-on 0.7s ease-out 0.35s both;
  }

  @keyframes grid-scroll {
    to {
      transform: translateY(56px);
    }
  }

  @keyframes rec-blink {
    0%,
    55% {
      opacity: 1;
    }

    56%,
    100% {
      opacity: 0.15;
    }
  }

  @keyframes tape-noise {
    0% {
      background-position: 0 0;
    }

    25% {
      background-position: -37px 13px;
    }

    50% {
      background-position: 61px -29px;
    }

    75% {
      background-position: -83px 41px;
    }

    100% {
      background-position: 19px -7px;
    }
  }

  @keyframes vhs-stutter {
    0%,
    86%,
    100% {
      transform: translate(0, 0) skewX(0deg);
    }

    87% {
      transform: translate(-4px, 1px) skewX(-6deg);
    }

    88% {
      transform: translate(5px, -1px) skewX(3deg);
    }

    89.5% {
      transform: translate(-2px, 0) skewX(0deg);
    }

    91% {
      transform: translate(2px, 1px) skewX(0deg);
    }

    92.5% {
      transform: translate(0, 0) skewX(0deg);
    }
  }

  @keyframes vhs-slice-upper {
    0%,
    86%,
    92.5%,
    100% {
      opacity: 0;
      transform: translateX(0);
    }

    87% {
      opacity: 1;
      transform: translateX(-16px);
    }

    88% {
      opacity: 1;
      transform: translateX(12px);
    }

    89.5% {
      opacity: 1;
      transform: translateX(-7px);
    }

    91% {
      opacity: 1;
      transform: translateX(5px);
    }
  }

  @keyframes vhs-slice-lower {
    0%,
    87%,
    93%,
    100% {
      opacity: 0;
      transform: translateX(0);
    }

    88% {
      opacity: 1;
      transform: translateX(18px);
    }

    89% {
      opacity: 1;
      transform: translateX(-10px);
    }

    90.5% {
      opacity: 1;
      transform: translateX(6px);
    }

    92% {
      opacity: 1;
      transform: translateX(-3px);
    }
  }

  @keyframes tune-in {
    0% {
      opacity: 0;
      transform: scaleX(1.3) translateX(-4%);
      filter: blur(10px);
    }

    30% {
      opacity: 0.85;
      transform: scaleX(0.97) translateX(1.5%);
      filter: blur(3px);
    }

    45% {
      opacity: 0.35;
      transform: translateX(-1%);
      filter: blur(2px);
    }

    60% {
      opacity: 1;
      transform: translateX(0.5%);
      filter: blur(1px);
    }

    100% {
      opacity: 0.94;
      transform: none;
      filter: blur(0.3px);
    }
  }

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

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

  @keyframes window-open {
    0% {
      opacity: 0;
      transform: scale(0.6, 0.04);
    }

    55% {
      opacity: 1;
      transform: scale(1, 0.04);
    }

    100% {
      opacity: 1;
      transform: none;
    }
  }

  @keyframes crt-on {
    0% {
      opacity: 0;
      transform: scaleY(0.02);
      filter: brightness(3);
    }

    60% {
      opacity: 1;
      transform: scaleY(1.04);
      filter: brightness(1.6);
    }

    100% {
      opacity: 1;
      transform: none;
      filter: none;
    }
  }

  @keyframes intro-failsafe {
    to {
      opacity: 0;
      visibility: hidden;
    }
  }

  /* The page headings' title glitches now and then. */
  [data-motion="on"] .tt-glitch::before {
    animation: glitch-upper 5s steps(1, end) infinite;
  }

  [data-motion="on"] .tt-glitch::after {
    animation: glitch-lower 5s steps(1, end) infinite;
  }

  @keyframes glitch-upper {
    0%,
    80%,
    88%,
    100% {
      opacity: 0;
      transform: none;
    }

    81% {
      opacity: 1;
      transform: translateX(-14px);
    }

    83% {
      opacity: 1;
      transform: translateX(9px);
    }

    85% {
      opacity: 1;
      transform: translateX(-4px);
    }
  }

  @keyframes glitch-lower {
    0%,
    81%,
    89%,
    100% {
      opacity: 0;
      transform: none;
    }

    82% {
      opacity: 1;
      transform: translateX(16px);
    }

    84% {
      opacity: 1;
      transform: translateX(-8px);
    }

    86% {
      opacity: 1;
      transform: translateX(5px);
    }
  }
}

@layer utilities {
  /* Makes sure [hidden] beats any display value set by a component. */
  [hidden] {
    display: none !important;
  }

  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* A white ring with a dark halo, so it shows on both the page and the screens. */
  :focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    box-shadow:
      0 0 0 2px var(--halo),
      0 0 0 6px var(--halo);
  }

  .intro:focus-visible .intro__skip {
    outline: 2px solid #fff;
    outline-offset: 2px;
  }

  /* Windows high contrast: drop the textures and effects and let the system colours through. */
  @media (forced-colors: active) {
    .screen::before,
    .screen::after,
    .hero__floor,
    .hero__glow,
    .hero__frame,
    .hero__noise,
    .hero__slice {
      display: none;
    }

    .hero__name {
      filter: none;
      text-shadow: none;
    }
  }

  @media print {
    .skip-link,
    .intro,
    .hero__floor,
    .hero__glow,
    .hero__frame,
    .hero__noise,
    .hero__visual,
    .console,
    .project-card__screen,
    .site-footer__controls {
      display: none !important;
    }

    :root {
      --page: #fff;
      --text: #000;
      --muted: #333;
      --link: #000;
      --screen-text: #000;
      --screen-dim: #333;
      --screen-soft: #333;
      --name: #000;
    }

    .screen {
      background: none;
      box-shadow: none;
    }

    .hero__name {
      filter: none;
      text-shadow: none;
    }
  }
}
