:root {
  --bg: #f3f4f5;
  --panel: #ffffff;
  --ink: #111316;
  --muted: #5f646b;
  --line: #111316;
  --hair: #d5d8dc;
  --grid: rgba(17, 19, 22, .045);
  --accent: #1f3cff;
  --accent-ink: #ffffff;
  --sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --pad: clamp(1rem, 4vw, 3rem);
}

/* Light by default; visitors can switch to dark with the toggle */
:root { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121416;
  --panel: #1a1d20;
  --ink: #eceef0;
  --muted: #949aa1;
  --line: #eceef0;
  --hair: #2c3035;
  --grid: rgba(236, 238, 240, .04);
  --accent: #7d8cff;
  --accent-ink: #0b0c0e;
}

.theme-toggle {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  background: none;
  border: 1px solid var(--line);
  padding: .2rem .55rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.theme-toggle:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.bar-right { display: flex; align-items: center; gap: clamp(.9rem, 3vw, 2.25rem); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
p { margin: 0; }
ul, ol { list-style: none; margin: 0; padding: 0; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* Uppercase "stampatello" elements */
.bar, h1, h2, .lede-label, .links a, .meta, .pub-links a, .tags li, footer {
  text-transform: uppercase;
}

/* ───────── Top bar ───────── */
.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem var(--pad);
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: .75rem;
  letter-spacing: .08em;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.mark { font-weight: 500; }
.bar nav { display: flex; gap: clamp(.9rem, 3vw, 2.25rem); }
.bar nav a:hover { color: var(--accent); }

main { padding: 0 var(--pad); max-width: 80rem; margin: 0 auto; }

/* ───────── Hero (graph-paper background) ───────── */
.hero-wrap {
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  border-bottom: 1px solid var(--line);
}
.hero {
  padding: clamp(3rem, 8vw, 6rem) var(--pad) clamp(2.5rem, 6vw, 4rem);
  max-width: 80rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(2rem, 5vw, 4rem);
}

.lede-label {
  font-family: var(--mono);
  font-size: .75rem;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: 1rem;
}

h1 {
  font-weight: 700;
  font-size: clamp(2rem, 4.5vw, 3.25rem);
  line-height: 1;
  letter-spacing: .01em;
  margin: 0 0 clamp(1.5rem, 3vw, 2.25rem);
}
.dot { color: var(--accent); }

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
}
.lede {
  margin: 0;
  font-size: clamp(1.35rem, 2.6vw, 2rem);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -.01em;
  max-width: 52ch;
}
.lede a { border-bottom: 2px solid var(--accent); }
.lede a:hover { color: var(--accent); }
.hl { color: var(--accent); font-weight: 500; }

.portrait {
  display: block;
  width: clamp(150px, 18vw, 230px);
  height: auto;
  border: 1px solid var(--hair);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: 2.5rem;
}
.links a {
  display: inline-block;
  padding: .5rem .9rem;
  border: 1px solid var(--line);
  background: var(--panel);
  font-family: var(--mono);
  font-size: .75rem;
  letter-spacing: .08em;
  transition: background .15s, color .15s, border-color .15s;
}
.links a:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ───────── Sections ───────── */
.block {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) 3fr;
  gap: 2rem;
  padding: 2.25rem 0 3rem;
  border-bottom: 1px solid var(--hair);
}
.block:last-child { border-bottom: 0; }
/* Leave room for the sticky top bar when jumping to a section */
[id] { scroll-margin-top: 3.5rem; }

h2 {
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.3;
}
h2 .num {
  display: block;
  font-family: var(--mono);
  font-weight: 400;
  font-size: .75rem;
  color: var(--accent);
  margin-bottom: .3rem;
}

.prose p { font-size: 1.15rem; max-width: 62ch; margin-bottom: 1rem; }
.prose a { border-bottom: 1px solid var(--accent); }
.prose a:hover { color: var(--accent); }

.tags { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; }
.tags li {
  font-family: var(--mono);
  font-size: .72rem;
  letter-spacing: .08em;
  padding: .3rem .65rem;
  border: 1px solid var(--hair);
  background: var(--panel);
}

.meta {
  font-family: var(--mono);
  font-size: .75rem;
  letter-spacing: .06em;
  color: var(--muted);
  padding-top: .25rem;
}

/* Rows (news, education) */
.rows li {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 1rem;
  padding: .85rem 0;
  border-bottom: 1px solid var(--hair);
}
.rows li:first-child { padding-top: 0; }
.rows li:last-child { border-bottom: 0; }
.rows strong { font-weight: 600; }
.rows .where { color: var(--muted); font-size: .95rem; }
.rows a { border-bottom: 1px solid var(--accent); }
.rows a:hover { color: var(--accent); }

/* Talks */
.sub {
  font-family: var(--mono);
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 .6rem;
}
.talks + .sub { margin-top: 2.25rem; }
.kind.award {
  background: var(--accent);
  color: var(--accent-ink);
}
.talk-fig { margin: .9rem 0 .25rem; }
.talk-fig.single { max-width: 26rem; }
.talk-fig.single .panel img { width: 100%; height: auto; }
.talk-fig.single.tall { max-width: 18rem; }
.fig-grid {
  display: inline-grid;
  grid-template-columns: auto auto;
  gap: .5rem;
}
.panel {
  position: relative;
  display: block;
  border: 0;
}
.panel img, .panel video {
  display: block;
  height: clamp(130px, 40vw, 190px);
  width: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  transition: opacity .15s;
}
a.panel:hover img { opacity: .85; }
/* Wide bottom panel: spans both columns and matches their combined width */
.panel.wide { grid-column: 1 / -1; }
.panel.wide img {
  width: 0;
  min-width: 100%;
  height: auto;
}
.panel-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: .1rem .4rem;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--mono);
  font-size: .7rem;
  font-weight: 500;
}
.talk-fig figcaption {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: .6rem;
  max-width: 32rem;
  line-height: 1.6;
}
.talk-fig figcaption b { color: var(--ink); font-weight: 500; }
.talk-photo figcaption {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: .5rem;
}
.talks strong { display: inline; line-height: 1.35; }
.kind {
  display: inline-block;
  font-family: var(--mono);
  font-size: .65rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: .05rem .4rem;
  margin-right: .5rem;
  border: 1px solid var(--accent);
  color: var(--accent);
  vertical-align: .15em;
}

