:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --fg: #1a1a1a;
  --muted: #4a4a4a;
  --border: rgba(0, 0, 0, 0.08);
  --accent: #1a1a1a;
  --placeholder: #ececec;
  --shadow: rgba(0, 0, 0, 0.08);
  --serif: "Young Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --max-w: 1200px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #1f1c18;
    --fg: #f0ebe1;
    --muted: #b8b1a5;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #f0ebe1;
    --placeholder: #2a2620;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--muted); }

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px;
}
@media (min-width: 576px) {
  .container { padding: 0 24px; }
}

/* Header / nav */
.site-header {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
@media (min-width: 576px) {
  .site-header { padding: 24px 0; }
}
.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
}
.brand {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
}
@media (min-width: 576px) {
  .brand { font-size: 24px; }
}
.nav-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
}
@media (min-width: 576px) {
  .nav-links { gap: 24px; font-size: 15px; }
}
.nav-links a { transition: color 0.2s; }
.nav-link { color: var(--muted); }
.nav-link:hover { color: var(--fg); }
.nav-link.active { color: var(--fg); }
.nav-resume {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  color: var(--fg);
  transition: background 0.2s, border-color 0.2s;
}
@media (min-width: 576px) {
  .nav-resume { padding: 6px 16px; }
}
.nav-resume:hover {
  color: var(--fg);
  background: var(--surface);
  border-color: var(--muted);
}

/* Hero socials */
.hero-socials {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 22px;
}
@media (min-width: 720px) {
  .hero-socials { justify-content: flex-start; }
}
.hero-socials a {
  display: inline-flex;
  color: var(--muted);
  transition: color 0.2s;
}
.hero-socials a:hover { color: var(--fg); }

/* Hero */
.hero {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 40px 0 32px;
  align-items: center;
  text-align: center;
}
@media (min-width: 576px) {
  .hero { padding: 56px 0 48px; gap: 28px; }
}
@media (min-width: 720px) {
  .hero {
    flex-direction: row;
    gap: 48px;
    align-items: center;
    justify-content: center;
    text-align: left;
    padding: 80px 0 64px;
  }
}
.hero-photo { flex-shrink: 0; }
.hero-photo img {
  width: clamp(150px, 45vw, 220px);
  height: clamp(150px, 45vw, 220px);
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 8px 24px var(--shadow);
}
.hero-content { max-width: 560px; }
.tagline {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--fg);
  margin: 0 0 12px;
}
@media (min-width: 576px) {
  .tagline { font-size: 26px; margin: 0 0 14px; }
}
.bio p {
  margin: 0 0 14px;
  color: var(--fg);
  font-size: 16px;
  line-height: 1.6;
}
@media (min-width: 576px) {
  .bio p { font-size: 17px; }
}
.bio p:last-child { margin-bottom: 0; }

/* Section */
.section {
  padding: 40px 0;
  border-top: 1px solid var(--border);
}
@media (min-width: 576px) {
  .section { padding: 56px 0; }
}
.section-title {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
}
@media (min-width: 576px) {
  .section-title { font-size: 34px; }
}
.section-lede {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}
@media (min-width: 576px) {
  .section-lede { margin: 0 0 32px; font-size: 15px; }
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
.section-more {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: 1px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.section-more:hover { color: var(--fg); border-color: var(--fg); }

/* Post cards (homepage Writing + blog listing) */
.post-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-top: 8px;
}
@media (min-width: 640px) {
  .post-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.post-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
@media (min-width: 576px) {
  .post-card { padding: 22px 24px; }
}
.post-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow);
  color: inherit;
}
.post-date {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.post-card-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 8px 0 8px;
}
.post-excerpt {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 14px;
}
.post-read-more {
  margin-top: auto;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
}

