:root {
  /* Core palette */
  --bg-color: #fafafa;
  --text-main: #171717;
  --text-muted: #525252;
  --text-light: #737373;
  --accent-color: #2563eb;
  --border-color: #e5e7eb;
  --card-bg: #ffffff;

  /* Extended surfaces */
  --surface-elevated: #ffffff;
  --surface-subtle: #f5f5f5;
  --accent-subtle: rgba(37, 99, 235, 0.08);
  --accent-hover: rgba(37, 99, 235, 0.12);
  --border-subtle: rgba(0, 0, 0, 0.06);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);

  /* Accent gradient */
  --gradient-accent: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);

  --container-max: 800px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --text-light: #64748b;
    --border-color: #1e293b;
    --card-bg: #0f172a;

    --surface-elevated: #1e293b;
    --surface-subtle: #131c2e;
    --accent-subtle: rgba(56, 189, 248, 0.08);
    --accent-hover: rgba(56, 189, 248, 0.12);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --accent-color: #38bdf8;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);

    --gradient-accent: linear-gradient(135deg, #38bdf8 0%, #a78bfa 100%);
  }
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

::selection {
  background: rgba(37, 99, 235, 0.2);
}

@media (prefers-color-scheme: dark) {
  ::selection {
    background: rgba(56, 189, 248, 0.25);
  }
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ─── Navigation ─── */
.site-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 0.75rem 1.5rem;
  transition:
    background-color 0.3s ease,
    box-shadow 0.3s ease,
    backdrop-filter 0.3s ease;
}

.site-nav.scrolled {
  background-color: rgba(15, 23, 42, 0.85);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

@media (prefers-color-scheme: light) {
  .site-nav.scrolled {
    background-color: rgba(250, 250, 250, 0.85);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  }
}

.nav-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  color: var(--text-main);
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--gradient-accent);
  color: #fff;
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-links a {
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-light);
  transition: color 0.2s ease;
  letter-spacing: 0.01em;
}

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

.nav-cta {
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  background: var(--accent-subtle);
  color: var(--accent-color) !important;
  border: 1px solid rgba(37, 99, 235, 0.15);
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease;
}

.nav-cta:hover {
  background: var(--accent-hover);
  border-color: var(--accent-color);
}

@media (max-width: 640px) {
  .nav-links {
    gap: 0.75rem;
  }
  .nav-links a {
    font-size: 0.75rem;
  }
  .nav-cta {
    display: none;
  }
}

/* ─── Scroll Reveal ─── */
.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.5s ease,
    transform 0.5s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger children in grids */
.lab-grid .reveal:nth-child(2) {
  transition-delay: 80ms;
}
.lab-grid .reveal:nth-child(3) {
  transition-delay: 160ms;
}
.lab-grid .reveal:nth-child(4) {
  transition-delay: 240ms;
}

.services .reveal:nth-child(2) {
  transition-delay: 80ms;
}
.services .reveal:nth-child(3) {
  transition-delay: 160ms;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
  html {
    scroll-behavior: auto;
  }
}

/* ─── Layout ─── */
.landing-container {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 6rem 1.5rem 4rem;
}

.content-wrapper {
  max-width: var(--container-max);
  width: 100%;
}

/* ─── Header ─── */
.header {
  margin-bottom: 2rem;
}

.header h1 {
  font-size: clamp(2.25rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.1;
  margin-bottom: 0.5rem;
  text-wrap: balance;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--accent-color);
}

.header .positioning {
  font-size: clamp(1.05rem, 2.5vw, 1.2rem);
  line-height: 1.65;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 0.75rem;
  max-width: 640px;
}

/* ─── Links / Buttons ─── */
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 3rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1.1rem;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
  background-color: transparent;
  color: var(--text-main);
}

.btn:hover {
  background-color: var(--accent-subtle);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 3px;
}

.btn-cta {
  background: var(--gradient-accent);
  color: #ffffff;
  border: none;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
}

.btn-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  background: var(--gradient-accent);
  color: #ffffff;
  border-color: transparent;
}

