:root {
  --bg: #f6efe6;
  --paper: #fffaf3;
  --ink: #2b211c;
  --muted: #8a7768;
  --accent: #d9534f;
  --accent-2: #e8a33d;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bar-h: 52px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--bar-h); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
button { font: inherit; cursor: pointer; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: .9em 2.2em;
  font-family: var(--sans);
  font-size: 1rem;
  letter-spacing: .04em;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgb(217 83 79 / .35); }
.btn-primary:active { transform: scale(.97); }

/* ---------- intro ---------- */
.intro {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 30%, #fffaf3 0%, var(--bg) 70%);
  text-align: center; padding: 2rem;
  transition: opacity .9s ease, visibility .9s;
}
.intro.gone { opacity: 0; visibility: hidden; }
.intro-kicker { font-family: var(--sans); letter-spacing: .35em; color: var(--muted); font-size: .8rem; margin: 0 0 1rem; }
.intro-title { font-size: clamp(2.6rem, 11vw, 5.5rem); font-weight: normal; margin: 0; line-height: 1.05; }
.intro-sub { color: var(--muted); font-style: italic; font-size: 1.15rem; margin: 1rem 0 2.5rem; }
.intro-hint { font-family: var(--sans); color: var(--muted); font-size: .8rem; margin-top: 1.2rem; }

/* ---------- barra anni ---------- */
.yearbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--bar-h);
  background: rgb(246 239 230 / .88);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgb(0 0 0 / .06);
  overflow-x: auto; scrollbar-width: none;
}
.yearbar::-webkit-scrollbar { display: none; }
.yearbar-track { display: flex; gap: .2rem; padding: 0 45vw; height: 100%; align-items: center; width: max-content; }
.yearbar a {
  font-family: var(--sans); font-size: .85rem; color: var(--muted);
  text-decoration: none; padding: .35rem .6rem; border-radius: 999px;
  transition: background .3s, color .3s;
}
.yearbar a.on { background: var(--ink); color: var(--paper); }

