/* ============================================================
   CSS Variables & Global Styles
   ============================================================ */
:root {
  --brand: #c50000;
  --brand-hover: #ff4d4d;
  --text: #e9edf2;
  --muted: #a7b0ba;
  --bg: #0f1115;
  --bg-alt: #151a22;
  --border: #222a35;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --sp-xs: 0.25rem;
  --sp-sm: 0.5rem;
  --sp-md: 1rem;
  --sp-lg: 1.5rem;
  --sp-xl: 2rem;
}

html {
  font-size: 1em;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(1100px 520px at 10% -10%, rgba(106, 160, 255, 0.16), transparent 60%),
    radial-gradient(900px 460px at 90% 0%, rgba(120, 160, 255, 0.1), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: 'Roboto Mono', monospace, system-ui;
  font-size: 1em;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, video {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--brand);
  text-decoration: none;
  transition: color 0.2s, text-decoration-color 0.2s;
}

a:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text);
  margin-top: var(--sp-md);
  margin-bottom: var(--sp-sm);
  line-height: 1.3;
  font-weight: 600;
  font-family: 'Roboto Mono', monospace, system-ui;
  letter-spacing: 0;
}

:where(a, button):focus-visible {
  outline: 2px dotted var(--brand);
  outline-offset: 2px;
}

::selection {
  background: #2b4d6f;
  color: #fff;
}

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

/* ============================================================
   Header & Navigation
   ============================================================ */
header {
  background-color: rgba(15, 17, 21, 0.8);
  padding: var(--sp-sm) var(--sp-lg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-md);
}

#site-name {
  font-size: 1.1em;
  font-weight: bold;
}

#site-name a {
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-sm);
}

#site-name a:hover {
  color: var(--brand-hover);
  text-decoration: none;
}

.site-logo {
  height: 1.5em;
}

nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: var(--sp-md);
  flex-wrap: wrap;
}

nav a {
  color: var(--text);
  font-weight: 500;
  font-size: 0.9em;
  padding: var(--sp-xs) var(--sp-sm);
}

nav a:hover {
  color: var(--brand-hover);
  text-decoration: none;
}

#theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.3em;
  cursor: pointer;
  padding: var(--sp-xs);
  border-radius: 999px;
}

#theme-toggle:hover {
  color: var(--brand-hover);
  border-color: var(--brand-hover);
}

/* ============================================================
   Main Layout
   ============================================================ */
main {
  max-width: 1360px;
  width: 90%;
  margin: var(--sp-lg) auto;
  padding: 0 var(--sp-md);
}

/* ============================================================
   Hero Section
   ============================================================ */
#hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--sp-md);
  gap: var(--sp-lg);
}

#image-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-md);
}

#image-container img {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

#bio-text-container {
  width: 100%;
}

#hero h1 {
  font-size: 1.6em;
  margin-bottom: var(--sp-sm);
}

#hero div {
  font-size: 1em;
  line-height: 1.6;
  text-align: left;
}

#social-links {
  display: flex;
  justify-content: center;
  gap: var(--sp-md);
}

#social-links a {
  font-size: 1.5em;
  color: var(--muted);
  display: flex;
  width: 1.5em;
  height: 1.5em;
}

#social-links a svg {
  width: 100%;
  height: 100%;
}

#social-links a:hover {
  color: var(--brand);
}

/* ============================================================
   Sections (Publications, Talks, Carousel)
   ============================================================ */
