:root {
  /* GitHub Primer-inspired tokens. Light is the default; dark is the
     "dimmed" variant (softer than pure-black), toggled via [data-theme]
     on <html>. See DESIGN.md for the full rationale. */
  --canvas: #ffffff;
  --surface: #ffffff;         /* light-mode boxes rely on the border, not a bg shift */
  --canvas-subtle: #f6f8fa;   /* hover tint / inset panels */
  --border: #d0d7de;
  --border-muted: #d8dee4;
  --fg: #1f2328;              /* primary text — 15.6:1 on canvas */
  --fg-muted: #59636e;        /* secondary text, meta — 5.1:1 */
  --accent: #0969da;          /* GitHub blue — links, repo names — 5.0:1 */
  --accent-emphasis: #0550ae; /* link/accent hover */
  --btn-bg: #f6f8fa;
  --btn-border: rgba(31, 35, 40, 0.15);
  --btn-hover-bg: #f3f4f6;
  --btn-primary-bg: #1f883d;  /* GitHub green — primary CTA */
  --btn-primary-hover: #1a7f37;
  --btn-primary-fg: #ffffff;
  --btn-primary-border: rgba(0, 0, 0, 0.15);
  --header-bg: #1f2328;       /* the header stays dark in both themes */
  --header-fg: #f0f6fc;
  --header-fg-muted: #9198a1;
  --focus: #0969da;
  --shadow-resting: 0 1px 0 rgba(31, 35, 40, 0.04);
  --radius: 6px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
}

:root[data-theme="dark"] {
  --canvas: #22272e;
  --surface: #2d333b;
  --canvas-subtle: #2d333b;
  --border: #444c56;
  --border-muted: #373e47;
  --fg: #adbac7;              /* 11.7:1 on canvas */
  --fg-muted: #909dab;        /* 6.6:1 */
  --accent: #539bf5;          /* 6.4:1 */
  --accent-emphasis: #6cb6ff;
  --btn-bg: #2d333b;
  --btn-border: #545d68;
  --btn-hover-bg: #444c56;
  --btn-primary-bg: #347d39;
  --btn-primary-hover: #46954a;
  --btn-primary-fg: #ffffff;
  --btn-primary-border: rgba(240, 246, 252, 0.1);
  --header-bg: #1c2128;
  --header-fg: #cdd9e5;
  --header-fg-muted: #768390;
  --focus: #6cb6ff;
  --shadow-resting: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

/* Keep anchored headings clear of the sticky header */
:where(#top, #work, #projects, #contact) {
  scroll-margin-top: 72px;
}

body {
  margin: 0;
  color: var(--fg);
  background: var(--canvas);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  font-kerning: normal;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 160ms ease, color 160ms ease;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 clamp(16px, 3vw, 32px);
  background: var(--header-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  transition: background-color 160ms ease;
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 12px 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--header-fg);
  color: var(--header-bg);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0;
}

nav {
  display: flex;
  gap: 4px;
}

nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--header-fg-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: color 120ms ease, background-color 120ms ease;
}

nav a:hover {
  color: var(--header-fg);
  background: rgba(255, 255, 255, 0.08);
}

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--header-fg-muted);
  cursor: pointer;
  transition: color 120ms ease, background-color 120ms ease;
}

.theme-toggle:hover {
  color: var(--header-fg);
  background: rgba(255, 255, 255, 0.08);
}

.theme-toggle svg {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%) scale(1) rotate(0deg);
  opacity: 1;
  transition: transform 300ms var(--ease-out-quint), opacity 200ms ease;
}

.theme-toggle .icon-moon {
  transform: translate(-50%, -50%) scale(0.5) rotate(-90deg);
  opacity: 0;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  transform: translate(-50%, -50%) scale(0.5) rotate(90deg);
  opacity: 0;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  transform: translate(-50%, -50%) scale(1) rotate(0deg);
  opacity: 1;
}

:where(a, button):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.contact a:focus-visible {
  outline-color: var(--header-fg);
}

main {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
}

.hero {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  padding: 32px 0 16px;
}

