/* ==========================================================================
   Giovanni Marraffini — personal site
   Modern academic theme · light + dark · typography-first
   ========================================================================== */

/* ---- Design tokens ---- */
:root {
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --bg:        #fbfaf7;
  --bg-tint:   #f3f1ea;
  --surface:   #ffffff;
  --text:      #1b1a17;
  --muted:     #6c6960;
  --faint:     #8f8c83;
  --border:    #e8e4da;
  --accent:    #34548a;   /* deep academic blue */
  --accent-rgb: 52, 84, 138;
  --bg-rgb: 251, 250, 247;
  --accent-soft:#eaeff7;
  --accent-ink:#28406b;
  --shadow:    0 1px 2px rgba(27,26,23,.04), 0 8px 28px rgba(27,26,23,.06);
  --shadow-lg: 0 2px 6px rgba(27,26,23,.06), 0 18px 48px rgba(27,26,23,.10);

  --maxw: 1080px;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #131318;
    --bg-tint:   #191920;
    --surface:   #1c1c24;
    --text:      #eceae4;
    --muted:     #a6a29a;
    --faint:     #7d7a72;
    --border:    #2b2b34;
    --accent:    #9db4e6;
    --accent-rgb: 157, 180, 230;
    --bg-rgb: 19, 19, 24;
    --accent-soft:#20222e;
    --accent-ink:#c3d1f2;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.35);
    --shadow-lg: 0 2px 6px rgba(0,0,0,.35), 0 18px 48px rgba(0,0,0,.5);
  }
}

/* ---- Reset / base ---- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 88px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; transition: color .18s ease; }
a:hover { color: var(--accent-ink); }
h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: 500; line-height: 1.18; letter-spacing: -.01em; color: var(--text); margin: 0; }
p { margin: 0 0 1rem; }
::selection { background: var(--accent-soft); }

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(20px, 5vw, 40px); }

/* ---- Section scaffolding ---- */
section { padding: clamp(64px, 9vw, 118px) 0; border-top: 1px solid var(--border); }
.section-head { margin-bottom: clamp(30px, 4vw, 52px); }
.overline {
  font-family: var(--font-sans);
  font-size: .74rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 .6rem;
}
.section-head h2 { font-size: clamp(1.9rem, 4vw, 2.7rem); }
.section-head .lede { color: var(--muted); max-width: 60ch; margin-top: .7rem; font-size: 1.05rem; }

/* ---- Header / nav ---- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(var(--bg-rgb), 0.82);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .25s ease, box-shadow .25s ease;
}
.site-header.scrolled { border-bottom-color: var(--border); box-shadow: 0 6px 24px rgba(27,26,23,.05); }
.nav { display: flex; align-items: center; justify-content: space-between; height: 68px; }
.brand { font-family: var(--font-serif); font-size: 1.28rem; font-weight: 600; color: var(--text); letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.nav-links { display: flex; gap: 2px; align-items: center; list-style: none; margin: 0; padding: 0; }
.nav-links a {
  color: var(--muted); font-size: .93rem; font-weight: 500; padding: 8px 13px; border-radius: 8px;
  transition: color .18s ease, background .18s ease;
}
.nav-links a:hover { color: var(--text); background: var(--bg-tint); }
.nav-links a.active { color: var(--accent); }
.nav-toggle { display: none; background: none; border: 0; cursor: pointer; padding: 8px; color: var(--text); }
.nav-toggle svg { width: 26px; height: 26px; }

/* ---- Hero ---- */
.hero { border-top: 0; padding-top: clamp(48px, 8vw, 96px); }
.hero-grid { display: grid; grid-template-columns: 1.35fr .9fr; gap: clamp(32px, 6vw, 72px); align-items: center; }
.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .82rem; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 6px 14px; border-radius: 999px; margin-bottom: 22px;
  font-family: var(--font-sans);
}
.hero-eyebrow .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.hero h1 { font-size: clamp(2.6rem, 6.5vw, 4.3rem); font-weight: 500; letter-spacing: -.025em; }
.hero h1 em { font-style: italic; color: var(--accent); }
.hero .role { font-size: clamp(1.05rem, 2.2vw, 1.32rem); color: var(--text); font-weight: 500; margin: 18px 0 6px; font-family: var(--font-sans); }
.hero .blurb { color: var(--muted); font-size: 1.08rem; max-width: 52ch; margin-top: 14px; }

