/* ── Fonts ────────────────────────────────────────────────────────────── */
/* Newsreader (SIL OFL), display cut, subset by tools/subset-fonts.sh. */
@font-face {
  font-family: "Newsreader";
  src: url("/fonts/newsreader-latin.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("/fonts/newsreader-latin-ext.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0106-0107, U+010C-010D, U+0110-0111, U+0160-0161, U+017D-017E;
}
/* Only downloaded when the arcade opens. */
@font-face {
  font-family: "Press Start 2P";
  src: url("/fonts/press-start-2p-latin-400-normal.woff2") format("woff2");
  font-display: block;
}

/* ── Tokens ───────────────────────────────────────────────────────────── */
:root {
  --bg: #fbf9f6;
  --surface: #f3efe9;
  --ink: #1f1c19;
  --ink-2: #57524c;
  --ink-3: #736d66;
  --line: #e8e2da;
  --accent: #a8431c;

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --side: 280px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151413;
    --surface: #201e1c;
    --ink: #ece8e2;
    --ink-2: #b5afa7;
    --ink-3: #928c84;
    --line: #2b2825;
    --accent: #e58a5f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151413;
  --surface: #201e1c;
  --ink: #ece8e2;
  --ink-2: #b5afa7;
  --ink-3: #928c84;
  --line: #2b2825;
  --accent: #e58a5f;
  color-scheme: dark;
}

/* ── Base ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg { display: block; max-width: 100%; }
img { height: auto; }
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
::selection { background: var(--accent); color: var(--bg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 50;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.9rem;
}
.skip-link:focus { top: 12px; }

/* ── Shell: sidebar + main ────────────────────────────────────────────── */
.shell { min-height: 100dvh; }

.side {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 20px 20px;
  view-transition-name: side;
}

.me { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.me-photo { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; }
.me-text { display: grid; line-height: 1.3; }
.me-name { font-weight: 600; font-size: 0.95rem; letter-spacing: -0.005em; }
.me-role { font-size: 0.82rem; color: var(--ink-3); }

.nav { display: grid; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 0.92rem;
  color: var(--ink-2);
  transition: background-color 0.2s, color 0.2s;
}
.nav a svg { flex: none; color: var(--ink-3); transition: color 0.2s; }
.nav a:hover { background: var(--surface); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--surface); color: var(--ink); }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav .nav-arrow { width: 14px; height: 14px; margin-left: auto; opacity: 0.6; }

.side-work { display: grid; gap: 6px; padding-top: 24px; border-top: 1px solid var(--line); }
.side-label { padding: 0 12px 4px; font-size: 0.78rem; color: var(--ink-3); }
.side-work a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  border-radius: 9px;
  transition: background-color 0.2s;
}
.side-work a:hover, .side-work a[aria-current="page"] { background: var(--surface); }
.side-work img {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--line);
}
.side-work span span { display: block; line-height: 1.3; }
.side-work-name { font-size: 0.88rem; }
.side-work-kind { font-size: 0.78rem; color: var(--ink-3); }

.side-foot { display: flex; align-items: center; gap: 2px; margin-top: auto; padding: 0 4px; }
.side-foot .theme-toggle { margin-left: auto; }

.icon-link {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s;
}
.icon-link:hover { color: var(--ink); background: var(--surface); }
.icon-x svg { width: 15px; height: 15px; }
.theme-toggle .i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: block; }
}

.main { min-width: 0; }
.main:focus { outline: none; }
.mobile-foot { display: none; }

/* Phones and small tablets: the sidebar becomes a top bar. */
@media (max-width: 899px) {
  .side {
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .me { padding: 0; }
  .me-photo { width: 34px; height: 34px; border-radius: 8px; }
  .me-role { display: none; }
  .nav { display: flex; gap: 0; }
  .nav a { height: 36px; padding: 0 10px; }
  .nav a svg, .nav a:first-child, .nav .nav-ext { display: none; }
  .me-name { white-space: nowrap; }
  .side-work, .side-foot { display: none; }

  .mobile-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 16px;
    padding: 20px 0 calc(20px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
  }
  .mobile-foot > span { display: flex; gap: 2px; }
}

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); }
  .side {
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    border-right: 1px solid var(--line);
  }
}

/* ── Shared type ──────────────────────────────────────────────────────── */
.page {
  max-width: 820px;
  padding: 56px 20px 72px;
}
@media (min-width: 900px) {
  .page { padding: 112px clamp(40px, 7vw, 120px) 120px; }
}

