:root {
  color-scheme: dark;
  --ink: #fff0dc;
  --canvas: #101126;
  --control: #24213a;
  --line: #9c8eac;
  --ring: #ffcf83;
  --scene: url("./art/background.webp");
  --title-font: system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 0;
  min-height: 100svh;
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--canvas);
}

.masthead {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1.5rem;
  padding: clamp(1rem, 3vw, 2.5rem) clamp(1rem, 5vw, 5rem);
}

h1 {
  margin: 0;
  font: 700 clamp(1.7rem, 4vw, 3.25rem)/1.1 var(--title-font);
  letter-spacing: -.04em;
  overflow-wrap: anywhere;
}

.scene {
  display: grid;
  grid-template-rows: 1fr;
  flex: 1;
  isolation: isolate;
  position: relative;
  padding: .5rem clamp(1rem, 5vw, 5rem) clamp(6rem, 12vw, 10rem);
}

.map {
  width: min(100%, 68rem);
  min-height: 28rem;
  margin: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  align-items: center;
  gap: 1.4rem clamp(1rem, 6vw, 5rem);
}

.map-node {
  min-width: 0;
  display: grid;
  place-items: center;
}

.project {
  position: relative;
  display: grid;
  width: min(100%, 19rem);
  min-height: 44px;
  justify-items: center;
  align-items: end;
  color: inherit;
  text-align: center;
  text-decoration: none;
  border-radius: 1.25rem;
}

.project img { display: block; width: 100%; height: auto; }

.project-title {
  max-width: 98%;
  padding: .32em .64em;
  border-radius: .8em;
  font: 700 clamp(.95rem, 1.8vw, 1.22rem)/1.15 var(--title-font);
  overflow-wrap: anywhere;
}

[data-theme="space"] .map--four {
  width: min(100%, 59rem);
  grid-template-columns: repeat(6, minmax(0, 1fr));
  column-gap: .35rem;
  row-gap: 0;
}

[data-theme="space"] .map--four .map-node:nth-child(1) { grid-area: 1 / 3 / 2 / 5; }
[data-theme="space"] .map--four .map-node:nth-child(2) { grid-area: 2 / 1 / 3 / 3; }
[data-theme="space"] .map--four .map-node:nth-child(3) { grid-area: 3 / 3 / 4 / 5; }
[data-theme="space"] .map--four .map-node:nth-child(4) { grid-area: 2 / 5 / 3 / 7; }

[data-theme="space"] .project { width: min(100%, 13rem); }


[data-theme="space"] .project-title {
  z-index: 1;
  margin-top: -.7em;
  color: #25192e;
  background: #f9dec2;
}

a.project {
  transition: transform .2s ease, filter .2s ease;
}

@media (hover: hover) {
  a.project:hover { transform: translateY(-.3rem); filter: brightness(1.08); }
  a.project:hover .project-title { text-decoration: underline; }
}

a:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 4px;
}

.observer {
  position: absolute;
  z-index: -1;
  inset: auto auto 0 clamp(1rem, 5vw, 5rem);
  width: clamp(7rem, 19vw, 17rem);
  pointer-events: none;
}

@media (max-width: 42rem) {
  .scene { padding-inline: 1rem; padding-bottom: 7rem; }
  [data-theme="space"] .map--four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 0;
    gap: 1.1rem .65rem;
  }

  [data-theme="space"] .map--four .map-node:nth-child(n) {
    grid-area: auto;
    translate: none;
  }

  [data-theme="space"] .map--four .map-node:nth-child(even) {
    margin-block-start: 3.25rem;
  }
}

@media (max-width: 23rem) {
  [data-theme="space"] .map--four {
    grid-template-columns: minmax(0, 1fr);
    justify-items: stretch;
  }

  [data-theme="space"] .map--four .map-node:nth-child(n) {
    margin: 0;
    justify-items: start;
  }

  [data-theme="space"] .map--four .map-node:nth-child(even) { justify-items: end; }

  .map--four .project { width: min(90%, 15rem); }
}

@media (prefers-reduced-motion: reduce) {
  a.project { transition: none; }
  a.project:hover { transform: none; }
}

.preview-settings {
  position: relative;
  flex: none;
  margin-inline-start: auto;
}

.preview-settings summary {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  cursor: pointer;
  list-style: none;
  border: 1px solid transparent;
  border-radius: 50%;
  color: var(--ink);
  opacity: .65;
}

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

