:root {
  --bone: #d9d3c4;
  --dim: rgba(217, 211, 196, 0.58);
  --faint: rgba(217, 211, 196, 0.32);
  --ink: #0b100e;
  --plate-p: url(/assets/img/p4.webp);
  --plate-l: url(/assets/img/l4.webp);
  --gutter: 16px;
  --display: "Pirata One", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  /* 4×4 Bayer matrix as an alpha mask: dithers small text like a PS1 frame buffer. */
  --dither: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' shape-rendering='crispEdges'%3E%3Crect x='0' y='0' width='1' height='1' fill-opacity='0.60'/%3E%3Crect x='1' y='0' width='1' height='1' fill-opacity='0.81'/%3E%3Crect x='2' y='0' width='1' height='1' fill-opacity='0.65'/%3E%3Crect x='3' y='0' width='1' height='1' fill-opacity='0.87'/%3E%3Crect x='0' y='1' width='1' height='1' fill-opacity='0.92'/%3E%3Crect x='1' y='1' width='1' height='1' fill-opacity='0.71'/%3E%3Crect x='2' y='1' width='1' height='1' fill-opacity='0.97'/%3E%3Crect x='3' y='1' width='1' height='1' fill-opacity='0.76'/%3E%3Crect x='0' y='2' width='1' height='1' fill-opacity='0.68'/%3E%3Crect x='1' y='2' width='1' height='1' fill-opacity='0.89'/%3E%3Crect x='2' y='2' width='1' height='1' fill-opacity='0.63'/%3E%3Crect x='3' y='2' width='1' height='1' fill-opacity='0.84'/%3E%3Crect x='0' y='3' width='1' height='1' fill-opacity='1.00'/%3E%3Crect x='1' y='3' width='1' height='1' fill-opacity='0.79'/%3E%3Crect x='2' y='3' width='1' height='1' fill-opacity='0.95'/%3E%3Crect x='3' y='3' width='1' height='1' fill-opacity='0.73'/%3E%3C/svg%3E");
}

:root[data-plate="7"] {
  --plate-p: url(/assets/img/p7.webp);
  --plate-l: url(/assets/img/l7.webp);
}

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

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--bone);
}

body {
  min-height: 100svh;
  font: 300 1rem/1.5 var(--mono);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

a { color: inherit; }

:focus-visible {
  outline: 1px dashed var(--bone);
  outline-offset: 4px;
}

/* ---------- Scene ---------- */

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.layer {
  position: absolute;
  inset: 0;
  will-change: transform;
}

/* The plates are deliberately low resolution (432×768 / 960×540) and scaled
   up with hard pixels for the PS1 look. */
.plate {
  position: absolute;
  inset: -4%;
  background: var(--ink) var(--plate-p) center / cover no-repeat;
  image-rendering: pixelated;
}

@media (min-aspect-ratio: 4/5) {
  .plate { background-image: var(--plate-l); }
}

.slices { position: absolute; inset: 0; }
.slices .plate { will-change: transform; }

.fog {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;
  height: 100%;
  background: url(/assets/img/fog.webp) repeat-x 0 0 / 50% 100%;
  image-rendering: pixelated;
  -webkit-mask-image: linear-gradient(to bottom, transparent 2%, #000 30%, #000 70%, transparent 98%);
  mask-image: linear-gradient(to bottom, transparent 2%, #000 30%, #000 70%, transparent 98%);
  animation: drift 90s linear infinite;
  opacity: 0.28;
  will-change: transform;
}

.fog--b {
  top: 18%;
  animation-duration: 140s;
  animation-direction: reverse;
  opacity: 0.18;
  transform: scaleY(-1);
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-50%, 0, 0); }
}

.vignette {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top, rgba(6, 10, 9, 0.9) 0%, rgba(6, 10, 9, 0.45) 30%, transparent 55%),
    radial-gradient(130% 95% at 50% 30%, transparent 45%, rgba(6, 10, 9, 0.7) 100%);
}

.grain {
  position: absolute;
  inset: -50%;
  background-image: var(--grain, none);
  opacity: 0.045;
  animation: grain 0.9s steps(6) infinite;
}

@keyframes grain {
  0%   { transform: translate3d(0, 0, 0); }
  20%  { transform: translate3d(-7%, 4%, 0); }
  40%  { transform: translate3d(5%, -9%, 0); }
  60%  { transform: translate3d(-3%, 8%, 0); }
  80%  { transform: translate3d(9%, 2%, 0); }
  100% { transform: translate3d(-5%, -4%, 0); }
}

/* ---------- Content ---------- */

/* Pinned to the visible viewport, like the fixed photo credit. On iOS Safari the
   floating toolbar overlaps 100svh, so an in-flow full-height layout ends up
   partly behind it. The content scrolls inside main if a group makes it too tall. */
