/* ══════════════════════════════════════════════════════
   Design tokens
   ══════════════════════════════════════════════════════ */
:root {
  /* Light — warm paper */
  --bg:          #faf8f4;
  --bg-2:        #f0ece4;
  --bg-3:        #e6e0d4;
  --text:        #1a1410;
  --muted:       #6b5f52;
  --accent:      #b85c20;   /* burnt sienna */
  --accent-soft: #f5ece4;
  --border:      #d8cfc4;
  --link:        #b85c20;

  /* Shadows */
  --shadow-sm:   0 1px 3px rgba(26, 20, 16, 0.08);
  --shadow-md:   0 4px 16px rgba(26, 20, 16, 0.10);

  /* Easing */
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* ── Dark mode: auto ───────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0f0e0c;
    --bg-2:        #1a1814;
    --bg-3:        #242018;
    --text:        #f0ece4;
    --muted:       #9a8e80;
    --accent:      #e8905a;
    --accent-soft: #1a1410;
    --border:      #2e2a24;
    --link:        #e8905a;
    --shadow-sm:   0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md:   0 4px 16px rgba(0, 0, 0, 0.4);
  }

  /* Fix: knob position also responds to system dark mode */
  :root:not([data-theme="light"]) .theme-toggle::after {
    transform: translateX(18px);
    background: var(--accent);
  }
}

/* ── Dark mode: explicit ───────────────────────────── */
[data-theme="dark"] {
  --bg:          #0f0e0c;
  --bg-2:        #1a1814;
  --bg-3:        #242018;
  --text:        #f0ece4;
  --muted:       #9a8e80;
  --accent:      #e8905a;
  --accent-soft: #1a1410;
  --border:      #2e2a24;
  --link:        #e8905a;
  --shadow-sm:   0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md:   0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ── Light mode: explicit ──────────────────────────── */
[data-theme="light"] {
  --bg:          #faf8f4;
  --bg-2:        #f0ece4;
  --bg-3:        #e6e0d4;
  --text:        #1a1410;
  --muted:       #6b5f52;
  --accent:      #b85c20;
  --accent-soft: #f5ece4;
  --border:      #d8cfc4;
  --link:        #b85c20;
  --shadow-sm:   0 1px 3px rgba(26, 20, 16, 0.08);
  --shadow-md:   0 4px 16px rgba(26, 20, 16, 0.10);
}


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

html {
  font-size: 20px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}


/* ══════════════════════════════════════════════════════
   Base
   ══════════════════════════════════════════════════════ */
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'EB Garamond', Georgia, serif;
  line-height: 1.8;
  padding: 0 1.5rem;
  transition: background 0.3s var(--ease-in-out), color 0.3s var(--ease-in-out);

  /* Subtle paper grain */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
}

a {
  color: var(--link);
  transition: opacity 0.2s;
}

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


/* ══════════════════════════════════════════════════════
   Layout
   ══════════════════════════════════════════════════════ */
.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 0 7rem;
}

/* ── Two-column grid ─────────────────────────────────── */
.columns {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 0 4rem;
  align-items: start;
  margin-top: 3rem;
}

.col-profile {
  position: sticky;
  top: 3rem;
  opacity: 0;
  animation: fadeUp 0.65s var(--ease-out) 0.05s forwards;
}

.col-research {
  border-left: 1px solid var(--border);
  padding-left: 4rem;
  opacity: 0;
  animation: fadeUp 0.65s var(--ease-out) 0.15s forwards;
}


/* ══════════════════════════════════════════════════════
   Header
   ══════════════════════════════════════════════════════ */
header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4rem;
  opacity: 0;
  animation: fadeUp 0.65s var(--ease-out) forwards;
}

.name {
  font-size: 2.5rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
  text-decoration: none;
  transition: opacity 0.2s;
}

.name:hover { opacity: 0.6; }

.name-viet {
  display: block;
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.76rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-top: 0.45rem;
}

nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-shrink: 0;
}

nav a {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: border-color 0.2s, opacity 0.2s;
}

nav a:hover {
  border-color: var(--accent);
  opacity: 0.75;
}

nav a.active {
  border-color: var(--accent);
  opacity: 0.35;
  pointer-events: none;
}


/* ── Theme toggle ─────────────────────────────────────── */
/*
  Fix: using padding instead of ::before to extend touch area.
  Negative margin compensates so visual layout is unaffected.
*/
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 38px;
  height: 20px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.3s;
}

.theme-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.3s var(--ease-out), background 0.3s;
  pointer-events: none;
}

[data-theme="dark"] .theme-toggle::after {
  transform: translateX(18px);
  background: var(--accent);
}


/* ══════════════════════════════════════════════════════
   Profile column
   ══════════════════════════════════════════════════════ */
.portrait-wrap {
  margin-bottom: 1.5rem;
}

.portrait {
  width: 100%;
  height: auto;
  border-radius: 3px;
  object-fit: cover;
  filter: grayscale(12%);
  display: block;
  box-shadow: var(--shadow-md);
  transition: filter 0.4s;
}

.portrait:hover { filter: grayscale(0%); }

.bio-text {
  font-size: 0.95rem;
  color: var(--muted);
  font-style: italic;
  line-height: 1.7;
  margin-bottom: 2rem;
}

.profile-section {
  margin-top: 2rem;
}


/* ══════════════════════════════════════════════════════
   Divider
   ══════════════════════════════════════════════════════ */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}


