/* Martian Mono, SIL OFL 1.1, Latin subset of the variable font (width 75 to 112.5, weight 300 to 400 used) */
@font-face {
  font-family: "Martian Mono";
  src: url("fonts/martian-mono-latin.woff2") format("woff2");
  font-weight: 100 800;
  font-stretch: 75% 112.5%;
  font-style: normal;
  font-display: swap;
}

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

:root {
  color-scheme: dark;
  scrollbar-gutter: stable;
  text-wrap: pretty;
  overflow-wrap: break-word;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;

  /* Two colours. Ground: Saigon at night under the trees. Panel: bone paper under a sodium lamp.
     Every mark is one or the other; the works themselves bring all other colour. */
  --ground: oklch(17% 0.016 165);
  --ground-deep: oklch(12.5% 0.012 165);
  --panel: oklch(94% 0.016 92);
  --panel-low: oklch(84% 0.03 78);
  --ink: var(--ground);
  --ink-soft: color-mix(in oklch, var(--ground) 62%, var(--panel-low));
  --ink-faint: color-mix(in oklch, var(--ground) 22%, transparent);
  --on-ground: color-mix(in oklch, var(--panel) 70%, var(--ground));

  --mono: "Martian Mono", ui-monospace, "Cascadia Mono", monospace;

  /* Phones get 14px body and 12px small text at least; mono reads small, so no lower */
  --text: clamp(0.875rem, 0.84rem + 0.15vw, 0.9375rem);
  --text-small: clamp(0.75rem, 0.73rem + 0.08vw, 0.8125rem);
  --text-lede: clamp(0.9375rem, 0.85rem + 0.4vw, 1.1875rem);
  --title: clamp(1.75rem, 0.9rem + 4.2vw, 4.25rem);
  --title-big: clamp(2rem, 0.9rem + 5.4vw, 5rem);

  --gutter: clamp(0.75rem, 0.3rem + 2.2vw, 2.5rem);
  --pad: clamp(1rem, 0.5rem + 2.4vw, 3rem);
  --measure: 76rem;
  --rail: 0rem;
}

body {
  margin: 0;
  min-height: 100svh;
  background-color: var(--ground);
  /* Dot field on the ground, so no margin is ever empty */
  background-image:
    radial-gradient(circle at center, color-mix(in oklch, var(--panel) 16%, transparent) 0.7px, transparent 1.2px),
    linear-gradient(to bottom, var(--ground), var(--ground-deep));
  background-size: 14px 14px, 100% 100%;
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--mono);
  font-size: var(--text);
  font-weight: 300;
  font-stretch: 87.5%;
  line-height: 1.7;
  padding-block: var(--gutter);
  padding-inline: var(--gutter) calc(var(--gutter) + var(--rail));
}

/* Grain, held below the level where it reads as texture */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0.09;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

::selection {
  background: var(--ground);
  color: var(--panel);
}

h1, h2, p, figure, ol, dl, dd {
  margin: 0;
}

h1, h2 {
  font-weight: 300;
  font-stretch: 112.5%;
  line-height: 1.02;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

img, video, audio {
  display: block;
  max-width: 100%;
}

img, video {
  height: auto;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  touch-action: manipulation;
}

a:focus-visible,
video:focus-visible,
audio:focus-visible {
  outline: 2px solid var(--ground);
  outline-offset: 3px;
}

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

/* Panels: square corners, a 1px edge, one vertical gradient, tick marks down the inline end */

.panel {
  position: relative;
  max-inline-size: var(--measure);
  margin-inline: auto;
  padding: var(--pad);
  padding-inline-end: calc(var(--pad) + 0.75rem);
  background: linear-gradient(to bottom, var(--panel), var(--panel-low));
  border: 1px solid var(--ground);
}

.panel::after {
  content: "";
  position: absolute;
  inset-block: var(--pad);
  inset-inline-end: 0.5rem;
  inline-size: 6px;
  background: repeating-linear-gradient(to bottom, var(--ground) 0 1px, transparent 1px 12px);
  opacity: 0.55;
}

.panel + .panel,
main > .panel:first-child {
  margin-block-start: var(--gutter);
}

.strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1rem;
  padding-block-end: 0.75rem;
  border-block-end: 1px solid var(--ground);
  font-size: var(--text-small);
  font-weight: 400;
}

.chip {
  background: var(--ground);
  color: var(--panel);
  padding-block: 0.15rem;
  padding-inline: 0.55rem;
  font-weight: 400;
}

.meta {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

/* Masthead */

.masthead {
  display: grid;
  gap: 1.25rem;
}

.masthead h1 {
  font-size: var(--title-big);
  margin-block-start: clamp(1.5rem, 1rem + 3vw, 4rem);
}

.lede {
  font-size: var(--text-lede);
  font-weight: 400;
}

.masthead > p {
  max-inline-size: 46em;
}

.note {
  color: var(--ink-soft);
}

.index {
  list-style: none;
  padding: 0;
  margin-block-start: 1rem;
  border-block-start: 1px solid var(--ground);
}

/* One line on wide screens. On a phone the title takes the first line,
   and the medium and length share the second. */
.index a {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.1rem 1.5rem;
  padding-block: 0.8rem;
  padding-inline: 0.5rem;
  border-block-end: 1px solid var(--ground);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}

.index a span:first-child {
  flex: 1 1 14rem;
  font-weight: 400;
}

.index a span:nth-child(2) {
  flex: 1 1 10rem;
}

.index a span:last-child {
  flex: none;
  margin-inline-start: auto;
  text-align: end;
}

/* Inverting is the hover: panel marks flip to ground and back */
.index a:active {
  background: var(--ground);
  color: var(--panel);
}

@media (hover: hover) and (pointer: fine) {
  .index a:hover {
    background: var(--ground);
    color: var(--panel);
  }
}

/* Works */

.work {
  display: grid;
  gap: clamp(1.25rem, 0.8rem + 1.6vw, 2.25rem);
  scroll-margin-block-start: var(--gutter);
}

.work h2 {
  font-size: var(--title);
  margin-block-start: clamp(0.5rem, 0.2rem + 1.5vw, 1.5rem);
}

.body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: clamp(1.25rem, 0.5rem + 3vw, 3.5rem);
  align-items: start;
}

