:root {
  --bg: #2b2826;
  --fg: #e8e4df;
  --muted: #a8a099;
  --accent: #d4a373;
  --accent-hover: #e8b98a;
  --border: #3a3735;
  --sidebar-bg: #252321;
  --photo-glow: rgba(212, 163, 115, 0.28);
  --selection-bg: rgba(212, 163, 115, 0.35);
  --selection-fg: #2b2826;
}

[data-theme="light"] {
  --bg: #f7f3ee;
  --fg: #2a2724;
  --muted: #6b645d;
  --accent: #9c6a3f;
  --accent-hover: #7a5230;
  --border: #e2dcd2;
  --sidebar-bg: #efe9e0;
  --photo-glow: rgba(156, 106, 63, 0.22);
  --selection-bg: rgba(156, 106, 63, 0.28);
  --selection-fg: #2a2724;
}

::selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

::-moz-selection {
  background: var(--selection-bg);
  color: var(--selection-fg);
}

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

*, *::before, *::after {
  transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.7;
  color: var(--fg);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-position: 0 100%;
  background-repeat: no-repeat;
  background-size: 0 1px;
  transition: color 0.2s ease, background-size 0.3s ease;
}

a:hover {
  color: var(--accent-hover);
  background-size: 100% 1px;
}

/* Layout */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  padding: 3rem 2rem;
  background-color: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

.main {
  margin-left: 280px;
  padding: 4rem 4rem 6rem;
  max-width: 780px;
}

/* Sidebar content */
.profile-photo {
  width: 195px;
  aspect-ratio: 10 / 9;
  border-radius: 8px;
  object-fit: cover;
  object-position: center 25%;
  margin-bottom: 1.5rem;
  filter: saturate(0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--border), 0 6px 28px var(--photo-glow);
  transition: box-shadow 0.4s ease;
}

.site-name {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-bottom: 0.25rem;
  line-height: 1.2;
}

.site-title {
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
  margin-bottom: 1.25rem;
  line-height: 1.4;
}

.cv-link,
.scholar-link {
  font-size: 0.9rem;
  display: block;
}

.cv-link {
  margin-bottom: 0.35rem;
}

.scholar-link {
  margin-bottom: 2rem;
}

.nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.nav a {
  font-size: 0.95rem;
  color: var(--fg);
  background-image: none;
  padding: 0.15rem 0;
  display: inline-block;
  position: relative;
}

.nav a::before {
  content: "";
  position: absolute;
  left: -0.85rem;
  top: 0.45rem;
  bottom: 0.45rem;
  width: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.25s ease, background-color 0.4s ease;
}

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

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

.nav a.active::before {
  opacity: 1;
}

.theme-toggle {
  margin-top: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease;
  padding: 0;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

/* Main content */
section {
  margin-bottom: 4.5rem;
  scroll-margin-top: 2rem;
}

.js-fade main section,
.js-fade .site-footer {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.js-fade main section.in-view,
.js-fade .site-footer.in-view {
  opacity: 1;
  transform: translateY(0);
}

section:last-child {
  margin-bottom: 0;
}

h1, h2, h3 {
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  font-weight: 500;
}

h3 {
  font-size: 1.3rem;
  margin: 2.25rem 0 1rem;
  color: var(--fg);
  font-weight: 600;
  letter-spacing: -0.005em;
}

p {
  margin-bottom: 1.1rem;
}

.paper {
  margin-bottom: 1.75rem;
}

.paper-title {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--fg);
}

a.paper-title {
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 0 1.5px;
  padding-bottom: 2px;
  transition: background-size 0.3s ease, color 0.25s ease;
}

a.paper-title:hover {
  color: var(--accent);
  background-size: 100% 1.5px;
}

.paper-meta {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 0.15rem;
}

.paper-status {
  font-style: italic;
  font-size: 0.95rem;
  margin-top: 0.15rem;
}

.paper-status strong {
  font-weight: 600;
}

.abstract-toggle {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.25rem 0;
  margin-top: 0.2rem;
  font-style: italic;
  letter-spacing: 0.01em;
}

.abstract-toggle:hover {
  color: var(--accent-hover);
}

.abstract {
  max-height: 0;
  overflow: hidden;
  margin-top: 0;
  padding: 0 1rem;
  border-left: 2px solid transparent;
  color: var(--fg);
  font-size: 0.95rem;
  line-height: 1.65;
  transition: max-height 0.35s ease, padding 0.35s ease, margin-top 0.35s ease, border-left-color 0.4s ease, color 0.4s ease;
}

.abstract.open {
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  border-left-color: var(--border);
}

.report, .media-item {
  margin-bottom: 1.5rem;
}

.lang-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.08rem 0.5rem;
  margin-top: 0.4rem;
  line-height: 1.4;
}

.report-title {
  font-weight: 600;
  font-size: 1rem;
}

.report-meta {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 0.15rem;
}

.contact-list {
  list-style: none;
}

.grants-list {
  list-style: none;
}

.grants-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.35rem 0;
  border-bottom: 1px dotted var(--border);
}

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

.grants-list .grant-year {
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.contact-list li {
  margin-bottom: 0.4rem;
}

.contact-label {
  font-weight: 600;
}

/* Footer */
.site-footer {
  margin-top: 5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  letter-spacing: 0.02em;
}

/* Back to top */
.back-to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease,
              color 0.15s ease, border-color 0.15s ease, background-color 0.4s ease;
  z-index: 10;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.back-to-top svg {
  width: 16px;
  height: 16px;
}

/* 404 page */
.page-center {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.page-center .error-code {
  font-size: 5rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 1rem;
  color: var(--accent);
}

.page-center p {
  color: var(--muted);
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 2.5rem 1.5rem 2rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    align-items: center;
    text-align: center;
  }

  .profile-photo {
    width: 50vw;
  }

  .nav {
    align-items: center;
  }

  .nav a::before {
    display: none;
  }

  .main {
    margin-left: 0;
    padding: 2.5rem 1.5rem 4rem;
    max-width: 100%;
  }

  .theme-toggle {
    margin-top: 1.5rem;
  }

  h2 {
    font-size: 1.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* Print */
@media print {
  :root {
    --bg: #ffffff;
    --fg: #000000;
    --muted: #333333;
    --accent: #000000;
    --accent-hover: #000000;
    --border: #cccccc;
    --sidebar-bg: #ffffff;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
    line-height: 1.5;
  }

  .sidebar,
  .theme-toggle,
  .back-to-top,
  .abstract-toggle {
    display: none !important;
  }

  .js-fade main section,
  .js-fade .site-footer {
    opacity: 1 !important;
    transform: none !important;
  }

  .profile-photo {
    box-shadow: none !important;
  }

  .main {
    margin-left: 0;
    max-width: 100%;
    padding: 0;
  }

  a {
    color: #000000 !important;
    text-decoration: underline;
    background-image: none !important;
  }

  .abstract {
    max-height: none !important;
    overflow: visible !important;
    margin-top: 0.5rem !important;
    padding: 0.5rem 0.75rem !important;
    border-left: 2px solid #cccccc !important;
  }

  section {
    page-break-inside: avoid;
    margin-bottom: 2rem;
  }

  h2, h3 {
    page-break-after: avoid;
  }

  .paper, .report, .media-item {
    page-break-inside: avoid;
  }

  .site-footer {
    border-top: 1px solid #cccccc;
    color: #333333;
  }
}
