:root {
  --black: #000000;
  --white: #ffffff;
  --soft: #d6d6d6;
  --muted: #8f8f8f;
  --rule: #2a2a2a;
  --edge: #3d3d3d;

  --measure: 38rem;
  --rail: 11rem;
  --gutter: clamp(1rem, 4vw, 2rem);

  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  background: var(--black);
  color: var(--white);
  font-family: "Schibsted Grotesk", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }

a {
  color: var(--white);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
a:hover { text-decoration-thickness: 2px; }

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

::selection { background: var(--white); color: var(--black); }

time { font-variant-numeric: tabular-nums; }

.skip {
  position: absolute;
  left: var(--gutter);
  top: -3rem;
  padding: 0.5rem 0.75rem;
  background: var(--white);
  color: var(--black);
}
.skip:focus { top: 1rem; }

.wrap,
.year {
  max-width: 58rem;
  margin-inline: max(var(--gutter), (100% - 58rem) / 2);
}

/* Intro */

.intro {
  padding-block: clamp(4rem, 14vh, 9rem) clamp(3rem, 8vh, 5rem);
}

.intro h1 {
  font-size: clamp(3rem, 9vw, 5.75rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.035em;
  margin-bottom: 1.75rem;
}

.lede {
  max-width: var(--measure);
  font-size: 1.1875rem;
  line-height: 1.55;
  color: var(--soft);
}

/* Contact: a button pinned to the top right that opens a small panel */

/* Desktop: the button floats in the corner. Phones: it sits in a top bar. */
.topbar {
  position: fixed;
  top: 1.25rem;
  right: var(--gutter);
  z-index: 10;
}
.topbar-name { display: none; }

.contact-toggle {
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--white);
  background: var(--black);
  border: 1px solid var(--edge);
  padding: 0.45rem 1rem;
  cursor: pointer;
}
.contact-toggle:hover,
.contact-toggle[aria-expanded="true"] { border-color: var(--white); }

.contact {
  inset: auto;
  top: 4.25rem;
  right: var(--gutter);
  width: min(100vw - 2 * var(--gutter), 19rem);
  margin: 0;
  padding: 0.5rem 1.25rem;
  background: var(--black);
  color: var(--white);
  border: 1px solid var(--edge);
}

.contact:popover-open { animation: drop 140ms ease-out; }

@keyframes drop {
  from { opacity: 0; transform: translateY(-0.375rem); }
}

.contact dl { margin: 0; }

.contact dl > div { padding-block: 0.75rem; }
.contact dl > div + div { border-top: 1px solid var(--rule); }

.contact dt {
  font-size: 0.875rem;
  color: var(--muted);
}

.contact dd {
  margin: 0.125rem 0 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.contact a {
  text-decoration: none;
  border-bottom: 1px solid var(--edge);
}
.contact a:hover { border-bottom-color: var(--white); }

/* Scrolling still works; the scrollbar itself is hidden */
html,
.detail { scrollbar-width: none; }
html::-webkit-scrollbar,
.detail::-webkit-scrollbar { display: none; }

/* Timeline: one section per year, the year stays pinned while its entries scroll */

.year {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, var(--measure));
  column-gap: 2rem;
  align-items: start;
  border-top: 1px solid var(--rule);
  padding-bottom: 3rem;
}
.year:first-child { border-top-color: var(--white); }

.year-label {
  position: sticky;
  top: 1.5rem;
  padding-top: 1.25rem;
  font-size: clamp(2.5rem, 5vw, 3.75rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.entries li + li { border-top: 1px solid var(--rule); }

.entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1.5rem;
  padding-block: 1.5rem;
  text-decoration: none;
}

.entry-title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.015em;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.18em;
}
.entry:hover .entry-title { text-decoration-color: currentColor; }

/* A plus mark beside each title shows the row opens into more detail */
.entry::after {
  --mark: var(--muted);
  content: "";
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  width: 0.875rem;
  height: 0.875rem;
  background:
    linear-gradient(var(--mark), var(--mark)) center / 100% 1.5px no-repeat,
    linear-gradient(var(--mark), var(--mark)) center / 1.5px 100% no-repeat;
}
.entry:hover::after { --mark: var(--white); }

.entry-blurb,
.entry-meta { grid-column: 1 / -1; }

.entry-blurb {
  margin-top: 0.375rem;
  color: var(--soft);
}

.entry-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.125rem 1.5rem;
  margin-top: 0.625rem;
  font-size: 0.9375rem;
  color: var(--muted);
}

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2rem;
  padding-block: 1.5rem 3rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
  color: var(--muted);
}

/* Hidden message easter egg (message.js) */

.text-button {
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 0.2em;
}
.text-button:hover { color: var(--white); text-decoration-color: currentColor; }

.intro { position: relative; }

.lede .ch { transition: color 450ms ease; }
.lede.revealing .ch { color: #2c2c2c; }
.lede.revealing .ch.hit { color: var(--white); }

/* The decoded word: beside the paragraph on wide screens, below it on narrow */
.decoded-word {
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: pre;
}
.decoded-word.side {
  position: absolute;
  left: calc(var(--measure) + 5rem);
}
.decoded-word.below {
  margin-top: 3.5rem;
  font-size: 2.25rem;
}
.decoded-word span {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.25rem);
  transition: opacity 350ms ease, transform 350ms ease;
}
.decoded-word span.in { opacity: 1; transform: none; }

.decode-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  overflow: visible;
  pointer-events: none;
}
.decode-lines path {
  fill: none;
  stroke: rgb(255 255 255 / 0.35);
  stroke-width: 1;
  transition: stroke-dashoffset 700ms ease-in-out;
}

