/* =========================================================================
   Francesco Amadori — personal research site
   Single stylesheet. Design tokens + base + components. Mobile-first.
   Dark "deep space" theme by default; optional light theme via [data-theme].
   ========================================================================= */

/* ---------- Design tokens ---------- */
:root {
  /* Dark (default) */
  --bg: #0b1020;
  --bg-grad-1: #0d1226;
  --bg-grad-2: #090d1a;
  --surface: #141a2e;
  --surface-2: #1b2238;
  --border: #283150;
  --text: #e6e9f2;
  --muted: #9aa3b8;
  --accent: #5eb1ff;        /* stellar blue */
  --accent-strong: #8cc6ff;
  --accent-2: #ffd27d;      /* warm starlight */
  --danger: #ff8a8a;
  --ring: rgba(94, 177, 255, 0.55);

  /* Type */
  --font-head: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Spacing / sizing */
  --maxw: 1120px;
  --prose: 70ch;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 4px 18px rgba(0, 0, 0, 0.25);
  --gutter: clamp(1.1rem, 4vw, 2.2rem);
  --section-y: clamp(3rem, 8vw, 6rem);

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f8fc;
  --bg-grad-1: #eef2fb;
  --bg-grad-2: #f8fafe;
  --surface: #ffffff;
  --surface-2: #f0f4fb;
  --border: #d8e0ee;
  --text: #131a2b;
  --muted: #586079;
  --accent: #2563c9;
  --accent-strong: #1d4ea3;
  --accent-2: #c7891f;
  --danger: #c0392b;
  --ring: rgba(37, 99, 201, 0.45);
  --shadow: 0 10px 30px rgba(28, 40, 80, 0.12);
  --shadow-soft: 0 4px 18px rgba(28, 40, 80, 0.08);
  color-scheme: light;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.075rem);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle star-field backdrop (cheap, no canvas) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(1200px 600px at 78% -8%, rgba(94,177,255,0.10), transparent 60%),
    radial-gradient(900px 500px at 12% 8%, rgba(255,210,125,0.06), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.5;
  background-image:
    radial-gradient(1.4px 1.4px at 20% 30%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1.2px 1.2px at 70% 20%, rgba(255,255,255,0.40), transparent),
    radial-gradient(1.6px 1.6px at 40% 70%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1.1px 1.1px at 85% 60%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1.3px 1.3px at 55% 45%, rgba(255,255,255,0.30), transparent),
    radial-gradient(1.2px 1.2px at 10% 80%, rgba(255,255,255,0.35), transparent);
  background-repeat: no-repeat;
}
[data-theme="light"] body::after { opacity: 0; }

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

a { color: var(--accent); text-decoration: none; transition: color 0.18s ease; }
a:hover { color: var(--accent-2); }

h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: clamp(2.1rem, 1.4rem + 3.4vw, 3.6rem); }
h2 { font-size: clamp(1.6rem, 1.2rem + 1.8vw, 2.4rem); }
h3 { font-size: clamp(1.2rem, 1.05rem + 0.8vw, 1.5rem); }
p { color: var(--text); }
strong { color: var(--text); font-weight: 600; }

/* ---------- Accessibility helpers ---------- */
:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
  border-radius: 4px;
}
.skip-link {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(-130%);
  top: 0.5rem;
  background: var(--accent);
  color: #001022;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  z-index: 1000;
  transition: transform 0.18s ease;
}
.skip-link:focus { transform: translateX(-50%) translateY(0); color: #001022; }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- Layout ---------- */
.container { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.section { padding-block: var(--section-y); }
.prose { max-width: none; }
.prose p + p { margin-top: 1.05rem; }

.eyebrow {
  font-family: var(--font-body);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.6rem;
}
.section-title { margin-bottom: 0.4rem; }
.section-lead { color: var(--muted); margin-top: 0.5rem; }

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  background: color-mix(in oklab, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--border);
}
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
}
.brand {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1.12rem;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.brand:hover { color: var(--text); }
.brand .dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent-2), var(--accent));
  box-shadow: 0 0 12px var(--accent);
  flex: none;
}
.nav-links { display: flex; align-items: center; gap: 0.25rem; list-style: none; padding: 0; }
.nav-links a {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.96rem;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  display: inline-block;
}
.nav-links a:hover { color: var(--text); background: var(--surface); }
.nav-links a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.nav-actions { display: flex; align-items: center; gap: 0.4rem; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; }
.theme-toggle .moon { display: none; }
[data-theme="light"] .theme-toggle .sun { display: none; }
[data-theme="light"] .theme-toggle .moon { display: block; }

.nav-toggle { display: none; }

