/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body, h1, h2, h3, p, ul, ol, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ============================================================
   Theme variables
   ============================================================ */
:root,
[data-theme="light"] {
  --bg:          #FAF8F4;
  --bg-elev:     #FFFFFF;
  --text:        #1a1a1a;
  --text-muted:  #6b6b6b;
  --accent:      #8B3A3A;
  --rule:        #e5e2dc;
  --mono-bg:     #f0ede6;
}
[data-theme="dark"] {
  --bg:          #1a1a1a;
  --bg-elev:     #242424;
  --text:        #e8e6e0;
  --text-muted:  #9a9a9a;
  --accent:      #C97A7A;
  --rule:        #333333;
  --mono-bg:     #2d2d2d;
}

/* ============================================================
   Typography & page frame
   ============================================================ */
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background 200ms ease, color 200ms ease;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

h1 {
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

section {
  margin-top: 4rem;
  scroll-margin-top: 5rem;
}

section h2 {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}

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

a { border-bottom: 1px solid transparent; transition: border-color 150ms ease, color 150ms ease; }
a:hover { color: var(--accent); border-bottom-color: currentColor; }

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

footer {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--rule);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ============================================================
   Hero
   ============================================================ */
.hero {
  display: flex;
  gap: 2rem;
  align-items: center;
  padding-top: 1rem;
}

.hero-photo {
  width: 160px;
  height: 160px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.hero-text { flex: 1; min-width: 0; }

.hero-text h1 { margin-bottom: 0.35rem; }

.affiliation {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.tagline {
  font-size: 1.05rem;
  margin-bottom: 1rem;
}

.contact-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.contact-row a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-muted);
  border-bottom: none;
}

.contact-row a:hover {
  color: var(--accent);
  background: var(--mono-bg);
  border-bottom: none;
}

@media (max-width: 640px) {
  .hero {
    flex-direction: column;
    text-align: center;
    gap: 1.25rem;
  }
  .contact-row { justify-content: center; }
}

/* ============================================================
   Publications
   ============================================================ */
.pub-list { display: flex; flex-direction: column; gap: 1.5rem; }

.pub {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.pub-venue {
  flex-shrink: 0;
  display: inline-block;
  width: 82px;
  text-align: center;
  padding: 0.25rem 0.4rem;
  background: var(--mono-bg);
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  border-radius: 4px;
  margin-top: 0.1rem;
}

.pub-body { flex: 1; min-width: 0; }

.pub-title {
  font-weight: 600;
  margin-bottom: 0.2rem;
  line-height: 1.35;
}

.pub-authors {
  color: var(--text-muted);
  font-size: 0.93rem;
  margin-bottom: 0.15rem;
}

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

.pub-meta {
  color: var(--text-muted);
  font-size: 0.93rem;
  margin-bottom: 0.4rem;
}

.pub-links {
  display: flex;
  gap: 0.4rem;
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 0.85rem;
  margin-bottom: 0;
}

.pub-links a {
  color: var(--text-muted);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  border-bottom: none;
}

.pub-links a:hover,
.pub-links .bib-toggle:hover {
  color: var(--accent);
  background: var(--mono-bg);
  border-bottom: none;
}

.pub-links .bib-toggle {
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  color: var(--text-muted);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  cursor: pointer;
}

.pub-links .bib-toggle[aria-expanded="true"] {
  color: var(--accent);
  background: var(--mono-bg);
}

.bib-snippet {
  margin-top: 0.6rem;
  padding: 0.8rem 1rem;
  background: var(--mono-bg);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  overflow-x: auto;
}

@media (max-width: 400px) {
  .pub { flex-direction: column; gap: 0.5rem; }
  .pub-venue { align-self: flex-start; }
  .pub-links { font-size: 0.8rem; }
}

/* ============================================================
   Teaching
   ============================================================ */
.teach-list { display: flex; flex-direction: column; gap: 1.25rem; margin-top: 0.75rem; }

.teach-course { margin-bottom: 0.2rem; }

.teach-meta {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
}

.teach-meta a {
  color: var(--text-muted);
  border-bottom: 1px solid var(--rule);
}

.teach-meta a:hover { color: var(--accent); border-bottom-color: currentColor; }

.teach-desc {
  color: var(--text);
  font-size: 0.93rem;
  margin-bottom: 0;
}

/* ============================================================
   CV
   ============================================================ */
.cv-highlights {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}

.cv-highlights li {
  padding-left: 1.1rem;
  position: relative;
}

.cv-highlights li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--accent);
}

.cv-download {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  background: var(--accent);
  color: #fff !important;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.95rem;
  border-bottom: none !important;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.cv-download:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(139, 58, 58, 0.25);
  border-bottom: none !important;
}

[data-theme="dark"] .cv-download { color: #1a1a1a !important; }

/* ============================================================
   Repositories
   ============================================================ */
.repo-grid {
  display: grid;
  gap: 0.9rem;
  margin-top: 1rem;
}

.repo-card {
  display: block;
  width: 100%;
  padding: 1rem 1.1rem 1.05rem;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg-elev) 88%, var(--accent) 12%), var(--bg-elev));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.05);
  border-bottom: none;
  transition: transform 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
  position: relative;
  overflow: hidden;
  text-align: left;
}

.repo-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), transparent 72%);
  opacity: 0.75;
}

.repo-card:hover {
  transform: translateY(-2px);
  color: inherit;
  border-color: color-mix(in srgb, var(--accent) 28%, var(--rule));
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.08);
  border-bottom: none;
}

.repo-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.65rem;
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.repo-source,
.repo-link-label {
  margin-bottom: 0;
  color: var(--text-muted);
}

.repo-link-label {
  color: var(--accent);
}

.repo-name {
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.repo-description {
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.repo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.8rem;
}

.repo-meta-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 60%, var(--mono-bg));
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 0.76rem;
  line-height: 1.4;
  margin-bottom: 0;
}

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

.repo-meta-value {
  color: var(--text);
}

.repo-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0;
}

.repo-tags span {
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--mono-bg);
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  font-size: 0.78rem;
}

/* ============================================================
   Sticky anchor nav
   ============================================================ */
.anchor-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  padding: 0.9rem 1rem;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--rule);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.anchor-nav a {
  color: var(--text-muted);
  text-transform: lowercase;
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
}

.anchor-nav a:hover { color: var(--accent); border-bottom-color: currentColor; }

.anchor-nav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.theme-toggle {
  position: fixed;
  top: 0.75rem;
  right: 0.9rem;
  z-index: 20;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  transition: color 150ms ease, background 150ms ease;
}
.theme-toggle:hover { color: var(--accent); }

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

@media (max-width: 640px) {
  .anchor-nav { gap: 0.85rem; font-size: 0.78rem; padding: 0.7rem 0.6rem; }
}

/* ============================================================
   Responsive refinements
   ============================================================ */
@media (max-width: 767px) {
  main { padding: 1.5rem 1rem 3rem; }
  section { margin-top: 3rem; }
  h1 { font-size: 1.85rem; }
  .tagline { font-size: 1rem; }
  .theme-toggle { top: 0.5rem; right: 0.5rem; width: 32px; height: 32px; }
  footer { padding: 1.5rem 1rem 2rem; }
}

@media (max-width: 400px) {
  .anchor-nav { gap: 0.6rem; font-size: 0.72rem; padding: 0.55rem 0.4rem; }
  .pub-venue { font-size: 0.7rem; }
}