.decoded {
  max-width: var(--measure);
  margin-top: 1.25rem;
  font-size: 0.9375rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 400ms ease;
}
.decoded.shown { opacity: 1; }
.decoded .text-button { display: block; margin-top: 0.25rem; }
/* Leave room under the paragraph for the wiring tracks */
.decoding-side .decoded { margin-top: 6.25rem; }

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

/* Project detail dialog */

.detail {
  width: min(100% - 2rem, 50rem);
  max-width: none;
  max-height: calc(100% - 3rem);
  margin: auto;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--black);
  color: var(--white);
  border: 1px solid var(--edge);
}

.detail::backdrop { background: rgb(0 0 0 / 0.82); }

.detail[open] { animation: rise 180ms ease-out; }

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

.detail-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  padding: 0.875rem 1rem;
  background: var(--black);
  border-bottom: 1px solid var(--rule);
}

.close {
  font: inherit;
  font-size: 0.9375rem;
  color: var(--white);
  background: none;
  border: 1px solid var(--edge);
  padding: 0.3rem 0.875rem;
  cursor: pointer;
}
.close:hover { border-color: var(--white); }

.detail-body {
  padding: 2rem clamp(1.25rem, 5vw, 3rem) 3rem;
}

.detail-body > h2,
.detail-body > p { max-width: var(--measure); }

.detail-body h2 {
  font-size: clamp(1.875rem, 5vw, 2.5rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.125rem 1.5rem;
  margin: 0.625rem 0 1.5rem;
  font-size: 0.9375rem;
  color: var(--muted);
}
.detail-meta span { color: var(--white); font-weight: 500; }

.detail-body p + p { margin-top: 0.875rem; }
.detail-body cite { font-style: italic; }

.detail-body .detail-stack {
  margin-top: 1.25rem;
  font-size: 0.9375rem;
  color: var(--muted);
}

.detail-body figure { margin-top: 2.5rem; }

.detail-body img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--rule);
}

.detail-body figcaption {
  max-width: var(--measure);
  margin-top: 0.625rem;
  font-size: 0.9375rem;
  color: var(--muted);
}

/* Narrow screens: the year becomes a pinned bar, the dialog fills the screen */

@media (max-width: 46rem) {
  :root { --gutter: 1.375rem; }

  /* A solid bar across the top holds the button, so it never sits on text */
  .topbar {
    position: sticky;
    top: 0;
    right: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3.5rem;
    padding-inline: var(--gutter);
    background: var(--black);
    border-bottom: 1px solid transparent;
    transition: border-color 200ms ease;
  }
  /* The name and the bar's bottom rule only appear once the big name has
     scrolled out of view, so the bar never repeats what's on screen */
  .topbar-name {
    display: block;
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    opacity: 0;
    transition: opacity 200ms ease;
  }
  .topbar.past-name { border-bottom-color: var(--rule); }
  .topbar.past-name .topbar-name { opacity: 1; }
  .contact-toggle { padding: 0.35rem 0.875rem; }
  .contact { top: 4rem; }

  .intro { padding-block: 3rem 2.75rem; }
  .intro h1 { font-size: 2.75rem; margin-bottom: 1.25rem; }
  .lede { font-size: 1.0625rem; line-height: 1.6; }

  /* Timeline: a narrow year column, then a vertical line with a dot per entry */
  .year {
    grid-template-columns: 3rem minmax(0, 1fr);
    column-gap: 0;
    border-top: 0;
    padding-bottom: 0;
  }

  .year-label {
    top: 4.75rem;
    padding-top: 2.05rem;
    font-size: 0.9375rem;
    font-weight: 500;
    letter-spacing: 0;
  }

  .entries {
    border-left: 1px solid var(--rule);
    padding-left: 1.25rem;
  }
  .entries li { position: relative; }
  .entries li::before {
    content: "";
    position: absolute;
    left: calc(-1.25rem - 4px);
    top: 2.2rem;
    width: 7px;
    height: 7px;
    border: 1px solid var(--muted);
    border-radius: 50%;
    background: var(--black);
  }
  .year:last-child .entries { padding-bottom: 1rem; }

  .entry { padding-block: 1.75rem; }
  .entry-title { font-size: 1.25rem; }
  .entry-blurb { margin-top: 0.5rem; }
  .entry-meta {
    display: block;
    margin-top: 0.875rem;
    font-size: 0.875rem;
  }
  .entry-meta time { display: block; margin-top: 0.125rem; }

  footer { padding-block: 1.5rem 3.5rem; }

  .detail {
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .detail[open],
  .contact:popover-open { animation: none; }
  .lede .ch,
  .topbar,
  .topbar-name,
  .decoded,
  .decoded-word span,
  .decode-lines path { transition: none; }
}

/* Neural network background behind everything (drawn by field.js) */
.field {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Full strength in the side margins, dimmed behind the text column */
  -webkit-mask-image: linear-gradient(to right, #000 0%, #000 14%, rgb(0 0 0 / 0.3) 30%, rgb(0 0 0 / 0.3) 70%, #000 86%, #000 100%);
  mask-image: linear-gradient(to right, #000 0%, #000 14%, rgb(0 0 0 / 0.3) 30%, rgb(0 0 0 / 0.3) 70%, #000 86%, #000 100%);
}

@media (max-width: 46rem) {
  .field {
    -webkit-mask-image: none;
    mask-image: none;
    opacity: 0.4;
  }
}
