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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 84px; /* compensa l'header sticky quando si salta a un'ancora */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; }

::selection { background: color-mix(in srgb, var(--accent) 26%, transparent); }

/* =========================================================
   Design token
   ========================================================= */
:root {
  /* Colore — palette chiara */
  --bg: #ffffff;
  --bg-alt: #f5f6f8;
  --surface: #ffffff;
  --surface-tint: #f0f3fb;
  --text: #16181d;
  --text-muted: #565d6b;
  --border: #e3e5ea;
  --border-strong: #d3d6dd;
  --accent: #1d4ed8;
  --accent-hover: #1a44bd;
  --accent-contrast: #ffffff;

  /* Elevazione */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, .08), 0 14px 40px rgba(16, 24, 40, .08);
  --shadow-header: 0 1px 0 var(--border), 0 8px 24px rgba(16, 24, 40, .07);

  /* Raggi */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Spaziatura — ritmo 4 / 8 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 96px;

  /* Scala tipografica */
  --fs-xs: 0.78rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.125rem;
  --fs-lg: 1.375rem;
  --fs-xl: 1.75rem;
  --fs-hero: clamp(2.4rem, 6vw, 3.5rem);

  --maxw: 1000px;
  --header-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0c10;
    --bg-alt: #121419;
    --surface: #16191f;
    --surface-tint: #182231;
    --text: #e9ebee;
    --text-muted: #9aa1ad;
    --border: #272b33;
    --border-strong: #363b45;
    --accent: #7ab0ff;
    --accent-hover: #9cc4ff;
    --accent-contrast: #0b0c10;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .4);
    --shadow-header: 0 1px 0 var(--border), 0 8px 24px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  --bg: #0b0c10;
  --bg-alt: #121419;
  --surface: #16191f;
  --surface-tint: #182231;
  --text: #e9ebee;
  --text-muted: #9aa1ad;
  --border: #272b33;
  --border-strong: #363b45;
  --accent: #7ab0ff;
  --accent-hover: #9cc4ff;
  --accent-contrast: #0b0c10;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .4);
  --shadow-header: 0 1px 0 var(--border), 0 8px 24px rgba(0, 0, 0, .5);
}

/* =========================================================
   Tipografia e layout di base
   ========================================================= */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; }
p { text-wrap: pretty; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: clamp(20px, 4vw, 28px);
}

.section { padding-block: clamp(var(--space-8), 10vw, var(--space-9)); }
.section-alt { background: var(--bg-alt); }
section[id] { scroll-margin-top: calc(var(--header-h) + var(--space-4)); }

.section-title { font-size: var(--fs-xl); margin-bottom: var(--space-4); }
.section-title::after {
  content: "";
  display: block;
  width: 40px;
  height: 3px;
  margin-top: var(--space-3);
  border-radius: 2px;
  background: var(--accent);
}
.section-lead {
  color: var(--text-muted);
  max-width: 62ch;
  margin-bottom: var(--space-6);
}

.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: 12px; top: -48px;
  background: var(--accent); color: var(--accent-contrast);
  padding: 8px 14px; border-radius: var(--radius-sm); z-index: 100;
  transition: top .15s ease;
}
.skip-link:focus { top: 12px; }

:where(a, button):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* =========================================================
   Header / navigazione
   ========================================================= */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.site-header.is-scrolled {
  border-bottom-color: var(--border);
  box-shadow: var(--shadow-header);
}
.header-inner {
  display: flex; align-items: center; gap: var(--space-4);
  min-height: var(--header-h);
}
.brand { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; font-weight: 700; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-contrast);
  font-size: var(--fs-sm); font-weight: 700; letter-spacing: .5px;
}
.brand-name { font-size: var(--fs-base); }

.site-nav { margin-left: auto; }
.nav-menu { list-style: none; display: flex; gap: var(--space-5); padding: 0; }
.nav-menu a {
  position: relative;
  display: inline-block;
  padding: 4px 2px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  transition: color .15s ease;
}
.nav-menu a:hover { color: var(--text); }
.nav-menu a[aria-current="true"] { color: var(--text); font-weight: 600; }
.nav-menu a[aria-current="true"]::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -6px;
  height: 2px; border-radius: 2px;
  background: var(--accent);
}