/* Publications */
.pubs { counter-reset: pub; }
.pubs li {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 1rem;
  padding: 1.25rem;
  margin-bottom: .75rem;
  background: var(--panel);
  border: 1px solid var(--hair);
  transition: border-color .15s;
}
.pubs li:hover { border-color: var(--line); }
.pubs .title {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: .3rem;
}
.pubs .authors, .pubs .venue { color: var(--muted); font-size: .98rem; }
.pubs .authors strong { color: var(--ink); font-weight: 600; }
.pub-links { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-top: .75rem; }
.cites {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-left: .5rem;
}
.cites b { color: var(--accent); font-weight: 500; }
.pub-links a {
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .08em;
  padding: .2rem .5rem;
  border: 1px solid var(--line);
  transition: background .15s, color .15s, border-color .15s;
}
.pub-links a:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ───────── Footer ───────── */
footer {
  border-top: 1px solid var(--line);
  padding: 2rem var(--pad);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--mono);
  font-size: .75rem;
  letter-spacing: .08em;
  color: var(--muted);
  margin-top: 2rem;
}
footer a { color: var(--ink); border-bottom: 1px solid var(--accent); }
footer a:hover { color: var(--accent); }

/* ───────── Small screens ───────── */
@media (max-width: 720px) {
  .block { grid-template-columns: 1fr; gap: 1.25rem; }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .portrait { order: -1; width: 140px; }
  .rows li, .pubs li { grid-template-columns: 1fr; gap: .2rem; }
  .bar nav a:not(:last-child) { display: none; }
}