.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--font-sans); font-size: .95rem; font-weight: 600;
  padding: 11px 20px; border-radius: 10px; cursor: pointer; transition: all .2s ease; border: 1px solid transparent;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }

.hero-socials { display: flex; gap: 6px; margin-top: 26px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 10px;
  color: var(--muted); border: 1px solid var(--border); background: var(--surface); transition: all .2s ease;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); transform: translateY(-2px); }
.icon-btn svg { width: 19px; height: 19px; }

.hero-portrait { position: relative; }
.hero-portrait img {
  width: 100%; max-width: 340px; margin-left: auto; aspect-ratio: 1/1.08; object-fit: cover;
  border-radius: 20px; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.hero-portrait::after {
  content: ""; position: absolute; inset: 0; border-radius: 20px; z-index: -1;
  background: radial-gradient(120% 120% at 80% 0%, var(--accent-soft), transparent 60%);
  transform: translate(18px, 18px); max-width: 340px; margin-left: auto;
}

/* ---- Stat row ---- */
.stats { display: flex; flex-wrap: wrap; gap: clamp(24px, 5vw, 56px); margin-top: 54px; padding-top: 34px; border-top: 1px solid var(--border); }
.stat .num { font-family: var(--font-serif); font-size: 2rem; font-weight: 600; color: var(--text); line-height: 1; }
.stat .lbl { font-size: .82rem; color: var(--muted); margin-top: 6px; letter-spacing: .02em; }

/* ---- About ---- */
.about-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: clamp(32px, 6vw, 64px); }
.about-lead { font-family: var(--font-serif); font-size: clamp(1.3rem, 2.6vw, 1.72rem); line-height: 1.4; font-weight: 400; }
.about-body { color: var(--muted); margin-top: 20px; font-size: 1.04rem; }
.interests h3 { font-family: var(--font-sans); font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  font-size: .88rem; font-weight: 500; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); padding: 7px 14px; border-radius: 999px;
}
.chip.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }

/* ---- Publications ---- */
.pub-list { display: flex; flex-direction: column; gap: 16px; }
.pub {
  display: grid; grid-template-columns: 150px 1fr; gap: 26px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px 28px; transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.pub:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: rgba(var(--accent-rgb), 0.45); }
.pub-meta { border-right: 1px solid var(--border); padding-right: 22px; }
.pub-venue { font-family: var(--font-sans); font-weight: 700; font-size: .95rem; color: var(--accent); }
.pub-sub { font-size: .82rem; color: var(--muted); margin-top: 3px; }
.pub-year { font-size: .82rem; color: var(--faint); margin-top: 8px; }
.pub-title { font-size: 1.22rem; line-height: 1.32; margin-bottom: 8px; }
.pub-authors { font-size: .95rem; color: var(--muted); margin-bottom: 10px; }
.pub-authors .me { color: var(--text); font-weight: 600; }
.pub-desc { font-size: .96rem; color: var(--muted); margin-bottom: 14px; }
.pub-links { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-sans);
  font-size: .82rem; font-weight: 600; padding: 5px 12px; border-radius: 8px;
  background: var(--bg-tint); color: var(--text); border: 1px solid var(--border); transition: all .18s ease;
}
.tag:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.tag svg { width: 13px; height: 13px; }

/* ---- Timeline (experience) ---- */
.timeline { position: relative; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-left: 42px; padding-bottom: 36px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ""; position: absolute; left: 2px; top: 6px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent); box-shadow: 0 0 0 4px var(--bg);
}
.tl-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 4px; }
.tl-role { font-family: var(--font-serif); font-size: 1.24rem; font-weight: 600; }
.tl-org { color: var(--accent); font-weight: 600; font-size: .98rem; font-family: var(--font-sans); }
.tl-date { margin-left: auto; font-size: .84rem; color: var(--faint); font-weight: 500; white-space: nowrap; }
.tl-place { font-size: .86rem; color: var(--faint); margin-bottom: 8px; }
.tl-desc { color: var(--muted); font-size: .98rem; max-width: 72ch; }

/* ---- Cards grid (education / conferences) ---- */
.grid { display: grid; gap: 18px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px 26px; transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: rgba(var(--accent-rgb), 0.40); }
.card .date { font-size: .82rem; font-weight: 600; color: var(--accent); letter-spacing: .02em; }
.card h3 { font-size: 1.24rem; margin: 8px 0 4px; }
.card .sub { color: var(--muted); font-size: .95rem; }
.card .place { color: var(--faint); font-size: .86rem; margin-top: 6px; }
.card .badge {
  display: inline-block; margin-top: 12px; font-size: .78rem; font-weight: 600; color: var(--accent-ink);
  background: var(--accent-soft); padding: 4px 11px; border-radius: 7px; font-family: var(--font-sans);
}

