/* =============================================================================
 * SITE STYLES
 * -----------------------------------------------------------------------------
 *  1. Colors (light + dark)     6. Home page            11. Blog post
 *  2. Base                      7. Publications         12. Table of contents
 *  3. Layout helpers            8. Social icons         13. CV
 *  4. Navbar                    9. Blog list            14. Back-to-top & search
 *  5. Page header              10. Blog filter          15. Small screens
 * ============================================================================= */

/* 1. Colors ------------------------------------------------------------------ */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --text: #000000;
  --text-light: #828282;
  --theme: #b91c1c; /* accent red */
  --hover: #991b1b;
  --divider: rgba(0, 0, 0, 0.1);
  --section-divider: #d1d5db;
  --card-bg: #ffffff;
  --code-bg: rgba(185, 28, 28, 0.05);
  --input-bg: #ffffff;
  --input-text: #000000;
  --back-to-top-bg: rgba(0, 0, 0, 0.4);
  --back-to-top-text: #ffffff;
  --max-width: 930px;
  --shadow: 0 2px 5px #00000029, 0 2px 10px #0000001f;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1c1d;
  --text: #e8e8e8;
  --text-light: #828282;
  --theme: #f87171;
  --hover: #fca5a5;
  --divider: #424246;
  --card-bg: #212529;
  --code-bg: #2c3237;
  --input-bg: #e8e8e8;
  --input-text: #1c1c1d;
  --back-to-top-bg: rgba(255, 255, 255, 0.5);
  --back-to-top-text: #000000;
}

/* Smooth color fade when the theme toggle is clicked */
html.transition,
html.transition *,
html.transition *::before,
html.transition *::after {
  transition-property: color, background-color, border-color, fill, stroke, box-shadow !important;
  transition-duration: 240ms !important;
  transition-timing-function: ease !important;
}

/* 2. Base -------------------------------------------------------------------- */
*,
::before,
::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding-top: 57px; /* room for the fixed navbar */
  padding-bottom: 70px;
  font-family: Roboto, sans-serif;
  font-size: 1rem;
  font-weight: 300;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 0.5rem;
  font-weight: 300;
  line-height: 1.2;
  color: var(--text);
  scroll-margin-top: 66px;
}
h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h6 { font-size: 1rem; }

p, ol, ul {
  margin-top: 0;
  margin-bottom: 1rem;
}

a {
  color: var(--theme);
  text-decoration: none;
}
a:hover {
  color: var(--theme);
  text-decoration: underline;
}

img {
  vertical-align: middle;
  border-style: none;
}

figure {
  margin: 0 0 1rem;
}

button, input {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  margin: 0;
}

blockquote {
  margin: 1.5em 0;
  padding: 1em;
  font-size: 1.2rem;
  background: var(--bg);
  border-left: 5px solid var(--theme);
}
blockquote p {
  margin-bottom: 0;
}

code {
  color: var(--theme);
  background-color: var(--code-bg);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 0.82em;
}

hr {
  border: 0;
  border-top: 1px solid var(--divider);
}

/* 3. Layout helpers ---------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-left: 15px;
  padding-right: 15px;
}

main.container {
  margin-top: 3rem;
}

.bold {
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 0.25em 0.4em;
  font-size: 75%;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  border-radius: 0.25rem;
  color: var(--card-bg);
  background-color: var(--theme);
}

.btn {
  display: inline-block;
  margin: 0.375rem 0.375rem 0.375rem 0;
  padding: 0.25rem 1rem;
  font-size: 0.64rem;
  font-weight: 400;
  line-height: 1.5;
  text-align: center;
  white-space: nowrap;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--text);
  border-radius: 0.125rem;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s, border-color 0.15s;
}
.btn:hover {
  color: var(--theme);
  border-color: var(--theme);
  text-decoration: none;
}

/* 4. Navbar ------------------------------------------------------------------ */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  padding: 0.5rem 1rem;
  background-color: var(--bg);
  border-bottom: 1px solid var(--divider);
  opacity: 0.95;
}
.navbar > .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}
.navbar a:hover {
  text-decoration: none;
}

.navbar-brand {
  margin-right: 1rem;
  padding: 0.3125rem 0;
  font-size: 1.25rem;
  font-weight: lighter;
  white-space: nowrap;
  color: var(--text);
}
.navbar-brand:hover {
  color: var(--text);
}

.navbar-collapse {
  display: flex;
  flex-grow: 1;
  justify-content: flex-end;
  align-items: center;
}

.navbar-nav {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}

.nav-link {
  display: block;
  padding: 0.5rem;
  color: var(--text);
}
.nav-link:hover {
  color: var(--hover);
}
.nav-item.active > .nav-link {
  font-weight: bolder;
  color: var(--theme);
}

