:root {
  --bg: #0b0a0e;           /* nero notte */
  --surface: #16131d;      /* carte e pannelli */
  --line: #2c2636;         /* bordi */
  --ink: #f3ecd8;          /* avorio */
  --muted: #9b8aa0;        /* secondario */
  --accent: #ff9d00;       /* zucca */
  --accent-hover: #ffb74d;
  --accent-dark: #8a5100;
  --ghost: #e8e8e8;
  --ok: #7ed957;
  --bad: #ff4d4d;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Decorazioni Halloween (sfondo, non intralciano l'uso) ---------- */
.decoration {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  user-select: none;
}
.decoration svg { display: block; }
.decoration.pumpkin { width: 64px; height: 64px; opacity: 0.55; }
.decoration.ghost { width: 48px; height: 48px; opacity: 0.6; }
.decoration.bat { width: 40px; height: 40px; opacity: 0.45; }

.decoration.pumpkin.l { top: 10px; left: 14px; animation: float 6s ease-in-out infinite; }
.decoration.pumpkin.r { bottom: 14px; right: 14px; animation: float 7.5s ease-in-out infinite 1.2s; }
.decoration.ghost.l { top: 70px; left: 10px; animation: float 5s ease-in-out infinite 0.4s; }
.decoration.ghost.r { bottom: 90px; right: 10px; animation: float 6.5s ease-in-out infinite 1.6s; }
.decoration.bat.t { top: 18px; right: 18px; animation: drift 4s ease-in-out infinite; }
.decoration.bat.b { bottom: 18px; left: 18px; animation: drift 5s ease-in-out infinite 0.8s; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-14px) rotate(4deg); }
}
@keyframes drift {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(18px, -12px) rotate(-8deg); }
  66% { transform: translate(-14px, 10px) rotate(6deg); }
}

h1, h2 { letter-spacing: 0.04em; }
h1::after { content: ''; }