/* ---- Skills ---- */
.skills-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 34px; }
.skill-group h3 { font-family: var(--font-sans); font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-bottom: 16px; }

/* ---- Contact ---- */
.contact { text-align: center; }
.contact-inner { max-width: 640px; margin: 0 auto; }
.contact h2 { font-size: clamp(2rem, 5vw, 3rem); }
.contact p { color: var(--muted); font-size: 1.1rem; margin: 16px 0 30px; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ---- Footer ---- */
.site-footer { border-top: 1px solid var(--border); padding: 34px 0; }
.footer-inner { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.footer-inner p { margin: 0; color: var(--faint); font-size: .88rem; }
.footer-socials { display: flex; gap: 6px; }

/* ---- Interactive: The Greatest Good ---- */
.gg-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: clamp(22px, 3.5vw, 36px); box-shadow: var(--shadow); }
.gg-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: clamp(28px, 4vw, 52px); align-items: start; }
.gg-items { display: flex; flex-direction: column; gap: 24px; }
.gg-q { font-size: .99rem; line-height: 1.45; margin: 0 0 14px; font-family: var(--font-sans); }
.gg-tag { display: inline-block; font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; margin-right: 8px; }
.gg-tag.ib { background: rgba(var(--accent-rgb), 0.15); color: var(--accent); }
.gg-tag.ih { background: rgba(194, 112, 58, 0.20); color: #b9682f; }
@media (prefers-color-scheme: dark) { .gg-tag.ih { color: #dd9160; } }

.gg-slider { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px; background: var(--bg-tint); outline: none; cursor: pointer; margin: 2px 0; }
.gg-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: var(--shadow); cursor: pointer; transition: transform .12s ease; }
.gg-slider::-webkit-slider-thumb:hover { transform: scale(1.14); }
.gg-slider::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: var(--shadow); cursor: pointer; }
.gg-slider:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.gg-scale { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; font-size: .72rem; color: var(--faint); }
.gg-scale .now { color: var(--accent); font-weight: 600; }

.gg-plot { width: 100%; height: auto; aspect-ratio: 1 / 1; display: block; overflow: visible; }
.gg-axis { stroke: var(--border); stroke-width: 1.5; }
.gg-axlbl { fill: var(--faint); font: 600 11px var(--font-sans); }
.gg-zone { fill: rgba(var(--accent-rgb), 0.12); stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 4; }
.gg-zone-lbl { fill: var(--accent-ink); font: 700 12px var(--font-sans); }
.gg-zone-sub { fill: var(--accent); font: 500 9px var(--font-sans); }
.gg-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 3; transition: cx .14s ease, cy .14s ease; }
.gg-readout { display: flex; gap: 22px; margin-top: 16px; flex-wrap: wrap; }
.gg-readout span { font-size: .8rem; color: var(--muted); }
.gg-readout b { font-family: var(--font-serif); font-size: 1.2rem; color: var(--text); margin-left: 5px; }
.gg-result { margin: 14px 0 0; font-size: .96rem; color: var(--text); line-height: 1.55; }
.gg-result strong { color: var(--accent); }
.gg-reset { margin-top: 16px; background: none; border: 1px solid var(--border); color: var(--muted); font: 600 .82rem var(--font-sans); padding: 7px 15px; border-radius: 8px; cursor: pointer; transition: all .18s ease; }
.gg-reset:hover { border-color: var(--accent); color: var(--accent); }
.gg-note { margin: 24px 0 0; font-size: .8rem; color: var(--faint); line-height: 1.55; border-top: 1px solid var(--border); padding-top: 16px; }
@media (max-width: 760px) { .gg-grid { grid-template-columns: 1fr; } }

