/* ───────────── Tokens ───────────── */
:root {
  color-scheme: light dark;

  --bg: #f3efe6;                       /* paper */
  --ink-rgb: 28 26 23;
  --accent: oklch(0.67 0.185 50);      /* the one colour: the Lightly string */
  --grain-blend: multiply;
  --grain-opacity: 0.2;
  --shadow: 28 20 8;

  /* objects are real things, so they keep their own paper in both themes */
  --paper: #fcfaf5;
  --paper-ink: 28 26 23;

  --ink: rgb(var(--ink-rgb));
  --muted: rgb(var(--ink-rgb) / 0.58);

  --sans: "Bricolage Grotesque", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;

  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --out: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131210;
    --ink-rgb: 238 233 223;
    --accent: oklch(0.74 0.17 55);
    --grain-blend: soft-light;
    --grain-opacity: 0.3;
    --shadow: 0 0 0;
    --paper: #ebe6da;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* paper grain */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5  0 0 0 0 .5  0 0 0 0 .5  0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a { color: inherit; text-decoration: none; }

/* ───────────── Stage ───────────── */
.stage {
  position: relative;
  min-height: max(100svh, 660px);
  overflow: hidden;
  isolation: isolate;
  /* set by main.js */
  --cx: 50%;
  --py: 40%;          /* portrait centre */
  --D: 220px;         /* portrait box */
  --name-top: 60%;
  --u: 1;             /* object scale */
}

.strings {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ───────────── Portrait — a black-and-white cut-out, no frame ───────────── */
.portrait {
  position: absolute;
  z-index: 2;
  left: var(--cx);
  top: var(--py);
  width: var(--D);
  height: var(--D);
  margin: 0;
  translate: -50% -50%;
  pointer-events: none;
  animation: bloom 1.1s var(--out) both;
}

.portrait img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 8%;          /* head and shoulders */
  filter: grayscale(1) contrast(1.12) brightness(1.04);
  /* the bust dissolves into the paper just above the name */
  -webkit-mask-image: linear-gradient(#000 58%, transparent 96%);
          mask-image: linear-gradient(#000 58%, transparent 96%);
}

/* stand-in until assets/me.webp exists */
.portrait__fallback {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  fill: color-mix(in oklab, var(--ink) 22%, var(--bg));
}
.portrait.is-empty .portrait__fallback { display: block; }

/* ───────────── Name — the centre of the composition ───────────── */
.mark {
  position: absolute;
  z-index: 3;
  left: var(--cx);
  top: var(--name-top);
  width: max-content;
  max-width: 94vw;
  translate: -50% 0;
  text-align: center;
  animation: rise 1s var(--out) 0.15s both;
}

.mark h1 {
  margin: 0;
  font-family: var(--display);
  font-style: italic;
  font-weight: 460;
  font-variation-settings: "SOFT" 100, "WONK" 1;
  font-size: clamp(46px, 5.2vw, 88px);
  letter-spacing: -0.035em;
  line-height: 1;
  white-space: nowrap;
}

.mark p {
  margin: 10px 0 0;
  font-size: 15px;
  color: var(--muted);
}

/* phones: the name becomes the title at the top, the map sits beneath it */
.stage[data-mode="column"] .mark { top: max(22px, env(safe-area-inset-top)); }
.stage[data-mode="column"] .mark h1 { font-size: clamp(34px, 10.5vw, 46px); }
.stage[data-mode="column"] .mark p  { margin-top: 6px; font-size: 13.5px; }

/* ───────────── Nodes — objects on a desk ───────────── */
.node {
  position: absolute;
  z-index: 3;
  left: var(--x, 50%);
  top: var(--y, 50%);
  width: 0;
  height: 0;
  outline: none;
  transition: opacity 0.35s ease;
  -webkit-tap-highlight-color: transparent;
}

/* native shapes, in px at --u = 1 */
.node[data-kind="card"]  { --w: 152; --h: 92;  --rad: 4px; }
.node[data-kind="album"] { --w: 98;  --h: 98;  --rad: 2px; }
.node[data-kind="art"]   { --w: 92;  --h: 92;  --rad: 14%; }
.node[data-kind="video"] { --w: 142; --h: 80;  --rad: 6px; }
.node[data-kind="book"]  { --w: 78;  --h: 114; --rad: 2px 5px 5px 2px; }
.node[data-kind="app"]   { --w: 86;  --h: 86;  --rad: 23%; }

.thing {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--w) * var(--u) * 1px);
  height: calc(var(--h) * var(--u) * 1px);
  translate: -50% -50%;
  rotate: var(--tilt, 0deg);
  border-radius: var(--rad, 3px);
  overflow: hidden;
  background: var(--paper);
  color: rgb(var(--paper-ink));
  box-shadow:
    0 0 0 0.5px rgb(var(--shadow) / 0.14),
    0 1px 2px rgb(var(--shadow) / 0.12),
    0 10px 22px -8px rgb(var(--shadow) / 0.32);
  transition:
    rotate 0.55s var(--spring),
    scale 0.55s var(--spring),
    opacity 0.5s ease,
    box-shadow 0.35s ease;
}

.thing img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* faint mark on a blank object, so an empty slot still reads as the thing it is */
.thing__blank {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(38%, 34px);
  height: min(38%, 34px);
  fill: none;
  stroke: rgb(var(--paper-ink) / 0.3);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.node[data-kind="book"] .thing::before {      /* spine */
  content: "";
  position: absolute;
  inset: 0 auto 0 7%;
  width: 1px;
  background: rgb(var(--paper-ink) / 0.14);
}

/* the Lightly calling card */
.card {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template: 1fr auto / 1fr auto;
  align-items: start;
  padding: calc(11px * var(--u)) calc(13px * var(--u));
}
.card__name {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-variation-settings: "SOFT" 100, "WONK" 1;
  font-size: calc(27px * var(--u));
  letter-spacing: -0.03em;
  line-height: 1;
}
.card__star {
  font-size: calc(17px * var(--u));
  line-height: 1;
  color: oklch(0.67 0.185 50);
}
.card__url {
  grid-column: 1 / -1;
  font-size: calc(10.5px * var(--u));
  letter-spacing: 0.01em;
  color: rgb(var(--paper-ink) / 0.6);
}

/* labels — identical treatment for every object */
.label {
  position: absolute;
  display: block;
  width: max-content;
  max-width: var(--label-max, 180px);
  left: 0;
  top: calc(var(--h) * var(--u) * 0.5px + 11px);
  translate: -50% 0;
  text-align: center;
  line-height: 1.2;
}
/* an object above the portrait carries its label above, so its string never runs through the text */
.node[data-label="above"] .label {
  top: auto;
  bottom: calc(var(--h) * var(--u) * 0.5px + 11px);
}

.label__title {
  display: block;
  font-size: 16px;
  font-weight: 620;
  letter-spacing: -0.025em;
}
.label__desc {
  display: block;
  margin-top: 1px;
  font-size: 13.5px;
  color: var(--muted);
}

.stage[data-mode="column"] .node[data-side="top"] .label { max-width: 92vw; }
.stage[data-mode="column"] .label__title { font-size: 15px; }
.stage[data-mode="column"] .label__desc  { font-size: 12px; }

/* interaction: the object lifts and straightens; main.js plucks its string */
@media (hover: hover) {
  .stage:has(.node:hover) .node:not(:hover) { opacity: 0.45; }
}
.node:focus-visible .thing { outline: 2px solid var(--accent); outline-offset: 4px; }

/* reveal — main.js adds .is-on when a string reaches its object, and it settles onto the desk */
.js .node .thing {
  opacity: 0;
  scale: 1.14;
  rotate: calc(var(--tilt, 0deg) * 3.5);
}
.js .node .label { opacity: 0; transition: opacity 0.7s ease 0.15s; }
.js .node.is-on .thing { opacity: 1; scale: 1; rotate: var(--tilt, 0deg); }
.js .node.is-on .label { opacity: 1; }

@media (hover: hover) {
  .js .node.is-on:hover .thing {
    rotate: 0deg;
    scale: 1.07;
    box-shadow:
      0 0 0 0.5px rgb(var(--shadow) / 0.14),
      0 2px 4px rgb(var(--shadow) / 0.12),
      0 22px 36px -12px rgb(var(--shadow) / 0.42);
  }
}
.js .node.is-on:focus-visible .thing { rotate: 0deg; scale: 1.07; }
.js .node.is-on:active .thing { scale: 0.97; }

/* ───────────── Footer — ways to reach me, kept quiet ───────────── */
.foot {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  font-size: 14px;
  color: var(--muted);
  animation: rise 0.9s var(--out) 0.6s both;
}

.foot__copy {
  display: none;
  position: absolute;
  left: 32px;
  bottom: 0;
  line-height: 32px;
  font-size: 13px;
}
.stage[data-mode="orbit"] .foot__copy { display: block; }

.foot__links { display: flex; gap: 6px; }

.foot__links a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  transition: color 0.2s ease, background-color 0.2s ease;
}
.foot__links a:hover,
.foot__links a:focus-visible {
  color: var(--ink);
  background: rgb(var(--ink-rgb) / 0.07);
  outline: none;
}
.foot__links svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ───────────── Motion ───────────── */
@keyframes bloom { from { opacity: 0; scale: 0.9; } }
@keyframes rise  { from { opacity: 0; translate: -50% 10px; } }
.foot { animation-name: rise-plain; }
@keyframes rise-plain { from { opacity: 0; translate: 0 8px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}

/* ───────────── No-JS fallback: a simple centred list ───────────── */
html:not(.js) .stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding: 60px 24px 90px;
}
html:not(.js) .strings { display: none; }
html:not(.js) .portrait,
html:not(.js) .mark { position: relative; left: auto; top: auto; translate: none; animation: none; }
html:not(.js) .nodes { display: grid; gap: 22px; }
html:not(.js) .node {
  position: relative;
  left: auto; top: auto; width: auto; height: auto;
  display: flex; align-items: center; gap: 16px;
}
html:not(.js) .thing { position: relative; translate: none; flex: none; }
html:not(.js) .label { position: static; translate: none; text-align: left; }
