:root {
  --bg: #0a0c16;
  --surface: #141726;
  --surface-strong: #1b1f30;
  --ink: #f2f1ec;
  --muted: #a3a6b5;
  --line: #262b3c;
  --accent: #e8c988;
  --accent-dark: #c9a35f;
  --accent-soft: #2a2618;
  --header-bg: #10121f;
  --max-width: 1180px;
  --radius: 22px;
  --shadow: 0 18px 50px rgba(0, 0, 0, .5);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", Times, serif;
  line-height: 1.6;
}

a {
  color: inherit;
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 12px;
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

img {
  max-width: 100%;
}

mjx-container {
  color: inherit;
}

/* ---- stellar background canvas ---- */
/* Explicit z-index layering (canvas below, content above) rather than a
   negative z-index on the canvas -- that approach previously rendered the
   background on top of the page in some stacking contexts. */

#stellar-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  pointer-events: none;
}

.site-header,
main,
.site-footer {
  position: relative;
  z-index: 1;
}

/* ---- header / nav ---- */

.site-header {
  width: 100%;
  padding: 22px max(32px, calc((100vw - var(--max-width)) / 2 + 32px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 32px;
  background: var(--header-bg);
  color: var(--accent);
  border-bottom: 1px solid var(--line);
}

.site-title,
.site-nav a {
  color: inherit;
  text-decoration: none;
}

.site-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.site-nav a:hover,
.site-nav a.active,
.site-title:hover {
  color: var(--ink);
}

.site-footer {
  max-width: var(--max-width);
  margin: 4rem auto 0;
  padding: 2rem 32px 3rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer a:hover {
  color: var(--accent-dark);
}

/* ---- shared components ---- */

.page-shell {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 12px;
}

.standard-page {
  margin: 3.5rem 0 5rem;
}

.standard-page h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -0.04em;
  color: var(--accent);
}

.meta {
  color: var(--muted);
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  margin: 0 0 2rem;
}

.standard-page article > .meta:last-child {
  margin-top: 1.5rem;
}

.section {
  margin: 4rem 0;
}

.section-label {
  margin-bottom: 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

.section-label span {
  display: inline-block;
  position: relative;
  padding-bottom: 0.75rem;
}

.section-label span::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 2.6rem;
  height: 2px;
  background: var(--accent);
}

.section-heading {
  max-width: 720px;
  margin-bottom: 1.5rem;
}

.section-heading h2 {
  margin: 0 0 0.75rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.03em;
  color: var(--accent);
}

.section-heading p {
  color: var(--muted);
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.3rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg) !important;
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none;
  box-shadow: 0 10px 24px rgba(232, 201, 136, 0.15);
}

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

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  box-shadow: none;
  min-width: 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1.75rem;
}

.text-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

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

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

/* ---- hero (home page) ---- */

.hero-section {
  margin: 2.5rem 0 4.5rem;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(260px, .8fr) minmax(0, 1.2fr);
  gap: 3rem;
  align-items: center;
}

.hero-portrait {
  display: block;
  width: 100%;
  max-width: 340px;
  border-radius: 18px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, .5);
}

.hero-copy h1 {
  margin: 0 0 1rem;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  letter-spacing: -0.045em;
  color: var(--accent);
}

.intro-text {
  margin: 0;
  max-width: 42rem;
  font-size: clamp(1.05rem, 1.5vw, 1.15rem);
  line-height: 1.55;
  color: var(--ink);
}

/* ---- generic content sections ---- */

.about-copy p {
  color: var(--ink);
  font-size: 1.05rem;
}

.pull {
  font-style: italic;
  font-size: 1.2rem;
  line-height: 1.5;
  color: var(--accent-dark);
  border-left: 3px solid var(--accent);
  padding: 0.2rem 0 0.2rem 1.25rem;
  margin: 2rem 0;
}

/* ---- book grid (reading list) ---- */

.book-card {
  padding: 1.5rem 1.75rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.1rem 2rem;
}

.book-grid .book-item {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  animation: book-bob 5s ease-in-out infinite;
}

