:root {
  color-scheme: light dark;
  --bg: #fff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e3e3e3;
  --accent: #2b6cb0;
  --danger: #b02b2b;
  --tessera: #ececec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #ececec;
    --muted: #9a9a9a;
    --border: #2c2c2c;
    --accent: #7cb0e8;
    --danger: #e08585;
    --tessera: #232323;
  }
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  padding: 0 1rem 2rem;
  color: var(--fg);
  background: var(--bg);
}

body.bloccato {
  overflow: hidden;
}

nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
  flex-wrap: wrap;
}

nav .brand {
  font-weight: 700;
  font-size: 1.1rem;
  margin-right: auto;
}

nav a {
  color: inherit;
  text-decoration: none;
  padding: 0.4rem 0.2rem;
}

main {
  max-width: 1100px;
  margin: 0 auto;
}

h1 {
  font-size: 1.4rem;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.button,
button[type="submit"] {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.7rem 1.1rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: 1rem;
  cursor: pointer;
}

button[type="submit"]:disabled {
  opacity: 0.6;
}

/* ---------------- Galleria ---------------- */

.giorno-titolo {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 0.9rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--bg);
}

.griglia {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 3px;
  /* I giorni fuori dallo schermo non vengono disegnati finché non servono:
     con qualche migliaio di tessere è la differenza tra fluido e scattoso. */
  content-visibility: auto;
  contain-intrinsic-size: auto 400px;
}

.tessera {
  position: relative;
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 3px;
  background: var(--tessera);
}

.tessera img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-segno {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 1.5rem;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.video-durata {
  position: absolute;
  right: 4px;
  bottom: 3px;
  color: #fff;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

#sentinella {
  height: 1px;
}

.fine,
.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
}

/* ---------------- Messaggi ---------------- */

.flash {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.flash li {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.flash-success {
  background: #e3f6e8;
  color: #1a6b32;
}

.flash-error {
  background: #fbe4e4;
  color: #b02b2b;
}

/* ---------------- Caricamento ---------------- */

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 460px;
}

.campo {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.campo input[type="text"] {
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--fg);
  background: var(--bg);
}

/* L'input vero resta raggiungibile da tastiera ma è la .scelta a farsi vedere. */
.file-vero {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.scelta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 2rem 1rem;
  border: 2px dashed var(--border);
  border-radius: 14px;
  text-align: center;
  cursor: pointer;
}

.file-vero:focus-visible + .scelta {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.scelta-piu {
  font-size: 2rem;
  line-height: 1;
  color: var(--accent);
}

.scelta-titolo {
  font-size: 1.05rem;
  font-weight: 600;
}

.scelta-nota,
.scelti,
.stato {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.barra {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}

.barra-piena {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s linear;
}

.avanzamento {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.errori {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--danger);
  font-size: 0.85rem;
}

.denied {
  text-align: center;
  padding: 3rem 1rem;
}

/* ---------------- Visore ---------------- */

.visore {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  touch-action: pan-y;
}

.visore[hidden] {
  display: none;
}

.visore-contenuto {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100dvh;
}

.visore-contenuto img,
.visore-contenuto video {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
  user-select: none;
}

.visore-bottone {
  position: absolute;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.visore-chiudi {
  top: max(1rem, env(safe-area-inset-top));
  right: 1rem;
}

.visore-scarica {
  top: max(1rem, env(safe-area-inset-top));
  left: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 1.3rem;
}

.visore-prec {
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
}

.visore-succ {
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
}

.visore-didascalia {
  position: absolute;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  color: #ddd;
  font-size: 0.85rem;
  pointer-events: none;
  text-shadow: 0 1px 4px #000;
}

/* Su schermo stretto le frecce coprirebbero la foto: bastano swipe e tocco. */
@media (max-width: 639px) {
  .visore-prec,
  .visore-succ {
    display: none;
  }
}

@media (min-width: 640px) {
  body {
    padding: 0 2rem 2rem;
  }

  .griglia {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 6px;
  }

  .giorno-titolo {
    font-size: 1.05rem;
    padding-top: 1.2rem;
  }
}