#latest-publications,
#selected-talks,
.carousel {
  background-color: var(--bg-alt);
  padding: var(--sp-lg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: var(--sp-lg);
}

#latest-publications h2,
#selected-talks h2,
.carousel h2 {
  font-size: 1.5em;
  margin-bottom: var(--sp-md);
  text-align: center;
}

/* ============================================================
   Publication Cards
   ============================================================ */
.publication-item {
  display: grid;
  grid-template-columns: 6em 1fr;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "img details"
    "controls controls"
    "abstract abstract";
  gap: var(--sp-md);
  background-color: var(--bg-alt);
  padding: var(--sp-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.pub-image-wrapper {
  grid-area: img;
  width: 6em;
  height: 8em;
  overflow: hidden;
  border-radius: var(--radius-sm);
}

.pub-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.pub-details {
  grid-area: details;
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  min-height: 7.5em;
}

.pub-type-label {
  background-color: var(--brand);
  color: #fff;
  font-size: 0.7em;
  padding: 0.2em 0.5em;
  border-radius: 999px;
  text-transform: uppercase;
  font-weight: 600;
  width: fit-content;
}

.pub-type-label.pub-type-journal-article {
  background-color: #2b6cb0;
}

.publication-item h3 {
  font-size: 1.1em;
  margin: var(--sp-xs) 0;
  line-height: 1.3;
  min-height: 0;
}

.publication-item h3.title-tight {
  font-size: 1em;
}

.publication-item h3 a {
  color: #fff;
}

.publication-item h3 a:hover {
  color: var(--brand-hover);
}

.pub-authors {
  font-size: 0.85em;
  color: var(--muted);
}

.pub-journal-info {
  font-size: 0.8em;
  color: var(--muted);
}

.toggle-abstract-btn {
  grid-area: controls;
  background-color: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: var(--sp-sm) var(--sp-md);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85em;
  min-width: 9.5em;
  text-align: center;
}

.toggle-abstract-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.pub-abstract-content {
  grid-area: abstract;
  max-height: 12em;
  height: 12em;
  overflow-y: auto;
  transition: max-height 0.3s ease;
  padding: var(--sp-sm);
  border-left: 3px solid var(--border);
}

.pub-abstract-content {
  scrollbar-width: thin;
  scrollbar-color: var(--brand) var(--bg-alt);
}

.pub-abstract-content::-webkit-scrollbar {
  width: 6px;
}

.pub-abstract-content::-webkit-scrollbar-thumb {
  background: var(--brand);
  border-radius: 3px;
}

.pub-abstract-title {
  font-weight: 700;
  color: var(--brand);
  margin-bottom: var(--sp-xs);
}

.pub-abstract {
  font-size: 0.9em;
  color: var(--text);
  line-height: 1.5;
  text-align: justify;
}

/* ============================================================
   Carousel
   ============================================================ */
.carousel {
  position: relative;
  overflow: hidden;
}

.carousel-viewport {
  overflow: hidden;
  width: 100%;
}

.carousel-track {
  display: flex;
  transition: transform 300ms ease;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0;
}

.carousel-slide {
  flex: 0 0 100%;
  padding: var(--sp-lg);
  display: grid;
  grid-template-columns: 14em 1fr;
  gap: var(--sp-lg);
  align-items: start;
  box-sizing: border-box;
}

.carousel-slide .thumb {
  width: 14em;
  height: 10em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}

.carousel-slide .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.carousel-slide h3 {
  margin: 0 0 var(--sp-xs);
  font-size: 1.2em;
}

.carousel-slide .meta {
  font-size: 0.9em;
  color: var(--muted);
  margin: 0 0 var(--sp-xs);
}

.carousel-slide .desc {
  font-size: 0.9em;
  margin: var(--sp-xs) 0;
}

.carousel a.cta {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  margin-top: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md);
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

.carousel a.cta:hover {
  background: var(--brand-hover);
  text-decoration: none;
}

.carousel-control {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-control:hover {
  background: rgba(0, 0, 0, 0.6);
}

.carousel-control.prev {
  left: var(--sp-sm);
}

.carousel-control.next {
  right: var(--sp-sm);
}

.carousel-indicators {
  display: flex;
  justify-content: center;
  gap: var(--sp-sm);
  padding: var(--sp-md) 0 0;
}

.carousel-indicators button {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 0;
  background: #445063;
  cursor: pointer;
}

.carousel-indicators button[aria-current="true"] {
  background: var(--brand-hover);
}

/* ============================================================
   Grids (Homepage & Talks Page)
   ============================================================ */
#talks-ul,
#latest-publications-dashboard,
#selected-talks-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-md);
}

#talks-ul li.talk-item {
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s;
}

#talks-ul li.talk-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.talk-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg);
  overflow: hidden;
}

.talk-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.talk-content {
  padding: var(--sp-md);
  flex-grow: 1;
}

.talk-content .title {
  font-size: 1.1em;
  margin: 0 0 var(--sp-sm);
  line-height: 1.3;
}

.talk-content .whenwhere {
  color: var(--muted);
  font-size: 0.85em;
  margin: var(--sp-xs) 0;
}

.talk-content .desc,
.talk-content .long-desc {
  font-size: 0.9em;
  margin-top: var(--sp-sm);
  line-height: 1.5;
}

/* Homepage grid cards */
#latest-publications-dashboard .publication-item,
#selected-talks-list .publication-item {
  display: flex;
  flex-direction: column;
  padding: var(--sp-md);
  min-height: 200px;
  font-size: 0.9em;
}

#latest-publications-dashboard .pub-image-wrapper,
#selected-talks-list .pub-image-wrapper {
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: var(--sp-sm);
  grid-area: unset;
}

#latest-publications-dashboard .pub-details,
#selected-talks-list .pub-details {
  grid-area: unset;
}

#latest-publications-dashboard h3,
#selected-talks-list h3 {
  font-size: 1em;
  margin: 0 0 var(--sp-xs);
  line-height: 1.3;
}