@media (prefers-color-scheme: dark) {
  .btn-cta:hover {
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.25);
  }
}

/* ─── Bio ─── */
.bio {
  margin-bottom: 3rem;
  color: var(--text-main);
  font-size: 1.05rem;
  line-height: 1.75;
  padding: 1.5rem;
  background: var(--surface-subtle);
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
}

.bio p {
  margin-bottom: 1.25rem;
}

.bio p:last-child {
  margin-bottom: 0;
}

.bio-flush {
  margin-top: 0;
}

/* ─── Section Titles ─── */
.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-light);
  margin: 4rem 0 2rem;
  padding-bottom: 0;
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.section-title::before {
  content: "";
  display: inline-block;
  width: 3px;
  height: 1em;
  background: var(--gradient-accent);
  border-radius: 2px;
  flex-shrink: 0;
}

.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

/* ─── Services ─── */
.services {
  display: grid;
  gap: 1.25rem;
}

.service-item {
  padding: 1.5rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-sm);
  transition:
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

.service-item:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent-color);
  transform: translateY(-1px);
}

.service-item h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.service-item h3::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-color);
  flex-shrink: 0;
}

.service-item p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

/* ─── Writing list ─── */
.writing-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.writing-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1rem;
  border-radius: 8px;
  text-decoration: none;
  transition: background-color 0.2s ease;
  margin: 0 -1rem;
}

.writing-item:hover {
  background-color: var(--accent-subtle);
}

.writing-item:hover .writing-title {
  color: var(--accent-color);
}

.writing-title {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-main);
  transition: color 0.2s ease;
}

.writing-title::after {
  content: " \2192";
  opacity: 0;
  transition: opacity 0.2s ease;
  font-size: 0.9em;
  color: var(--accent-color);
}

.writing-item:hover .writing-title::after {
  opacity: 1;
}

.writing-date {
  font-size: 0.8rem;
  color: var(--text-light);
  white-space: nowrap;
  margin-left: 1.5rem;
  font-variant-numeric: tabular-nums;
}

/* ─── Experience Timeline ─── */
.journey-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-left: 2px solid var(--border-color);
  padding-left: 1.5rem;
  margin-left: 0.5rem;
}

.journey-item {
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: 2rem;
}

.journey-item::before {
  content: "";
  position: absolute;
  left: calc(-1.5rem - 5px);
  top: 0.35rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-color);
  border: 2px solid var(--bg-color);
}

.journey-item:first-child::before {
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.journey-item:last-child {
  padding-bottom: 0;
}

@media (min-width: 640px) {
  .journey-item {
    flex-direction: row;
    align-items: baseline;
  }
  .journey-meta {
    min-width: 220px;
    padding-right: 2rem;
  }
}

.journey-meta strong {
  display: block;
  font-size: 1.05rem;
  color: var(--text-main);
  font-weight: 700;
}

.journey-meta span {
  font-size: 0.8rem;
  color: var(--text-light);
  display: block;
  margin-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}

.journey-desc {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-top: 0.5rem;
}

@media (min-width: 640px) {
  .journey-desc {
    margin-top: 0;
  }
}

/* ─── Publications ─── */
.publications {
  margin-top: 2rem;
  margin-bottom: 3rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface-subtle);
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
}

.subsection-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.publications ul {
  list-style: none;
  padding: 0;
}

.publications li {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.7;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-subtle);
}

.publications li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.publications li em {
  color: var(--text-main);
  font-style: italic;
  font-weight: 500;
}

/* ─── Lab Cards (Sandolab projects) ─── */
.lab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .lab-grid {
    grid-template-columns: 1fr;
  }
}

.lab-card {
  padding: 1.25rem 1.5rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--surface-elevated);
  box-shadow: var(--shadow-sm);
  transition:
    box-shadow 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
  text-decoration: none;
  color: inherit;
  display: block;
}

.lab-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.lab-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.lab-card p {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.65;
}

