/* Tokens ------------------------------------------------------------------ */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 5rem;

  --radius: 8px;
  --container: 64rem;
  --header-h: 3.5rem;

  /* Dark is the default theme. */
  --bg: #0b0d10;
  --surface: #12151a;
  --surface-2: #181c22;
  --border: #252a32;
  --text: #e7e9ec;
  --muted: #9ba4ae;
  --accent: #8ab4ff;
  --accent-text: #0b0d10;
  --focus: #8ab4ff;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #fbfbfc;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e2e5e9;
  --text: #15181d;
  --muted: #59616c;
  --accent: #2456c8;
  --accent-text: #ffffff;
  --focus: #2456c8;
  color-scheme: light;
}

/* Base -------------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + var(--space-4));
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.65 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img { display: block; max-width: 100%; height: auto; }

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

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

code, .mono { font-family: var(--font-mono); font-size: 0.875em; }

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

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -3rem;
  z-index: 20;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: var(--radius);
}
.skip-link:focus { top: var(--space-2); }

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 40rem) {
  .container { padding-inline: var(--space-6); }
}

/* Header ------------------------------------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--header-h);
}

.brand {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--accent); }

.site-nav { margin-left: auto; min-width: 0; }

.site-nav ul {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav ul::-webkit-scrollbar { display: none; }

.site-nav a {
  display: block;
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
  color: var(--muted);
  border-radius: 6px;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }

.theme-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle svg { width: 1rem; height: 1rem; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* Phones: the brand row stays, the nav becomes a scrollable second row. */
@media (max-width: 47.99rem) {
  .site-header .container { flex-wrap: wrap; gap: 0 var(--space-4); padding-top: var(--space-2); }
  .brand { flex: 1; }
  .site-nav { order: 3; flex-basis: 100%; margin: 0 calc(var(--space-3) * -1); }
  html { scroll-padding-top: 6.5rem; }
}

/* Sections ---------------------------------------------------------------- */
.section {
  padding-block: var(--space-8) 0;
}
.section:last-of-type { padding-bottom: var(--space-8); }

.section-label {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: var(--space-3);
}

.section h2 {
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 600;
}

.lead {
  margin-top: var(--space-4);
  max-width: 44rem;
  color: var(--muted);
}

.prose p { max-width: 44rem; }
.prose p + p { margin-top: var(--space-4); }

/* Hero -------------------------------------------------------------------- */
.hero { padding-block: var(--space-8) var(--space-4); }

.hero-name {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--muted);
}

.hero h1 {
  margin-top: var(--space-4);
  font-size: clamp(2.25rem, 1.4rem + 4vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 650;
  max-width: 14ch;
}

.hero-tagline {
  margin-top: var(--space-5);
  max-width: 38rem;
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.3125rem);
  line-height: 1.5;
}

.hero-intro {
  margin-top: var(--space-4);
  max-width: 38rem;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  padding: 0 var(--space-5);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.button:hover { text-decoration: none; background: var(--surface-2); }
.button svg { width: 1.125rem; height: 1.125rem; }

.button-primary {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}
.button-primary:hover { background: var(--accent); filter: brightness(1.08); }

/* About ------------------------------------------------------------------- */
.about {
  display: grid;
  gap: var(--space-6);
  margin-top: var(--space-5);
}

.about-photo {
  width: 8rem;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid var(--border);
}

@media (min-width: 48rem) {
  .about { grid-template-columns: 1fr 11rem; align-items: start; }
  .about-photo { width: 11rem; order: 2; }
}

/* Cards and grids --------------------------------------------------------- */
.grid {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-6);
}

@media (min-width: 40rem) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 64rem) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 40rem) and (max-width: 63.99rem) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card h3,
.card h4 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}
.card .mono { font-size: 0.9375rem; }

.card p { color: var(--muted); font-size: 0.9375rem; }

.card .question {
  color: var(--text);
  padding-left: var(--space-3);
  border-left: 2px solid var(--border);
}

.card-index {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: auto;
  padding-top: var(--space-2);
  font-size: 0.875rem;
}

.list {
  display: grid;
  gap: var(--space-2);
  font-size: 0.9375rem;
}
.list li { padding-left: var(--space-4); position: relative; }
.list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.7em;
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 50%;
  background: var(--muted);
}