/* Research page: 2-column grid */
#journal-articles-container,
#working-papers-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-md);
}

/* ============================================================
   CV Page
   ============================================================ */
#cv-content {
  max-width: 1180px;
  margin: var(--sp-lg) auto;
}

.cv-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: var(--sp-lg);
  align-items: start;
}

.cv-index {
  position: sticky;
  top: var(--sp-lg);
  align-self: start;
  padding: var(--sp-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg-alt);
  box-shadow: var(--shadow);
}

.cv-index-title {
  font-size: 0.9em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 var(--sp-sm);
  color: var(--muted);
}

.cv-index ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--sp-xs);
}

.cv-index a {
  color: var(--text);
  font-size: 0.85em;
  display: inline-flex;
  padding: 0.2em 0.4em;
  border-radius: 6px;
}

.cv-index a:hover {
  color: var(--brand);
  text-decoration: none;
  background-color: rgba(197, 0, 0, 0.08);
}

.cv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-xl);
  flex-wrap: wrap;
  gap: var(--sp-md);
}

.cv-header h1 {
  font-size: 2em;
  margin: 0;
}

.cv-download-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-sm);
  background-color: var(--brand);
  color: white;
  padding: var(--sp-sm) var(--sp-md);
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9em;
}

.cv-download-btn:hover {
  background-color: var(--brand-hover);
  text-decoration: none;
}

.cv-section {
  margin-bottom: var(--sp-xl);
  padding: var(--sp-sm) var(--sp-md);
  background-color: var(--bg-alt);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9em;
}

.cv-section h2 {
  font-size: 1.3em;
  color: var(--text);
  margin-bottom: var(--sp-sm);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--sp-xs);
}

.cv-section-title {
  margin: 0 0 var(--sp-sm);
}

.cv-section-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: 0;
  cursor: pointer;
}

.cv-section-toggle::after {
  content: "-";
  margin-left: auto;
  color: var(--muted);
  font-weight: 600;
}

.cv-section.collapsed .cv-section-toggle::after {
  content: "+";
}

.cv-section-body {
  margin-top: var(--sp-sm);
}

.cv-section.collapsed .cv-section-body {
  display: none;
}

.cv-item {
  margin-bottom: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background-color: var(--bg-alt);
}

.cv-item:last-child {
  margin-bottom: 0;
}

.cv-items-grid {
  display: grid;
  gap: var(--sp-sm);
}

.cv-items-grid .cv-item {
  margin-bottom: 0;
}

.cv-education .cv-items-grid {
  grid-template-columns: 1fr;
}

.cv-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--sp-xs);
  gap: var(--sp-md);
  flex-wrap: wrap;
}

.cv-item h3 {
  font-size: 1.1em;
  margin: 0;
  flex: 1;
}

.cv-date {
  font-size: 0.9em;
  color: var(--brand-hover);
  font-weight: 600;
  white-space: nowrap;
}

.cv-institution {
  font-size: 0.95em;
  color: var(--muted);
  margin: var(--sp-xs) 0;
  font-style: italic;
}

.cv-details,
.cv-list li {
  font-size: 0.9em;
  color: var(--muted);
  line-height: 1.45;
}

.cv-list {
  margin: var(--sp-sm) 0 0 var(--sp-lg);
  padding: 0;
}

.cv-item.verbose .cv-details,
.cv-item.verbose .cv-list li {
  font-size: 0.85em;
}

.cv-skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  grid-auto-flow: dense;
  gap: var(--sp-sm);
}

.cv-skill-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-xs);
  padding: var(--sp-sm) var(--sp-md);
  background-color: transparent;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.cv-skill-item.span-2 {
  grid-column: span 2;
}

.cv-skill-item h4 {
  font-size: 0.95em;
  color: var(--text);
  margin: 0;
  width: 100%;
  padding-bottom: var(--sp-xs);
  border-bottom: 1px solid var(--border);
}

.cv-skill-item p {
  margin: 0;
  font-size: 0.85em;
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
  white-space: normal;
}

#skills .cv-skills-grid {
  grid-template-columns: 1fr;
}

#skills .cv-skill-item {
  padding: var(--sp-xs) var(--sp-md);
}

.cv-section.cv-tight-list .cv-item {
  padding: var(--sp-xs) var(--sp-md);
  margin-bottom: var(--sp-xs);
}

.cv-section.cv-tight-list .cv-conference {
  font-size: 0.85em;
}


/* ============================================================
   Footer
   ============================================================ */
.section-divider {
  border: 0;
  height: 1px;
  background-color: var(--border);
  margin: var(--sp-xl) 0;
}