.facts {
  border-block-start: 1px solid var(--ground);
}

/* Label beside value where there is room; on a narrow phone the value drops under its label */
.facts div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 1rem;
  padding-block: 0.6rem;
  border-block-end: 1px solid var(--ink-faint);
}

.facts dt {
  flex: 0 0 7rem;
  color: var(--ink-soft);
}

.facts dd {
  flex: 1 1 13rem;
  font-weight: 400;
}

.zoom {
  display: block;
  cursor: zoom-in;
}

/* A 44px tap area without making the row taller */
.facts dd a {
  display: inline-block;
  padding-block: 0.7rem;
  margin-block: -0.7rem;
}

.about {
  display: grid;
  gap: 1rem;
  max-inline-size: 40em;
}

.about p:first-child {
  font-size: var(--text-lede);
  font-weight: 400;
  line-height: 1.55;
}

/* Signal strip: the work's real audio as bars, filled up to the play position */

.signal {
  display: grid;
  gap: 0.4rem;
}

.wave {
  --p: 0%;
  block-size: clamp(2.5rem, 2rem + 2vw, 4rem);
  background: linear-gradient(to right, var(--ground) var(--p), color-mix(in oklch, var(--ground) 32%, transparent) var(--p));
  mask-size: 100% 100%;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
}

.wave-silent-breaths { mask-image: url("media/wave-silent-breaths.svg"); -webkit-mask-image: url("media/wave-silent-breaths.svg"); }
.wave-caught { mask-image: url("media/wave-caught.svg"); -webkit-mask-image: url("media/wave-caught.svg"); }
.wave-shattered { mask-image: url("media/wave-shattered.svg"); -webkit-mask-image: url("media/wave-shattered.svg"); }

.ticks {
  display: flex;
  justify-content: space-between;
  padding-block-start: 0.35rem;
  border-block-start: 1px solid var(--ground);
  background: repeating-linear-gradient(to right, var(--ground) 0 1px, transparent 1px 10%) top / 100% 5px no-repeat;
  font-size: var(--text-small);
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

.signal figcaption,
.extra figcaption {
  font-size: var(--text-small);
  color: var(--ink-soft);
}

/* Media sit in a ground-coloured frame; the tile reveal lives here */

.screen {
  position: relative;
  border: 1px solid var(--ground);
  background: var(--ground);
}

.screen video,
.screen img {
  inline-size: 100%;
}

.screen.square {
  inline-size: 100%;
  max-inline-size: min(100%, 46rem);
  justify-self: center;
}

.tiles {
  position: absolute;
  inset: 0;
  display: grid;
  pointer-events: none;
}

.tiles span {
  background: var(--ground);
}

.tiles.open span {
  transform: scale(0);
}

@media (prefers-reduced-motion: no-preference) {
  .tiles span {
    transition: transform 160ms steps(3, end) var(--d, 0ms);
  }
}

.extras {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: clamp(1rem, 0.5rem + 2vw, 2rem);
  align-items: start;
}

.extra {
  display: grid;
  gap: 0.6rem;
}

.extra audio {
  inline-size: 100%;
}

.credit {
  font-size: var(--text-small);
  color: var(--ink-soft);
  max-inline-size: 70em;
}

/* An action is a filled chip that inverts on hover */
.action {
  justify-self: start;
  padding-block: 0.85rem;
  padding-inline: 1rem;
  background: var(--ground);
  color: var(--panel);
  border: 1px solid var(--ground);
  font-weight: 400;
  text-decoration: none;
}

.action:active {
  background: transparent;
  color: var(--ground);
}

@media (hover: hover) and (pointer: fine) {
  .action:hover {
    background: transparent;
    color: var(--ground);
  }
}

/* Close */

.close {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-small);
}

/* Side rail, only where there is room for it */

.rail {
  display: none;
}

@media (width >= 72rem) {
  :root {
    --rail: 2.5rem;
  }

  .rail {
    position: fixed;
    inset-block: var(--gutter);
    inset-inline-end: 0.75rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.5rem;
    font-size: var(--text-small);
    font-weight: 400;
    border-inline-start: 1px solid color-mix(in oklch, var(--panel) 30%, transparent);
    padding-inline-start: 0.5rem;
  }

  .rail a {
    writing-mode: vertical-rl;
    background: var(--ground-deep);
    color: var(--on-ground);
    padding-block: 0.6rem;
    padding-inline: 0.2rem;
    text-decoration: none;
  }

  .rail a:focus-visible {
    outline-color: var(--panel);
  }

  .rail a:active {
    background: var(--panel);
    color: var(--ground);
  }
}

@media (width >= 72rem) and (hover: hover) and (pointer: fine) {
  .rail a:hover {
    background: var(--panel);
    color: var(--ground);
  }
}
