/* ==========================================================================
   Luca Patrignani: personal academic website
   Plain CSS, no build step.

   0. Fonts
   1. Design tokens   (edit these to restyle the whole site)
   2. Base
   3. Header & navigation
   4. Buttons & chips
   5. Hero
   6. Sections
   7. Publications
   8. Talks
   9. CV
   10. Contact & footer
   11. Motion & print
   ========================================================================== */

/* 0. Fonts ---------------------------------------------------------------
   Served from this site (assets/fonts), so visitors never contact Google.
   Inter is free under the SIL Open Font License (see assets/fonts). */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/inter.woff2") format("woff2");
}

/* 1. Design tokens ------------------------------------------------------- */
:root {
  /* Colours (dark theme) */
  --bg: #101010;
  --surface: #161616;                    /* card background */
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.24);
  --text: #f7f7f7;
  --text-muted: #b3b3ba;
  --text-subtle: #8b8b94;
  --accent: #7a96ff;                     /* links and highlights */
  --award: #f0c36b;

  /* Typography */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  /* Layout */
  --container: 1040px;
  --gutter: clamp(1.25rem, 4vw, 2rem);
  --radius: 6px;
  --header-h: 64px;
  --section-space: clamp(2.75rem, 5vw, 3.75rem);
}

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

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p, figure { margin: 0; }
:where(ul[class], ol[class]) { margin: 0; padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
img { height: auto; }
button { font: inherit; color: inherit; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.accent { color: var(--accent); }
.accent-link { color: var(--accent); text-decoration: none; }
.accent-link:hover { text-decoration: underline; }
.icon { width: 1rem; height: 1rem; flex: none; fill: currentColor; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem; top: -3rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

/* 3. Header & navigation ------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(16, 16, 16, 0.85);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}
.site-header.is-scrolled { border-bottom-color: var(--border); }

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  height: var(--header-h);
}

.wordmark {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  text-decoration: none;
  white-space: nowrap;
}
.wordmark:hover { color: var(--accent); }

.nav-links { display: flex; gap: 1.75rem; }
.nav-links a {
  font-size: 0.9375rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}
.nav-links a:hover,
.nav-links a[aria-current="true"] { color: var(--text); }

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.5rem; height: 2.5rem;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.nav-toggle-bars { position: relative; width: 16px; height: 10px; }
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 1.5px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.2s ease, top 0.2s ease;
}
.nav-toggle-bars::before { top: 1px; }
.nav-toggle-bars::after { top: 7.5px; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::before { top: 4.25px; transform: rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::after { top: 4.25px; transform: rotate(-45deg); }

@media (max-width: 639.98px) {
  .js .nav-toggle { display: inline-flex; }
  .js .nav {
    position: absolute;
    top: var(--header-h);
    left: 0; right: 0;
    display: none;
    padding: 0 var(--gutter) 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .js .nav.is-open { display: block; }
  .js .nav-links { flex-direction: column; gap: 0; }
  .js .nav-links a {
    display: block;
    padding-block: 0.8rem;
    font-size: 1.0625rem;
    color: var(--text);
    border-bottom: 1px solid var(--border);
  }

  /* Without JavaScript the links are simply shown in a wrapped row */
  .no-js .header-inner { flex-wrap: wrap; height: auto; padding-block: 0.75rem; }
  .no-js .nav-links { flex-wrap: wrap; gap: 0.5rem 1.25rem; }
}

/* 4. Buttons & chips ----------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.5rem;
  padding: 0 0.95rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: 500 0.9375rem/1 var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: var(--text); border-color: var(--text); color: var(--bg); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  height: 1.875rem;
  padding: 0 0.7rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font: 500 0.8125rem/1 var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* 5. Hero ---------------------------------------------------------------- */
.hero {
  position: relative;
  isolation: isolate;          /* keeps the mesh behind the hero's content */
  padding-block: clamp(2.5rem, 7vw, 5.5rem) clamp(1rem, 3vw, 2rem);
}

/* Interactive mesh behind the hero (assets/js/mesh.js), fading out at the edges */
.hero-mesh {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 15%, #000 70%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 15%, #000 70%, transparent);
}

/* "Hi," / "Ciao," / "Hola," (cycled by assets/js/main.js) */
.greet { display: inline-block; white-space: nowrap; transition: width 0.45s cubic-bezier(0.2, 0.7, 0.2, 1); }
.greet-word {
  display: inline-block;
  color: var(--greet, var(--accent));
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.greet-word.is-out { opacity: 0; transform: translateY(-0.12em); }

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 2.5rem;
}
@media (min-width: 900px) {
  .hero-grid { grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.65fr); gap: 4rem; }
}

.hero-name {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
}

.hero-role {
  margin-top: 1.25rem;
  font-size: clamp(1.125rem, 2vw, 1.3125rem);
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.hero-statement {
  text-wrap: pretty;
  max-width: 34em;
  margin-top: 1.25rem;
  font-size: clamp(1.0625rem, 1.6vw, 1.1875rem);
  line-height: 1.6;
  color: var(--text-muted);
}

.hero-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 2rem; }
.hero-links .btn { height: 2.375rem; padding: 0 0.8rem; font-size: 0.875rem; }

/* Photo: on top on phones (like mhouge.dk), on the right on wide screens */
.hero-photo {
  order: -1;
  width: min(100%, 15rem);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
@media (min-width: 900px) {
  .hero-photo { order: 0; width: 100%; max-width: 22rem; justify-self: end; }
}

/* 6. Sections ------------------------------------------------------------ */
.section { padding-top: var(--section-space); }

.section-title {
  margin-bottom: 1.75rem;
  font-size: clamp(1.75rem, 3.5vw, 2.25rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

/* 7. Publications -------------------------------------------------------- */
.pub-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}
@media (min-width: 760px) { .pub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.pub {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s ease;
}
.pub:hover { border-color: var(--border-strong); }

.pub-meta {
  font: 0.75rem/1.4 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-subtle);
}

.pub-title {
  text-wrap: balance;
  margin-top: 0.15rem;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.pub-title a { text-decoration: none; transition: color 0.15s ease; }
.pub-title a:hover { color: var(--accent); }

.pub-authors { font-size: 0.875rem; color: var(--text-muted); }
.pub-authors strong { font-weight: 600; color: var(--text); }
.pub-venue { font-size: 0.875rem; color: var(--text-subtle); }

.pub-links {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.75rem;
}

.bibtex[open] { flex-basis: 100%; }
.bibtex summary { width: max-content; list-style: none; }
.bibtex summary::-webkit-details-marker { display: none; }
.bibtex-box { position: relative; margin-top: 0.6rem; }
.bibtex-box pre {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: 0.75rem/1.6 var(--font-mono);
  color: var(--text-muted);
}
.copy-btn {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  padding: 0.3rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font: 500 0.75rem/1 var(--font-sans);
  cursor: pointer;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.no-js .copy-btn { display: none; }

/* 8. Talks --------------------------------------------------------------- */
.talk-list { border-top: 1px solid var(--border); }

.talk {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  gap: 0.15rem 1rem;
  padding-block: 0.9rem;
  border-bottom: 1px solid var(--border);
}
@media (min-width: 640px) {
  .talk { grid-template-columns: 4rem minmax(0, 1fr) auto; align-items: baseline; gap: 1.5rem; }
}

.talk-year {
  font: 0.8125rem/1.6 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-subtle);
}
.talk-event { font-weight: 500; }
.talk-meta { grid-column: 2; font-size: 0.875rem; color: var(--text-subtle); }
@media (min-width: 640px) { .talk-meta { grid-column: auto; text-align: right; } }

.award {
  margin-left: 0.5rem;
  font: 500 0.75rem/1 var(--font-mono);
  color: var(--award);
  white-space: nowrap;
}

/* 9. CV ------------------------------------------------------------------ */
.cv-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
}
@media (min-width: 720px) {
  .cv-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 2.5rem; }

  /* Line up the entries of the three columns row by row (room for up to 8 per column) */
  @supports (grid-template-rows: subgrid) {
    .cv-grid > div { display: grid; grid-row: span 9; grid-template-rows: subgrid; }
    .cv-grid .cv-list { display: grid; grid-row: 2 / -1; grid-template-rows: subgrid; }
  }
}

.cv-heading {
  margin-bottom: 0.5rem;
  font: 600 0.75rem/1.2 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.cv-list li { padding-block: 0.7rem; border-bottom: 1px solid var(--border); }
.cv-list li:last-child { border-bottom: 0; }
.cv-list strong { display: block; font-size: 0.9375rem; font-weight: 600; line-height: 1.4; }
.cv-list span { display: block; font-size: 0.875rem; color: var(--text-muted); }
.cv-list .cv-when {
  margin-bottom: 0.1rem;
  font: 0.75rem/1.5 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-subtle);
}

/* 10. Contact & footer --------------------------------------------------- */
.contact-list { display: grid; gap: 0.7rem; }
.contact-list li { display: flex; align-items: center; gap: 0.75rem; color: var(--text-muted); }
.contact-list .icon { width: 1.125rem; height: 1.125rem; color: var(--text-subtle); }
.contact-list a { color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.contact-list a:hover { color: var(--accent); }
.contact-list .contact-email { margin-bottom: 0.35rem; }
.contact-list .contact-email .icon { width: 1.25rem; height: 1.25rem; }
.contact-list .contact-email a {
  font-size: clamp(1.125rem, 2.4vw, 1.375rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--accent);
}
.contact-list .contact-email a:hover { text-decoration: underline; }
.local-time time { font-variant-numeric: tabular-nums; color: var(--text); }

.contact-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2rem; }
@media (min-width: 760px) {
  .contact-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 340px); align-items: stretch; gap: 3rem; }
}