@media (max-width: 820px) {
  .nav-toggle { display: inline-grid; }
  .nav-links {
    position: absolute;
    inset: 64px 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem var(--gutter) 1rem;
    box-shadow: var(--shadow);
    transform: translateY(-12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
  .nav-links.open { transform: translateY(0); opacity: 1; pointer-events: auto; }
  .nav-links a { padding: 0.75rem 0.8rem; font-size: 1.02rem; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.96rem;
  padding: 0.72rem 1.15rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #03152e;
  box-shadow: 0 8px 24px rgba(94, 177, 255, 0.30);
}
.btn-primary:hover { color: #03152e; box-shadow: 0 10px 30px rgba(94, 177, 255, 0.45); }
.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }

/* ---------- Hero ---------- */
.hero { padding-block: clamp(3rem, 7vw, 5.5rem) clamp(2rem, 5vw, 3.5rem); }
.hero-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: clamp(1.5rem, 5vw, 3.5rem);
  align-items: center;
}
.hero h1 { margin-bottom: 0.3rem; }
.hero .tagline { font-family: var(--font-head); font-weight: 500; font-size: clamp(1.35rem, 0.9rem + 1.7vw, 2rem); line-height: 1.2; color: var(--text); margin-bottom: 0.7rem; }
.hero .role { color: var(--accent); font-weight: 600; font-size: 1.1rem; }
.hero .hook { color: var(--muted); font-size: 1.12rem; margin-top: 1rem; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.6rem; }

.portrait {
  position: relative;
  justify-self: center;
  width: min(320px, 80vw);
  aspect-ratio: 1;
  border-radius: 50%;
  padding: 6px;
  background: conic-gradient(from 200deg, var(--accent), var(--accent-2), var(--accent));
  box-shadow: var(--shadow);
}
.portrait img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.socials { display: flex; gap: 0.5rem; margin-top: 1.4rem; flex-wrap: wrap; }
.socials a {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.socials a:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); }
.socials svg { width: 20px; height: 20px; }

@media (max-width: 760px) {
  .hero-grid { grid-template-columns: 1fr; text-align: center; }
  .hero .hook { margin-inline: auto; }
  .hero-cta, .socials { justify-content: center; }
  .portrait { order: -1; }
}

/* ---------- Cards / grids ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.2rem, 3vw, 1.8rem);
  box-shadow: var(--shadow-soft);
}
.card h3 { margin-bottom: 0.5rem; }
.card p { color: var(--muted); }

.grid { display: grid; gap: clamp(1rem, 2.5vw, 1.5rem); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) { .grid-3 { grid-template-columns: 1fr; } .grid-2 { grid-template-columns: 1fr; } }

/* Highlights strip */
.highlights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.highlight {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
}
.highlight .k { font-family: var(--font-head); font-size: 1.05rem; color: var(--text); }
.highlight .v { color: var(--muted); font-size: 0.92rem; }

/* Feature block (icon + text) */
.feature { display: flex; gap: 0.9rem; align-items: flex-start; }
.feature .ic {
  flex: none; width: 44px; height: 44px; border-radius: 11px;
  display: grid; place-items: center;
  background: color-mix(in oklab, var(--accent) 18%, var(--surface));
  color: var(--accent); border: 1px solid var(--border);
}
.feature .ic svg { width: 22px; height: 22px; }
.feature h3 { font-size: 1.15rem; }
.feature p { color: var(--muted); margin-top: 0.25rem; }

/* ---------- Tags / chips ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.6rem; }
.tag {
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag.accent { color: var(--accent); border-color: color-mix(in oklab, var(--accent) 40%, var(--border)); }

/* ---------- Page header band ---------- */
.page-hero { padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(1.5rem, 4vw, 2.5rem); }
.page-hero h1 { margin-bottom: 0.6rem; }
.page-hero p { color: var(--muted); }

/* ---------- CV: in-page nav + timeline + lists ---------- */
.subnav {
  position: sticky; top: 64px; z-index: 50;
  display: flex; flex-wrap: wrap; gap: 0.3rem;
  padding: 0.6rem 0;
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.subnav a {
  font-size: 0.88rem; font-weight: 500; color: var(--muted);
  padding: 0.35rem 0.7rem; border-radius: 8px;
}
.subnav a:hover { color: var(--text); background: var(--surface); }

.cv-section { padding-block: clamp(2rem, 5vw, 3rem); border-top: 1px solid var(--border); }
.cv-section:first-of-type { border-top: 0; }
.cv-section > h2 { margin-bottom: 1.3rem; }

.timeline { display: grid; gap: 1.1rem; }
.entry {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 1.2rem;
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.entry .when { color: var(--accent); font-weight: 600; font-size: 0.9rem; }
.entry .where { color: var(--muted); font-size: 0.88rem; margin-top: 0.2rem; }
.entry h3 { font-size: 1.18rem; }
.entry .org { color: var(--muted); font-weight: 500; margin-top: 0.15rem; }
.entry p { color: var(--muted); margin-top: 0.5rem; font-size: 0.97rem; }
.entry ul { color: var(--muted); margin-top: 0.5rem; padding-left: 1.1rem; font-size: 0.95rem; }
.entry ul li { margin-top: 0.25rem; }
.entry .grade { display: inline-block; margin-top: 0.4rem; font-size: 0.85rem; color: var(--accent-2); font-weight: 600; }
@media (max-width: 680px) { .entry { grid-template-columns: 1fr; gap: 0.5rem; } }

/* Contribution badges */
.badge {
  display: inline-block;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.18rem 0.55rem; border-radius: 999px; margin-left: 0.4rem;
  vertical-align: middle;
}
.badge.talk { background: color-mix(in oklab, var(--accent) 22%, var(--surface)); color: var(--accent-strong); }
.badge.poster { background: color-mix(in oklab, var(--accent-2) 24%, var(--surface)); color: var(--accent-2); }
.badge.attend { background: var(--surface-2); color: var(--muted); }

/* Skills bars */
.skills-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.8rem 1.6rem; }
.skill { display: grid; gap: 0.3rem; }
.skill .row { display: flex; justify-content: space-between; font-size: 0.92rem; }
.skill .row .lvl { color: var(--muted); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ---------- Publications ---------- */
.pub-group { margin-top: 1.5rem; }
.pub-group h3 { color: var(--muted); font-family: var(--font-body); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.82rem; font-weight: 700; margin-bottom: 0.8rem; }
.pub-list { display: grid; gap: 0.8rem; list-style: none; padding: 0; }
.pub {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.2rem;
  border-left: 3px solid var(--border);
}
.pub.first { border-left-color: var(--accent-2); }
.pub .pub-title { font-family: var(--font-head); font-size: 1.08rem; color: var(--text); display: block; }
.pub .pub-authors { color: var(--muted); font-size: 0.92rem; margin-top: 0.3rem; }
.pub .pub-authors .me { color: var(--text); font-weight: 700; }
.pub .pub-meta { display: flex; flex-wrap: wrap; gap: 0.5rem 0.9rem; align-items: center; margin-top: 0.55rem; font-size: 0.88rem; }
.pub .venue { color: var(--accent); font-weight: 600; }
.pub .role-pill {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.pub .role-pill.first { background: color-mix(in oklab, var(--accent-2) 22%, var(--surface)); color: var(--accent-2); }
.pub .doi { color: var(--muted); }

/* ---------- Gallery ---------- */
.gallery-cat { margin-top: clamp(1.8rem, 4vw, 2.6rem); }
.gallery-cat h2 { font-size: 1.4rem; margin-bottom: 0.9rem; }
.masonry { columns: 3 240px; column-gap: 0.9rem; }
.masonry .shot { break-inside: avoid; margin-bottom: 0.9rem; }
.shot button {
  display: block; width: 100%; padding: 0; border: 1px solid var(--border);
  background: var(--surface); border-radius: var(--radius-sm); overflow: hidden;
  cursor: zoom-in; transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.shot button:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow-soft); }
.shot img, .shot video { width: 100%; display: block; background: var(--surface-2); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: none;
  place-items: center;
  background: rgba(4, 7, 16, 0.92);
  padding: clamp(1rem, 4vw, 3rem);
}
.lightbox.open { display: grid; }
.lightbox figure { margin: 0; max-width: min(1100px, 96vw); max-height: 92vh; display: grid; gap: 0.6rem; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 84vh; object-fit: contain; border-radius: 8px; margin-inline: auto; }
.lightbox figcaption { color: var(--muted); text-align: center; font-size: 0.92rem; }
.lb-close, .lb-prev, .lb-next {
  position: fixed; z-index: 1001;
  width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(20, 26, 46, 0.8); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.lb-close { top: 1rem; right: 1rem; }
.lb-prev { left: 1rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: 1rem; top: 50%; transform: translateY(-50%); }
.lb-close:hover, .lb-prev:hover, .lb-next:hover { border-color: var(--accent); color: var(--accent); }
.lb-close svg, .lb-prev svg, .lb-next svg { width: 24px; height: 24px; }

/* ---------- Contact ---------- */
.contact-grid { display: grid; grid-template-columns: 1fr; gap: 0.8rem; }
.contact-card {
  display: flex; gap: 0.9rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.2rem;
}
.contact-card:hover { border-color: var(--accent); }
.contact-card .ic { flex: none; width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; background: color-mix(in oklab, var(--accent) 18%, var(--surface)); color: var(--accent); }
.contact-card .ic svg { width: 22px; height: 22px; }
.contact-card .label { color: var(--muted); font-size: 0.82rem; }
.contact-card .val { color: var(--text); font-weight: 600; word-break: break-word; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: var(--section-y);
  padding-block: 2rem;
  color: var(--muted);
}
.footer-inner { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: center; }
.footer-inner .socials a { width: 38px; height: 38px; }
.footer-inner small { color: var(--muted); }

/* ---------- Scroll reveal ---------- */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; } }

/* ---------- Utilities ---------- */
.text-muted { color: var(--muted); }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2rem; }
.center { text-align: center; }
.divider { height: 1px; background: var(--border); border: 0; margin-block: 1.5rem; }
