/* ==========================================================================
   Stefano Gualandi — academic website
   Single stylesheet, no external dependencies (system fonts only).
   ========================================================================== */

/* ---- Design tokens ----------------------------------------------------- */
:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f3f1ec;
  --text: #1c2129;
  --muted: #5a6370;
  --border: #e3dfd8;
  --accent: #8a1c2b;          /* University of Pavia bordeaux */
  --accent-hover: #6b1420;
  --accent-soft: #f7ebed;
  --notice-bg: #fff6e0;
  --notice-border: #e8c46a;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, "Iowan Old Style", Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgb(20 20 30 / 0.04), 0 4px 16px rgb(20 20 30 / 0.05);
  --container: 64rem;
  --measure: 46rem;
  --gutter: clamp(1rem, 4vw, 2rem);

  color-scheme: light dark;
}

/* Dark theme: follows the system unless the visitor picked a theme (data-theme on <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418;
    --surface: #1a1d22;
    --surface-2: #22262d;
    --text: #e7e5e0;
    --muted: #a2a9b3;
    --border: #2f343c;
    --accent: #e8909b;
    --accent-hover: #f3b3bb;
    --accent-soft: #2c1e22;
    --notice-bg: #2b2516;
    --notice-border: #806a2e;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121418;
  --surface: #1a1d22;
  --surface-2: #22262d;
  --text: #e7e5e0;
  --muted: #a2a9b3;
  --border: #2f343c;
  --accent: #e8909b;
  --accent-hover: #f3b3bb;
  --accent-soft: #2c1e22;
  --notice-bg: #2b2516;
  --notice-border: #806a2e;
  --shadow: none;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 1rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.65 var(--font-sans);
  font-kerning: normal;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img { max-width: 100%; height: auto; display: block; }

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0 0 0.6em;
  text-wrap: balance;
}
h1 { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 1.2rem + 0.7vw, 1.65rem); margin-top: 2.2em; }
h3 { font-size: 1.15rem; margin-top: 1.6em; }

p, ul, ol, dl { margin: 0 0 1em; }
ul, ol { padding-left: 1.4em; }
li + li { margin-top: 0.35em; }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
a:hover { color: var(--accent-hover); text-decoration-color: currentColor; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

code { font-family: var(--font-mono); font-size: 0.9em; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: #fff; padding: 0.5rem 1rem; z-index: 10;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.prose { max-width: var(--measure); }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- Header / navigation ---------------------------------------------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-top: 4px solid var(--accent);
}
.site-header .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
}
.brand {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.brand:hover { color: var(--accent); }
.brand small {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.site-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.site-nav li + li { margin: 0; }
.site-nav a {
  display: block;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

/* Mobile: navigation becomes a single scrollable row under the name */
@media (max-width: 40rem) {
  .site-header .container { padding-bottom: 0.5rem; }
  .site-nav { margin: 0 calc(-1 * var(--gutter)); width: calc(100% + 2 * var(--gutter)); }
  .site-nav ul {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 var(--gutter) 0.4rem;
    scrollbar-width: none;
  }
  .site-nav ul::-webkit-scrollbar { display: none; }
  .site-nav a { white-space: nowrap; padding: 0.45rem 0.8rem; }
}

/* ---- Main / page header ------------------------------------------------ */
main { flex: 1; padding: clamp(2rem, 5vw, 3.5rem) 0 4rem; }

.page-header { margin-bottom: 2rem; max-width: var(--measure); }
.page-header h1 { margin-bottom: 0.3em; }
.page-header .lead { font-size: 1.125rem; color: var(--muted); margin: 0; }

.breadcrumb { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.75rem; }
.breadcrumb a { color: var(--muted); }

/* ---- Home: hero -------------------------------------------------------- */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: start;
}
.hero-photo {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  aspect-ratio: 2 / 3;
  object-fit: cover;
  width: 100%;
}
.hero h1 { margin-bottom: 0.15em; }
.hero .role {
  font-size: 1.1rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}
