/* ---- Tokens ------------------------------------------------------------ */

:root, :root[data-theme='dark'] {
  --bg: #06070a;
  --fg: #eaeaf0;
  --muted: #71717f;
  --line: rgba(255,255,255,0.12);
  --card: #0d0e13;
  --accent: 120, 255, 60;
  /* torus scene */
  --wire: 155, 220, 255;
  --node: 120, 255, 214;
  --smoke: 205, 210, 220;
  --spark: 255, 255, 235;
}
:root[data-theme='light'] {
  --bg: #f6f6f4;
  --fg: #0e0e13;
  --muted: #6b6b76;
  --line: rgba(0,0,0,0.12);
  --card: #ffffff;
  --accent: 55, 185, 15;
  --wire: 30, 70, 120;
  --node: 10, 130, 105;
  --smoke: 105, 110, 120;
  --spark: 40, 40, 55;
}

/* ---- Base -------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 2rem clamp(1.5rem, 5vw, 4rem);
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid rgb(var(--accent));
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---- Header / nav -------------------------------------------------------- */

.site-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.wordmark {
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-left: auto;
}

.site-nav a {
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  text-decoration: none;
  color: var(--muted);
  transition: color 0.2s ease;
}
.site-nav a:hover,
.site-nav a[aria-current='page'] { color: var(--fg); }

.toggle {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: border-color 0.2s ease;
}
.toggle:hover { border-color: var(--muted); }
.toggle span {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--fg);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}
:root[data-theme='light'] .toggle span {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--fg);
}

@media (max-width: 560px) {
  .site-nav { gap: 1rem; }
  .site-nav a { font-size: 0.75rem; }
}

/* ---- Home (torus) -------------------------------------------------------- */

.home { overflow: hidden; }

#scene { position: fixed; inset: 0; z-index: 0; }

.home .hero {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  align-items: center;
  pointer-events: none;
}
.home .email {
  margin: 1rem 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.875rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  pointer-events: auto;
  user-select: all;
}
.home h1 {
  margin: 0;
  max-width: 14ch;
  font-size: clamp(2.25rem, 7vw, 4.75rem);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.035em;
  text-shadow: 0 2px 40px var(--bg);
}

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

.page {
  flex: 1;
  width: 100%;
  max-width: 44rem;
  padding: clamp(2rem, 6vh, 5rem) 0 3rem;
}
.page h1 {
  margin: 0 0 1.5rem;
  font-size: clamp(1.75rem, 4.5vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.page p { margin: 0 0 1rem; max-width: 60ch; }
.page .lede { font-size: 1.125rem; }
.muted { color: var(--muted); }

.pill-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1.5rem 0 0; padding: 0; list-style: none; }
.pill {
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-top: 2rem; }
.card {
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  text-decoration: none;
  display: block;
  transition: border-color 0.2s ease;
}
.card:hover { border-color: var(--muted); }
.card h2 { margin: 0 0 0.375rem; font-size: 1rem; font-weight: 550; }
.card p { margin: 0; font-size: 0.875rem; color: var(--muted); }

.site-footer { position: relative; z-index: 1; font-size: 0.75rem; color: var(--muted); }

/* ---- Fun: Nose Breakout ------------------------------------------------------ */

.arcade {
  flex: 1;
  width: 100%;
  max-width: 72rem;
  padding: clamp(1.5rem, 5vh, 3.5rem) 0 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(240px, 28vw, 340px);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: start;
}
.arcade-left { min-width: 0; max-width: 640px; }
.arcade-right { position: sticky; top: 2rem; }

.arcade h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.75rem, 4.5vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.03em;
}
.arcade .lede { margin: 0 0 1.5rem; color: var(--muted); max-width: 60ch; }

.game-frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
}
#game { display: block; width: 100%; height: auto; }

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.75rem 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8125rem;
  color: var(--muted);
}
.hud strong { color: var(--fg); font-weight: 600; }