.preview-settings[open] summary,
.preview-settings summary:hover,
.preview-settings summary:focus-visible {
  border-color: var(--line);
  background: var(--control);
  opacity: 1;
}

.preview-settings summary:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.preview-panel {
  position: absolute;
  inset: calc(100% + .5rem) 0 auto auto;
  display: grid;
  justify-items: start;
  gap: .65rem;
  width: min(15rem, calc(100vw - 2rem));
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--control);
  box-shadow: 0 .6rem 1.8rem #1a13204d;
}

.motion-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  color: var(--ink);
  font: 600 .9rem/1.2 system-ui, sans-serif;
}

.motion-controls[hidden],
.motion-replay[hidden] { display: none; }

.motion-controls select,
.motion-replay {
  min-height: 44px;
  padding: .35rem .75rem;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  color: inherit;
  background: var(--control);
  font: inherit;
}

.motion-replay { cursor: pointer; }

.motion-controls :focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 3px;
}

.map {
  position: relative;
  isolation: isolate;
}

.motion-traces {
  position: absolute;
  z-index: -1;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

/* The painted Planets backdrop and the live scene are separate layers. */
[data-theme="space"] body {
  position: relative;
  isolation: isolate;
  background: #131527;
}

.space-backdrop {
  position: absolute;
  z-index: -1;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.space-sky {
  position: absolute;
  inset: -1.5rem;
  background: var(--scene) center bottom / cover no-repeat;
}

.space-stars {
  position: absolute;
  inset: 0;
}

@media (max-width: 46rem) {
  .space-sky { background-image: url("./art/background-mobile.webp"); }
}

.space-stars span {
  position: absolute;
  inset: var(--y) auto auto var(--x);
  width: var(--size);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffe7c9;
  opacity: .49;
}

.space-sky .observer {
  z-index: 1;
  inset: auto auto 1.5rem calc(1.5rem + clamp(1rem, 5vw, 5rem));
}

.space-sun {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: calc(var(--orbit-count, 0) + 1);
  width: clamp(7rem, 17vw, 13rem);
  height: auto;
  translate: -50% -50%;
  filter: brightness(calc(.82 + .18 * var(--daylight, .7)));
  pointer-events: none;
}

[data-theme="space"] .motion-traces {
  z-index: calc(2 * var(--orbit-count, 0) + 2);
  overflow: hidden;
}

.planet-orbit {
  fill: none;
  stroke: url("#planet-orbit-ink");
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  opacity: 0;
}

[data-orbit-test] .planet-orbit { opacity: .59; }

@media (min-width: 46.01rem) {
  .planet-orbit { opacity: .59; }
}

.planet-orbit.is-highlighted { opacity: .88; }

.orbit-test {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: .6rem;
  font: 600 .9rem/1.2 system-ui, sans-serif;
  cursor: pointer;
}

.orbit-test input { accent-color: var(--ring); }

.space-traffic {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.space-traffic > span { position: absolute; opacity: 0; }

@media (prefers-reduced-motion: no-preference) {
  [data-motion="live"] .space-stars span:nth-child(5n) {
    animation: twinkle 8s ease-in-out infinite alternate;
  }

  [data-motion="live"] .space-stars span:nth-child(10n) {
    animation-duration: 11s;
    animation-delay: -4s;
  }

  [data-motion]:not([data-motion="still"]) .meteor {
    inset: 20% auto auto 79%;
    width: 4rem;
    height: 2px;
    border-radius: 100%;
    background: linear-gradient(90deg, #fff4cd, transparent);
    animation: sky-meteor 14s linear infinite;
  }

  [data-motion]:not([data-motion="still"]) .meteor:nth-child(2) {
    inset: 34% auto auto 54%;
    animation-duration: 19s;
    animation-delay: 5s;
  }

  [data-motion]:not([data-motion="still"]) .asteroid {
    inset: var(--flight-top) auto auto var(--flight-left);
    width: 2rem;
    aspect-ratio: 84 / 68;
    background: url("./art/asteroid-sprite-sheet.webp") var(--asteroid-frame, 0%) center / 500% 100% no-repeat;
    animation: asteroid-pass 31s linear infinite;
  }

  [data-motion]:not([data-motion="still"]) .asteroid:nth-child(4) {
    width: 1.45rem;
    animation-delay: -12s;
    animation-duration: 38s;
  }

  [data-motion]:not([data-motion="still"]) .asteroid:nth-child(5) {
    width: 1rem;
    animation-delay: -20s;
    animation-duration: 43s;
  }

  [data-motion]:not([data-motion="still"]) .satellite {
    inset: var(--flight-top) auto auto var(--flight-left);
    width: clamp(2rem, 4vw, 3.5rem);
    aspect-ratio: 1.7;
    background: url("./art/satellite-beacon.webp") center / contain no-repeat;
    animation: satellite-pass 105s linear -12s infinite;
  }

  [data-motion="live"] .satellite.satellite--dish {
    background-image: url("./art/satellite-dish.webp");
    animation-duration: 140s;
    animation-delay: -68s;
  }
}

@keyframes twinkle {
  from { opacity: .48; }
  to { opacity: 1; }
}

@keyframes sky-meteor {
  0%, 70% { transform: translate(0, 0) rotate(-31deg); opacity: 0; }
  72% { opacity: .84; }
  79%, 100% { transform: translate(-145px, 88px) rotate(-31deg); opacity: 0; }
}

@keyframes asteroid-pass {
  0% { transform: translate(0, 0) rotate(var(--flight-tilt)); opacity: 0; }
  9%, 83% { opacity: .6; }
  100% { transform: translate(var(--flight-x), var(--flight-y)) rotate(calc(var(--flight-tilt) + 112deg)); opacity: 0; }
}

@keyframes satellite-pass {
  0%, 15% { transform: translate(0, 0) rotate(var(--flight-tilt)); opacity: 0; }
  17%, 44% { opacity: .92; }
  48%, 100% { transform: translate(var(--flight-x), var(--flight-y)) rotate(calc(var(--flight-tilt) + 16deg)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .space-sky,
  [data-theme="space"] .map { transition: none; }
}

@media (prefers-reduced-motion: no-preference) {
  [data-motion="live"] .space-sun {
    animation: sunlight-breath 8s ease-in-out infinite alternate;
  }
}

@keyframes sunlight-breath {
  from { scale: 1; }
  to { scale: 1.12; }
}

.planet-artwork {
  position: relative;
  isolation: isolate;
  width: var(--planet-size, 83%);
}

.planet-visual {
  position: absolute;
  inset: 0;
  isolation: isolate;
  scale: .5;
}

.planet-visual > img { position: relative; }

.planet-ring {
  position: absolute;
  inset: 34% -12% 34%;
  border: 2px solid var(--ring-color, #e1bd98a6);
  border-radius: 50%;
  box-shadow: inset 0 0 3px #eed3ad66, 0 0 3px #eed3ad55;
  rotate: var(--ring-angle, -18deg);
  pointer-events: none;
}

.planet-ring--back {
  z-index: -1;
  clip-path: inset(-4px -4px 49%);
}

.planet-ring--front {
  z-index: 1;
  clip-path: inset(49% -4px -4px);
}

[data-project="games"] { --ring-angle: 18deg; --ring-color: #b2c9b4af; }

.planet-moon-track {
  position: absolute;
  inset: -12%;
  rotate: var(--moon-angle, -17deg);
  pointer-events: none;
}

.planet-moon {
  position: absolute;
  inset: 0 auto auto 0;
  width: clamp(7px, 7%, 14px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: url("./art/moon-rock.webp") center / contain no-repeat;
  filter: drop-shadow(0 0 3px #dec4ad56);
  offset-path: ellipse(var(--moon-rx, 50%) var(--moon-ry, 31%) at 50% 50%);
  offset-distance: var(--moon-position, 46%);
  offset-rotate: 0deg;
}

[data-project="photo"] {
  --moon-angle: 23deg;
  --moon-position: 4%;
  --moon-rx: 48%;
  --moon-ry: 40%;
  --moon-direction: reverse;
  --moon-period: 13s;
  --moon-delay: -1s;
}

@media (prefers-reduced-motion: no-preference) {
  [data-motion="live"] .planet-moon {
    animation: moon-orbit var(--moon-period, 10s) linear var(--moon-delay, -5s) infinite var(--moon-direction, normal);
  }

  [data-motion="live"] .planet-moon-track {
    animation: moon-depth var(--moon-period, 10s) steps(1, end) var(--moon-delay, -5s) infinite var(--moon-direction, normal);
  }
}

@keyframes moon-orbit {
  from { offset-distance: 0%; }
  to { offset-distance: 100%; }
}

@keyframes moon-depth {
  0%, 100% { z-index: 1; }
  50% { z-index: -1; }
}

[data-theme="space"] .scene { overflow-x: clip; }

@media (max-width: 46rem) {
  .planet-moon-track { inset: -8%; }
}

.planet-terminator {
  position: absolute;
  inset: 1.25%;
  z-index: 0;
  border-radius: 50%;
  background: linear-gradient(90deg,
    transparent 30%, #0b091b4d 48%, #090715d9 68%, #070611 93%);
  pointer-events: none;
}

[data-project="games"] { --ring-period: 19s; --ring-phase: -7s; }

@media (prefers-reduced-motion: no-preference) {
  [data-motion="live"] .planet-ring {
    animation: ring-tilt var(--ring-period, 15s) ease-in-out var(--ring-phase, -2s) infinite alternate;
  }

  [data-theme="space"] .project-title {
    transition: opacity .3s ease, translate .35s ease;
  }

  .planet-visual { transition: scale .4s cubic-bezier(.2,.65,.25,1); }
  .planet-terminator { transition: opacity .4s ease; }
  .planet-orbit { transition: opacity .4s ease; }
}

@keyframes ring-tilt {
  from { rotate: calc(var(--ring-angle, -18deg) - 5deg); scale: 1 .81; }
  to { rotate: calc(var(--ring-angle, -18deg) + 5deg); scale: 1 1.13; }
}

[data-theme="space"] a.project:hover { transform: none; }

[data-theme="space"] .project:focus-visible .planet-terminator { opacity: .33; }
[data-theme="space"] .project:focus-visible .planet-visual { scale: 1; }

@media (hover: hover) and (pointer: fine) {
  [data-theme="space"] .project-title { opacity: 0; }
  [data-theme="space"] .project:is(:hover, :focus-visible) .project-title { opacity: 1; }
  [data-theme="space"] .project:hover .planet-terminator { opacity: .33; }
  [data-theme="space"] .project:hover .planet-visual { scale: 1; }

  /* The target follows the resting disc, even when the illustration grows. */
  [data-theme="space"] .map-node,
  [data-theme="space"] .project { pointer-events: none; }

  .planet-artwork::after {
    position: absolute;
    inset: 50% auto auto 50%;
    z-index: 2;
    width: 50%;
    aspect-ratio: 1;
    translate: -50% -50%;
    clip-path: circle(50%);
    pointer-events: auto;
    content: "";
  }
}

@media (prefers-reduced-motion: no-preference) and (hover: hover) and (pointer: fine) {
  [data-theme="space"] .project-title { translate: 0 .35rem; }
  [data-theme="space"] .project:is(:hover, :focus-visible) .project-title { translate: 0; }

}

[data-project="animation"] { --planet-size: 93%; }
[data-project="cabinet"] { --planet-size: 79%; }
[data-project="games"] { --planet-size: 86%; }
[data-project="photo"] { --planet-size: 75%; }

@media (max-width: 23rem) {
  [data-theme="space"] h1 { font-size: 1.5rem; }
}

[data-theme="space"] .map-node {
  z-index: calc(var(--orbit-count, 0) - var(--orbit-rank, 0));
}

[data-theme="space"] .map-node[data-orbit-side="near"] {
  z-index: calc(var(--orbit-count, 0) + 2 + var(--orbit-rank, 0));
}

[data-theme="space"] .map-node:has(.project:is(:hover, :focus-visible)) {
  z-index: calc(2 * var(--orbit-count, 0) + 3);
}

[data-theme="space"] .planet-artwork {
  aspect-ratio: 1;
}

[data-theme="space"] .planet-artwork img {
  height: 100%;
  object-fit: contain;
}

@media (min-width: 46.01rem) {
  [data-theme="space"] .scene {
    padding-inline: 2.5%;
    padding-bottom: clamp(4.5rem, 8vw, 7rem);
  }

  [data-theme="space"] .map--four { width: 100%; }
}

@media (max-width: 46rem) {
  [data-orbit-test] .map {
    min-height: clamp(26rem, 74svh, 40rem);
  }

  [data-orbit-test] .map .map-node:nth-child(n) {
    position: absolute;
    inset: 50% auto auto 50%;
    grid-area: auto;
    width: clamp(4.75rem, 23vw, 6.5rem);
    margin: 0;
    translate: -50% -50%;
  }

  [data-orbit-test] .map .map-node .project { width: 100%; }
}

body[data-page-hidden] * { animation-play-state: paused; }