.lab-card-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.tag-cyan {
  background: rgba(6, 182, 212, 0.1);
  color: #06b6d4;
  border: 1px solid rgba(6, 182, 212, 0.2);
}
.tag-violet {
  background: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
  border: 1px solid rgba(139, 92, 246, 0.2);
}
.tag-green {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
}
.tag-purple {
  background: rgba(168, 85, 247, 0.1);
  color: #a855f7;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

@media (prefers-color-scheme: dark) {
  .lab-card:hover {
    border-color: var(--accent-color);
  }
}

/* Hoverable card with colored border on hover */
a.lab-card:hover {
  border-color: #06b6d4;
}

.lab-cta {
  text-align: center;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
}

.lab-cta p {
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* ─── Research Items ─── */
.research-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.research-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  transition: background-color 0.2s ease;
  margin: 0 -1rem;
}

.research-item:hover {
  background-color: var(--accent-subtle);
}

.research-item strong {
  font-size: 0.95rem;
  color: var(--text-main);
}

.research-item span {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ─── Text link ─── */
.text-link {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
  border-bottom: 1px solid transparent;
}

.text-link:hover {
  border-bottom-color: var(--accent-color);
}

/* ─── Writing layout (posts + about) ─── */
.back-nav {
  margin-bottom: 3rem;
}

.back-nav a {
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.back-nav a:hover {
  color: var(--accent-color);
}

.post-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
}

.post-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.post-meta {
  color: var(--text-light);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* Post body typography */
.post-body {
  font-size: 1.1rem;
  line-height: 1.85;
  color: var(--text-main);
}

.post-body p {
  margin-bottom: 1.75rem;
  text-wrap: pretty;
}

.post-body h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 3rem 0 1.25rem;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.post-body h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 2.5rem 0 1rem;
  color: var(--text-main);
}

.post-body strong {
  font-weight: 600;
}

.post-body hr {
  border: none;
  margin: 3.5rem 0;
  text-align: center;
  height: auto;
  line-height: 1;
}

.post-body hr::before {
  content: "\2022\2009\2022\2009\2022";
  color: var(--text-light);
  font-size: 1rem;
  letter-spacing: 0.5em;
}

.post-body blockquote {
  border-left: 3px solid var(--accent-color);
  padding: 0.5rem 0 0.5rem 1.5rem;
  margin: 2rem 0;
  color: var(--text-muted);
  font-style: italic;
}

.post-body blockquote p:last-child {
  margin-bottom: 0;
}

.post-body code {
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, monospace;
  font-size: 0.875em;
  background-color: var(--accent-subtle);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: var(--accent-color);
}

.post-body pre {
  background: var(--surface-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 2rem 0;
  font-size: 0.875rem;
  line-height: 1.7;
}

.post-body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
}

.post-body ul,
.post-body ol {
  margin: 1.5rem 0;
  padding-left: 1.5rem;
}

.post-body li {
  margin-bottom: 0.5rem;
  line-height: 1.7;
}

/* ─── Footer ─── */
footer {
  margin-top: 6rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-light);
  letter-spacing: 0.02em;
}

/* ─── Focus styles ─── */
:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 3px;
  border-radius: 4px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ─── Mobile ─── */
@media (max-width: 640px) {
  .landing-container {
    padding: 5rem 1.25rem 2.5rem;
  }

  .links {
    gap: 0.5rem;
    margin-bottom: 2.5rem;
  }

  .btn {
    padding: 0.45rem 0.9rem;
    font-size: 0.8rem;
  }

  .section-title {
    margin: 3rem 0 1.5rem;
  }

  .service-item {
    padding: 1.25rem;
  }

  .writing-item {
    padding: 0.85rem 0.75rem;
    margin: 0 -0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .writing-date {
    margin-left: 0;
  }

  .journey-list {
    padding-left: 1.25rem;
  }

  .journey-desc {
    font-size: 0.9rem;
  }

  .post-title {
    font-size: 1.5rem;
  }

  .post-body {
    font-size: 1rem;
    line-height: 1.8;
  }
}