.btn {
  font: inherit;
  font-size: 0.8125rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: rgb(var(--accent)); color: #06070a; border-color: transparent; }

.cam-frame {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 3;
}
#cam { display: block; width: 100%; height: 100%; }
#video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.cam-note { margin-top: 1rem; font-size: 0.8125rem; color: var(--muted); }
.cam-note strong { color: var(--fg); font-weight: 550; }
.cam-note p { margin: 0 0 0.625rem; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.75rem;
}
.status::before {
  content: '';
  width: 0.5rem; height: 0.5rem;
  border-radius: 50%;
  background: var(--muted);
}
.status[data-state='ok']::before { background: rgb(var(--accent)); }
.status[data-state='err']::before { background: #ff4d6d; }

@media (max-width: 760px) {
  .arcade { grid-template-columns: 1fr; }
  .arcade-right { position: static; }
}

/* ---- Home: social icons ---------------------------------------------------------- */

.social {
  display: flex;
  gap: 1rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
  pointer-events: auto;
}
.social a {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  color: var(--fg);
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}
.social a:hover { transform: translateY(-2px); }
.social svg { width: 1.5rem; height: 1.5rem; display: block; }
.social a[data-brand='linkedin']:hover { color: #0a66c2; }
.social a[data-brand='github']:hover   { color: #3fb950; }

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

/* ---- Toy pages: controls -------------------------------------------------------- */

.crumb { margin: 0 0 0.75rem; font-size: 0.75rem; letter-spacing: 0.04em; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--fg); }

.panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  padding: 1rem 1.125rem;
  font-size: 0.8125rem;
}
.panel + .panel { margin-top: 1rem; }
.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.seg { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.seg button {
  font: inherit;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.75rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
.seg button:hover { border-color: var(--muted); color: var(--fg); }
.seg button[aria-pressed='true'] { background: rgb(var(--accent)); color: #06070a; border-color: transparent; }

.ctl { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.25rem 0.75rem; margin-top: 0.75rem; }
.ctl label { color: var(--fg); }
.ctl output { font-family: ui-monospace, Menlo, monospace; color: var(--muted); font-size: 0.75rem; text-align: right; }
.ctl input[type='range'] { grid-column: 1 / -1; width: 100%; accent-color: rgb(var(--accent)); margin: 0; }

.check { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.625rem; cursor: pointer; }
.check input { accent-color: rgb(var(--accent)); margin: 0; }

.readout { width: 100%; border-collapse: collapse; font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; }
.readout td { padding: 0.2rem 0; border-bottom: 1px dashed var(--line); }
.readout td:first-child { color: var(--muted); }
.readout td:last-child { text-align: right; }
.readout tr:last-child td { border-bottom: 0; }

.matrix { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; white-space: pre; line-height: 1.5; margin: 0.5rem 0 0; }

.toy-frame { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.toy-frame canvas { display: block; width: 100%; height: auto; touch-action: none; }
.toy-hint { margin: 0.75rem 0 0; font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: var(--muted); }

/* ---- Fun Stuff list ---------------------------------------------------------------- */

.toy-list { list-style: none; margin: 2rem 0 0; padding: 0; border-top: 1px solid var(--line); }
.toy-list li { border-bottom: 1px solid var(--line); }
.toy-list a {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  align-items: baseline;
  gap: 1rem;
  padding: 1.125rem 0.25rem;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.toy-list a:hover { background: var(--card); }
.toy-num { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: var(--muted); }
.toy-body { display: flex; flex-direction: column; gap: 0.25rem; }
.toy-title { font-size: 1.0625rem; font-weight: 550; }
.toy-desc { font-size: 0.875rem; color: var(--muted); max-width: 60ch; }
.toy-arrow { color: var(--muted); transition: transform 0.15s ease, color 0.15s ease; }
.toy-list a:hover .toy-arrow { transform: translateX(4px); color: var(--fg); }

.status-line { margin: 0.75rem 0 0; font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: rgb(var(--accent)); min-height: 1.2em; }
.kbd { display: inline-block; padding: 0 0.375rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; font-family: ui-monospace, Menlo, monospace; font-size: 0.6875rem; color: var(--fg); }
.seg button.go { color: var(--fg); border-color: rgba(var(--accent), 0.6); }
.seg button.go:hover { background: rgb(var(--accent)); color: #06070a; }


/* ---- Blog ------------------------------------------------------------------------- */

.post-list { list-style: none; margin: 2rem 0 0; padding: 0; border-top: 1px solid var(--line); }
.post-list li { border-bottom: 1px solid var(--line); }
.post-list a {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 1rem;
  padding: 1.125rem 0.25rem;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.post-list a:hover { background: var(--card); }
.post-date { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: var(--muted); padding-top: 0.2rem; }
.post-title { display: block; font-size: 1.0625rem; font-weight: 550; margin-bottom: 0.25rem; }
.post-excerpt { display: block; font-size: 0.875rem; color: var(--muted); max-width: 60ch; }
@media (max-width: 560px) { .post-list a { grid-template-columns: 1fr; gap: 0.25rem; } }

.post { max-width: 40rem; }
.post .meta { font-family: ui-monospace, Menlo, monospace; font-size: 0.75rem; color: var(--muted); margin: 0 0 2rem; }
.post h2 { font-size: 1.25rem; font-weight: 550; margin: 2.5rem 0 0.75rem; letter-spacing: -0.01em; }
.post p { max-width: 62ch; }
.post pre { padding: 1rem 1.125rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); overflow-x: auto; font-size: 0.8125rem; line-height: 1.6; }
.post code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875em; }
.post img { border-radius: 10px; border: 1px solid var(--line); }