/* ---------- Base ---------- */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0.9rem 1.5rem;
  display: flex; align-items: center; gap: 1rem;
  z-index: 10; position: relative;
}
.h-ween { background: linear-gradient(180deg, #16131d, #0f0c14); }
.btn-admin {
  flex-shrink: 0; padding: 0.4rem 0.85rem; font-size: 0.75rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.06em; text-decoration: none;
  color: var(--accent); border: 1px solid var(--accent); border-radius: 999px;
}
.btn-admin:hover { background: var(--accent); color: #111; }
.logo {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 800; letter-spacing: 0.08em; color: var(--accent);
  font-size: 1.35rem; text-transform: uppercase;
  text-shadow: 0 0 12px rgba(255, 157, 0, 0.35);
  animation: flicker 5s infinite alternate;
}
.logo-icon { width: 30px; height: 30px; fill: var(--accent); }
.logo span { color: var(--ink); }

@keyframes flicker {
  0%, 89% { opacity: 1; text-shadow: 0 0 12px rgba(255, 157, 0, 0.35); }
  90% { opacity: 0.6; text-shadow: none; }
  92% { opacity: 1; text-shadow: 0 0 16px rgba(255, 157, 0, 0.5); }
  100% { opacity: 1; text-shadow: 0 0 12px rgba(255, 157, 0, 0.35); }
}

.container { max-width: 980px; margin: 0 auto; padding: 1.5rem; position: relative; z-index: 1; }

.btn, button {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 0.6rem 1.1rem; border-radius: var(--radius); font-size: 0.95rem;
  font-weight: 700; cursor: pointer; transition: transform 0.1s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
button.btn-primary, button.primary {
  background: var(--accent); border-color: var(--accent); color: #111;
  box-shadow: 0 0 0 0 rgba(255, 157, 0, 0);
}
button.btn-primary:hover, button.primary:hover {
  background: var(--accent-hover); border-color: var(--accent-hover);
  box-shadow: 0 0 14px rgba(255, 157, 0, 0.45); transform: translateY(-1px);
}
button.btn-primary:active { transform: translateY(1px) scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
button.danger:hover { background: rgba(255, 77, 77, 0.1); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; margin: 1rem 0; box-shadow: var(--shadow);
  position: relative; z-index: 1;
}
.closed-card { text-align: center; padding: 2.5rem 1.5rem; }
.done-card { text-align: center; padding: 2rem 1.5rem; }
.closed-icon, .done-icon { font-size: 3rem; display: block; margin: 0 0 0.75rem; opacity: 0.85; }

h1 { font-size: 1.6rem; margin: 0 0 0.5rem; color: var(--ink); }
h2 { font-size: 1.25rem; margin: 1rem 0 0.5rem; color: var(--ink); }
p { color: var(--muted); margin: 0.5rem 0; }
label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.35rem; font-weight: 700; }
input[type=text], input[type=email], input[type=password], input[type=datetime-local], select, textarea {
  width: 100%; padding: 0.6rem; border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 1rem; background: #0f0c14; color: var(--ink);
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.stat { font-size: 1.5rem; font-weight: 800; color: var(--ink); }

.hidden { display: none !important; }
.flash {
  padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: 0.95rem; border: 1px solid transparent;
}
.flash.bad { background: rgba(255, 77, 77, 0.1); color: var(--bad); border-color: rgba(255, 77, 77, 0.35); }
.flash.ok { background: rgba(126, 217, 87, 0.1); color: var(--ok); border-color: rgba(126, 217, 87, 0.35); }

/* ---------- Stato votazione ---------- */
.status {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.9rem; border-radius: 2rem; font-size: 0.85rem; font-weight: 800;
  border: 1px solid var(--line); background: var(--surface);
}
.status.open { color: var(--ok); border-color: rgba(126, 217, 87, 0.35); background: rgba(126, 217, 87, 0.08); }
.status.closed { color: var(--bad); border-color: rgba(255, 77, 77, 0.35); background: rgba(255, 77, 77, 0.08); }

/* ---------- Voto ---------- */
.board-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; flex-wrap: wrap; gap: 0.75rem;
}
.board-header h2 { margin: 0; }
.progress {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.45rem 0.9rem; border-radius: 2rem;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 0.9rem; font-weight: 700;
}
.progress::before {
  content: '🎃'; font-size: 1.1rem;
}

/* ---------- Admin ---------- */
.admin-nav { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.admin-nav a.btn { text-decoration: none; background: #1a1622; color: var(--ink); }
.admin-nav a.btn:hover { background: #241e2e; }

table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; font-size: 0.9rem; }
th, td { border-bottom: 1px solid var(--line); padding: 0.55rem 0.75rem; text-align: left; }
th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
tr:hover { background: rgba(255, 157, 0, 0.06); }
.photo-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

.results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-top: 1rem; }
.result-col { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: var(--surface); }
.result-col h3 { font-size: 0.95rem; margin: 0 0 0.75rem; color: var(--accent); border-bottom: 1px solid var(--line); padding-bottom: 0.4rem; }
.result-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0; border-bottom: 1px solid #1a1622; }
.result-item:last-child { border-bottom: none; }
.result-item img { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; }
.result-item .votes { margin-left: auto; font-weight: 800; color: var(--muted); }
.result-item.winner { color: var(--ok); font-weight: 800; }

.tokens-list { columns: 170px 4; column-gap: 1rem; }
.tokens-list .token { display: inline-block; margin-bottom: 0.5rem; padding: 0.35rem 0.5rem;
  background: #1a1622; border-radius: 6px; font-size: 0.78rem; word-break: break-all;
  border: 1px solid #2c2636; color: var(--muted); }

footer { margin-top: 2.5rem; padding: 1.5rem; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); text-align: center; }

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
  .container { padding: 0.75rem; }
  header { padding: 0.75rem 1rem; }
  .logo { font-size: 1.1rem; }
  .decoration { display: none; } /* meno ingombro sui telefoni */
  .camera-row { flex-direction: column; align-items: stretch; gap: 1rem; }
  .camera-preview-wrap { width: 100%; max-width: 320px; }
}

/* ============================================================
   HALLOWEEN — decorazioni spaventose, 3D e "bucano lo schermo"
   ============================================================ */

/* Colori aggiuntivi */
:root {
  --web: #5b4a66;           /* ragnatela */
  --moon: #f3ecd8;          /* luna piena */
  --bones: #d8d8d8;         /* ossa */
  --crack: #ff4d4d;         /* crepe */
}

/* ---------- Decorazioni fisse (sfondo, non intralciano l'uso) ---------- */
.decoration {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  user-select: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.45));
}

/* Ragnatele agli angoli */
.decoration.web {
  width: 110px; height: 110px; opacity: 0.5; filter: none;
}
.decoration.web.tl { top: 10px; left: 10px; animation: float 8s ease-in-out infinite; }
.decoration.web.tr { top: 10px; right: 10px; animation: float 9s ease-in-out infinite 1.5s; }
.decoration.web.bl { bottom: 10px; left: 10px; animation: float 7s ease-in-out infinite 2s; }
.decoration.web.br { bottom: 10px; right: 10px; animation: float 8.5s ease-in-out infinite 0.5s; }

/* Luna piena (angolo alto destra) */
.decoration.moon {
  width: 70px; height: 70px; border-radius: 50%;
  background: var(--moon); box-shadow: 0 0 30px var(--moon), 0 0 60px rgba(243,236,216,0.35);
  top: 20px; right: 20px; opacity: 0.9;
  animation: pulse-moon 5s ease-in-out infinite;
}

/* Scheletro / ossa che "escono" dallo schermo (bordo basso) */
.decoration.skeleton {
  width: 120px; height: 60px; opacity: 0.7;
  bottom: 0; left: 50%; transform: translateX(-50%);
  animation: float 5s ease-in-out infinite 1s;
}

/* Crepa che "buca" lo schermo (bordo sinistro) */
.decoration.crack {
  width: 60px; height: 140px; opacity: 0.55;
  left: 0; top: 35%;
  animation: crack-flicker 3s ease-in-out infinite;
}

/* Zucca grande che sporge dall'angolo in basso a destra */
.decoration.pumpkin.big {
  width: 110px; height: 110px; opacity: 0.9;
  bottom: 10px; right: 10px;
  animation: float 6s ease-in-out infinite 2s, spin 10s linear infinite;
}

@keyframes pulse-moon {
  0%, 100% { opacity: 0.9; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.05); }
}
@keyframes crack-flicker {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.03); }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---------- Voto: gallery partecipanti (blocco unico) ----------
   --gap: spazio tra le card; --pad: padding interno delle card.
   Le coppie/gruppi occupano due colonne e ogni metà è larga quanto una card singola. */