#search-toggle,
#light-toggle {
  padding: 0;
  border: 0;
  background-color: inherit;
  color: var(--text);
  cursor: pointer;
}
#search-toggle:hover .nav-link {
  color: var(--hover);
}

#light-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
}
#light-toggle:hover {
  color: var(--hover);
}

/* Show the icon matching the current theme setting */
#light-toggle-dark,
#light-toggle-light { display: none; }
#light-toggle-system { display: inline-block; }
html[data-theme-setting="dark"] #light-toggle-system,
html[data-theme-setting="light"] #light-toggle-system { display: none; }
html[data-theme-setting="dark"] #light-toggle-dark { display: inline-block; }
html[data-theme-setting="light"] #light-toggle-light { display: inline-block; }

/* Half-sun / half-moon icon for "system" mode */
.fa-half-sun-moon {
  position: relative;
  display: inline-block;
  width: 1em;
  height: 1em;
  --fa-font: var(--fa-font-solid);
  font-style: normal;
  -webkit-font-smoothing: antialiased;
}
.fa-half-sun-moon::before,
.fa-half-sun-moon::after {
  position: absolute;
  inset: -0.5px 0;
  line-height: 1em;
  text-align: center;
  font: var(--fa-font);
  color: var(--text);
}
.fa-half-sun-moon::before {
  content: "\f111"; /* left half: filled circle */
  clip-path: polygon(0 0, calc(50% - 0.5px) 0, calc(50% - 0.5px) 100%, 0 100%);
}
.fa-half-sun-moon::after {
  content: "\f185"; /* right half: sun */
  clip-path: polygon(calc(50% + 0.5px) 0, 100% 0, 100% 100%, calc(50% + 0.5px) 100%);
  right: -1.5px;
  transform: translateX(-1px);
}
#light-toggle:hover .fa-half-sun-moon::before,
#light-toggle:hover .fa-half-sun-moon::after {
  color: var(--theme);
}

/* Hamburger button (only on small screens) */
.navbar-toggler {
  display: none;
  margin-left: auto;
  padding: 0.25rem 0.75rem;
  font-size: 1.25rem;
  line-height: 1;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.navbar-toggler .icon-bar {
  display: block;
  width: 22px;
  height: 2px;
  margin-bottom: 4px;
  border-radius: 1px;
  background-color: var(--text);
  transition: all 0.2s;
}
.navbar-toggler .top-bar { transform: rotate(45deg); transform-origin: 10% 10%; }
.navbar-toggler .middle-bar { opacity: 0; }
.navbar-toggler .bottom-bar { transform: rotate(-45deg); transform-origin: 10% 90%; }
.navbar-toggler.collapsed .top-bar,
.navbar-toggler.collapsed .bottom-bar { transform: rotate(0); }
.navbar-toggler.collapsed .middle-bar { opacity: 1; }

/* Reading progress bar under the navbar */
progress {
  position: fixed;
  top: 57px;
  left: 0;
  z-index: 10;
  width: 100%;
  height: 1px;
  appearance: none;
  border: none;
  background-color: transparent;
  color: var(--theme);
}
progress::-webkit-progress-bar { background-color: transparent; }
progress::-webkit-progress-value { background-color: var(--theme); }
progress::-moz-progress-bar { background-color: var(--theme); }

/* 5. Page header ------------------------------------------------------------- */
.post-header .post-title {
  font-size: 2.5rem;
}
.post-header .desc {
  margin: 0.75rem 0 1.5rem;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text-light);
}
.post-description {
  margin-bottom: 2rem;
  font-size: 0.875rem;
}

/* 6. Home page --------------------------------------------------------------- */
.profile {
  float: right;
  width: 30%;
  margin-left: 1rem;
}
.profile img {
  width: 100%;
  height: auto;
  border-radius: 0.25rem;
  box-shadow: var(--shadow);
}
.clearfix::after {
  content: "";
  display: block;
  clear: both;
}

/* Section headings (news, latest posts, selected publications) */
.section-title {
  margin-top: 2.25rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--section-divider);
}
.section-title a {
  color: inherit;
}
.section-title a:hover {
  text-decoration: none;
}

.news .scrollable {
  max-height: 60vw;
  overflow-y: auto;
}
.news-table {
  width: 100%;
  margin-bottom: 1rem;
  border-collapse: collapse;
}
.news-table th,
.news-table td {
  padding: 0.6rem 0.3rem;
  vertical-align: top;
  text-align: left;
}
.news-table th {
  width: 20%;
  font-weight: 700;
}