/* ---- Inline demo (details/summary) + standout Play button ---- */
.pub-demo { grid-column: 1 / -1; margin-top: 6px; }
.play-btn {
  display: inline-flex; align-items: center; gap: 10px; cursor: pointer; width: fit-content;
  list-style: none; -webkit-tap-highlight-color: transparent;
  font-family: var(--font-sans); font-weight: 600; font-size: .93rem; color: #fff;
  background: linear-gradient(135deg, #4260a0, #2b4270); background-size: 180% 180%;
  padding: 12px 20px; border-radius: 11px; border: 0;
  box-shadow: 0 6px 18px rgba(var(--accent-rgb), 0.34);
  transition: transform .18s ease, box-shadow .18s ease;
  animation: playpulse 2.8s ease-in-out infinite;
}
.play-btn::-webkit-details-marker { display: none; }
.play-btn::marker { content: ""; }
.play-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(var(--accent-rgb), 0.48); }
.play-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.play-ico { width: 17px; height: 17px; flex: none; }
.play-btn .lbl-close { display: none; }
details[open] .play-btn .lbl-open { display: none; }
details[open] .play-btn .lbl-close { display: inline; }
details[open] .play-btn { animation: none; background: var(--accent); }
@keyframes playpulse {
  0%, 100% { box-shadow: 0 6px 16px rgba(var(--accent-rgb), 0.26); }
  50%      { box-shadow: 0 8px 30px rgba(var(--accent-rgb), 0.58); }
}

.pub-demo-panel {
  margin-top: 18px; background: var(--bg-tint); border: 1px solid var(--border);
  border-radius: 13px; padding: clamp(18px, 2.6vw, 30px);
  animation: demofade .38s ease;
}
@keyframes demofade { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.demo-intro { font-size: .96rem; color: var(--muted); line-height: 1.55; margin: 0 0 22px; max-width: 68ch; }
.demo-intro strong { color: var(--text); }

/* ---- Skewness widget (Variance Brain paper) ---- */
.sk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(24px, 4vw, 46px); align-items: center; }
.sk-readout { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 18px; }
.sk-readout span { font-size: .8rem; color: var(--muted); }
.sk-readout b { font-family: var(--font-serif); font-size: 1.18rem; color: var(--text); margin-left: 5px; }
.sk-result { margin: 16px 0 0; font-size: .95rem; color: var(--text); line-height: 1.55; }
.sk-result strong { color: var(--accent); }
.sk-plot { width: 100%; height: auto; aspect-ratio: 320 / 210; display: block; overflow: visible; }
.sk-curve { fill: rgba(var(--accent-rgb), 0.16); stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; transition: d .12s ease; }
.sk-meanline { stroke: var(--faint); stroke-width: 1.4; stroke-dasharray: 4 4; }
.sk-axlbl { fill: var(--faint); font: 600 10.5px var(--font-sans); }
@media (max-width: 760px) { .sk-grid { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) {
  .play-btn { animation: none; }
  .pub-demo-panel { animation: none; }
  .sk-curve { transition: none; }
}

/* ---- Reveal on scroll (only hidden when JS is available) ---- */
.js .reveal { opacity: 0; transform: translateY(22px); transition: opacity .6s ease, transform .6s ease; }
.js .reveal.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .js .reveal { opacity: 1; transform: none; transition: none; }
  html { scroll-behavior: auto; }
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .hero-grid { grid-template-columns: 1fr; }
  .hero-portrait { order: -1; max-width: 260px; }
  .hero-portrait img, .hero-portrait::after { margin: 0 auto; max-width: 260px; }
  .about-grid { grid-template-columns: 1fr; }
  .skills-grid { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  body { font-size: 16px; }
  .nav-links {
    position: fixed; inset: 68px 0 auto 0; flex-direction: column; align-items: stretch; gap: 0;
    background: var(--bg); border-bottom: 1px solid var(--border); padding: 8px 16px 16px;
    transform: translateY(-130%); opacity: 0; visibility: hidden;
    transition: transform .28s ease, opacity .28s ease, visibility 0s linear .28s;
    box-shadow: var(--shadow-lg);
  }
  .nav-links.open { transform: none; opacity: 1; visibility: visible; transition: transform .28s ease, opacity .28s ease; }
  .nav-links a { padding: 12px 8px; border-radius: 8px; font-size: 1rem; }
  .nav-toggle { display: inline-flex; }
  .pub { grid-template-columns: 1fr; gap: 14px; }
  .pub-meta { border-right: 0; border-bottom: 1px solid var(--border); padding: 0 0 14px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
  .pub-year { margin-top: 0; }
  .tl-date { margin-left: 0; width: 100%; }
  .grid.cols-3, .grid.cols-2, .skills-grid { grid-template-columns: 1fr; }
  .stats { gap: 28px; }
}
