/* ---------- Fonts (self-hosted, latin subset) ---------- */
@font-face {
  font-family: "Geist";
  src: url("../fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("../fonts/geist-mono.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("../fonts/instrument-serif.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("../fonts/instrument-serif-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --fg: #ecebe6;
  --muted: #8a8983;   /* 5.8:1 on --bg */
  --dim: #9c9b95;     /* inactive row names, 7:1 on --bg */
  --line: rgba(236, 235, 230, 0.1);

  --stage-bg: #121211;
  --stage-edge: rgba(236, 235, 230, 0.07);
  --stage-fg: #ecebe6;
  --stage-muted: rgba(236, 235, 230, 0.55);
  --stage-dot: rgba(236, 235, 230, 0.82);

  --accent: #ff5b24;

  --serif: "Instrument Serif", ui-serif, Georgia, serif;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --gutter: clamp(16px, 2vw, 28px);
  --radius: 18px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent); color: #0a0a0a; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "stage head"
    "stage index"
    "stage foot";
  column-gap: clamp(24px, 4vw, 72px);
  padding: var(--gutter);
}
.head  { grid-area: head; padding-top: 8px; }
.stage { grid-area: stage; }
.index { grid-area: index; }
.foot  { grid-area: foot; }

/* ---------- Header ---------- */
.name {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(44px, 5.4vw, 88px);
  line-height: 0.92;
  letter-spacing: -0.02em;
}
.name em { font-style: italic; color: var(--muted); }
.intro {
  margin: 18px 0 0;
  max-width: 34ch;
  color: var(--muted);
}

/* ---------- Stage ---------- */
.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--stage-bg);
  color: var(--stage-fg);
  box-shadow: inset 0 0 0 1px var(--stage-edge);
  isolation: isolate;
  touch-action: pan-y;
}
/* A faint wash of the active project's color behind the dots. */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(60% 55% at 50% 40%, var(--accent), transparent 70%);
  opacity: 0.09;
  transition: background 0.8s var(--ease);
}
.field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* Fade the dots out where the text sits. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 2%, #000 16%, #000 40%, transparent 70%);
          mask-image: linear-gradient(to bottom, transparent 2%, #000 16%, #000 40%, transparent 70%);
}
.stage-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 22px 26px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--stage-muted);
  pointer-events: none;
}
.counter [data-d="index"] { color: var(--stage-fg); }

.detail {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 0 clamp(22px, 3vw, 40px) clamp(22px, 3vw, 36px);
}
.detail > * {
  transition: opacity 0.5s var(--ease), transform 0.6s var(--ease);
}
.detail > :nth-child(2) { transition-delay: 0.03s; }
.detail > :nth-child(3) { transition-delay: 0.06s; }
.detail > :nth-child(4) { transition-delay: 0.09s; }
.detail > :nth-child(5) { transition-delay: 0.12s; }
.detail.is-out > * {
  opacity: 0;
  transform: translateY(10px);
  transition-duration: 0.14s;
  transition-delay: 0s;
}