.book-grid .book-item:nth-child(4n+1) { animation-delay: 0s; }
.book-grid .book-item:nth-child(4n+2) { animation-delay: 0.5s; }
.book-grid .book-item:nth-child(4n+3) { animation-delay: 1s; }
.book-grid .book-item:nth-child(4n+4) { animation-delay: 1.5s; }

@keyframes book-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.book-grid .book-author {
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .book-grid .book-item {
    animation: none;
  }
}

/* ---- notes / course card grid ---- */

.course-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
}

.course-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.course-card h3 a {
  color: var(--ink);
  text-decoration: none;
}

.course-card h3 a:hover {
  color: var(--accent);
}

.course-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ---- floating note bubbles ---- */

.bubble-field {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem 2rem;
  padding: 1.5rem 0 1rem;
}

.bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 150px;
  height: 150px;
  padding: 1.1rem;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  cursor: pointer;
  animation: bob 7s ease-in-out infinite;
  transition: transform 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.bubble:hover {
  color: var(--accent);
  border-color: var(--accent);
  animation-play-state: paused;
  transform: translateY(-6px) scale(1.04);
}

.bubble:nth-child(2) { animation-delay: -1.5s; animation-duration: 8s; }
.bubble:nth-child(3) { animation-delay: -3s; animation-duration: 6.5s; }
.bubble:nth-child(4) { animation-delay: -4.5s; animation-duration: 7.5s; }
.bubble:nth-child(5) { animation-delay: -2s; animation-duration: 6s; }
.bubble:nth-child(6) { animation-delay: -5s; animation-duration: 8.5s; }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

@media (prefers-reduced-motion: reduce) {
  .bubble {
    animation: none;
  }
}

/* ---- note popup modal ---- */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.65);
}

.modal-backdrop.is-open {
  display: flex;
}

.modal {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  background: var(--surface-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal h3 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  color: var(--accent);
}

.modal p {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.modal-close {
  position: absolute;
  top: 0.9rem;
  right: 1rem;
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--accent);
}

/* ---- entry lists: publications / talks ---- */

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.entry {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem;
}

.entry-year {
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  padding-top: 0.2rem;
}

.entry-body .venue {
  display: block;
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.entry-body .links {
  display: inline-flex;
  gap: 0.5rem;
  margin-left: 0.5rem;
}

/* ---- notes index (list page) ---- */

.notes-index {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.notes-index li {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1.1rem 1.4rem;
  margin: 0;
}

.notes-index .idx {
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
}

.notes-index a {
  font-size: 1.05rem;
  text-decoration: none;
}

.notes-index a:hover {
  color: var(--accent);
}

/* ---- CV numbered sections ---- */

article {
  counter-reset: section;
}

article h1 {
  counter-increment: section;
  font-size: 1rem;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border-top: 1px solid var(--line);
  padding-top: 2.25rem;
  margin: 0 0 1.25rem;
}

article h1:first-child {
  padding-top: 0;
  border-top: none;
}

article h1::before {
  content: counter(section, decimal-leading-zero) "\00a0\00a0";
}

article h2 {
  font-size: 1.15rem;
  margin: 2rem 0 0.8rem;
  color: var(--ink);
}

h3 {
  font-size: 1rem;
  margin: 1.5rem 0 0.5rem;
}

p, ul, ol {
  margin: 0 0 1.1rem;
}

ul, ol {
  padding-left: 1.4rem;
}

li {
  margin-bottom: 0.5rem;
}

code, pre {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

@media (max-width: 900px) {
  .hero-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
    text-align: left;
  }

  .hero-portrait {
    max-width: 220px;
  }

  .course-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .notes-index {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .site-header {
    padding: 16px 20px;
    flex-wrap: wrap;
  }

  main {
    padding: 0 20px;
  }

  .site-nav {
    gap: 16px;
    font-size: 0.85rem;
  }

  body {
    font-size: 16px;
  }

  .course-grid {
    grid-template-columns: 1fr;
  }

  .entry {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }
}