/* 7. Publications ------------------------------------------------------------ */
.publications {
  margin-top: 2rem;
}
.year-heading {
  margin-top: 2rem;
  margin-bottom: 1rem;
  padding-top: 1rem;
  text-align: right;
  color: var(--divider);
  border-top: 1px solid var(--divider);
}
.bibliography {
  list-style: none;
  margin-top: 0;
  padding: 0;
}
.bibliography > li {
  margin-bottom: 1rem;
}
.pub {
  display: flex;
  gap: 30px;
}
.pub-abbr {
  flex: 0 0 calc(16.6667% - 25px);
  min-width: 0;
  margin-bottom: 0.5rem;
}
.pub-abbr .badge {
  width: 100%;
  margin-bottom: 0.5rem;
}
.pub-abbr .preview {
  width: 100%;
  margin-bottom: 1rem;
  border-radius: 0.25rem;
  box-shadow: var(--shadow);
}
.pub-body {
  flex: 0 0 calc(66.6667% - 30px);
}
.pub .title {
  font-weight: 400;
}
.pub .author > em {
  font-style: normal;
  border-bottom: 1px solid;
}

.pub .abstract {
  max-height: 0;
  overflow: hidden;
  font-size: 0.875rem;
  text-align: justify;
  border: 1px dashed var(--bg);
  transition: all 0.15s ease;
}
.pub .abstract.open {
  max-height: 100em;
  border-color: var(--text);
}
.pub .abstract p {
  margin: 10px;
  line-height: 1.4em;
}

/* Filter box on the publications page */
.search-input {
  width: 100%;
  max-width: 350px;
  padding: 8px 12px;
  font-size: 16px;
  color: var(--input-text);
  background: var(--input-bg);
  border: 1px solid var(--input-text);
  border-radius: 6px;
  outline: none;
  box-shadow: rgba(0, 0, 0, 0.05) 0 1px 2px;
}
.search-input:focus {
  border-color: var(--theme);
}

/* 8. Social icons ------------------------------------------------------------ */
.social {
  margin-top: 2.25rem;
  padding-top: 1.75rem;
  text-align: center;
  border-top: 1px solid var(--section-divider);
}
.social .contact-icons {
  font-size: 4rem;
}
.social .contact-icons a {
  color: var(--text);
}
.social .contact-icons a:hover {
  color: var(--theme);
  text-decoration: none;
}
.social .contact-note {
  font-size: 0.8rem;
}

/* 9. Blog list --------------------------------------------------------------- */
.header-bar {
  padding: 2rem 0 3rem;
  text-align: center;
  border-bottom: 1px solid var(--divider);
}
.header-bar h1 {
  font-size: 5rem;
  color: var(--theme);
}

.tag-category-list {
  padding-top: 1rem;
  text-align: center;
  border-bottom: 1px solid var(--divider);
}
.tag-category-list ul {
  margin: 0;
  padding: 0;
}
.tag-category-list li,
.tag-category-list p {
  display: inline-block;
  margin: 0;
  padding: 1rem 0.5rem;
  list-style: none;
  color: var(--text-light);
}

.post-list {
  margin: 0 0 40px;
  padding: 0;
}
.post-list li {
  padding: 2rem 0;
  list-style: none;
  border-bottom: 1px solid var(--divider);
}
.post-list a {
  color: var(--text);
}
.post-list a:hover {
  color: var(--theme);
  text-decoration: none;
}

.post-meta,
.post-tags {
  font-size: 0.875rem;
  color: var(--text-light);
}
.post-meta {
  margin-bottom: 0;
}
.post-tags {
  padding-top: 0.25rem;
}
.post-tags a,
.post-list .post-tags a {
  color: var(--text-light);
}
.post-tags a:hover,
.post-list .post-tags a:hover {
  color: var(--theme);
  text-decoration: none;
}

/* 10. Blog filter notice ----------------------------------------------------- */
.blog-filter {
  margin: 1.5rem 0 0;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-light);
}