.detail-kind {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--stage-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}
.detail-kind::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  transition: background-color 0.4s var(--ease);
}
.detail-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(48px, 6.4vw, 104px);
  line-height: 0.95;
  letter-spacing: -0.02em;
}
.detail-desc {
  margin: 14px 0 0;
  max-width: 46ch;
  font-size: 16px;
  color: rgba(236, 235, 230, 0.78);
}
.detail-tags {
  margin: 12px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--stage-muted);
}
.detail-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid rgba(236, 235, 230, 0.22);
  transition: background-color 0.25s var(--ease), border-color 0.25s var(--ease), color 0.25s var(--ease);
}
.btn:hover { border-color: rgba(236, 235, 230, 0.6); }
.btn--primary {
  background: var(--stage-fg);
  color: var(--stage-bg);
  border-color: var(--stage-fg);
}
.btn--primary:hover { background: var(--accent); border-color: var(--accent); color: #0f0f0f; }
.btn .arrow { transition: transform 0.25s var(--ease); }
.btn:hover .arrow { transform: translate(2px, -2px); }

/* ---------- Project index ---------- */
.index {
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 0;
}
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid var(--line);
}
.list li {
  position: relative;
  border-top: 1px solid var(--line);
}
.list li::before {
  content: "";
  position: absolute;
  top: -1px; left: 0;
  width: 100%; height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.6s var(--ease);
}
.list li:has(.row[aria-current="true"])::before { transform: scaleX(1); }
.row {
  width: 100%;
  display: grid;
  grid-template-columns: 3ch minmax(0, 1fr) auto minmax(5ch, auto);
  align-items: baseline;
  column-gap: 16px;
  padding: clamp(10px, 1.6vh, 16px) 2px;
  text-align: left;
  transition: color 0.3s var(--ease), opacity 0.3s var(--ease);
}
.row-num, .row-year, .row-kind {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}
.row-year { text-align: right; white-space: nowrap; }
.row-name {
  position: relative;
  font-size: clamp(18px, 1.6vw, 24px);
  letter-spacing: -0.01em;
  transition: transform 0.45s var(--ease);
}
.row-name::after {
  content: "↗";
  display: inline-block;
  margin-left: 10px;
  font-size: 0.7em;
  color: var(--accent);
  opacity: 0;
  transform: translate(-4px, 4px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.row[aria-current="true"] .row-name { transform: translateX(10px); }
.row[aria-current="true"] .row-name::after { opacity: 1; transform: none; }
.row[aria-current="true"] .row-num { color: var(--accent); }

/* Inactive rows recede via color (not opacity) so text stays readable. */
.list .row .row-name { color: var(--dim); transition: color 0.3s var(--ease), transform 0.45s var(--ease); }
.list .row[aria-current="true"] .row-name,
.list .row:hover .row-name,
.list .row:focus-visible .row-name { color: var(--fg); }
.list .row[aria-current="true"] :is(.row-kind, .row-year) { color: var(--fg); }

/* ---------- Footer ---------- */
.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 4px;
  font-size: 13px;
  color: var(--muted);
}
.social {
  display: flex;
  gap: 18px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.social a { color: var(--fg); background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat; transition: background-size 0.35s var(--ease); }
.social a:hover { background-size: 100% 1px; }
.foot-meta { display: flex; align-items: center; gap: 16px; font-family: var(--mono); font-size: 12px; }
.hint kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px; height: 20px;
  margin-right: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: inherit;
  font-size: 11px;
}

/* ---------- Entrance ---------- */
.js .head, .js .foot, .js .stage-top, .js .detail {
  transition: opacity 0.9s var(--ease), transform 1s var(--ease);
}
.js:not(.is-ready) .head,
.js:not(.is-ready) .foot,
.js:not(.is-ready) .stage-top,
.js:not(.is-ready) .detail { opacity: 0; transform: translateY(14px); }
.js .head { transition-delay: 0.1s; }
.js .detail { transition-delay: 0.45s; }
.js .stage-top, .js .foot { transition-delay: 0.6s; }
.js .index .list li {
  transition: opacity 0.7s var(--ease), transform 0.8s var(--ease);
  transition-delay: calc(0.3s + var(--i, 0) * 60ms);
}
.js:not(.is-ready) .index .list li { opacity: 0; transform: translateY(8px); }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .shell {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "head" "stage" "index" "foot";
    row-gap: 20px;
  }
  .head { padding-top: 12px; }
  .stage { height: min(78svh, 640px); min-height: 460px; }
  .index { padding: 4px 0 8px; }
  .row { grid-template-columns: 3ch minmax(0, 1fr) minmax(5ch, auto); padding: 16px 2px; }
  .row-kind { display: none; }
  .hint { display: none; }
}

@media (hover: none) {
  .hint { display: none; }
}

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