/* Blog listing + post pages */
.container-narrow { max-width: 720px; }
.blog-listing { padding: 72px 0 64px; }
.page-title {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
@media (min-width: 576px) {
  .page-title { font-size: 40px; }
}
.page-subtitle {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 32px;
}
@media (min-width: 576px) {
  .page-subtitle { font-size: 17px; margin: 0 0 40px; }
}
.empty-state { color: var(--muted); }

.post { padding: 32px 0 48px; }
@media (min-width: 576px) {
  .post { padding: 56px 0 64px; }
}
.post-back {
  display: inline-block;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 28px;
  transition: color 0.2s;
}
.post-back:hover { color: var(--fg); }
.post-header { margin-bottom: 40px; }
.post-title {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 12px 0 16px;
}
@media (min-width: 576px) {
  .post-title { font-size: 40px; }
}
.post-lede {
  font-size: 17px;
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
}
@media (min-width: 576px) {
  .post-lede { font-size: 19px; }
}

/* Markdown body typography */
.post-body { font-size: 17px; line-height: 1.7; }
@media (min-width: 576px) {
  .post-body { font-size: 18px; line-height: 1.75; }
}
.post-body > *:first-child { margin-top: 0; }
.post-body h2 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 2em 0 0.5em;
}
.post-body h3 {
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  margin: 1.6em 0 0.5em;
}
.post-body p { margin: 0 0 1.25em; }
.post-body ul,
.post-body ol { margin: 0 0 1.25em; padding-left: 1.4em; }
.post-body li { margin-bottom: 0.4em; }
.post-body a {
  color: var(--fg);
  border-bottom: 1px solid var(--muted);
  transition: border-color 0.2s;
}
.post-body a:hover { border-color: var(--fg); }
.post-body blockquote {
  margin: 1.5em 0;
  padding: 0.2em 0 0.2em 1.2em;
  border-left: 3px solid var(--border);
  color: var(--muted);
  font-style: italic;
}
.post-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.4em;
}
.post-body pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  overflow-x: auto;
  margin: 0 0 1.5em;
}
.post-body pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.9em;
}
.post-body img { max-width: 100%; border-radius: 10px; }
.post-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

/* Projects */
.project-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-top: 24px;
}
@media (min-width: 640px) {
  .project-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 32px;
    margin-top: 32px;
  }
}
.project-card {
  transition: transform 0.2s ease;
}
.project-card:hover { transform: translateY(-2px); }
.project-media {
  border-radius: 10px;
  overflow: hidden;
  background: var(--placeholder);
  margin-bottom: 14px;
  aspect-ratio: 16 / 9;
}
.video-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}
.video-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.project-title {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 6px;
}
.project-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 10px;
}
.project-links {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--fg);
}
.project-links a {
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.project-links a:hover { border-color: var(--fg); }

/* Cert grid */
.cert-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (min-width: 576px) {
  .cert-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}
@media (min-width: 768px) {
  .cert-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
  }
}
@media (min-width: 992px) {
  .cert-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.cert-card {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
@media (min-width: 576px) {
  .cert-card { padding: 14px; }
}
.cert-card:hover,
.cert-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--shadow);
  outline: none;
}
.cert-card:focus-visible {
  border-color: var(--accent);
}
.cert-card img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* Lightbox — native <dialog>; the browser handles Esc, focus-trap & backdrop */
.lightbox {
  border: 0;
  padding: 0;
  max-width: min(1000px, 92vw);
  max-height: 92vh;
  background: transparent;
  overflow: visible;
}
.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}
.lightbox[open] { animation: lbFade 0.2s ease-out; }
.lightbox-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.lightbox-figure img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}
.lightbox-figure figcaption {
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  text-align: center;
}
.lightbox-close,
.lightbox-nav {
  position: fixed;
  font: inherit;
  cursor: pointer;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.lightbox-close:hover,
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.3); }
.lightbox-close {
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  font-size: 28px;
  line-height: 1;
}
.lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  font-size: 32px;
  line-height: 1;
}
.lightbox-prev { left: 24px; }
.lightbox-next { right: 24px; }
@media (max-width: 600px) {
  .lightbox-nav {
    top: auto;
    bottom: 24px;
    transform: none;
    width: 52px;
    height: 52px;
  }
  .lightbox-figure img { max-height: 72vh; }
}

@keyframes lbFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .lightbox[open] { animation: none; }
}

/* Footer */
.site-footer {
  padding: 40px 0 56px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
  color: var(--muted);
  font-size: 13px;
}

/* Fade-up animation */
.fade-up {
  animation: fadeUp 0.6s ease-out both;
}
.fade-up.delay-1 { animation-delay: 80ms; }
.fade-up.delay-2 { animation-delay: 160ms; }
.fade-up.delay-3 { animation-delay: 240ms; }

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fade-up { animation: none; }
  .project-card, .cert-card, .nav-socials a { transition: none; }
}