.nav-toggle {
  display: none;
  width: 40px; height: 40px; border: 1px solid var(--border-strong);
  background: var(--surface); border-radius: var(--radius-sm); cursor: pointer;
  position: relative;
}
.nav-toggle-bar, .nav-toggle-bar::before, .nav-toggle-bar::after {
  content: ""; position: absolute; left: 50%; width: 18px; height: 2px;
  background: var(--text); transform: translateX(-50%); border-radius: 2px;
}
.nav-toggle-bar { top: 50%; transform: translate(-50%, -50%); }
.nav-toggle-bar::before { top: -6px; }
.nav-toggle-bar::after { top: 6px; }

.theme-toggle {
  width: 40px; height: 40px; border: 1px solid var(--border-strong);
  background: var(--surface); border-radius: var(--radius-sm); cursor: pointer;
  display: grid; place-items: center; color: var(--text);
  transition: border-color .15s ease, color .15s ease;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

/* =========================================================
   Hero
   ========================================================= */
:root                      { --hero-bg: url("hero-bg-light.webp"); }
:root[data-theme="dark"]   { --hero-bg: url("hero-bg-dark.webp"); }
:root[data-theme="light"]  { --hero-bg: url("hero-bg-light.webp"); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --hero-bg: url("hero-bg-dark.webp"); }
}

.hero {
  position: relative;
  overflow: hidden;
  padding-block: clamp(var(--space-8), 12vw, var(--space-9)) clamp(var(--space-7), 9vw, var(--space-8));
  background-image:
    linear-gradient(180deg,
      color-mix(in srgb, var(--bg) 30%, transparent) 0%,
      color-mix(in srgb, var(--bg) 62%, transparent) 60%,
      var(--bg) 100%),
    linear-gradient(90deg,
      var(--bg) 0%,
      color-mix(in srgb, var(--bg) 60%, transparent) 42%,
      color-mix(in srgb, var(--bg) 15%, transparent) 100%),
    var(--hero-bg);
  background-repeat: no-repeat;
  background-position: center, center, right center;
  background-size: cover;
}
.hero::before { /* bagliore d'accento, tenue perché ora c'è l'immagine */
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 420px; z-index: 0;
  background: radial-gradient(60% 55% at 15% 0%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%);
  pointer-events: none;
}
.hero-inner { position: relative; z-index: 1; }

@media (prefers-reduced-data: reduce) {
  .hero { background-image: none; }
}
.hero-kicker {
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent);
}
.hero-title { font-size: var(--fs-hero); margin-block: var(--space-2) var(--space-3); }
.hero-role { font-size: clamp(1.1rem, 3vw, 1.4rem); font-weight: 600; color: var(--text); }
.hero-pitch {
  max-width: 56ch;
  margin-top: var(--space-4);
  font-size: var(--fs-md);
  color: var(--text-muted);
}
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-6); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  text-decoration: none;
  font-weight: 600; font-size: var(--fs-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .18s ease, background-color .18s ease, border-color .18s ease, box-shadow .18s ease, color .18s ease;
}
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-ghost { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
@media (hover: hover) {
  .btn:hover { transform: translateY(-2px); }
  .btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
  .btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
}

/* =========================================================
   Chi sono
   ========================================================= */
.about-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(240px, 1fr);
  gap: clamp(var(--space-5), 5vw, var(--space-7));
  align-items: start;
}
.about-text { max-width: 62ch; }
.about-text p + p { margin-top: var(--space-4); }