.hero-copy {
  max-width: 640px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--fg-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 20ch;
  margin-bottom: 4px;
  font-size: clamp(1.75rem, 3.4vw, 2.25rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.011em;
  text-wrap: balance;
}

h2 {
  max-width: 24ch;
  margin-bottom: 0;
  font-size: clamp(1.25rem, 1.9vw, 1.5rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.logo {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  object-fit: contain;
}

.hero-meta {
  margin: 0 0 10px;
  color: var(--fg-muted);
  font-size: 0.95rem;
}

.lede {
  max-width: 60ch;
  color: var(--fg-muted);
  font-size: clamp(0.92rem, 1.2vw, 1rem);
  text-wrap: pretty;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.button,
.contact-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: var(--shadow-resting);
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.button:hover {
  background: var(--btn-hover-bg);
}

.button.primary {
  border-color: var(--btn-primary-border);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
}

.button.primary:hover {
  background: var(--btn-primary-hover);
}

.section {
  display: grid;
  grid-template-columns: minmax(200px, 0.4fr) minmax(0, 1fr);
  gap: clamp(16px, 3vw, 32px);
  padding: 40px 0 0;
}

.section-heading {
  position: static;
  align-self: start;
}

.timeline,
.project-grid {
  display: grid;
  gap: 8px;
}

.timeline article,
.project {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-resting);
  transition: background-color 120ms ease, border-color 120ms ease;
}

.timeline article {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 14px;
}

.timeline article:hover,
.project:hover {
  background: var(--canvas-subtle);
  border-color: var(--fg-muted);
}

.timeline p,
.project p {
  margin-bottom: 0;
  color: var(--fg-muted);
  text-wrap: pretty;
}

.period {
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.project-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.project {
  min-height: 74px;
  padding: 12px 14px;
}

.project h3 {
  margin-top: 0;
  color: var(--accent);
}

.project:hover h3 {
  color: var(--accent-emphasis);
  text-decoration: underline;
}

.topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.topic {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  background: color-mix(in oklab, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 500;
}

.contact {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  margin: 40px 0 6px;
  padding: 20px 24px;
  border-radius: var(--radius);
  background: var(--header-bg);
  color: var(--header-fg);
}

.contact .eyebrow {
  color: var(--header-fg-muted);
}

.contact h2 {
  max-width: 20ch;
}

.contact-note {
  max-width: 44ch;
  margin: 10px 0 0;
  color: var(--header-fg-muted);
  font-size: 0.92rem;
  line-height: 1.5;
  text-wrap: pretty;
}

.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.contact-links a {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: var(--header-fg);
  box-shadow: none;
}

.contact-links a:hover {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.14);
}

footer {
  display: flex;
  justify-content: space-between;
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 20px 0 24px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.01em;
}

.footer-meta {
  display: flex;
  gap: 16px;
}

footer a {
  color: var(--fg-muted);
  transition: color 120ms ease;
}

footer a:hover {
  color: var(--accent);
}

/* Progress page */
.progress-section {
  grid-template-columns: 1fr;
}

.progress-bar-outer {
  height: 8px;
  margin: 18px 0 8px;
  border-radius: 999px;
  background: var(--canvas-subtle);
  border: 1px solid var(--border-muted);
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  width: 100%;
  background: var(--btn-primary-bg);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 300ms ease;
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
}

.progress-stats strong {
  color: var(--fg);
  font-weight: 700;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 22px 0 14px;
}

.chip {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease, background-color 120ms ease;
}

.chip:hover {
  border-color: var(--fg-muted);
  color: var(--fg);
}

.chip.active {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--accent) 14%, transparent);
  color: var(--accent);
}

.goal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
  opacity: 1;
  transition: opacity 150ms ease-out;
}

.goal-grid.grid-fade-out {
  opacity: 0;
}

.goal-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-resting);
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.goal-card:hover,
.goal-card:focus-visible {
  background: var(--canvas-subtle);
  border-color: var(--fg-muted);
}

.goal-check {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-top: 3px;
  border: 1px solid var(--fg-muted);
  border-radius: 4px;
  color: transparent;
  font-size: 10px;
}

@keyframes goal-check-pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.goal-check.pop {
  animation: goal-check-pop 260ms var(--ease-out-quint);
}

.goal-card.done {
  border-color: var(--btn-primary-bg);
}

.goal-card.done .goal-check {
  border-color: var(--btn-primary-bg);
  background: var(--btn-primary-bg);
  color: #fff;
}

.goal-card.done h3 {
  color: var(--fg-muted);
  text-decoration: line-through;
}

.goal-cat {
  margin-top: 2px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.progress-note {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg-muted);
  font-size: 0.82rem;
  line-height: 1.5;
  text-wrap: pretty;
}

.lede code {
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.progress-note code {
  padding: 1px 4px;
  border-radius: 4px;
  background: color-mix(in oklab, var(--accent) 14%, transparent);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.78em;
}

#gated-content {
  display: none;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--canvas);
}

.gate-card {
  width: min(360px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-resting);
}

.gate-card h2 {
  margin-bottom: 6px;
}

.gate-copy {
  margin: 0 0 16px;
  color: var(--fg-muted);
  font-size: 0.85rem;
}

.gate-row {
  display: flex;
  gap: 8px;
}

.gate-input {
  flex: 1;
  min-width: 0;
  padding: 0 10px;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 0.9rem;
}

.gate-input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.gate-error {
  margin: 10px 0 0;
  color: var(--fg-muted);
  font-size: 0.8rem;
}

button.button {
  font-family: inherit;
  cursor: pointer;
}

@keyframes gate-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

.gate-card.shake {
  animation: gate-shake 400ms ease;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  main,
  footer {
    width: min(1120px, calc(100% - 28px));
  }

  .hero,
  .section,
  .contact {
    grid-template-columns: 1fr;
  }

  .hero {
    flex-direction: column;
    padding-top: 24px;
  }

  .contact {
    padding: 20px;
  }

  .section {
    padding-top: 32px;
  }

  .section-heading {
    position: static;
  }

  .project-grid,
  .goal-grid {
    grid-template-columns: 1fr;
  }

  .timeline article {
    grid-template-columns: 1fr;
  }

  .contact-links {
    justify-content: flex-start;
  }

  footer {
    display: grid;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: clamp(1.6rem, 8vw, 2rem);
  }

  .hero-actions {
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* A CV should print cleanly to PDF */
@media print {
  .site-header {
    display: none;
  }

  body {
    background: #fff;
    color: #1f2328;
    font-size: 11pt;
  }

  .timeline article,
  .project {
    break-inside: avoid;
  }

  .contact {
    background: #fff;
    color: #1f2328;
    border: 1px solid #d0d7de;
  }

  .contact .eyebrow,
  .contact-note,
  .contact h2 {
    color: #1f2328;
  }

  .contact-links a {
    color: #1f2328;
    border-color: #d0d7de;
    background: none;
  }
}
