:root {
  --bg: #0d1117;
  --bg-alt: #161b22;
  --card: #1c2128;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-2: #3fb950;
  --border: #30363d;
  --mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* capture ball cursors (closed + semi-open) */
  --ball-closed: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='white' stroke='%23222' stroke-width='2'/%3E%3Cpath d='M2 12a10 10 0 0 1 20 0z' fill='%23e0383e'/%3E%3Crect x='2' y='11' width='20' height='2' fill='%23222'/%3E%3Ccircle cx='12' cy='12' r='3.2' fill='white' stroke='%23222' stroke-width='2'/%3E%3C/svg%3E") 12 12, auto;
  --ball-open: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 28 28'%3E%3Cg transform='rotate(-18 14 8) translate(0 -3)'%3E%3Cpath d='M4 11a10 10 0 0 1 20 0z' fill='%23e0383e' stroke='%23222' stroke-width='2'/%3E%3C/g%3E%3Cpath d='M4 17a10 10 0 0 0 20 0z' fill='white' stroke='%23222' stroke-width='2'/%3E%3Ccircle cx='14' cy='17' r='3' fill='white' stroke='%23222' stroke-width='2'/%3E%3C/svg%3E") 14 14, auto;
}

body {
  background: var(--bg);
  background-image: radial-gradient(circle, rgba(88, 166, 255, 0.07) 1px, transparent 1px);
  background-size: 26px 26px;
  color: var(--text);
  font-family: "Inter", -apple-system, sans-serif;
  line-height: 1.65;
  cursor: var(--ball-closed);
}
body:active { cursor: var(--ball-open); }