.about-side {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.about-side-title {
  font-size: var(--fs-xs);
  margin-bottom: var(--space-4);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chips li {
  background: var(--surface-tint);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
}

/* =========================================================
   Progetti
   ========================================================= */
.projects-grid {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: var(--space-3);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:focus-within { border-color: var(--accent); box-shadow: var(--shadow-md); }
@media (hover: hover) {
  .card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  }
}
.card-title { font-size: var(--fs-md); line-height: 1.3; }
.card-title small {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-muted);
}
.card-text { color: var(--text-muted); }

/* Utility */
.text-muted { color: var(--text-muted); }
.tags { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: auto; }
.tags li {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
}
.card-links {
  display: flex; flex-wrap: wrap; gap: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.card-links a { font-size: var(--fs-sm); font-weight: 600; color: var(--accent); text-decoration: none; }
.card-links a:hover { text-decoration: underline; }

/* =========================================================
   Timeline esperienza
   ========================================================= */
.timeline {
  --tl-gutter: 132px;
  --tl-gap: 28px;
  list-style: none; padding: 0; position: relative;
}
.timeline::before {
  content: "";
  position: absolute;
  top: 10px; bottom: 10px;
  left: calc(var(--tl-gutter) + var(--tl-gap) / 2);
  width: 2px;
  background: var(--border-strong);
}
.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: var(--tl-gutter) 1fr;
  column-gap: var(--tl-gap);
  padding: var(--space-5) 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-item::before {
  content: "";
  position: absolute;
  top: 30px;
  left: calc(var(--tl-gutter) + var(--tl-gap) / 2);
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--bg);
  transform: translateX(-50%);
}
.timeline-period {
  text-align: right;
  padding-right: var(--space-1);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.timeline-role { font-size: var(--fs-md); margin-bottom: var(--space-1); }
.timeline-body p { color: var(--text-muted); max-width: 60ch; }

/* =========================================================
   Contatti
   ========================================================= */
.contact-grid {
  list-style: none;
  padding: 0;
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.contact-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: 100%;
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  text-decoration: none;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.contact-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) {
  .contact-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  }
}
.contact-card-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--surface-tint);
  color: var(--accent);
}
.contact-card-icon svg { width: 20px; height: 20px; display: block; }
.contact-card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.contact-card-name {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.contact-card-value { color: var(--accent); font-weight: 500; word-break: break-word; }

/* =========================================================
   Footer
   ========================================================= */
.site-footer { border-top: 1px solid var(--border); padding-block: var(--space-6); }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); }
.footer-note { color: var(--text-muted); font-size: var(--fs-sm); }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 720px) {
  .nav-toggle { display: block; }
  .site-nav { position: relative; }
  .nav-menu {
    position: absolute; right: 0; top: calc(100% + 10px);
    flex-direction: column; gap: var(--space-1);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: var(--space-2); min-width: 200px;
    box-shadow: var(--shadow-md);
    display: none;
  }
  .nav-menu.is-open { display: flex; }
  .nav-menu a { display: block; padding: 10px 12px; border-radius: var(--radius-sm); }
  .nav-menu a:hover { background: var(--bg-alt); }
  .nav-menu a[aria-current="true"] { background: var(--bg-alt); }
  .nav-menu a[aria-current="true"]::after { display: none; }

  .about-grid { grid-template-columns: 1fr; gap: var(--space-6); }

  .timeline::before,
  .timeline-item::before { left: 5px; }
  .timeline-item { grid-template-columns: 1fr; row-gap: var(--space-1); padding-left: var(--space-6); }
  .timeline-period { text-align: left; padding-right: 0; }

  .contact-card { padding: var(--space-4); }
}

/* =========================================================
   Movimento ridotto
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .btn:hover, .card:hover { transform: none; }
}

/* =========================================================
   Stampa
   ========================================================= */
@media print {
  .site-header, .theme-toggle, .nav-toggle, .hero-actions,
  .hero::before, #esperienza .section-lead { display: none !important; }
  .hero { background-image: none !important; }
  * { box-shadow: none !important; }
  .section { padding-block: var(--space-4); }
  .card, .about-side { border: 1px solid #bbb; break-inside: avoid; }
  .timeline-item { break-inside: avoid; }
  a { text-decoration: underline; }
}
