:root {
  --bg: #fafaf8;
  --surface: #f2f2f0;
  --text: #1c1c1c;
  --muted: #737373;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e5e5e3;
}

[data-theme="dark"] {
  --bg: #111;
  --surface: #1c1c1c;
  --text: #e2e2e2;
  --muted: #888;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --border: #2a2a2a;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

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

html { font-size: 17px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  line-height: 1.75;
  transition: background 0.2s, color 0.2s;
}

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

/* Layout */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* Nav */
nav {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 3rem;
}

nav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.nav-brand {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}
@keyframes flag-wave {
  0%   { transform: perspective(200px) rotateY(0deg); }
  25%  { transform: perspective(200px) rotateY(25deg); }
  50%  { transform: perspective(200px) rotateY(0deg); }
  75%  { transform: perspective(200px) rotateY(-15deg); }
  100% { transform: perspective(200px) rotateY(0deg); }
}
.nav-brand .flag {
  font-size: 1.5rem;
  vertical-align: middle;
  display: inline-block;
  transform-origin: left center;
  animation: flag-wave 2s ease-in-out infinite;
}
.nav-brand:hover { text-decoration: none; color: var(--text); }

.nav-links {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}
.nav-links a {
  color: var(--muted);
  font-size: 0.875rem;
}
.nav-links a:hover,
.nav-links a.active { color: var(--text); text-decoration: none; }

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0;
  line-height: 1;
  transition: color 0.15s;
}
.theme-toggle:hover { color: var(--text); }

/* Main */
main { padding-bottom: 4rem; }

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Typography */
h1 {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
  margin-top: 2.75rem;
  margin-bottom: 0.75rem;
  color: var(--text);
}

h3 { font-size: 0.975rem; font-weight: 600; line-height: 1.4; }

p { margin-bottom: 1rem; }
p:last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono {
  font-family: ui-monospace, "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.85em;
}

/* Page header */
.page-header { margin-bottom: 2rem; }
.page-header h1 { margin-bottom: 0.35rem; }
.page-header .tagline { color: var(--muted); font-size: 0.975rem; }

/* Social links */
.social-links {
  display: flex;
  gap: 0.1rem 1rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
  font-size: 0.9rem;
}

/* Tags */
.tags {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin: 0.5rem 0;
}
.tag {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", monospace;
}

/* Timeline (experience) */
.timeline { margin-top: 0.25rem; }

.timeline-item {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }

.timeline-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.2rem;
  flex-wrap: wrap;
}

.timeline-title { font-weight: 600; font-size: 0.975rem; }

.timeline-period {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  font-family: ui-monospace, "SF Mono", monospace;
}

.timeline-org {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 0.6rem;
}
.timeline-org a { color: var(--muted); }
.timeline-org a:hover { color: var(--accent); }

.timeline-desc ul { padding-left: 1.15rem; }
.timeline-desc li {
  margin-bottom: 0.2rem;
  font-size: 0.875rem;
  color: var(--muted);
}

/* Education */
.edu-list { margin-top: 0.25rem; }
.edu-item {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
}
.edu-item:last-child { border-bottom: none; }

.edu-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: baseline;
}
.edu-degree { font-weight: 600; font-size: 0.975rem; }
.edu-year {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", monospace;
}
.edu-institution { font-size: 0.875rem; color: var(--muted); margin-top: 0.15rem; }

/* Interests */
.interests { display: flex; gap: 0 0.2rem; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); }
.interest-item::after { content: " ·"; margin-right: 0.2rem; }
.interest-item:last-child::after { content: ""; }

/* Projects */
.project-list { margin-top: 0.25rem; }
.project-item {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}
.project-item:last-child { border-bottom: none; }
.project-item h3 { margin-bottom: 0.35rem; }
.project-item > p { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.5rem; }

.project-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.project-links { font-size: 0.85rem; display: flex; gap: 0.75rem; }
.project-year { font-size: 0.8rem; color: var(--muted); font-family: ui-monospace, "SF Mono", monospace; }

/* Publications */
.pub-list { margin-top: 0.25rem; }
.pub-item {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}
.pub-item:last-child { border-bottom: none; }
.pub-item h3 { margin-bottom: 0.4rem; font-size: 1rem; }
.pub-venue { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; font-style: italic; }
.pub-authors { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }
.pub-abstract {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.65;
}
.pub-links { font-size: 0.85rem; display: flex; gap: 0.75rem; }

/* Writing / blog */
.post-list { margin-top: 0.25rem; }
.post-item {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}
.post-item:last-child { border-bottom: none; }
.post-title a { color: var(--text); }
.post-title a:hover { color: var(--accent); text-decoration: none; }
.post-date {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  font-family: ui-monospace, "SF Mono", monospace;
}

.empty-state {
  padding: 3rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* CV-specific */
.cv-download {
  font-size: 0.875rem;
  display: inline-block;
  border: 1px solid var(--border);
  padding: 0.35rem 0.85rem;
  border-radius: 4px;
  color: var(--muted);
  transition: border-color 0.15s, color 0.15s;
  margin-top: 0.75rem;
}
.cv-download:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

/* Post / article */
.post-header { margin-bottom: 2rem; }
.post-back {
  display: inline-block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1rem;
}
.post-back:hover { color: var(--accent); text-decoration: none; }
.post-header h1 { margin-bottom: 0.25rem; }
.post-header-date { font-size: 0.85rem; color: var(--muted); font-family: ui-monospace, "SF Mono", monospace; }

.post-content { line-height: 1.8; }
.post-content h2 { margin-top: 2.5rem; }
.post-content h3 { margin-top: 1.75rem; margin-bottom: 0.5rem; }
.post-content p { margin-bottom: 1rem; }
.post-content ul, .post-content ol { padding-left: 1.25rem; margin-bottom: 1rem; }
.post-content li { margin-bottom: 0.35rem; }
.post-content li img { margin-top: 0.75rem; }
.post-content img {
  max-width: 100%;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: block;
  margin: 1.25rem 0;
}

/* Mobile */
@media (max-width: 520px) {
  html { font-size: 16px; }
  nav { margin-bottom: 2rem; }
  .timeline-meta { flex-direction: column; gap: 0.1rem; }
  .edu-meta { flex-direction: column; gap: 0.1rem; }
  .post-item { flex-direction: column; gap: 0.25rem; }
}
