/* =========================================================
   App Station — styles.css
   Tema scuro, mobile-first, schermata non zoomabile.
   ========================================================= */

:root {
  --bg: #141414;
  --bg-elev: #1e1e1e;
  --text: #ffffff;
  --text-dim: #b5b5b5;
  --accent: #6ea8fe;
  --card-radius: 20px;
  --gap: 12px;
  --pad: 16px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

html {
  /* Anti-zoom / stabilità testo */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  /* Blocca il pinch-zoom lasciando lo scroll verticale della pagina */
  touch-action: pan-y;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* =============== Header (minimale) =============== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--pad) 6px;
}

.app-header__title {
  margin: 0;
  font-size: clamp(1rem, 4.2vw, 1.25rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-dim);
}

/* Tasto per attivare/disattivare il riordino */
.reorder-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 36px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.reorder-toggle:hover { background: rgba(255,255,255,0.1); }
.reorder-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.reorder-toggle__icon { font-size: 1rem; line-height: 1; }

/* Stato attivo (modalità riordino ON) */
.reorder-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1b3a;
}

/* =============== Griglia card =============== */
.grid {
  display: grid;
  grid-template-columns: 1fr;              /* mobile: 1 colonna larga (come mockup) */
  gap: var(--gap);
  padding: 6px var(--pad) calc(env(safe-area-inset-bottom, 0px) + 12px);
  max-width: 1200px;
  margin: 0 auto;
}

/* Desktop: sfrutta lo spazio con più colonne */
@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1080px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* =============== Card =============== */
.card {
  position: relative;
  display: block;
  width: 100%;
  /* Altezza compatta: 5 card entrano in un iPhone 16e senza scroll.
     Cresce leggermente in altezza sui display alti, con tetto massimo. */
  height: clamp(96px, 15.5vh, 150px);
  border: 0;
  border-radius: var(--card-radius);
  overflow: hidden;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  background-color: var(--bg-elev);
  background-size: cover;
  background-position: center;
  /* Overlay scuro sfumato per leggibilità del titolo, sopra la foto/gradiente */
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  touch-action: pan-y;                      /* tap/scroll normali; il JS gestisce il drag in reorder */
  user-select: none;
  -webkit-user-select: none;
}

/* Desktop: card un po' più alte, layout a griglia */
@media (min-width: 720px) {
  .card { height: clamp(130px, 22vh, 190px); }
}

.card::after {
  /* Velo scuro per contrasto testo */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0.15) 45%, rgba(0,0,0,0.35) 100%);
}

.card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,0.45); }
.card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.card__title {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 0 16px;
  width: 100%;
  text-align: center;
  font-size: clamp(1.4rem, 5.2vw, 2.4rem);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* =============== Modalità riordino =============== */
/* Attiva sul contenitore quando l'utente preme "Riordina". */
.grid.reordering .card {
  cursor: grab;
  animation: wobble 0.4s ease-in-out infinite alternate;
}
.grid.reordering .card:nth-child(even) { animation-delay: 0.15s; }

@keyframes wobble {
  from { transform: rotate(-0.5deg); }
  to   { transform: rotate(0.5deg); }
}

/* Stati drag-and-drop */
.card.is-dragging {
  z-index: 30;
  opacity: 0.92;
  transform: scale(1.03);
  box-shadow: 0 16px 34px rgba(0,0,0,0.55);
  cursor: grabbing;
  animation: none;
}

/* Linea indicatrice del punto di inserimento */
.drop-line {
  position: fixed;
  z-index: 40;
  height: 4px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(110,168,254,0.35), 0 0 12px rgba(110,168,254,0.6);
  pointer-events: none;
  transition: top 0.08s ease, left 0.08s ease, width 0.08s ease;
}

/* =============== Overlay Viewer (iframe) =============== */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
}
.viewer[hidden] { display: none; }

.viewer__stage {
  position: absolute;
  inset: 0;
  background: var(--bg);
}

/* =============== Floating button spostabile (FAB) =============== */
.fab {
  position: fixed;
  /* Posizione iniziale: in alto a sinistra, sotto la safe-area. */
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 12px;
  z-index: 120;
  touch-action: none;                        /* il JS gestisce il drag del bottone */
}

/* Animazione dell'aggancio al lato al rilascio (non durante il trascinamento). */
.fab.is-snapping { transition: left 0.22s cubic-bezier(0.22, 1, 0.36, 1); }

/* Bottone principale (semitrasparente + blur) */
.fab__main {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 50%;
  background: rgba(20,20,20,0.45);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  color: var(--text);
  cursor: grab;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  transition: background 0.15s ease, transform 0.15s ease;
}
.fab__main:hover { background: rgba(30,30,30,0.6); }
.fab__main:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fab.is-dragging .fab__main { cursor: grabbing; transform: scale(1.06); }

/* Icona "menu" (⋮ tre puntini) -> diventa X quando aperto.
   Costruita con pseudo-elementi per non dipendere da font/emoji. */
.fab__dots,
.fab__dots::before,
.fab__dots::after {
  content: "";
  display: block;
  background: currentColor;
  transition: all 0.18s ease;
}
.fab__dots {
  position: relative;
  width: 4px; height: 4px; border-radius: 50%;
}
.fab__dots::before,
.fab__dots::after {
  position: absolute;
  left: 0;
  width: 4px; height: 4px; border-radius: 50%;
}
.fab__dots::before { top: -7px; }
.fab__dots::after  { top: 7px; }

/* Stato aperto: le tre parti diventano una X */
.fab[data-open="true"] .fab__dots {
  width: 20px; height: 2px; border-radius: 2px;
  transform: rotate(45deg);
}
.fab[data-open="true"] .fab__dots::before {
  top: 0; left: 0; width: 20px; height: 2px; border-radius: 2px;
  transform: rotate(90deg);
}
.fab[data-open="true"] .fab__dots::after { opacity: 0; }
.fab[data-open="true"] .fab__main { background: rgba(30,30,30,0.75); }

/* Menu azioni (blur come il bottone) */
.fab__menu {
  position: absolute;
  top: 56px;
  left: 0;
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  min-width: 210px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 14px;
  background: rgba(20,20,20,0.55);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.fab[data-open="true"] .fab__menu { display: flex; }

/* Se il FAB è nella metà destra dello schermo, il menu si apre verso sinistra */
.fab[data-side="right"] .fab__menu { left: auto; right: 0; }

.fab__item {
  display: flex;
  align-items: center;
  gap: 10px;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  padding: 12px 14px;
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.fab__item:hover { background: rgba(255,255,255,0.1); }
.fab__item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.viewer__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;                          /* evita flash nero in caricamento */
}

/* Spinner di caricamento */
.viewer__spinner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-dim);
  background: var(--bg);
  z-index: 2;
}
.viewer__spinner[hidden] { display: none; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Messaggio "bloccato" */
.viewer__blocked {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
  background: var(--bg);
  z-index: 3;
}
.viewer__blocked[hidden] { display: none; }
.viewer__blocked-title { font-size: 1.2rem; font-weight: 700; margin: 0; }
.viewer__blocked-text { color: var(--text-dim); margin: 0; max-width: 420px; }

.btn-primary {
  display: inline-block;
  margin-top: 6px;
  padding: 12px 20px;
  min-height: 44px;
  background: var(--accent);
  color: #0b1b3a;
  font-weight: 700;
  text-decoration: none;
  border-radius: 12px;
}
.btn-primary:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* =============== Riduzione movimento =============== */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