.page-head { margin-bottom: 56px; }
.page-head h1, .project-head h1, .lost h1 {
  font: 400 clamp(2.5rem, 1.6rem + 3vw, 3.6rem)/1.05 var(--serif);
  letter-spacing: -0.02em;
}
.lede {
  margin-top: 16px;
  max-width: 44ch;
  font-size: 1.12rem;
  line-height: 1.55;
  color: var(--ink-2);
}

.arrow-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}
.arrow-link span { transition: transform 0.3s var(--ease); }
a.arrow-link:hover span, a:hover .arrow-link span { transform: translateX(4px); }

.quiet-link { font-size: 0.95rem; color: var(--ink-2); }
.quiet-link:hover { color: var(--ink); }

.i-ext { display: inline-block; width: 14px; height: 14px; margin-left: 3px; vertical-align: -1px; opacity: 0.7; }

/* ── Home ─────────────────────────────────────────────────────────────── */
.home {
  display: grid;
  gap: 48px;
  padding: 56px 20px 64px;
}
.hello { font: 400 clamp(1.7rem, 1.3rem + 1.4vw, 2.5rem)/1.1 var(--serif); letter-spacing: -0.01em; }
.hello-name {
  margin-top: 4px;
  font: 500 clamp(2.9rem, 1.8rem + 4vw, 4.6rem)/1.02 var(--serif);
  letter-spacing: -0.025em;
  color: var(--accent);
  white-space: nowrap;
}
.home-line {
  max-width: 36ch;
  margin-top: 22px;
  font-size: 1.15rem;
  line-height: 1.55;
  color: var(--ink-2);
}
.home-links { display: flex; align-items: center; gap: 28px; margin-top: 30px; }

.home-photo { width: min(100%, 380px); }
.photo {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 2px rgb(31 28 25 / 0.06), 0 24px 48px -28px rgb(31 28 25 / 0.35);
}
.photo img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.photo:focus-visible { outline-offset: 4px; border-radius: 18px; }
.photo-stamp {
  position: absolute;
  right: 18px;
  bottom: 16px;
  font: 600 1rem/1 var(--mono);
  letter-spacing: 0.14em;
  color: #ff8a2a;
  text-shadow: 0 0 6px rgb(255 120 30 / 0.85), 0 0 1px #ffb46b;
  opacity: 0;
  transition: opacity 0.4s;
}
.photo-stamp.is-on { opacity: 0.95; }
.photo-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.photo-flash.is-firing { animation: flash 0.7s ease-out; }
@keyframes flash { 8% { opacity: 1; } 100% { opacity: 0; } }

@media (min-width: 900px) {
  .home {
    min-height: 100dvh;
    max-width: 1160px;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
    align-items: center;
    gap: 72px;
    padding: 64px clamp(40px, 7vw, 120px);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .js .home-text > *, .js .home-photo { animation: rise 0.9s var(--ease) both; }
  .js .home-text > :nth-child(2) { animation-delay: 0.06s; }
  .js .home-text > :nth-child(3) { animation-delay: 0.12s; }
  .js .home-text > :nth-child(4) { animation-delay: 0.18s; }
  .js .home-photo { animation-delay: 0.1s; }
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ── Work ─────────────────────────────────────────────────────────────── */
.page:has(.work-list) { max-width: 1000px; }

.work-list { border-top: 1px solid var(--line); }
.work-item { border-bottom: 1px solid var(--line); }
.work-item a {
  display: grid;
  gap: 20px;
  padding: 28px 0;
}
@media (min-width: 700px) {
  .work-item a { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr); gap: 40px; align-items: center; padding: 32px 0; }
}

.work-media {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
}
.work-media img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.9s var(--ease); }
.work-item a:hover .work-media img { transform: scale(1.03); }

.work-text { display: grid; gap: 8px; justify-items: start; }
.work-kind { font-size: 0.85rem; color: var(--ink-3); }
.work-name { font: 400 clamp(1.7rem, 1.3rem + 1vw, 2.1rem)/1.1 var(--serif); letter-spacing: -0.015em; }
.work-summary { max-width: 40ch; color: var(--ink-2); }
.work-text .arrow-link { margin-top: 8px; }

.also { margin-top: 72px; }
.also h2 { margin-bottom: 20px; font: 400 1.6rem/1.2 var(--serif); }
.also ul { display: grid; gap: 28px; }
@media (min-width: 700px) { .also ul { grid-template-columns: 1fr 1fr; gap: 40px; } }
.also h3 { font-size: 1rem; font-weight: 600; }
.also p { margin-top: 4px; color: var(--ink-2); font-size: 0.97rem; }
.also-links { display: flex; gap: 18px; }
.also-links a, .facts a { font-weight: 500; color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 0.22em; text-decoration-thickness: 1px; transition: text-decoration-color 0.2s; }
.also-links a:hover, .facts a:hover { text-decoration-color: var(--accent); }

