/* ==========================================================================
   Portfolio stylesheet. Hand-written, no build step, no dependencies.
   Structure: tokens → reset → layout → components → motion → responsive → print
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light dark;

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

  /* Fluid type scale: min at 360px viewport, max at 1200px */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: clamp(1.0625rem, 0.99rem + 0.32vw, 1.1875rem);
  --text-lg: clamp(1.25rem, 1.15rem + 0.45vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.3rem + 0.9vw, 2rem);
  --text-2xl: clamp(1.875rem, 1.5rem + 1.6vw, 2.75rem);
  --text-3xl: clamp(2.5rem, 1.85rem + 2.9vw, 4.25rem);

  /* Spacing */
  --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: 4rem;
  --space-9: 6rem;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --container: 64rem;
  --header-h: 4rem;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --transition: 200ms var(--ease-out);

  /* Light palette (default) */
  --bg: #ffffff;
  --bg-subtle: #f7f8f9;
  --bg-elevated: #ffffff;
  --bg-inset: #f1f3f5;
  --border: #e4e7eb;
  --border-strong: #cdd3da;
  --text: #14171c;
  --text-muted: #5c6774;
  /* Kept at >=4.5:1 on white so small meta text still passes WCAG AA. */
  --text-faint: #656f7c;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --success: #0b7a53;
  --shadow-sm: 0 1px 2px rgba(20, 23, 28, 0.05);
  --shadow: 0 1px 2px rgba(20, 23, 28, 0.04), 0 10px 24px -14px rgba(20, 23, 28, 0.18);
  --shadow-lg: 0 1px 2px rgba(20, 23, 28, 0.05), 0 28px 56px -28px rgba(20, 23, 28, 0.28);
  --header-bg: rgba(255, 255, 255, 0.72);
}

/* Explicit dark mode (set by the theme toggle) */
html[data-theme="dark"] {
  --bg: #0b0d10;
  --bg-subtle: #0f1216;
  --bg-elevated: #14181d;
  --bg-inset: #1a1f25;
  --border: #23282f;
  --border-strong: #343b45;
  --text: #f6f7f8;
  --text-muted: #a2adba;
  --text-faint: #79838f;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-contrast: #0b0d10;
  --accent-soft: rgba(129, 140, 248, 0.14);
  --success: #34d399;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 24px -14px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.3), 0 28px 56px -28px rgba(0, 0, 0, 0.8);
  --header-bg: rgba(11, 13, 16, 0.72);
}

/* Follow the OS preference until the visitor picks a theme explicitly. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0b0d10;
    --bg-subtle: #0f1216;
    --bg-elevated: #14181d;
    --bg-inset: #1a1f25;
    --border: #23282f;
    --border-strong: #343b45;
    --text: #f6f7f8;
    --text-muted: #a2adba;
    --text-faint: #79838f;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-contrast: #0b0d10;
    --accent-soft: rgba(129, 140, 248, 0.14);
    --success: #34d399;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 24px -14px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.3), 0 28px 56px -28px rgba(0, 0, 0, 0.8);
    --header-bg: rgba(11, 13, 16, 0.72);
  }
}

/* --------------------------------------------------------------------------
   2. Reset & base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Keeps anchored headings clear of the sticky header */
  scroll-padding-top: calc(var(--header-h) + var(--space-5));
}