::selection { background: var(--accent); color: #0d1117; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- nav ---------- */
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 5vw;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.brand {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--text);
}
.brand .cursor { color: var(--accent-2); animation: blink 1.2s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.nav nav { display: flex; gap: 1.4rem; align-items: center; flex-wrap: wrap; }
.nav nav a { color: var(--muted); font-size: 0.95rem; }
.nav nav a:hover { color: var(--text); text-decoration: none; }
.nav .cta {
  background: var(--accent);
  color: #0d1117;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  font-weight: 600;
}
.nav .cta:hover { background: #79b8ff; }

/* ---------- layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 0 5vw; }
section { padding: 4.5rem 0; border-bottom: 1px solid var(--border); }
section:last-of-type { border-bottom: none; }
h1, h2, h3 { line-height: 1.25; }
h2.section-title {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}
h2.section-title::before {
  content: "// ";
  color: var(--accent-2);
  font-family: var(--mono);
}
h2.section-title::after {
  content: "";
  display: block;
  width: 64px; height: 3px;
  margin-top: 0.5rem;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.section-sub { color: var(--muted); margin-bottom: 2.2rem; max-width: 640px; }

/* ---------- hero ---------- */
.hero { padding: 6rem 0 5rem; border-bottom: 1px solid var(--border); }
.hero-inner { display: flex; align-items: center; gap: 3rem; justify-content: space-between; }
.headshot {
  border-radius: 50%;
  border: 3px solid var(--border);
  box-shadow: 0 0 0 6px rgba(88, 166, 255, 0.15);
  flex-shrink: 0;
}
.hero .kicker {
  font-family: var(--mono); color: var(--accent-2); margin-bottom: 0.8rem;
  display: inline-block; overflow: hidden; white-space: nowrap;
  border-right: 2px solid var(--accent-2);
  animation: typing 1.4s steps(9) 0.3s both, caret 1s step-end infinite;
}
@keyframes typing { from { width: 0; } to { width: 9ch; } }
@keyframes caret { 50% { border-color: transparent; } }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); font-weight: 800; margin-bottom: 1.2rem; }
.hero h1 em {
  font-style: normal;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { max-width: 620px; color: var(--muted); font-size: 1.12rem; margin-bottom: 2rem; }
.btn {
  display: inline-block;
  background: var(--accent);
  color: #0d1117;
  font-weight: 600;
  padding: 0.75rem 1.6rem;
  border-radius: 8px;
  margin: 0 0.8rem 0.8rem 0;
}
.btn:hover { background: #79b8ff; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

/* ---------- cards ---------- */
.grid { display: grid; gap: 1.2rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.card h3 { margin-bottom: 0.6rem; font-size: 1.1rem; }
.card p { color: var(--muted); font-size: 0.95rem; }
.card .src { display: block; margin-top: 0.8rem; font-family: var(--mono); font-size: 0.8rem; color: var(--accent-2); }

/* ---------- experience timeline ---------- */
.timeline { list-style: none; }
.timeline li {
  border-left: 2px solid var(--border);
  padding: 0 0 2rem 1.6rem;
  position: relative;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
.timeline .role { font-weight: 700; font-size: 1.1rem; }
.timeline .org { color: var(--accent-2); font-family: var(--mono); font-size: 0.9rem; }
.timeline .dates { color: var(--muted); font-family: var(--mono); font-size: 0.85rem; }
.timeline p { color: var(--muted); margin-top: 0.4rem; max-width: 680px; }
.tags { margin-top: 0.6rem; }
.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.75rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  margin: 0.15rem 0.25rem 0 0;
}

/* ---------- blog ---------- */
.post-list { list-style: none; }
.post-list li {
  padding: 1.4rem 0;
  border-bottom: 1px solid var(--border);
}
.post-list h3 { font-size: 1.3rem; }
.post-list .meta { font-family: var(--mono); font-size: 0.82rem; color: var(--muted); margin: 0.25rem 0 0.5rem; }
.post-list p { color: var(--muted); }

article.post { padding: 3rem 0; max-width: 760px; margin: 0 auto; }
article.post h1 { font-size: 2.3rem; margin-bottom: 0.4rem; }
article.post .meta { font-family: var(--mono); color: var(--muted); font-size: 0.85rem; margin-bottom: 2rem; }
article.post h2 { margin: 2rem 0 0.8rem; }
article.post h3 { margin: 1.5rem 0 0.6rem; }
article.post p, article.post ul, article.post ol { margin-bottom: 1.1rem; color: #c9d1d9; }
article.post ul, article.post ol { padding-left: 1.4rem; }
article.post img { max-width: 100%; border-radius: 8px; }
article.post blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--muted);
  margin: 1.2rem 0;
}
article.post code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
article.post pre {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  margin-bottom: 1.2rem;
}
article.post pre code { border: none; padding: 0; background: none; }
article.post { overflow-x: hidden; }
article.post table { border-collapse: collapse; margin-bottom: 1.2rem; width: 100%; }
article.post th, article.post td { border: 1px solid var(--border); padding: 0.5rem 0.8rem; text-align: left; }
article.post th { background: var(--bg-alt); }
.viz {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  margin: 1.5rem 0;
}

/* ---------- contact form ---------- */
.contact-form label { display: block; margin-bottom: 1rem; font-size: 0.9rem; color: var(--muted); }
.contact-form input, .contact-form select, .contact-form textarea {
  width: 100%;
  margin-top: 0.3rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  padding: 0.6rem 0.8rem;
}
.contact-form input:focus, .contact-form select:focus, .contact-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.contact-form button { border: none; cursor: pointer; font: inherit; font-weight: 600; }

/* ---------- footer ---------- */
footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding: 2.5rem 5vw;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  /* --- nav: compact, not sticky (don't eat the viewport) --- */
  .nav {
    position: static;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.8rem 4vw;
  }
  .nav nav { justify-content: center; gap: 0.7rem 1rem; }
  .nav nav a { font-size: 0.88rem; }
  .nav .cta { padding: 0.4rem 0.9rem; }

  /* --- layout rhythm --- */
  section { padding: 2.8rem 0; }
  h2.section-title { font-size: 1.6rem; }

  /* --- hero: stacked, full-width buttons that never overlap --- */
  .hero { padding: 2.5rem 0 3rem; }
  .hero-inner { flex-direction: column-reverse; gap: 1.5rem; align-items: flex-start; }
  .headshot { width: 132px; height: 132px; }
  .hero p { font-size: 1.02rem; }
  .btn, .btn.ghost {
    display: block;
    text-align: center;
    margin: 0 0 0.8rem 0;
  }

  /* --- charts: shorter so they fit a phone screen --- */
  #viz-scatter { height: 340px !important; }
  #viz-funnel { height: 300px !important; }

  /* --- blog posts: tame wide content --- */
  article.post { padding: 1.8rem 0; }
  article.post h1 { font-size: 1.7rem; }
  article.post table { display: block; overflow-x: auto; white-space: nowrap; }
  article.post iframe { max-width: 100%; }

  /* --- wild pokémon: slightly smaller targets --- */
  .critter img { width: 56px; height: 56px; }
  .critter:hover img { width: 64px; height: 64px; }

  /* --- pokédex: full-width sheet above the buttons --- */
  #dex-panel {
    left: 0.8rem;
    right: 0.8rem;
    width: auto;
    max-width: none;
    max-height: 55vh;
  }
  .dex-grid { grid-template-columns: repeat(7, 1fr); gap: 5px; }
  .dex-cell { font-size: 0.75rem; }
  #dex-badge, #dex-open { font-size: 0.82rem; padding: 0.45rem 0.85rem; }

  /* --- footer: leave room for the dex buttons --- */
  footer { padding-bottom: 5.5rem; }
}