/* ── Project page ─────────────────────────────────────────────────────── */
.page.project { max-width: 1000px; }
.crumb { margin-bottom: 40px; font-size: 0.9rem; }
.crumb a { color: var(--ink-3); }
.crumb a:hover { color: var(--ink); }
.project-kind { margin-bottom: 14px; font-size: 0.9rem; color: var(--ink-3); }
.project-head h1 { display: flex; align-items: baseline; gap: 14px; }
.h1-ext { color: var(--ink-3); transition: color 0.2s; }
.h1-ext svg { width: 30px; height: 30px; }
.h1-ext:hover { color: var(--accent); }

.project-cover {
  position: relative;
  margin: 48px 0 56px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line), 0 30px 60px -40px rgb(31 28 25 / 0.45);
}
.project-cover img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }

.prose { max-width: 62ch; font-size: 1.06rem; line-height: 1.75; color: var(--ink-2); }
.prose p + p, .prose p + pre, .prose pre + p { margin-top: 1.1em; }
.prose-lead { font: 400 1.5rem/1.4 var(--serif); color: var(--ink); letter-spacing: -0.01em; }
.prose a, .about-section a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
.prose a:hover, .about-section a:hover { color: var(--accent); }
.prose pre {
  margin: 0;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--surface);
  overflow-x: auto;
  font: 0.85rem/1.6 var(--mono);
  color: var(--ink);
}