.source {
  margin-top: auto;
  padding-top: var(--space-2);
  font-size: 0.8125rem;
  color: var(--muted);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.tags li {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  padding: 0 var(--space-2);
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.subsection { margin-top: var(--space-7); }
.subsection > h3 {
  font-size: 1.125rem;
  font-weight: 600;
}
.subsection > p { margin-top: var(--space-2); color: var(--muted); max-width: 44rem; }

/* Selected work ----------------------------------------------------------- */
.work-list { display: grid; gap: var(--space-4); margin-top: var(--space-6); }

.work {
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.work-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-1) var(--space-4);
}
.work-head h3 { font-size: 1.0625rem; font-weight: 600; }
.work-meta { font-size: 0.875rem; color: var(--muted); }

.work dl {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
  font-size: 0.9375rem;
}
.work dt {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.work dd { margin-top: var(--space-1); }
.work .tags { margin-top: var(--space-4); }

@media (min-width: 48rem) {
  .work dl { grid-template-columns: 9rem 1fr; gap: var(--space-3) var(--space-5); }
  .work dd { margin-top: 0; }
  .work dt { padding-top: 0.2rem; }
}

.earlier { margin-top: var(--space-6); }
.earlier h3 { font-size: 1rem; font-weight: 600; }
.earlier ul { margin-top: var(--space-3); color: var(--muted); }

/* Experience timeline ----------------------------------------------------- */
.timeline { margin-top: var(--space-6); border-top: 1px solid var(--border); }

.role {
  display: grid;
  gap: var(--space-1);
  padding-block: var(--space-5);
  border-bottom: 1px solid var(--border);
}

.role-period {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
}
.role h3 { font-size: 1rem; font-weight: 600; }
.role-company { color: var(--muted); font-weight: 400; }
.role p { margin-top: var(--space-1); font-size: 0.9375rem; color: var(--muted); max-width: 44rem; }
.role .tags { margin-top: var(--space-2); }
.role .list { margin-top: var(--space-2); font-size: 0.9375rem; color: var(--muted); }

@media (min-width: 48rem) {
  .role { grid-template-columns: 11rem 1fr; gap: var(--space-5); }
  .role-period { padding-top: 0.15rem; }
}

.education { display: grid; gap: var(--space-2); margin-top: var(--space-4); font-size: 0.9375rem; }
.education span { color: var(--muted); }

/* Contact ----------------------------------------------------------------- */
.contact-list {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-6);
}
@media (min-width: 40rem) {
  .contact-list { grid-template-columns: repeat(2, 1fr); }
}

.contact-list a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}
.contact-list a:hover { text-decoration: none; background: var(--surface-2); }
.contact-list svg { flex: none; width: 1.25rem; height: 1.25rem; color: var(--muted); }
.contact-list span { min-width: 0; overflow-wrap: anywhere; }
.contact-list small { display: block; color: var(--muted); font-size: 0.8125rem; }

.location { margin-top: var(--space-4); color: var(--muted); font-size: 0.9375rem; }

/* Footer ------------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-6);
  font-size: 0.875rem;
  color: var(--muted);
}
.site-footer .container { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); }

/* Accents ----------------------------------------------------------------- */
:root { --grid-line: rgba(255, 255, 255, 0.045); --accent-soft: rgba(138, 180, 255, 0.12); }
:root[data-theme="light"] { --grid-line: rgba(15, 23, 42, 0.06); --accent-soft: rgba(36, 86, 200, 0.08); }

.section-label { color: var(--accent); }
.card .question { border-left-color: var(--accent); }

.card,
.work,
.layer { transition: border-color 0.15s ease, background-color 0.15s ease; }
.card:hover,
.work:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

@media (prefers-reduced-motion: reduce) {
  .card, .work, .layer { transition: none; }
}

/* Hero -------------------------------------------------------------------- */
.hero {
  position: relative;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: center top;
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-7);
}

.hero-grid {
  display: grid;
  gap: var(--space-7);
  align-items: center;
}

@media (min-width: 64rem) {
  .hero-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); }
}

.hero-role {
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--accent);
}