/* ============================================================
   WILD DATA CRITTERS (the click-to-catch game)
   ============================================================ */
.critter {
  position: fixed;
  left: 0; top: 0;
  z-index: 900;
  cursor: var(--ball-closed);
  user-select: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
  will-change: transform;
}
.critter img {
  width: 72px; height: 72px;
  image-rendering: pixelated;
  transition: width 0.15s, height 0.15s;
  pointer-events: none;
}
.critter:hover img { width: 88px; height: 88px; }
.critter:active { cursor: var(--ball-open); }
.critter.sparkle { animation: sparkle 0.8s ease-in-out infinite alternate; }
@keyframes sparkle { from { filter: drop-shadow(0 0 4px #d29922); } to { filter: drop-shadow(0 0 14px #ffdf5d); } }
.critter.caught { animation: catchPop 0.45s ease-out forwards; pointer-events: none; }
@keyframes catchPop {
  30% { scale: 1.6; opacity: 1; rotate: 10deg; }
  100% { scale: 0; opacity: 0; rotate: -220deg; }
}
.critter.flee { opacity: 0; transition: opacity 0.5s; pointer-events: none; }

.critter-spark {
  position: fixed;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
  pointer-events: none;
  z-index: 901;
  animation: sparkFly 0.7s ease-out forwards;
}
@keyframes sparkFly {
  to { transform: translate(var(--dx), var(--dy)); opacity: 0; }
}

#dex-ui {
  position: fixed;
  bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px));
  right: 1.2rem;
  z-index: 950;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#dex-badge {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-family: var(--mono);
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
#dex-badge:hover { border-color: var(--accent); }
#dex-badge.bounce { animation: dexBounce 0.5s; }
@keyframes dexBounce { 30% { transform: scale(1.25) rotate(-6deg); } 60% { transform: scale(0.95); } }
#dex-open {
  background: linear-gradient(135deg, #e0383e, #a2262b);
  color: #fff;
  border: 1px solid #e0383e;
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
#dex-open:hover { filter: brightness(1.15); }
#dex-open.pulse { animation: dexPulse 1.6s ease-in-out infinite; }
@keyframes dexPulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 0 0 rgba(224, 56, 62, 0.6); }
  50%      { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 0 10px rgba(224, 56, 62, 0); }
}

#dex-panel {
  position: fixed;
  bottom: calc(4.4rem + env(safe-area-inset-bottom, 0px));
  right: 1.2rem;
  z-index: 949;
  width: 280px;
  max-width: calc(100vw - 2.4rem);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#dex-panel.open { display: block; }
#dex-panel h4 { font-family: var(--mono); color: var(--accent-2); margin-bottom: 0.3rem; }
#dex-panel .dex-sub { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.6rem; }
#dex-panel ul { list-style: none; }
#dex-panel li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
#dex-panel li:last-child { border-bottom: none; }
#dex-panel li small { color: var(--muted); }
#dex-panel li.undiscovered { opacity: 0.5; }
#dex-panel .dex-emoji { margin-right: 0.4rem; }
.dex-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 0.4rem;
}
.dex-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  opacity: 0.3;
  overflow: hidden;
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  color: inherit;
  line-height: 1;
  min-width: 0;
}
.dex-cell img { width: 100%; height: 100%; image-rendering: pixelated; }
.dex-cell.caught {
  opacity: 1;
  border-color: var(--accent-2);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, border-color 0.12s;
}
.dex-cell.caught:hover { transform: scale(1.15); border-color: var(--accent); }

.critter-toast {
  position: fixed;
  bottom: 4.4rem; left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 951;
  background: var(--card);
  border: 1px solid var(--accent-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.critter-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