body {
  background-color: var(--bg);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1,
h2,
h3,
h4 {
  color: var(--text);
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h1 {
  font-size: var(--text-3xl);
  letter-spacing: -0.035em;
}
h2 {
  font-size: var(--text-2xl);
}
h3 {
  font-size: var(--text-lg);
  letter-spacing: -0.015em;
}
h4 {
  font-size: var(--text-base);
  letter-spacing: -0.01em;
}

p {
  text-wrap: pretty;
}

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

img,
svg,
picture,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

ul,
ol {
  list-style: none;
  padding: 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

strong {
  color: var(--text);
  font-weight: 600;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
}

/* Keyboard-only focus ring, always visible against both themes */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* --------------------------------------------------------------------------
   3. Helpers
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

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

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  transform: translateY(-160%);
  transition: transform var(--transition);
}

.skip-link:focus-visible {
  transform: translateY(0);
  outline-color: var(--text);
}

.mono {
  font-family: var(--font-mono);
}

.text-muted {
  color: var(--text-muted);
}

.link-inline {
  color: var(--text);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: var(--border-strong);
  transition: text-decoration-color var(--transition), color var(--transition);
}

.link-inline:hover {
  text-decoration-color: var(--accent);
}

/* --------------------------------------------------------------------------
   4. Buttons, tags, badges
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.7rem 1.15rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition: background-color var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.btn:active {
  transform: translateY(1px);
}

.btn svg {
  flex-shrink: 0;
}

.btn-primary {
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
}

.btn-primary:hover {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-lg);
}

.btn-ghost {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.5rem;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.35rem 0.7rem 0.35rem 0.6rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent);
}

/* --------------------------------------------------------------------------
   5. Header & navigation
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  border-bottom: 1px solid transparent;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  transition: border-color var(--transition), background-color var(--transition);
}

.site-header.is-scrolled {
  border-bottom-color: var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: var(--header-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 700;
  transition: background-color var(--transition), transform var(--transition);
}

.brand:hover .brand-mark {
  background: var(--accent);
  color: var(--accent-contrast);
  transform: rotate(-6deg);
}

.nav-desktop {
  display: none;
  align-items: center;
  gap: var(--space-1);
}

.nav-link {
  position: relative;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--transition);
}

.nav-link:hover {
  color: var(--text);
}

.nav-link[aria-current="true"] {
  color: var(--text);
}

.nav-link[aria-current="true"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-3);
  bottom: 2px;
  height: 2px;
  border-radius: var(--radius-full);
  background: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-muted);
  transition: color var(--transition), border-color var(--transition),
    background-color var(--transition);
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Theme toggle swaps which icon is shown based on the resolved theme */
.icon-sun {
  display: none;
}
html[data-theme="dark"] .icon-sun {
  display: block;
}
html[data-theme="dark"] .icon-moon {
  display: none;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .icon-sun {
    display: block;
  }
  html:not([data-theme="light"]) .icon-moon {
    display: none;
  }
}

.nav-toggle {
  display: grid;
}

.nav-panel {
  display: none;
  padding-bottom: var(--space-4);
  border-top: 1px solid var(--border);
}

.nav-panel.is-open {
  display: block;
}

.nav-panel ul {
  display: flex;
  flex-direction: column;
  padding-top: var(--space-3);
}

.nav-panel a {
  display: block;
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
}

.nav-panel a:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

/* --------------------------------------------------------------------------
   6. Sections
   -------------------------------------------------------------------------- */
.section {
  padding-block: var(--space-8);
  border-top: 1px solid var(--border);
}

.section-head {
  margin-bottom: var(--space-6);
}

.section-label {
  display: block;
  margin-bottom: var(--space-3);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.section-intro {
  max-width: 60ch;
  margin-top: var(--space-3);
  font-size: var(--text-md);
}

/* --------------------------------------------------------------------------
   7. Hero
   -------------------------------------------------------------------------- */
.hero {
  position: relative;
  padding-block: var(--space-8) var(--space-8);
  overflow: hidden;
}

/* Decorative graph-paper texture, masked so it fades out downward. */
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  color: var(--text-faint);
  background-image: linear-gradient(
      to right,
      color-mix(in srgb, currentColor 16%, transparent) 1px,
      transparent 1px
    ),
    linear-gradient(
      to bottom,
      color-mix(in srgb, currentColor 16%, transparent) 1px,
      transparent 1px
    );
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 75% 65% at 45% 0%, #000 25%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 75% 65% at 45% 0%, #000 25%, transparent 100%);
  pointer-events: none;
}

.hero-inner {
  display: grid;
  gap: var(--space-5);
}

.hero-title {
  margin-top: var(--space-5);
}

.hero-role {
  display: block;
  margin-top: var(--space-4);
  color: var(--text);
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.hero-role .accent {
  color: var(--accent);
}

.hero-summary {
  max-width: 58ch;
  margin-top: var(--space-5);
  font-size: var(--text-md);
}

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

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: var(--text-sm);
}

.hero-meta li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.hero-meta svg {
  color: var(--text-faint);
}

.hero-portrait {
  position: relative;
  /* On narrow screens the portrait reads better above the text than stranded
     below it, so it is reordered and shrunk here and reset at 900px. */
  order: -1;
  width: 108px;
  /* Matches the portrait's own proportions so nothing important gets cropped. */
  aspect-ratio: 4 / 5;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  box-shadow: var(--shadow-lg);
}

.hero-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Bias the crop towards the face rather than the centre of the frame. */
  object-position: 50% 22%;
}

/* --------------------------------------------------------------------------
   8. Project cards
   -------------------------------------------------------------------------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.filter-chip {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  transition: color var(--transition), border-color var(--transition),
    background-color var(--transition);
}

.filter-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.filter-chip[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.projects {
  display: grid;
  gap: var(--space-5);
}

.project-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition),
    transform var(--transition);
}

.project-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-lg);
}

.project-card[hidden] {
  display: none;
}

.project-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.project-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 400ms var(--ease-out);
}

.project-card:hover .project-thumb img {
  transform: scale(1.03);
}

.project-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: var(--space-3);
  padding: var(--space-5);
}

.project-eyebrow {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.project-title a {
  color: var(--text);
  transition: color var(--transition);
}

.project-title a:hover {
  color: var(--accent);
}

.project-desc {
  font-size: var(--text-sm);
}

.project-outcome {
  /* Block, not flex: the <strong> label has to stay inline with the sentence,
     otherwise multi-word labels collapse into a narrow column. */
  display: block;
  padding: var(--space-3);
  border-left: 2px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
  font-size: var(--text-sm);
}

