/* =======================================================
   SPAZIO X — STYLE.CSS
   Versione finale
   ✅ Mobile perfetta
   ✅ Desktop/Widescreen: dropdown "index" non taglia il testo
======================================================= */

/* FONT */
@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap');

/* =======================================================
   VARIABILI GLOBALI
======================================================= */
:root {
  --flyer-offset: -6svh;
  --flyer-box-h: 48svh;
  --flyer-w: 250px;
  --header-h: 64px;
  --footer-h: 40px;
}

/* =======================================================
   STRUTTURA BASE
======================================================= */
body {
  margin: 0;
  font-family: 'Source Code Pro', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: #333;
  background: #fff;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
}

#header { min-height: var(--header-h); }
#footer { min-height: var(--footer-h); }

.site-header { padding: 20px 40px; text-align: left; }
.site-footer {
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
  padding: 10px 40px;
  margin-bottom: 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
}

.page-title {
  padding: 0 40px;
  margin: 0 0 8px;
  font-size: 2rem;
  line-height: 1.2;
}

/* =======================================================
   BLOCCO FLYER
======================================================= */
.flyer-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform: translateY(var(--flyer-offset));
}
.flyer-block { display: flex; flex-direction: column; align-items: center; }

.flyer-header, .flyer-image, .flyer-info, .flyer-footer {
  width: var(--flyer-w);
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}
.flyer-header {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .7em; color: #444; margin-bottom: 6px;
}