.gallery {
  --gap: 1rem;
  --pad: 0.65rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  grid-auto-flow: row dense;
  gap: var(--gap);
}
.participant {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: var(--pad);
  display: flex; flex-direction: column; align-items: center;
  transition: transform 0.2s, border-color 0.15s, box-shadow 0.2s;
}
.photo-wrap {
  position: relative; flex-shrink: 0;
  width: 100%; aspect-ratio: 4 / 5; border-radius: 12px;
  border: 2px solid var(--line); background: #0f0c14;
  overflow: hidden;
}
.participant .photo-wrap img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.participant .name {
  margin-top: 0.55rem; max-width: 100%;
  font-weight: 800; font-size: 0.92rem; line-height: 1.25;
  text-align: center; color: var(--ink); overflow-wrap: anywhere;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* Pulsanti categoria: colonna di righe uguali (icona + testo), sempre dentro la card */
.cat-group {
  margin-top: auto; padding-top: 0.6rem;
  width: 100%; display: flex; flex-direction: column; gap: 0.4rem;
}
.cat-btn {
  width: 100%; min-width: 0; min-height: 2.6rem; margin: 0;
  padding: 0.35rem 0.55rem;
  display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: 0.45rem;
  border-radius: 10px; border: 1px solid var(--line); background: #0f0c14; color: var(--muted);
  font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; text-align: left;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.cat-btn svg { width: 17px; height: 17px; flex: 0 0 17px; fill: currentColor; }
/* Icone a tratto: il CSS non deve riempirle */
.cat-btn svg[fill="none"] { fill: none; stroke: currentColor; }
.cat-btn span { min-width: 0; line-height: 1.15; overflow-wrap: anywhere; }
.cat-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cat-btn.selected {
  background: var(--accent); border-color: var(--accent); color: #111;
  box-shadow: 0 0 12px rgba(255, 157, 0, 0.5);
}

/* Hover solo con un puntatore vero: su touch l'hover "resta attaccato" dopo il tap */
@media (hover: hover) {
  .participant:not(.duo):hover,
  .duo:hover .duo-half, .duo:hover .duo-caption {
    border-color: var(--accent);
    box-shadow: 0 8px 20px rgba(255, 157, 0, 0.15);
  }
  .participant:hover { transform: translateY(-3px); }
  .cat-btn:hover { border-color: var(--accent); color: var(--ink); }
  .cat-btn.selected:hover { color: #111; }
}

/* ---------- Coppie e gruppi: due card unite con una cucitura al centro ---------- */
.participant.duo {
  grid-column: span 2;
  padding: 0; border: 0; background: none;
  align-items: stretch;
}
.duo-pair {
  position: relative; flex: 1;
  container-type: inline-size;
  display: grid; grid-template-columns: 1fr 1fr;
}
.duo-half {
  position: relative; min-width: 0;
  display: flex; flex-direction: column; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  padding: var(--pad);
  transition: border-color 0.15s, box-shadow 0.2s;
}
/* Il bordo verso il seam è trasparente e il padding verso il seam assorbe metà gap:
   così ogni metà ha la stessa area utile di una card singola */
.duo-half.left {
  border-radius: var(--radius) 0 0 0; border-right-color: transparent;
  padding-right: calc(var(--pad) + var(--gap) / 2);
}
.duo-half.right {
  border-radius: 0 var(--radius) 0 0; border-left-color: transparent;
  padding-left: calc(var(--pad) + var(--gap) / 2);
}
.duo-half .cat-group { padding-top: 1.5rem; } /* spazio per il cuore sul seam */

/* Una foto sola spezzata in due: metà sinistra a sinistra, metà destra a destra */
.photo-wrap.split img { width: 200%; object-position: center 35%; }
.duo-half.left .photo-wrap.split img { left: 0; right: auto; }
.duo-half.right .photo-wrap.split img { left: -100%; right: auto; }

/* Cucitura "Frankenstein": linea verticale con punti trasversali */
.duo-pair::before, .duo-pair::after {
  content: ''; position: absolute; top: 0.6rem; bottom: 0.6rem; left: 50%;
  transform: translateX(-50%); pointer-events: none; z-index: 1;
}
.duo-pair::before { width: 2px; background: var(--web); border-radius: 2px; }
.duo-pair::after {
  width: 12px; opacity: 0.85;
  background: repeating-linear-gradient(to bottom, transparent 0 9px, var(--web) 9px 11px);
}

/* Didascalia condivisa (nome + tipo): la "base" che tiene unite le due metà */
.duo-caption {
  display: flex; flex-direction: column; align-items: center;
  padding: 0.45rem var(--pad) var(--pad);
  background: var(--surface); border: 1px solid var(--line); border-top: 1px dashed var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  transition: border-color 0.15s, box-shadow 0.2s;
}
.duo-caption .name { margin-top: 0; }

/* Bottone rotondo "Miglior Coppia/Gruppo" a cavallo del seam, poco sopra il bordo basso delle foto.
   50cqw = larghezza di una metà: l'altezza della foto (aspect-ratio 4/5) si ricava da lì */
.cat-btn.heart-btn {
  position: absolute; z-index: 2;
  left: 50%;
  top: 48%; /* ripiego per browser senza container query */
  top: calc(var(--pad) + 1px + (50cqw - 2px - 2 * var(--pad) - var(--gap) / 2) * 1.25 - 6px);
  width: 3rem; height: 3rem; min-height: 0; padding: 0;
  justify-content: center; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: #0f0c14; border: 2px solid var(--accent); color: var(--accent);
  box-shadow: 0 0 0 4px var(--surface), 0 4px 14px rgba(0, 0, 0, 0.6);
}
.cat-btn.heart-btn svg { width: 26px; height: 26px; flex-basis: 26px; }
.cat-btn.heart-btn.selected {
  background: var(--accent); border-color: var(--accent); color: #111;
  box-shadow: 0 0 0 4px var(--surface), 0 0 20px rgba(255, 157, 0, 0.8);
}
.cat-btn.heart-btn.selected svg { stroke-width: 2.8; animation: heartbeat 1.4s ease-in-out infinite; }
@media (hover: hover) {
  .cat-btn.heart-btn:hover { color: var(--accent-hover); border-color: var(--accent-hover); transform: translate(-50%, -50%) scale(1.08); }
  .cat-btn.heart-btn.selected:hover { color: #111; }
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.15); }
  30% { transform: scale(1); }
  45% { transform: scale(1.1); }
}
@media (prefers-reduced-motion: reduce) {
  .cat-btn.heart-btn.selected svg { animation: none; }
}

/* ---------- Voto su telefono ---------- */
@media (max-width: 600px) {
  .vote-page .container { padding: 1rem; }
  .gallery {
    --gap: 0.75rem;
    --pad: 0.6rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Badge tipo partecipante (voto e admin) */
.tipo-badge {
  display: inline-block; font-size: 0.72rem; font-weight: 800;
  padding: 0.15rem 0.5rem; border-radius: 1rem; margin-top: 0.35rem;
  background: #1a1622; border: 1px solid var(--line); color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.tipo-badge.coppia, .tipo-badge.gruppo { color: var(--accent); border-color: var(--accent); }

/* ---------- Admin: modulo camera ---------- */
.camera-row {
  display: flex; gap: 1.2rem; align-items: flex-start; flex-wrap: wrap;
}
.camera-preview-wrap {
  position: relative; width: 340px; max-width: 100%;
  background: #0a080f; border: 2px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.camera-preview-wrap video {
  width: 100%; height: auto; display: block;
}
.camera-preview-wrap canvas { width: 100%; height: auto; display: block; }
.camera-empty {
  color: var(--muted); font-size: 0.9rem; text-align: center; padding: 1rem;
}
.camera-controls {
  display: flex; flex-direction: column; gap: 0.6rem; align-items: flex-start;
}
.camera-controls .btn { width: 100%; max-width: 220px; }
.camera-fields { display: flex; flex-direction: column; gap: 0.5rem; width: 100%; max-width: 260px; }
.camera-fields label { font-size: 0.85rem; }
.camera-hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem; }
.camera-status { min-height: 1.2rem; }

/* ---------- Admin: tabella partecipanti con tipo ---------- */
.tipo-badge { font-size: 0.7rem; }