.project-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-2);
}

.project-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.project-links a {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: color var(--transition);
}

.project-links a:hover {
  color: var(--accent);
}

/* Used where a project has no public link (internal work). */
.project-note {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.projects-empty {
  padding: var(--space-6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
  font-size: var(--text-sm);
}

/* --------------------------------------------------------------------------
   9. Case study
   -------------------------------------------------------------------------- */
.case-study {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  overflow: hidden;
}

.case-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.case-metric {
  padding: var(--space-5);
  background: var(--bg-elevated);
}

.case-metric dt {
  color: var(--text-faint);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.case-metric dd {
  margin-top: var(--space-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.case-metric dd .delta {
  color: var(--success);
  font-size: var(--text-sm);
}

.case-body {
  padding: var(--space-6) var(--space-5);
}

.case-step + .case-step {
  margin-top: var(--space-5);
}

.case-step h3 {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  /* Kept at body size on purpose: these are steps, not section headings. */
  font-size: var(--text-base);
  letter-spacing: -0.01em;
}

.case-step h3::before {
  content: attr(data-step);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 700;
}

.case-step p {
  font-size: var(--text-sm);
  padding-left: calc(22px + var(--space-3));
}

.teaching-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* --------------------------------------------------------------------------
   10. Experience timeline & education
   -------------------------------------------------------------------------- */
.timeline {
  position: relative;
  display: grid;
  gap: var(--space-6);
}

.timeline-item {
  position: relative;
  padding-left: var(--space-6);
}

.timeline-item::before {
  content: "";
  position: absolute;
  top: 0.55rem;
  left: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  z-index: 1;
}

.timeline-item:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 1.4rem;
  bottom: calc(var(--space-6) * -1);
  left: 4px;
  width: 1px;
  background: var(--border);
}

.timeline-period {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
}

.timeline-role {
  margin-top: var(--space-1);
}

.timeline-company {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
}

.timeline-points {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.timeline-points li {
  position: relative;
  padding-left: var(--space-4);
  font-size: var(--text-sm);
}

.timeline-points li::before {
  content: "";
  position: absolute;
  top: 0.65em;
  left: 0;
  width: 5px;
  height: 1px;
  background: var(--border-strong);
}

.education {
  margin-top: var(--space-7);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}

.education-title {
  font-size: var(--text-base);
  margin-bottom: var(--space-4);
}

.education-list {
  display: grid;
  gap: var(--space-4);
}

.education-item dt {
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
}

.education-item dd {
  margin-top: var(--space-1);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* --------------------------------------------------------------------------
   11. Skills
   -------------------------------------------------------------------------- */
.skills {
  display: grid;
  gap: var(--space-5);
}

.skill-group {
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}

.skill-group h3 {
  font-size: var(--text-base);
  margin-bottom: var(--space-4);
}

.skill-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* --------------------------------------------------------------------------
   12. Writing
   -------------------------------------------------------------------------- */
.posts {
  display: grid;
}

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

.post:first-child {
  border-top: 0;
  padding-top: 0;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.post-title {
  font-size: var(--text-md);
  font-weight: 600;
}

.post-title a {
  color: var(--text);
  transition: color var(--transition);
}

.post-title a:hover {
  color: var(--accent);
}

.post-excerpt {
  font-size: var(--text-sm);
  max-width: 68ch;
}

/* --------------------------------------------------------------------------
   13. Contact
   -------------------------------------------------------------------------- */
.contact-card {
  padding: var(--space-7) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
  text-align: center;
}

.contact-card h2 {
  margin-bottom: var(--space-4);
}

.contact-card p {
  max-width: 48ch;
  margin-inline: auto;
  font-size: var(--text-md);
}

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

/* Full address, shown so it can be read and copied without a mail client.
   Allowed to break because the address is longer than a phone is wide. */
.contact-address {
  margin-top: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

.contact-address a {
  color: var(--text-faint);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
  transition: color var(--transition);
}

.contact-address a:hover {
  color: var(--text);
}

.socials {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

/* --------------------------------------------------------------------------
   14. Footer & back-to-top
   -------------------------------------------------------------------------- */
.site-footer {
  padding-block: var(--space-6);
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: var(--text-sm);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.footer-note {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.to-top {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 40;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-muted);
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity var(--transition), transform var(--transition),
    visibility var(--transition), color var(--transition);
}

.to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.to-top:hover {
  color: var(--text);
}

/* --------------------------------------------------------------------------
   15. Motion: reveal on scroll (opt-in, JS-gated, motion-safe)
   -------------------------------------------------------------------------- */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translate3d(0, 14px, 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/*
 * Content is visible by default. JS adds `.is-armed` immediately before it
 * starts observing an element, so if JS is disabled, fails, or the visitor
 * prefers reduced motion, nothing is ever hidden. A failsafe in main.js also
 * un-arms everything after a short delay, which keeps the text visible to
 * crawlers and screenshot tools that never scroll.
 */
.reveal.is-armed {
  opacity: 0;
}

.reveal.is-visible {
  animation: fade-up 550ms var(--ease-out) both;
}

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

  .reveal,
  .reveal.is-armed,
  .reveal.is-visible {
    opacity: 1;
    animation: none;
  }

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

/* --------------------------------------------------------------------------
   16. Responsive
   -------------------------------------------------------------------------- */
@media (min-width: 640px) {
  .container {
    padding-inline: var(--space-6);
  }

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

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

  /* With an odd number of groups, let the last one span the row instead of
     leaving a hole in the grid. */
  .skill-group:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .education-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-5);
  }

  .case-body {
    padding: var(--space-6);
  }

  .contact-card {
    padding: var(--space-8) var(--space-7);
  }
}

@media (min-width: 900px) {
  :root {
    --header-h: 4.5rem;
  }

  .section {
    padding-block: var(--space-9);
  }

  .hero {
    padding-block: var(--space-9);
  }

  .hero-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: var(--space-8);
  }

  .hero-portrait {
    order: 0;
    width: 232px;
    margin-top: var(--space-5);
    border-radius: var(--radius-lg);
  }

  .nav-desktop {
    display: flex;
  }

  .nav-toggle {
    display: none;
  }

  .nav-panel {
    display: none !important;
  }

  .timeline {
    gap: var(--space-7);
  }

  .timeline-item:not(:last-child)::after {
    bottom: calc(var(--space-7) * -1);
  }
}

/* --------------------------------------------------------------------------
   17. Print: makes the page usable as a one-page résumé
   -------------------------------------------------------------------------- */
@media print {
  .site-header,
  .to-top,
  .filters,
  .hero-actions,
  .contact-actions,
  .socials,
  .hero::before {
    display: none !important;
  }

  /* Printing never scrolls, so make sure nothing is left mid-animation. */
  .reveal,
  .reveal.is-armed {
    opacity: 1 !important;
    animation: none !important;
  }

  html {
    --bg: #fff;
    --text: #000;
    --text-muted: #333;
  }

  body {
    font-size: 11pt;
  }

  .section {
    padding-block: 1rem;
    break-inside: avoid;
  }

  .project-card,
  .timeline-item,
  .case-study {
    break-inside: avoid;
  }

  a::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #555;
  }
}