.hero-diagram {
  width: 100%;
  max-width: 28rem;
  justify-self: center;
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.hero-diagram svg { display: block; width: 100%; height: auto; }
.hero-diagram figcaption {
  margin-top: var(--space-4);
  font-size: 0.8125rem;
  color: var(--muted);
}

.d-lines path { fill: none; stroke: var(--muted); stroke-width: 1.25; opacity: 0.7; }
.d-arrow { fill: var(--muted); }
.d-box rect { fill: var(--surface-2); stroke: var(--border); }
.d-box-accent { fill: var(--accent-soft); stroke: var(--accent); }
.d-label text {
  font-family: var(--font-mono);
  font-size: 12px;
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: middle;
}
.d-label .d-label-accent { fill: var(--accent); font-weight: 600; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-7);
}
@media (min-width: 48rem) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.stats div {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-1);
  padding-left: var(--space-4);
  border-left: 1px solid var(--border);
}
.stats dd {
  font-size: clamp(1.75rem, 1.4rem + 1.2vw, 2.25rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.stats dt { font-size: 0.8125rem; color: var(--muted); }

/* Focus: one card can span the whole row --------------------------------- */
@media (min-width: 40rem) {
  .card-wide { grid-column: 1 / -1; }
  .card-wide .list { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--space-6); }
}

/* PHP Systems Lab stack -------------------------------------------------- */
.stack {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

.layer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.layer[open] { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.layer summary {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  list-style: none;
}
.layer summary::-webkit-details-marker { display: none; }
.layer summary::after {
  content: "+";
  font-family: var(--font-mono);
  color: var(--muted);
}
.layer[open] summary::after { content: "−"; }
.layer summary:hover { background: var(--surface-2); border-radius: var(--radius); }

.layer-level {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
}
.layer-name { font-family: var(--font-mono); font-size: 0.9375rem; font-weight: 600; }
.layer-focus {
  grid-column: 2 / -1;
  grid-row: 2;
  font-size: 0.8125rem;
  color: var(--muted);
}
@media (min-width: 48rem) {
  .layer summary { grid-template-columns: 2.5rem 13rem minmax(0, 1fr) auto; }
  .layer-focus { grid-column: auto; grid-row: auto; }
}

.layer-body {
  display: grid;
  gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-4) calc(2.5rem + var(--space-3) + var(--space-4));
  font-size: 0.9375rem;
}
.layer-body p { color: var(--muted); max-width: 44rem; }
.layer-body .question {
  color: var(--text);
  padding-left: var(--space-3);
  border-left: 2px solid var(--accent);
}
.layer-body .card-links { margin-top: 0; padding-top: 0; }
@media (max-width: 47.99rem) {
  .layer-body { padding-left: var(--space-4); }
}

/* Code -------------------------------------------------------------------- */
.code {
  margin-top: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.code figcaption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: 0.8125rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.code-note { font-family: var(--font-mono); font-size: 0.75rem; }
.code pre {
  margin: 0;
  padding: var(--space-4);
  overflow-x: auto;
  font: 0.8125rem/1.7 var(--font-mono);
  tab-size: 4;
}
.code .k { color: #c792ea; }
.code .f { color: #82aaff; }
.code .v { color: var(--text); }
.code .t { color: #ffcb6b; }
.code .n { color: #f78c6c; }
.code .c { color: var(--muted); font-style: italic; }
:root[data-theme="light"] .code .k { color: #7c3aed; }
:root[data-theme="light"] .code .f { color: #1d4ed8; }
:root[data-theme="light"] .code .t { color: #a16207; }
:root[data-theme="light"] .code .n { color: #c2410c; }
.code pre { color: var(--muted); }

/* Metric callout ---------------------------------------------------------- */
.metric {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--accent-soft);
  border-radius: var(--radius);
  font-size: 0.9375rem;
}
.metric strong {
  font-size: 1.75rem;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--accent);
}

/* Language switch --------------------------------------------------------- */
.lang-switch {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 var(--space-2);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.lang-switch:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
@media (max-width: 47.99rem) {
  .lang-switch { margin-left: auto; }
}

/* Case diagrams ----------------------------------------------------------- */
.work-diagram {
  margin: var(--space-4) 0 0;
  max-width: 30rem;
}
.work-diagram svg { display: block; width: 100%; height: auto; }

/* Case screenshots -------------------------------------------------------- */
.work-shots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: var(--space-3);
  max-width: 40rem;
  margin-top: var(--space-4);
}
.work-shots a { display: block; }
.work-shots img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Screenshot lightbox ----------------------------------------------------- */
.lightbox {
  max-width: min(64rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: visible;
}
.lightbox::backdrop { background: rgb(0 0 0 / 0.75); }
.lightbox img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 5rem);
  border-radius: var(--radius) var(--radius) 0 0;
}
.lightbox-close {
  position: absolute;
  top: -0.875rem;
  right: -0.875rem;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 1.375rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { border-color: var(--accent); color: var(--accent); }
.work-shots a { cursor: zoom-in; }

/* Screenshot carousel ----------------------------------------------------- */
.work-shots.carousel {
  display: flex;
  max-width: none;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: var(--space-2);
}
.work-shots.carousel a { flex: 0 0 auto; scroll-snap-align: start; }
.work-shots.carousel img { width: auto; height: 10rem; }
.carousel-controls { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.carousel-btn,
.lightbox-nav {
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 1.375rem;
  line-height: 1;
  cursor: pointer;
}
.carousel-btn:hover,
.lightbox-nav:hover { border-color: var(--accent); color: var(--accent); }
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}
.lightbox-prev { left: 0.5rem; }
.lightbox-next { right: 0.5rem; }
.lightbox-caption {
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
  color: var(--muted);
}
/* Small dialog screenshots are upscaled so they stay readable. */
.lightbox img { min-width: min(36rem, calc(100vw - 2rem)); }
@media (min-width: 48rem) {
  .lightbox-prev { left: -3rem; }
  .lightbox-next { right: -3rem; }
}
/* A grid item defaults to min-width: auto; the carousel would stretch the card. */
.work { min-width: 0; }