.facts {
  display: grid;
  max-width: 62ch;
  margin-top: 56px;
  border-top: 1px solid var(--line);
}
.facts > div {
  display: grid;
  gap: 2px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
@media (min-width: 600px) { .facts > div { grid-template-columns: 140px minmax(0, 1fr); gap: 16px; } }
.facts dt { font-size: 0.88rem; color: var(--ink-3); }
.facts dd { font-size: 0.97rem; }
.facts dd a + a { margin-left: 18px; }

.next { margin-top: 72px; }
.next a { display: inline-grid; gap: 2px; }
.next-label { font-size: 0.88rem; color: var(--ink-3); }
.next-name { font: 400 1.7rem/1.2 var(--serif); letter-spacing: -0.01em; }
.next-name span { display: inline-block; color: var(--accent); transition: transform 0.3s var(--ease); }
.next a:hover .next-name span { transform: translateX(5px); }

/* Slipstream: five red lights on hover, then lights out. */
.lights {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 9px;
  background: rgb(8 8 8 / 0.85);
  opacity: 0;
  transition: opacity 0.3s;
}
.lights i { width: 9px; height: 9px; border-radius: 50%; background: #3a1414; }
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .has-lights:hover .lights { opacity: 1; }
  .has-lights:hover .lights i { animation: light1 5s steps(1, end) forwards; }
  .has-lights:hover .lights i:nth-child(2) { animation-name: light2; }
  .has-lights:hover .lights i:nth-child(3) { animation-name: light3; }
  .has-lights:hover .lights i:nth-child(4) { animation-name: light4; }
  .has-lights:hover .lights i:nth-child(5) { animation-name: light5; }
}
@keyframes light1 { 8%  { background: #ff2b2b; box-shadow: 0 0 8px #ff2b2b; } 86% { background: #3a1414; box-shadow: none; } }
@keyframes light2 { 24% { background: #ff2b2b; box-shadow: 0 0 8px #ff2b2b; } 86% { background: #3a1414; box-shadow: none; } }
@keyframes light3 { 40% { background: #ff2b2b; box-shadow: 0 0 8px #ff2b2b; } 86% { background: #3a1414; box-shadow: none; } }
@keyframes light4 { 56% { background: #ff2b2b; box-shadow: 0 0 8px #ff2b2b; } 86% { background: #3a1414; box-shadow: none; } }
@keyframes light5 { 72% { background: #ff2b2b; box-shadow: 0 0 8px #ff2b2b; } 86% { background: #3a1414; box-shadow: none; } }

/* ── About ────────────────────────────────────────────────────────────── */
.about .page-head { margin-bottom: 40px; }
.about-section { max-width: 760px; margin-top: 64px; }
.about-section h2 { margin-bottom: 16px; font: 400 1.6rem/1.2 var(--serif); letter-spacing: -0.01em; }
.about-section > p { font-size: 1.06rem; line-height: 1.75; color: var(--ink-2); }

.rows { border-top: 1px solid var(--line); }
.rows > div {
  display: grid;
  gap: 4px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
@media (min-width: 640px) { .rows > div { grid-template-columns: 210px minmax(0, 1fr); gap: 24px; } }
.rows dt { font-size: 0.95rem; line-height: 1.6; }
.rows dd { font-size: 0.97rem; line-height: 1.6; color: var(--ink-2); }
.rows--problems dt { font-weight: 600; color: var(--ink); }
.rows--tools dt { color: var(--ink-3); }
.rows--tools dd { color: var(--ink); }

#email.is-highlight { color: var(--accent); }

/* ── 404 ──────────────────────────────────────────────────────────────── */
.lost { min-height: 70dvh; display: grid; align-content: center; gap: 0; }
.lost .arrow-link { margin-top: 28px; }

/* ── Arcade (↑ ↑ ↓ ↓ ← → ← → B A) ─────────────────────────────────────── */
.arcade {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: #07070c;
  color: #e8e6ff;
  overflow: hidden;
}
.arcade::backdrop { background: #000; }
.arcade[open] { display: grid; place-items: center; animation: crt-on 0.5s ease-out; }
@keyframes crt-on {
  0% { transform: scaleY(0.004) scaleX(0.6); filter: brightness(4); }
  45% { transform: scaleY(0.004) scaleX(1); }
  100% { transform: none; filter: none; }
}
.arcade::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgb(0 0 0 / 0.35) 0 1px, transparent 1px 3px),
    radial-gradient(120% 90% at 50% 50%, transparent 55%, rgb(0 0 0 / 0.75));
}
.arcade-screen {
  width: min(760px, 92vw);
  font-family: "Press Start 2P", var(--mono);
  font-size: clamp(9px, 1.6vw, 14px);
  line-height: 1.9;
  text-align: center;
  text-shadow: 0 0 6px currentColor;
}
.arcade-title { margin-bottom: 1.6em; font-size: 1.9em; color: #ff4fa3; }
.arcade-table { width: 100%; margin: 0 auto 2.2em; border-collapse: collapse; }
.arcade-table th { padding-bottom: 0.9em; font-weight: 400; color: #6ee7ff; }
.arcade-table td { padding: 0.35em 0.4em; white-space: nowrap; }
.arcade-table :is(th, td):nth-child(2) { text-align: left; }
.arcade-table :is(th, td):nth-child(3) { text-align: right; }
.arcade-table tr:nth-child(1) td { color: #ffd84a; }
.arcade-table tr:nth-child(2) td { color: #ff9b3d; }
.arcade-table tr:nth-child(3) td { color: #ff5f5f; }
.arcade-table tr:nth-child(4) td { color: #b98cff; }
.arcade-table tr:nth-child(5) td { color: #6ee7ff; }
.arcade-table tbody tr { opacity: 0; animation: row-in 0.01s forwards; }
.arcade-table tbody tr:nth-child(1) { animation-delay: 0.5s; }
.arcade-table tbody tr:nth-child(2) { animation-delay: 0.8s; }
.arcade-table tbody tr:nth-child(3) { animation-delay: 1.1s; }
.arcade-table tbody tr:nth-child(4) { animation-delay: 1.4s; }
.arcade-table tbody tr:nth-child(5) { animation-delay: 1.7s; }
@keyframes row-in { to { opacity: 1; } }
.arcade-player { margin-bottom: 1.2em; color: #9df59d; }
.arcade-blink { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.arcade-hint { margin-top: 2.4em; font-size: 0.75em; color: #8a88a8; }
.arcade-hint button { padding: 0.4em; border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }

/* ── Page and theme transitions ───────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: fade-out 0.18s ease both; }
  ::view-transition-new(root) { animation: fade-in 0.32s var(--ease) both; }
  ::view-transition-group(side),
  ::view-transition-old(side),
  ::view-transition-new(side) { animation: none; }
  /* The theme switch reveals the whole page at once, sidebar included. */
  :root.theme-switch .side { view-transition-name: none; }
  :root.theme-switch::view-transition-old(root) { animation: none; }
  :root.theme-switch::view-transition-new(root) { animation: reveal 0.6s var(--ease); }
}
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes reveal {
  from { clip-path: circle(0 at var(--vt-x, 0) var(--vt-y, 100%)); }
  to { clip-path: circle(var(--vt-r, 150vmax) at var(--vt-x, 0) var(--vt-y, 100%)); }
}

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