/* ---------- timeline ---------- */
.timeline { max-width: 1100px; margin: 0 auto; padding: 0 1rem 4rem; }
.year { padding: 3.5rem 0 1rem; }
.year-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: .4rem; }
.year-num { font-size: clamp(2.8rem, 12vw, 4.5rem); line-height: 1; margin: 0; font-weight: normal; }
.year-age { font-family: var(--sans); color: var(--accent); font-size: .95rem; letter-spacing: .05em; }
.year-cap { font-style: italic; font-size: 1.15rem; line-height: 1.5; color: #4a3d35; margin: .2rem 0 1.4rem; max-width: 40em; white-space: pre-line; }

.grid { columns: 2 160px; column-gap: .7rem; }
@media (min-width: 700px) { .grid { columns: 3 220px; column-gap: 1rem; } }
.grid figure {
  margin: 0 0 .7rem; break-inside: avoid;
  background: var(--paper); padding: .45rem .45rem 1.1rem;
  box-shadow: 0 2px 10px rgb(60 40 20 / .12);
  border-radius: 3px;
  opacity: 0; transform: translateY(24px) rotate(var(--r, 0deg));
  transition: opacity .8s ease, transform .8s ease;
  cursor: zoom-in;
}
.grid figure.in { opacity: 1; transform: translateY(0) rotate(var(--r, 0deg)); }
.grid img { display: block; width: 100%; height: auto; background: #e9dfd2; border-radius: 2px; }

/* ---------- finale ---------- */
.finale {
  min-height: 100vh; min-height: 100svh;
  display: grid; place-items: center; text-align: center;
  padding: 4rem 1.5rem 6rem;
  background: linear-gradient(180deg, var(--bg), #fbe3d6);
}
.finale-age { font-size: clamp(7rem, 40vw, 14rem); line-height: .9; margin: 0; color: var(--accent);
  text-shadow: 0 10px 40px rgb(217 83 79 / .25); }
.finale-year { font-family: var(--sans); letter-spacing: .4em; color: var(--muted); margin: .5rem 0 2.5rem; }
.surprise { max-width: 34em; margin: 0 auto; animation: rise 1.2s ease both; }
.surprise h2 { font-weight: normal; font-size: clamp(1.8rem, 7vw, 2.8rem); margin: 0 0 1rem; }
.surprise p { font-size: 1.2rem; line-height: 1.6; white-space: pre-line; }
.finale-sign { font-style: italic; color: var(--muted); }
@keyframes rise { from { opacity: 0; transform: translateY(30px); } }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ---------- pulsanti fissi ---------- */
.fab { position: fixed; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); z-index: 30; display: flex; gap: .6rem; }
.fab-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--ink); color: var(--paper); font-size: 1.1rem;
  box-shadow: 0 4px 14px rgb(0 0 0 / .25);
}
.fab-btn.off { opacity: .45; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 70;
  background: rgb(15 10 8 / .96);
  display: grid; place-items: center;
  touch-action: none;
}
.lightbox[hidden], .film[hidden] { display: none; }
.lightbox img { max-width: 96vw; max-height: 84vh; max-height: 84svh; object-fit: contain; transition: opacity .25s, transform .25s; user-select: none; }
.lb-cap { position: absolute; bottom: max(1rem, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #d8cabb; font-family: var(--sans); font-size: .9rem; margin: 0; }
.lb-btn { position: absolute; background: none; border: 0; color: #fff; font-size: 2rem; padding: .6rem 1rem; opacity: .8; }
.lb-close { top: max(.5rem, env(safe-area-inset-top)); right: .5rem; font-size: 1.5rem; }
.lb-prev { left: .2rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: .2rem; top: 50%; transform: translateY(-50%); }
@media (hover: none) { .lb-prev, .lb-next { display: none; } }

/* ---------- modalità film ---------- */
.film { position: fixed; inset: 0; z-index: 80; background: #000; color: #fff; overflow: hidden; }
.film-stage { position: absolute; inset: 0; }
.film-layer {
  position: absolute; inset: 0; overflow: hidden;
  opacity: 0; transition: opacity 1.2s ease;
}
.film-layer img { position: absolute; inset: 0; width: 100%; height: 100%; }
.film-layer .bg { object-fit: cover; filter: blur(40px) brightness(.45) saturate(1.2); transform: scale(1.2); }
.film-layer .fg { object-fit: contain; }
.film-layer.show { opacity: 1; }
.film-layer.kb-a .fg { animation: kbA var(--dur, 5s) linear both; }
.film-layer.kb-b .fg { animation: kbB var(--dur, 5s) linear both; }
@keyframes kbA { from { transform: scale(1) translate(0, 0); } to { transform: scale(1.08) translate(-1%, -1%); } }
@keyframes kbB { from { transform: scale(1.08) translate(1%, 1%); } to { transform: scale(1) translate(0, 0); } }
.film-card {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  background: radial-gradient(ellipse at center, rgb(0 0 0 / .55), rgb(0 0 0 / .85));
  opacity: 0; transition: opacity 1s ease; pointer-events: none; padding: 2rem;
}
.film-card.show { opacity: 1; }
.fc-year { font-size: clamp(4rem, 18vw, 10rem); margin: 0; line-height: 1; }
.fc-age { font-family: var(--sans); letter-spacing: .3em; color: var(--accent-2); margin: .8rem 0; text-transform: uppercase; font-size: .95rem; }
.fc-cap { font-style: italic; font-size: clamp(1.1rem, 3vw, 1.6rem); max-width: 30em; margin: 0 auto; white-space: pre-line; }
.film-bar {
  position: absolute; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: .4rem; align-items: center;
  background: rgb(0 0 0 / .55); border-radius: 999px; padding: .3rem .6rem;
  transition: opacity .6s;
}
.film.idle .film-bar { opacity: 0; }
.film.idle { cursor: none; }
.film-bar button { background: none; border: 0; color: #fff; font-size: 1.1rem; padding: .4rem .6rem; }
.film-label { font-family: var(--sans); font-size: .85rem; min-width: 4.5em; text-align: center; color: #ddd; }
.film-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgb(255 255 255 / .12); }
.film-progress div { height: 100%; width: 0; background: var(--accent); transition: width .5s linear; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .grid figure { transition: none; opacity: 1; transform: none; }
  .film-layer.kb-a, .film-layer.kb-b .fg { animation: none; }
}