main {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  max-width: 44rem;
  padding:
    calc(72px + env(safe-area-inset-top))
    calc(var(--gutter) + env(safe-area-inset-right))
    calc(40px + env(safe-area-inset-bottom))
    calc(var(--gutter) + env(safe-area-inset-left));
}

/* Bottom-aligned, but still scrollable to the top when it overflows
   (justify-content: flex-end would clip the top instead). */
main > :first-child { margin-top: auto; }

@media (min-width: 768px) {
  :root { --gutter: 56px; }
  main { padding-bottom: 64px; }
  .nav summary, .nav-link { font-size: 1.05rem; }
}

.wordmark {
  margin: 0 0 1.2rem;
  font: 400 clamp(3.1rem, 14vw, 5.75rem)/1 var(--display);
  letter-spacing: 0.01em;
  transition: none;
}

/* With JS, the wordmark is drawn small onto a canvas and scaled up with hard
   pixels (main.js). The text stays in the page for screen readers and search. */
.wordmark canvas { display: block; image-rendering: pixelated; }

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

.glitching .wordmark { transform: translateX(-3px) skewX(-5deg); }

/* Small text: dithered, slightly soft and fringed, so it sits with the pixel art. */
.nav,
.back,
.corner,
.credit,
.experiments,
.lost {
  -webkit-mask-image: var(--dither);
  mask-image: var(--dither);
  -webkit-mask-size: 4px 4px;
  mask-size: 4px 4px;
  text-shadow:
    0.6px 0 rgba(255, 60, 90, 0.22),
    -0.6px 0 rgba(60, 255, 220, 0.16),
    0 0 1.5px rgba(217, 211, 196, 0.35);
}

.nav { display: flex; flex-direction: column; align-items: flex-start; }

.nav summary,
.nav-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-size: 1rem;
  letter-spacing: 0.22em;
  color: var(--dim);
  text-decoration: none;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color 0.3s, opacity 0.3s;
}

.nav summary::-webkit-details-marker { display: none; }

.nav summary::after {
  content: "+";
  margin-left: 0.7em;
  font-size: 0.8em;
  color: var(--faint);
  transition: transform 0.3s;
}

.nav details[open] > summary { color: var(--bone); }
.nav details[open] > summary::after { content: "−"; }

.nav summary:hover,
.nav-link:hover { color: var(--bone); }

.nav:has(details[open]) > details:not([open]) > summary,
.nav:has(details[open]) > .nav-link { opacity: 0.5; }

.links { padding: 0 0 0.9rem 1.1rem; }

.links ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.links li { display: flex; align-items: baseline; gap: 1rem; }

.links a {
  display: inline-block;
  padding: 0.4rem 0;
  min-height: 40px;
  text-decoration: none;
  letter-spacing: 0.06em;
  white-space: pre;
}

.links a:hover { text-decoration: underline; text-underline-offset: 0.3em; text-decoration-thickness: 1px; }

.links .aside { font-size: 0.78rem; color: var(--dim); }

.group {
  margin: 0.6rem 0 0.1rem;
  font-size: 0.66rem;
  letter-spacing: 0.32em;
  color: rgba(217, 211, 196, 0.45);
}

.group:first-child { margin-top: 0.2rem; }

.corner {
  position: fixed;
  z-index: 2;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--dim);
  transition: color 0.3s;
}

.corner:hover { color: var(--bone); }

/* Photo credit: both background photos are by Katelyn G on Unsplash. */
.credit {
  position: fixed;
  z-index: 2;
  right: calc(var(--gutter) + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  padding: 8px 0;
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  color: var(--faint);
  text-decoration: none;
}

.credit:hover { color: var(--bone); }

/* ---------- Inner pages ---------- */


.back {
  position: fixed;
  z-index: 2;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(var(--gutter) + env(safe-area-inset-left));
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  color: var(--dim);
  text-decoration: none;
}

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

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

.experiments li + li { margin-top: 1.6rem; }

.experiments a { display: inline-block; text-decoration: none; }

.experiments .title {
  display: block;
  font-size: 1.15rem;
  letter-spacing: 0.12em;
}

.experiments a:hover .title { text-decoration: underline; text-underline-offset: 0.3em; text-decoration-thickness: 1px; }

.experiments .meta,
.experiments .note {
  display: block;
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: rgba(217, 211, 196, 0.75);
  max-width: 36ch;
}

.experiments .note { color: var(--dim); }

.experiments .note a { display: inline; text-decoration: underline; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }

.lost { margin: 0 0 1rem; color: var(--dim); letter-spacing: 0.18em; }

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .fog, .grain { animation: none; }
  .nav summary, .nav-link, .corner, .back { transition: none; }
}