/* ══════════════════════════════════════════════════════
   Sections (right column)
   ══════════════════════════════════════════════════════ */
section {
  margin-top: 3rem;
}

/* Fix: :first-of-type is more robust than :first-child
   when other element types precede the first section */
.col-research section:first-of-type {
  margin-top: 0;
}

.section-label {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.68rem;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

/* Decorative rule after label */
.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}


/* ══════════════════════════════════════════════════════
   Generic item list
   ══════════════════════════════════════════════════════ */
.item-list {
  list-style: none;
}

.item-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  transition: padding-left 0.2s var(--ease-out);
}

.item-list li:last-child {
  border-bottom: none;
}

.item-list li:hover {
  padding-left: 0.3rem;
}

.year {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.7rem;
  color: var(--muted);
  margin-right: 0.5rem;
}

.sub {
  display: block;
  font-size: 0.875rem;
  color: var(--muted);
  margin-top: 0.15rem;
}


/* ══════════════════════════════════════════════════════
   Publications
   ══════════════════════════════════════════════════════ */
.pub-list {
  list-style: none;
  counter-reset: pub;
}

.pub-list li {
  counter-increment: pub;
  position: relative;
  padding: 0.85rem 0 0.85rem 2.2rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.97rem;
}

.pub-list li:last-child {
  border-bottom: none;
}

.pub-list li::before {
  content: counter(pub) ".";
  position: absolute;
  left: 0;
  top: 0.85rem;
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.68rem;
  color: var(--muted);
}

.pub-links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.pub-tag {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 2px 7px;
  border-radius: 2px;
  text-decoration: none;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.pub-tag:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  opacity: 1;
}


/* ══════════════════════════════════════════════════════
   Contact
   ══════════════════════════════════════════════════════ */
.contact-line {
  font-size: 1rem;
}

.contact-line a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.2s, opacity 0.2s;
}

.contact-line a:hover {
  border-color: var(--accent);
  opacity: 1;
}


/* ══════════════════════════════════════════════════════
   Research interest tags
   ══════════════════════════════════════════════════════ */
.interest-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.interest-tag {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 2px;
  transition: background 0.2s, color 0.2s;
}

.interest-tag:hover {
  background: var(--bg-3);
  color: var(--text);
}


/* ══════════════════════════════════════════════════════
   Teaching page
   ══════════════════════════════════════════════════════ */
.page > main {
  max-width: 660px;
  margin-top: 2.5rem;
  opacity: 0;
  animation: fadeUp 0.65s var(--ease-out) 0.05s forwards;
}

.teaching-blurb {
  font-size: 0.97rem;
  color: var(--muted);
  line-height: 1.75;
}

.teaching-link {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
  padding-bottom: 1px;
  transition: opacity 0.2s;
}

.teaching-link:hover { opacity: 0.6; }

/* ── Course cards ─────────────────────────────────────── */
.course-list {
  list-style: none;
}

.course-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.course-list li:last-child {
  border-bottom: none;
}

.course-meta {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.course-title {
  font-size: 1rem;
  font-weight: 500;
}

.course-code {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.63rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 300;
}

.course-desc {
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.3rem;
  line-height: 1.65;
}

.course-links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}


/* ══════════════════════════════════════════════════════
   404 page
   ══════════════════════════════════════════════════════ */
.not-found {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 12rem);
  max-width: 500px;
}

.not-found-code {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.2rem;
}

.not-found-title {
  font-size: 2.2rem;
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: 1rem;
}

.not-found-desc {
  font-size: 1rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 2.5rem;
  line-height: 1.7;
}

.not-found-link {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
  padding-bottom: 1px;
  transition: opacity 0.2s;
  align-self: flex-start;
}

.not-found-link:hover { opacity: 0.6; }


/* ══════════════════════════════════════════════════════
   Footer
   ══════════════════════════════════════════════════════ */
footer {
  margin-top: 6rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.66rem;
  letter-spacing: 0.07em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}


/* ══════════════════════════════════════════════════════
   Animations
   ══════════════════════════════════════════════════════ */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}


/* ══════════════════════════════════════════════════════
   Responsive — ≤ 700px
   ══════════════════════════════════════════════════════ */
@media (max-width: 700px) {
  html { font-size: 17px; }

  body { padding: 0 1rem; }

  .page { padding: 2rem 0 4rem; }

  /* Header: wrap name above nav */
  header {
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-bottom: 2.5rem;
    align-items: flex-start;
  }

  .name { font-size: 1.9rem; }

  nav { margin-left: auto; }

  /* Single column */
  .columns {
    grid-template-columns: 1fr;
    gap: 2rem 0;
    margin-top: 1.5rem;
  }

  /* Profile: thumbnail beside bio */
  .col-profile {
    position: static;
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 0 1.2rem;
    align-items: start;
  }

  .portrait-wrap { grid-row: span 2; }

  .bio-text {
    margin-bottom: 0;
    font-size: 0.88rem;
  }

  .profile-section {
    grid-column: 1 / -1;
    margin-top: 1.5rem;
  }

  /* Research column: top border instead of left */
  .col-research {
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 2rem;
  }

  /* Teaching main */
  .page > main { margin-top: 1.5rem; }

  section { margin-top: 2.2rem; }

  .pub-list li { padding-left: 1.6rem; }

  footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
  }
}