/* =======================================================
   CORNICE
======================================================= */
.flyer-image { box-sizing: border-box; }
.flyer-image > img, .flyer-image > .flyer-frame {
  display: block; width: 100%; border: 1px solid #000; box-sizing: border-box;
}
.flyer-frame { background: #fafafa; overflow: hidden; }

.flyer-scroll {
  overflow: auto; padding: 10px 12px; text-align: left;
  font-size: .9em; line-height: 1.5; color: #333;
}
.flyer-scroll::-webkit-scrollbar { width: 6px; }
.flyer-scroll::-webkit-scrollbar-thumb { background: #888; border-radius: 3px; }
.flyer-scroll::-webkit-scrollbar-thumb:hover { background: #555; }

.flyer-info {
  text-align: right; font-size: .7em; color:#444;
  border-top: 1px solid #ccc; padding-top: 8px; margin-top: 8px;
}
.flyer-footer {
  display:flex; justify-content:space-between; align-items:baseline;
  font-size:.7em; color:#444; border-top:1px solid #ccc;
  padding-top:8px; margin-top:8px;
}

/* =======================================================
   OGGETTO VOLANTE
======================================================= */
.flier { pointer-events:none; position:fixed; top:0; left:0; z-index:2147483647; width:0; height:0; overflow:visible!important; }
.flier img { width:48px!important; height:48px!important; opacity:.75; object-fit:contain; will-change:transform; animation:flyAcross 90s linear infinite; }
@keyframes flyAcross{
  0%,98.001%{ transform:translate3d(-200%,100vh,0) rotateZ(0deg); }
  15%{ transform:translate3d(100vw,-100%,0) rotateZ(180deg); }
  15.001%,18%{ transform:translate3d(100vw,-30%,0) rotateZ(0deg); }
  40%{ transform:translate3d(-200%,3vh,0) rotateZ(-180deg); }
  65%{ transform:translate3d(100vw,50vh,0) rotateZ(0deg); }
  95%{ transform:translate3d(10vw,100vh,0) rotateZ(0deg); }
}

/* =======================================================
   DESKTOP / TABLET
======================================================= */
@media (min-width: 481px) {
  :root { --flyer-box-h: 375px; --flyer-w: 300px; }

  .flyer-image { height: var(--flyer-box-h); }
  .flyer-image > img, .flyer-image > .flyer-frame { height:100%; object-fit: cover; }
  .flyer-scroll { height: calc(var(--flyer-box-h) - 2px - 20px); }
  .flyer-container { transform: translateY(-2svh); }

  .flyer-info, .flyer-footer {
    width: var(--flyer-w); text-align: right; font-size:.7em; line-height:1.4;
    border-top:1px solid #ccc; padding-top:8px; margin-top:8px;
  }

  /* === HOME desktop === */
  body.is-home .home-actions-top,
  body.is-home .hydra-credit,
  body.is-home .home-actions-bottom {
    width: var(--flyer-w);
    margin: 0 auto;
    text-align: center;
    position: relative;
    z-index: 2;
  }
  body.is-home .home-actions-top { margin-bottom: 10px; }
  body.is-home .home-actions-top .btn { display: inline-block; margin: 0 auto; }

  /* 👉 FIX: "prossimi eventi" su una sola riga in desktop */
  body.is-home .btn.btn-eventi { white-space: nowrap; }

  /* Dropdown desktop */
  body.is-home details.dropdown { position: relative; display: inline-block; }
  body.is-home details.dropdown > summary { list-style: none; outline: none; }
  body.is-home details.dropdown > summary::-webkit-details-marker { display: none; }
  body.is-home details.dropdown[open] > summary.btn { background: #eee; }

  body.is-home details.dropdown .menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 10;
    min-width: 160px;
    width: max-content;
    white-space: nowrap;
    border: 1px solid #888;
    background: #fff;
    padding: 6px;
    box-sizing: border-box;
  }

  /* === FIX: "index" si adatta al testo (desktop) === */
  body.is-home details.dropdown > summary.btn.btn-archivio + .menu {
    min-width: max-content !important;   /* almeno quanto il testo */
    width: auto !important;              /* lascia larghezza naturale */
    white-space: nowrap;
    overflow: visible;
    padding: 6px 10px;
    box-sizing: border-box;
  }

  /* Evita clipping dei menu */
  body.is-home .home-actions-bottom { overflow: visible; }
}

/* =======================================================
   GRANDI SCHERMI (≥1600px)
======================================================= */
@media (min-width: 1600px) {
  .site-header, .site-footer, .page-title { padding-left: 6vw; padding-right: 6vw; }
  .flyer-block { transform: scale(1.15); transform-origin: center top; }
  .flyer-container { transform: translateY(-3svh); }

  .page-title { margin-bottom: 14px; font-size: 2.3rem; }
  .site-footer { font-size: 16px; line-height: 1.4; }
  .flyer-info, .flyer-footer { width: var(--flyer-w); }

  body.is-home .home-actions-top,
  body.is-home .hydra-credit,
  body.is-home .home-actions-bottom {
    width: var(--flyer-w);
    margin: 0 auto;
    text-align: center;
  }

  /* 👉 FIX: "prossimi eventi" su una riga anche in widescreen */
  body.is-home .btn.btn-eventi { white-space: nowrap; }

  /* === FIX: "index" si adatta al testo (widescreen) === */
  body.is-home details.dropdown > summary.btn.btn-archivio + .menu {
    min-width: max-content !important;
    width: auto !important;
    white-space: nowrap;
    overflow: visible;
    padding: 6px 10px;
    box-sizing: border-box;
  }
}

/* =======================================================
   MOBILE (≤480px) — invariato
======================================================= */
@media (max-width:480px){
  :root{
    --pad-m: clamp(12px, 5vw, 24px);
    --flyer-offset: -3svh;
    --header-h: 56px;
    --footer-h: 36px;
    --flyer-w: min(300px, calc(100vw - (2 * var(--pad-m)) - 2px));
  }

  *, *::before, *::after { box-sizing: border-box; }
  html, body { width:100%; max-width:100%; overflow-x:hidden !important; }

  .flyer-container, .flyer-block { width:100%; max-width:100%; overflow-x:visible; }

  .site-header, .page-title {
    box-sizing:border-box; max-width:100vw;
    padding-left:var(--pad-m); padding-right:var(--pad-m); overflow-x:hidden;
  }

  .site-footer {
    white-space: normal; overflow-wrap: anywhere; word-break: break-word;
    box-sizing: border-box; max-width: 100vw;
    padding-left: var(--pad-m); padding-right: var(--pad-m);
    overflow-x: hidden; font-size: 12px; line-height: 1.4;
  }

  .flyer-container { transform:none; margin-top:var(--flyer-offset); }

  .flyer-image{
    width:var(--flyer-w); aspect-ratio:4/5; height:auto;
    border:1px solid #000; background:#fafafa; display:block; overflow:hidden; position:relative; z-index:1;
  }
  .flyer-image > img{ width:100%; height:100%; object-fit:contain; border:0; display:block; }
  .flyer-image > .flyer-frame{
    width:100%; height:100%; border:0; background:transparent;
    display:flex; align-items:stretch; justify-content:stretch; min-height:0; box-sizing:border-box;
  }
  .flyer-scroll{ flex:1; min-height:0; overflow:auto; -webkit-overflow-scrolling:touch; padding:10px 12px; height:auto; box-sizing:border-box; }

  .flyer-info, .flyer-footer{
    width:var(--flyer-w); text-align:right; font-size:.7em; line-height:1.4;
    border-top:1px solid #ccc; padding-top:8px; margin-top:8px; position:relative; z-index:2;
  }

  .page-title{ font-size:1.6rem; margin:0 0 6px; }
  .flyer-header{ margin-bottom:4px; }

  body.is-home .home-actions-top,
  body.is-home .hydra-credit,
  body.is-home .home-actions-bottom{
    width: var(--flyer-w); margin-left:auto; margin-right:auto; overflow:visible;
    position:relative; z-index:2; text-align:center;
  }
  body.is-home .home-actions-top{ margin:0 auto 10px; }
  body.is-home .home-actions-top .btn{ display:inline-block; margin:0 auto; }

  body.is-home .flyer-image{
    aspect-ratio:auto; height:200px !important; max-width:300px; width:100%;
    margin:0 auto; border:1px solid #000; position:relative; z-index:1;
  }
  body.is-home .flyer-image > .flyer-frame{ height:100%; display:flex; align-items:stretch; justify-content:center; border:0; background:#fafafa; overflow:hidden; }
  body.is-home #hydra-canvas{ width:100%; height:100%; display:block; image-rendering:crisp-edges; }

  body.is-home details.dropdown{ position:relative; }
  body.is-home details.dropdown .menu{
    position:absolute; top:calc(100% + 6px); left:0; z-index:10000;
    display:inline-block; width:fit-content; max-width:calc(100vw - (2 * var(--pad-m)));
    box-sizing:border-box; white-space:nowrap; overflow:visible;
    border:1px solid #888; background:#fff; padding:6px;
  }

  /* Solo “index” mobile (già ok, preservato) */
  body.is-home details.dropdown:has(> summary.btn.btn-archivio) .menu {
    min-width: auto !important;
    width: fit-content !important;
    white-space: nowrap;
    padding: 6px 10px;
    box-sizing: border-box;
  }

  body.is-home .menu a{ display:block; padding:6px 8px; border:1px solid transparent; text-decoration:none; color:#333; font-size:.9em; white-space:nowrap; }
  body.is-home .menu a:hover{ border-color:#888; background:#f7f7f7; }

  body.is-home{ overflow-y:hidden; }
}

/* =======================================================
   LINK / FIX VISIVO / SCROLL CONTROL
======================================================= */
.flyer-scroll{ background:#fafafa; padding:12px 12px 10px; }
.flyer-scroll > :first-child{ margin-top:0; }
.flyer-scroll > :last-child{ margin-bottom:0; }
.flyer-scroll p{ margin:0 0 1em; }

@supports (height:100dvh){ body{ height:100dvh; } }
@supports not (height:100dvh){ body{ height:100svh; } }

html, body{ overscroll-behavior:none; }
.flyer-scroll{ overscroll-behavior:contain; -webkit-overflow-scrolling:touch; }

a{ color:#555; text-decoration:none; transition: color .2s ease, opacity .2s ease; }
a:hover, a:focus{ color:#000; }
a:active{ opacity:.7; }
.flyer-scroll a{ color:#333; border-bottom:1px dashed #666; text-decoration:none; }
.flyer-scroll a:hover, .flyer-scroll a:focus{ color:#000; border-color:#000; }