footer {
  text-align: center;
  padding: var(--sp-md);
  margin-top: var(--sp-xl);
  color: var(--muted);
  font-size: 0.85em;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Light Theme
   ============================================================ */
body.light-theme {
  background:
    radial-gradient(1100px 520px at 10% -10%, rgba(106, 160, 255, 0.12), transparent 60%),
    radial-gradient(900px 460px at 90% 0%, rgba(106, 160, 255, 0.08), transparent 55%),
    #dde3ea;
  color: #222833;
  --text: #222833;
  --muted: #3b4654;
  --bg: #dde3ea;
  --bg-alt: #ffffff;
  --border: #c3ccd6;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.16);
}

body.light-theme a {
  color: var(--brand);
}

body.light-theme h1,
body.light-theme h2,
body.light-theme h3,
body.light-theme h4,
body.light-theme h5,
body.light-theme h6 {
  color: #222;
}

body.light-theme header {
  background-color: rgba(245, 247, 250, 0.9);
  border-bottom-color: #e1e5ea;
}

body.light-theme nav a,
body.light-theme #site-name a,
body.light-theme #theme-toggle {
  color: #333;
}

body.light-theme #image-container img {
  border-color: #d7dce2;
}

body.light-theme #social-links a,
body.light-theme #social-links a svg {
  color: #5b6673;
}

body.light-theme #latest-publications,
body.light-theme #selected-talks,
body.light-theme .publication-item,
body.light-theme .cv-section,
body.light-theme .carousel,
body.light-theme #talks-ul li.talk-item {
  background-color: #ffffff;
  box-shadow: var(--shadow);
}

body.light-theme .pub-image-wrapper img,
body.light-theme .carousel-slide .thumb {
  border-color: #ddd;
}

body.light-theme .publication-item h3 a {
  color: #16181d;
}

body.light-theme .pub-authors,
body.light-theme .pub-journal-info,
body.light-theme .talk-content .whenwhere,
body.light-theme .carousel-slide .meta {
  color: #5b6673;
}

body.light-theme .pub-abstract,
body.light-theme .talk-content .desc,
body.light-theme .talk-content .long-desc {
  color: #16181d;
}

body.light-theme .toggle-abstract-btn {
  background-color: transparent;
  color: #16181d;
  border: 1px solid #d5dae0;
}

body.light-theme .toggle-abstract-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

body.light-theme .pub-abstract-content,
body.light-theme .section-divider {
  border-color: #d5dae0;
}

body.light-theme .carousel-control {
  background: rgba(0, 0, 0, 0.08);
  color: #16181d;
}

body.light-theme .carousel-control:hover {
  background: rgba(0, 0, 0, 0.15);
}

body.light-theme .cv-skill-item {
  background-color: #f8f8f8;
}

body.light-theme .cv-skill-item p {
  color: #2f3742;
}

body.light-theme footer {
  border-top-color: #e1e5ea;
}

/* ============================================================
   Responsive Design
   ============================================================ */
@media (min-width: 768px) {
  #hero {
    flex-direction: row;
    text-align: left;
    align-items: flex-start;
    gap: var(--sp-xl);
  }
  
  #image-container {
    align-items: flex-start;
  }
  
  #social-links {
    justify-content: flex-start;
  }
  
  #bio-text-container {
    flex-grow: 1;
    max-width: 65%;
    text-align: left;
  }
  
  .carousel-slide {
    grid-template-columns: 14em 1fr;
  }
  
  #journal-articles-container,
  #working-papers-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  #latest-publications-dashboard,
  #selected-talks-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .cv-education .cv-items-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .carousel-slide {
    grid-template-columns: 1fr;
    padding: var(--sp-md);
  }
  
  .carousel-slide .thumb {
    width: 100%;
    height: 140px;
  }
  
  #image-container img {
    width: 160px;
    height: 160px;
  }

  .cv-skill-item.span-2 {
    grid-column: span 1;
  }
}

@media (max-width: 900px) {
  .cv-layout {
    grid-template-columns: 1fr;
  }

  .cv-index {
    position: static;
  }
}

@media (max-width: 480px) {
  header {
    padding: var(--sp-sm);
  }
  
  nav ul {
    gap: var(--sp-sm);
  }
  
  nav a {
    font-size: 0.8em;
    padding: var(--sp-xs);
  }
  
  #site-name {
    font-size: 0.95em;
  }
  
  #theme-toggle {
    font-size: 1.1em;
  }
  
  .publication-item {
    grid-template-columns: 1fr;
    grid-template-areas:
      "img"
      "details"
      "controls"
      "abstract";
  }
  
  .pub-image-wrapper {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }
  
  .cv-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .cv-section {
    padding: var(--sp-md);
  }
}