/* 11. Blog post -------------------------------------------------------------- */
.blog-hero {
  margin-bottom: 2.5rem;
}
.blog-hero .post-title {
  margin-bottom: 1rem;
  font-size: clamp(2.35rem, 5vw, 3.6rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.035em;
}
.blog-description {
  max-width: 760px;
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.55;
}
.blog-metadata {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 0.8fr;
  gap: 2rem;
  margin-top: 2.5rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
}
.blog-metadata-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.blog-metadata-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.blog-tags {
  margin-top: 1rem;
}

.post-content blockquote,
.post-content blockquote p {
  font-size: inherit;
}
.post-content h2,
.post-content h3,
.post-content h4 {
  letter-spacing: -0.02em;
  scroll-margin-top: 6.5rem;
}
.post-content h2 {
  margin: 3.25rem 0 1.15rem;
  padding-top: 1.5rem;
  font-size: 2rem;
  font-weight: 650;
  border-top: 1px solid var(--divider);
}
.post-content h3 {
  margin: 2.5rem 0 0.9rem;
  font-size: 1.5rem;
  font-weight: 650;
  line-height: 1.3;
}
.post-content h4 {
  margin: 2rem 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.4;
}
.post-content img {
  max-width: 100%;
  height: auto;
}
/* Big highlighted paragraph: <p class="callout">...</p> */
.post-content .callout {
  margin: 2.5rem 0;
  padding: 1.1rem 0 1.1rem 1.75rem;
  font-size: 1.15rem;
  line-height: 1.75;
  border-left: 4px solid var(--theme);
}

/* 12. Table of contents (blog posts + CV, wide screens only) ----------------- */
.with-toc {
  position: relative;
}
.toc-column {
  display: none;
}
#toc-sidebar::before {
  content: "Contents";
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
}
#toc-sidebar .toc-list {
  margin: 0;
  padding-left: 0.8rem;
  list-style: none;
}
#toc-sidebar .toc-list .toc-list {
  margin-top: 0.12rem;
}
.toc-link {
  position: relative;
  display: block;
  padding: 0.14rem 0.25rem 0.14rem 0.4rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text);
}
.toc-link::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background-color: var(--divider);
}
.toc-link:hover {
  color: var(--hover);
  text-decoration: none;
}
.toc-link.is-active-link {
  font-weight: 600;
  color: var(--theme);
}
.toc-link.is-active-link::before {
  background-color: var(--theme);
}

@media (min-width: 1400px) {
  .toc-column {
    display: block;
    position: absolute;
    top: 0;
    left: -230px;
    width: 210px;
    height: 100%;
  }
  #toc-sidebar {
    position: sticky;
    top: 6.5rem;
  }
  .with-toc > .content-column {
    transform: translateX(1.5rem);
  }
}

/* 13. CV --------------------------------------------------------------------- */
.cv {
  margin-bottom: 40px;
}
/* Same look as the home page section headings */
.cv-section-title {
  margin: 3rem 0 1.25rem;
  font-size: 2rem;
  font-weight: 300;
}
.cv-section-title:first-child {
  margin-top: 0.5rem;
}
.cv-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.cv-item {
  display: grid;
  grid-template-columns: 125px 1fr;
  column-gap: 40px;
  border-top: 1px solid var(--divider);
  padding: 1rem 0 1.25rem;
}
.cv-list .cv-item:last-child {
  border-bottom: 1px solid var(--divider);
}
/* Left column: grey monospace dates */
.cv-date {
  padding-top: 0.1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--text-light);
}
/* Right column: title, grey subtitle, short description */
.cv-title {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.5;
}
.cv-title a {
  color: inherit;
}
.cv-title a:hover {
  color: var(--theme);
  text-decoration: none;
}
.cv-subtitle {
  margin: 0 0 0.4rem;
  font-size: 0.875rem;
  color: var(--text-light);
}
.cv-text {
  margin: 0;
}

/* Compact sections (Awards & Honors, Service & Teaching): one line per row */
.cv-list.compact .cv-item {
  padding: 0.6rem 0;
}
.cv-list.compact .cv-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 300;
}

/* 14. Back-to-top & search palette ------------------------------------------ */
#back-to-top {
  position: fixed;
  right: 30px;
  bottom: 30px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--back-to-top-text);
  background: var(--back-to-top-bg);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

ninja-keys {
  --ninja-accent-color: var(--theme);
  --ninja-icon-size: 0px;
  --ninja-modal-background: var(--bg);
  --ninja-z-index: 1031;
}
ninja-keys::part(ninja-input) {
  color: var(--ninja-selected-text-color);
}
ninja-keys::part(ninja-input-wrapper) {
  background: var(--bg);
}

.medium-zoom-overlay,
.medium-zoom-image--opened {
  z-index: 999;
}

/* 15. Small screens ---------------------------------------------------------- */
@media (max-width: 767.98px) {
  .blog-metadata {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
  .post-content h2 { font-size: 1.7rem; }
  .post-content h3 { font-size: 1.35rem; }
}

@media (max-width: 575.98px) {
  .navbar > .container {
    padding-left: 0;
    padding-right: 0;
  }
  .navbar-toggler {
    display: block;
  }
  .navbar-collapse {
    display: none;
    flex-basis: 100%;
  }
  .navbar-collapse.show {
    display: block;
  }
  .navbar-nav {
    flex-direction: column;
    align-items: flex-start;
    margin-left: 0;
  }
  .nav-link {
    padding: 0.5rem 0;
  }

  .profile {
    float: none;
    width: 100%;
    margin-left: 0;
  }

  .pub {
    flex-direction: column;
    gap: 0;
  }
  .pub-abbr,
  .pub-body {
    flex-basis: auto;
  }

  /* CV: dates sit above each entry */
  .cv-item {
    grid-template-columns: 1fr;
  }
}
