/* ==========================================================================
   La Costante — foglio di stile
   1. Font e variabili   2. Base   3. Componenti   4. Hero   5. Filo d'oro
   6. Sezioni   7. La storia   8. Sfoglia   9. E dopo l'ultima pagina?
   10. L'autrice e chiusura   11. Footer   12. Tablet (700px)   13. Desktop (1024px)
   14. Movimento ridotto
   Mobile first: le media query aggiungono le differenze per schermi larghi.
   ========================================================================== */


/* 1. Font e variabili
   ========================================================================== */

@font-face {
  font-family: 'Costellazione';
  src: url('../fonts/A1-Costellazione-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --blue: #0B2D6B;
  --blue-deep: #03113e;
  --blue-alt: #082058;   /* sezioni alternate: Sfoglia, E dopo */
  --night: #020a2a;
  --gold: #F2C94C;
  --gold-soft: rgba(242, 201, 76, .35);
  --beige: #F5EEDC;
  --ink: #f7f1df;
  --muted: #c9cfe3;

  --font-title: 'Costellazione', Georgia, serif;
  --font-text: 'Lora', Georgia, 'Times New Roman', serif;
  --font-ui: system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;

  --gutter: clamp(20px, 6vw, 80px);
  --max: 1180px;
}


/* 2. Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--blue-deep);
  font-family: var(--font-text);
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

h1, h2, h3 {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 400;
  line-height: 1;
}

h2 {
  font-size: clamp(2.3rem, 6vw, 4.2rem);
  color: var(--beige);
  margin-bottom: .5em;
}

h3 { font-size: 1.9rem; color: var(--gold); }

p { margin: 0 0 1em; }

a { color: var(--gold); }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  padding: 10px 16px; background: var(--gold); color: var(--night);
  font-family: var(--font-ui);
}
.skip:focus { top: 12px; }


/* 3. Componenti
   ========================================================================== */

.button {
  display: inline-block;
  padding: 15px 26px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  background: var(--gold);
  color: var(--night);
  font: 700 .78rem/1 var(--font-ui);
  letter-spacing: .12em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 0 0 0 var(--gold-soft);
  transition: background .25s, color .25s, box-shadow .35s;
}
.button:hover {
  background: transparent;
  color: var(--gold);
  box-shadow: 0 0 28px 2px var(--gold-soft);
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--gold);
  font: 700 .72rem/1.2 var(--font-ui);
  letter-spacing: .2em;
  text-transform: uppercase;
}

.lead { font-size: 1.25rem; line-height: 1.6; color: var(--beige); }

.round {
  width: 46px; height: 46px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--gold-soft);
  border-radius: 50%;
  background: rgba(2, 10, 42, .6);
  color: var(--gold);
  font-size: 1.1rem;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.round:hover { border-color: var(--gold); background: rgba(242, 201, 76, .12); }
.round:disabled { opacity: .35; cursor: default; }


/* 4. Hero
   ========================================================================== */

.hero {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  padding: 20px var(--gutter) 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: "nav" "copy" "figure" "scroll";
  background:
    linear-gradient(180deg, rgba(2,10,42,.15) 0%, rgba(2,10,42,0) 50%, var(--blue-deep) 100%),
    url('../imgs/lacostante_bg.webp') center / cover no-repeat;
}

/* Stelle create da main.js */
.stars { position: absolute; inset: 0; pointer-events: none; }
.star {
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: #fff8dc;
  box-shadow: 0 0 6px 1px rgba(255, 240, 190, .8);
  opacity: .2;
  animation: twinkle var(--d, 4s) ease-in-out var(--delay, 0s) infinite;
}
@keyframes twinkle { 50% { opacity: 1; transform: scale(1.4); } }

.nav {
  grid-area: nav;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font: .74rem/1 var(--font-ui);
  letter-spacing: .16em;
  text-transform: uppercase;
}
.nav a { color: var(--ink); text-decoration: none; }
.nav a:hover { color: var(--gold); }
.nav-brand { font-family: var(--font-title); font-size: 1.4rem; letter-spacing: 0; text-transform: none; }
.nav ul { display: none; margin: 0; padding: 0; list-style: none; gap: 30px; }

.hero-copy {
  grid-area: copy;
  position: relative;
  margin-top: clamp(40px, 9vh, 110px);
}