/* Von Neumann's elephant (assets/js/mesh.js) */
.vn-fig { width: 100%; max-width: 340px; }
.vn-canvas { display: block; width: 100%; height: 170px; cursor: crosshair; touch-action: pan-y; }
.vn-quote { margin-top: 0.35rem; font-size: 0.75rem; line-height: 1.45; color: var(--text-muted); text-wrap: balance; }
.vn-credit { margin-top: 0.15rem; font-size: 0.6875rem; line-height: 1.45; color: var(--text-subtle); }
@media (min-width: 760px) {
  /* The elephant takes exactly the height of the "Get in touch" column */
  .vn-fig { display: flex; flex-direction: column; height: 100%; }
  .vn-canvas { flex: 1 1 0; min-height: 0; height: 0; }
}

/* The sliding elephant (previous version, currently commented out in index.html) */
.slide-fig { width: 100%; max-width: 340px; }
.slide-svg { width: 100%; height: auto; overflow: hidden; }
.slide-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 1.875rem;
  margin-top: 0.4rem;
  font: 0.75rem/1.4 var(--font-mono);
  color: var(--text-subtle);
}

.site-footer { padding-block: var(--section-space) 2.5rem; font-size: 0.875rem; color: var(--text-subtle); }
.footer-inner { padding-top: 1.5rem; border-top: 1px solid var(--border); }

/* Easter egg: the © is a button, and the elephant walks along the footer line */
.site-footer { position: relative; overflow: hidden; }
.egg { padding: 0; background: none; border: 0; font: inherit; color: inherit; cursor: pointer; }
.egg:hover { color: var(--text); }
.walker {
  position: absolute;
  left: 0;
  width: 84px;
  height: auto;
  cursor: pointer;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}

/* Speech balloons (assets/js/main.js): used by data-balloon and the elephants */
.balloon {
  position: absolute;
  z-index: 60;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  font: 500 0.8125rem/1.35 var(--font-sans);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transform-origin: var(--tail, 18px) 100%;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.balloon.is-on { opacity: 1; transform: none; }
.balloon::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: calc(var(--tail, 18px) - 5px);
  width: 10px;
  height: 10px;
  background: var(--surface);
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  transform: rotate(45deg);
}

/* 11. Motion & print ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --text-muted: #333; --text-subtle: #555; --border: #ccc; --accent: #000; }
  .site-header, .skip-link, .hero-links, .copy-btn, .site-footer { display: none !important; }
  .section, .hero { padding-block: 1rem; }
  .pub { break-inside: avoid; }
}