.hero .role strong { color: var(--text); font-weight: 600; }
.hero .bio { max-width: var(--measure); }

@media (max-width: 44rem) {
  .hero { grid-template-columns: 1fr; }
  .hero-photo { width: 10rem; aspect-ratio: 1; object-position: 50% 18%; border-radius: 50%; }
}

/* Profile links (pill buttons) */
.links { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0; margin: 1.5rem 0 0; list-style: none; }
.links li + li { margin: 0; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  line-height: 1.3;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn svg { width: 1.05em; height: 1.05em; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary, :root:not([data-theme="light"]) .btn-primary:hover { color: #1a1d22; }
}
:root[data-theme="dark"] .btn-primary, :root[data-theme="dark"] .btn-primary:hover { color: #1a1d22; }

/* Topic tags */
.tags { display: flex; flex-wrap: wrap; gap: 0.5rem; list-style: none; padding: 0; margin: 0 0 1rem; }
.tags li + li { margin: 0; }
.tags li {
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.92rem;
}

/* ---- Cards ------------------------------------------------------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: 1rem;
  margin: 0 0 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.card h3 { margin: 0 0 0.4rem; font-size: 1.1rem; }
.card p { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.96rem; }
.card .card-link { margin-top: auto; font-weight: 500; font-size: 0.95rem; }
.card .eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

/* Featured book */
.book {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.25rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}
.book-cover {
  width: 5.5rem;
  aspect-ratio: 155 / 235;
  border-radius: 3px 6px 6px 3px;
  background: linear-gradient(160deg, #123a63, #0b2340);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.55rem 0.5rem;
  font-family: var(--font-serif);
  box-shadow: inset 4px 0 0 rgb(255 255 255 / 0.15), 0 4px 10px rgb(0 0 0 / 0.2);
}
.book-cover .bc-authors { font-size: 0.5rem; letter-spacing: 0.04em; opacity: 0.85; }
.book-cover .bc-title { font-size: 0.62rem; overflow-wrap: anywhere; hyphens: auto; font-weight: 600; line-height: 1.15; }
.book-cover .bc-pub { font-family: var(--font-sans); font-size: 0.45rem; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.8; }
.book h3 { margin: 0 0 0.25rem; }
.book p { margin: 0 0 0.4rem; }
@media (max-width: 30rem) {
  .book { grid-template-columns: 1fr; }
}

/* ---- Contact block ----------------------------------------------------- */
.contact {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1.25rem 2rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.contact h3 {
  margin: 0 0 0.3rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.contact address, .contact p { font-style: normal; margin: 0; }

/* ---- Publications ------------------------------------------------------ */
.toc {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  list-style: none; padding: 0; margin: 0 0 1rem;
}
.toc li + li { margin: 0; }
.toc a {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
  text-decoration: none;
  background: var(--surface);
}
.toc a:hover { border-color: var(--accent); }

.pubs { padding-left: 0; list-style: none; counter-reset: pub; }
.pubs > li {
  position: relative;
  padding: 0.8rem 0 0.8rem 2.6rem;
  border-bottom: 1px solid var(--border);
  margin: 0;
  counter-increment: pub;
}
.pubs > li::before {
  content: counter(pub);
  position: absolute;
  left: 0;
  top: 0.85rem;
  width: 2rem;
  text-align: right;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.pubs.unnumbered > li { padding-left: 0; }
.pubs.unnumbered > li::before { content: none; }
.pub-authors { color: var(--muted); }
.pub-authors .me { color: var(--text); font-weight: 600; }
.pub-title { display: block; font-weight: 600; color: var(--text); margin: 0.1rem 0; }
.pub-venue { font-style: italic; }
.pub-links { white-space: nowrap; }
.pub-links a {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.45rem;
  margin-left: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
}
.pub-links a:hover { border-color: var(--accent); }
.year-heading {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.5rem 0 0;
}

/* ---- Teaching / generic lists ----------------------------------------- */
.course-year { margin: 0 0 1.75rem; }
.course-year h3 { margin: 0 0 0.5rem; font-family: var(--font-sans); font-size: 1rem; color: var(--muted); }
.course-list { list-style: none; padding: 0; margin: 0; }
.course-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  margin: 0 0 0.5rem;
}
.course-list .code { font-family: var(--font-mono); font-size: 0.85rem; color: var(--muted); margin-right: 0.35rem; }
.course-list .where { display: block; font-size: 0.9rem; color: var(--muted); }
.course-list .credits { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

details.archive {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 1.25rem;
  margin: 0 0 1rem;
}
details.archive > summary {
  cursor: pointer;
  padding: 0.9rem 0;
  font-weight: 600;
}
details.archive[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 1rem; }

.theses { padding-left: 0; list-style: none; }
.theses li { padding: 0.65rem 0; border-bottom: 1px solid var(--border); margin: 0; }
.theses .t-title { display: block; font-style: italic; }
.theses .t-meta { font-size: 0.92rem; color: var(--muted); }

/* ---- Notices / tables (course pages) ----------------------------------- */
.notice {
  background: var(--notice-bg);
  border: 1px solid var(--notice-border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 0 0 1.5rem;
}
.notice > :last-child { margin-bottom: 0; }
.notice .date { font-weight: 700; }

.table-wrap { overflow-x: auto; margin: 0 0 1.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; background: var(--surface-2); }

figure { margin: 0 0 1.5rem; }
figure img { border-radius: 8px; margin: 0 auto; }
figcaption { font-size: 0.9rem; color: var(--muted); text-align: center; margin-top: 0.5rem; }

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: 0 2.5rem;
}

/* ---- Footer ------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
  color: var(--muted);
}
.site-footer .container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2rem;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
}
.site-footer p { margin: 0; }
.site-footer ul { list-style: none; display: flex; flex-wrap: wrap; gap: 0.25rem 1.1rem; padding: 0; margin: 0; }
.site-footer li + li { margin: 0; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

/* ---- Print ------------------------------------------------------------- */
@media print {
  .site-nav, .skip-link, .links, .site-footer ul { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .site-header { border: 0; }
  a { color: inherit; text-decoration: none; }
  .card, .book, .contact { box-shadow: none; }
}

/* Open-access labels on the publication list */
:root { --oa: #1f7a4d; --oa-soft: #e8f4ed; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --oa: #6fd3a0; --oa-soft: #17291f; } }
:root[data-theme="dark"] { --oa: #6fd3a0; --oa-soft: #17291f; }
.pub-links a.oa, .oa-key {
  color: var(--oa);
  background: var(--oa-soft);
  border-color: color-mix(in srgb, var(--oa) 35%, transparent);
}
.oa-key {
  font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0 0.4rem; border: 1px solid; border-radius: 4px; white-space: nowrap;
}

/* Nested lists inside a course/talk card (e.g. a lecture series) */
.course-list li ul { list-style: disc; padding-left: 1.25rem; margin: 0.5rem 0 0; }
.course-list li li { background: none; border: 0; border-radius: 0; padding: 0; margin: 0.35rem 0 0; }

/* ---- Theme toggle ------------------------------------------------------ */
.site-nav { margin-left: auto; }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; padding: 0;
  border: 1px solid var(--border); border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }
.theme-toggle .icon-sun { display: none; }
.theme-switching *, .theme-switching *::before, .theme-switching *::after { transition: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (max-width: 40rem) {
  .theme-toggle { order: 1; margin-left: auto; }
  .site-nav { order: 2; margin-left: calc(-1 * var(--gutter)); }
}

/* Award note on a publication */
.pub-award { color: var(--accent); font-weight: 600; }