h1 {
  color: var(--gold);
  font-size: clamp(3rem, 12vw, 7.6rem);
  letter-spacing: -.02em;
  white-space: nowrap;
  text-shadow: 0 0 40px rgba(242, 201, 76, .35);
}

.hero-sub {
  margin: .5em 0 1.4em;
  color: var(--beige);
  font-family: var(--font-title);
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  line-height: 1.2;
}

.hero-figure {
  grid-area: figure;
  align-self: end;
  justify-self: center;
  width: min(100% + 2 * var(--gutter), 520px);
  max-width: none;
  height: auto;
  margin-top: 32px;
  pointer-events: none;
}

.hero-scroll {
  grid-area: scroll;
  justify-self: center;
  padding: 18px 0 26px;
  color: var(--beige);
  font: .7rem/1 var(--font-ui);
  letter-spacing: .2em;
  text-transform: uppercase;
  text-decoration: none;
}
.hero-scroll span { display: inline-block; animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(5px); } }


/* 5. Filo d'oro
   ========================================================================== */

.thread {
  display: block;
  width: 100%;
  height: clamp(70px, 10vw, 140px);
  overflow: visible;
}
.thread path {
  fill: none;
  stroke: var(--gold);
  stroke-width: 2.5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 4px #ffcf5a) drop-shadow(0 0 12px rgba(255, 170, 40, .7));
  stroke-dasharray: var(--len, 2000);
  stroke-dashoffset: var(--len, 2000);
  transition: stroke-dashoffset 2.6s ease-out;
}
.thread.is-drawn path { stroke-dashoffset: 0; }


/* 6. Sezioni
   ========================================================================== */

main { overflow-x: clip; }

.section {
  max-width: var(--max);
  margin: 0 auto;
  padding: 72px var(--gutter);
}

.section-head { margin-bottom: 36px; }

/* Sezioni alternate in blu più chiaro, da bordo a bordo dello schermo */
.section-alt {
  background: var(--blue-alt);
  box-shadow: 0 0 0 100vmax var(--blue-alt);
  clip-path: inset(0 -100vmax);
}
.gallery.section-alt { box-shadow: none; clip-path: none; }

/* comparsa morbida all'ingresso (attivata da main.js) */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .9s ease, transform .9s ease; }
.reveal.is-visible { opacity: 1; transform: none; }


/* 7. La storia
   ========================================================================== */

.story-body { max-width: 680px; }

.facts {
  display: grid;
  grid-template-columns: repeat(2, auto);
  justify-content: start;
  gap: 18px 40px;
  margin: 40px 0 0;
  padding-top: 28px;
  border-top: 1px solid rgba(245, 238, 220, .2);
  font-family: var(--font-ui);
}
.facts dt { color: var(--gold); font-size: .68rem; letter-spacing: .18em; text-transform: uppercase; }
.facts dd { margin: 4px 0 0; font-size: .95rem; color: var(--beige); }


/* 8. Sfoglia
   ========================================================================== */

.gallery { max-width: none; padding-left: 0; padding-right: 0; }
.gallery .section-head { max-width: var(--max); margin-left: auto; margin-right: auto; padding: 0 var(--gutter); }
.gallery h2 { font-size: clamp(1.9rem, 4.5vw, 3.2rem); }

/* Slider a scorrimento orizzontale */
.gallery-track {
  display: flex;
  gap: 18px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 var(--gutter);
  padding: 8px var(--gutter) 22px;
  scrollbar-width: none;
}
.gallery-track::-webkit-scrollbar { display: none; }

.spread { flex: 0 0 88vw; margin: 0; scroll-snap-align: center; }
.spread button {
  display: block; width: 100%; padding: 0;
  border: 0; background: none; cursor: zoom-in;
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45), 0 0 0 1px rgba(242, 201, 76, .15);
  transition: transform .4s ease, box-shadow .4s ease;
}
.spread button:hover { transform: translateY(-4px); box-shadow: 0 24px 60px rgba(0,0,0,.5), 0 0 30px rgba(242,201,76,.25); }
.spread img { width: 100%; height: auto; }

.gallery-controls {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  font: .8rem/1 var(--font-ui); letter-spacing: .12em; color: var(--muted);
}

.lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: rgba(1, 6, 26, .95);
  color: var(--ink);
}
.lightbox[open] { display: grid; place-items: center; }
.lightbox::backdrop { background: transparent; }
.lightbox img { max-width: 94vw; max-height: 84vh; width: auto; height: auto; border-radius: 4px; }
.lightbox .round { position: absolute; }
.lightbox-close { top: 18px; right: 18px; }
.lightbox-prev { left: 14px; bottom: 22px; }
.lightbox-next { right: 14px; bottom: 22px; }


/* 9. E dopo l'ultima pagina?
   ========================================================================== */

.after-grid { display: grid; gap: 40px; }

.after-form {
  display: grid;
  gap: 18px;
  padding: 28px 22px;
  border: 1px solid var(--gold-soft);
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(3, 17, 62, .6), rgba(2, 10, 42, .8));
  box-shadow: 0 0 60px rgba(242, 201, 76, .06) inset;
}

.after-form label { display: grid; gap: 7px; font: 600 .82rem/1.3 var(--font-ui); color: var(--beige); letter-spacing: .02em; }
.after-form .opt { font-weight: 400; color: var(--muted); }

.field-row { display: grid; grid-template-columns: 1fr 140px; gap: 14px; align-items: end; }

.after-form input:not([type="checkbox"]),
.after-form textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(245, 238, 220, .25);
  border-radius: 8px;
  background: rgba(2, 10, 42, .55);
  color: var(--ink);
  font: 1rem/1.5 var(--font-text);
  transition: border-color .2s, box-shadow .2s;
}
.after-form textarea { resize: vertical; min-height: 140px; }
.after-form input::placeholder { color: rgba(201, 207, 227, .55); }
.after-form input:focus, .after-form textarea:focus {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242, 201, 76, .18);
}
.after-form [aria-invalid="true"] { border-color: #ff9b8a; }

.after-form .check { grid-template-columns: 22px 1fr; align-items: start; font-weight: 400; line-height: 1.5; color: var(--muted); }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--gold); }

.after-form .button { justify-self: start; }
.form-note { margin: 0; font: .8rem/1.5 var(--font-ui); color: var(--muted); }
.form-error { margin: 0; color: #ffb4a6; font: .88rem/1.4 var(--font-ui); }
.form-done { padding: 14px 16px; border-radius: 8px; background: rgba(242, 201, 76, .1); font: .88rem/1.5 var(--font-ui); }
.form-done p { margin: 0 0 6px; }
.link-button { padding: 0; border: 0; background: none; color: var(--gold); font: inherit; text-decoration: underline; cursor: pointer; }



/* 10. L'autrice e chiusura
   ========================================================================== */

.author-body { max-width: 680px; }

.closing { text-align: center; padding-top: 40px; padding-bottom: 100px; }
.closing-line { font: clamp(2rem, 5vw, 3.4rem)/1.1 var(--font-title); color: var(--gold); margin-bottom: 30px; }


/* 11. Footer
   ========================================================================== */

.footer {
  display: flex; flex-direction: column; gap: 6px;
  padding: 32px var(--gutter);
  background: var(--night);
  border-top: 1px solid rgba(242, 201, 76, .15);
  color: var(--muted);
  font: .75rem/1.6 var(--font-ui);
  letter-spacing: .06em;
}


/* 12. Tablet (da 700px)
   ========================================================================== */

@media (min-width: 700px) {
  .nav ul { display: flex; }

  .section { padding-top: 92px; padding-bottom: 92px; }

  .spread { flex-basis: 76vw; }


  .after-form { padding: 36px; }



  .footer { flex-direction: row; justify-content: space-between; }
}


/* 13. Desktop (da 1024px)
   ========================================================================== */

@media (min-width: 1024px) {
  .hero {
    grid-template-columns: 1fr minmax(0, 40vw);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "nav    nav"
      "copy   figure"
      "scroll figure";
    column-gap: 4vw;
  }
  .hero-copy { align-self: center; margin-top: 0; }
  .hero-figure { justify-self: end; width: min(40vw, 600px); }
  .hero-scroll { justify-self: start; }

  .spread { flex-basis: 70vw; }


  .after-grid { grid-template-columns: 1fr 1.15fr; gap: 72px; align-items: start; }
  .after-intro { position: sticky; top: 40px; }

}


/* 14. Movimento ridotto
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { opacity: 1; transform: none; }
  .thread path { stroke-dashoffset: 0; }
}
