/* ============================================================
   Conta Vite — foglio di stile unico
   Mobile-first, pulsanti grandi, stati ben distinti.
   ============================================================ */

:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;

  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --plus: #16a34a;
  --plus-soft: #dcfce7;
  --minus: #dc2626;
  --minus-soft: #fee2e2;
  --danger: #dc2626;

  --winner: #d4af37;
  --winner-bg: #fffbeb;
  --eliminated-bg: #f1f3f5;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.14);

  --tap: 56px; /* dimensione minima area tattile */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  padding: max(env(safe-area-inset-top), 0px) 0 max(env(safe-area-inset-bottom), 16px);
}

/* ---------------- Header ---------------- */
.app-header {
  text-align: center;
  padding: 18px 16px 6px;
}
.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}
.app-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px 32px;
}

.screen[hidden] { display: none; }

/* ---------------- Pulsanti generici ---------------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-height: var(--tap);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: transform 0.05s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.btn-block { width: 100%; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: #f8fafc; }

.btn-danger {
  background: var(--minus-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fecaca; }

/* ---------------- Configurazione ---------------- */
.config-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  max-width: 440px;
  margin: 24px auto 0;
}
.config-card h2 { margin: 0 0 16px; font-size: 1.3rem; }

.form-row { margin-bottom: 18px; display: flex; flex-direction: column; }
.form-row label { font-weight: 600; margin-bottom: 6px; }
.form-row input {
  font: inherit;
  font-size: 1.2rem;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  min-height: var(--tap);
}
.form-row input:focus-visible { outline: 3px solid var(--primary); outline-offset: 1px; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }

.form-error {
  background: var(--minus-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 0.9rem;
}

.config-secondary {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.config-secondary p { color: var(--muted); margin: 0 0 10px; font-size: 0.9rem; }

/* ---------------- Banner & vincitore ---------------- */
.banner {
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  text-align: center;
}

.winner-banner {
  background: linear-gradient(135deg, #fef9c3, #fde68a);
  color: #854d0e;
  border: 2px solid var(--winner);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow);
}

/* ---------------- Toolbar ---------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.toolbar .btn { flex: 1 1 auto; min-width: 120px; font-size: 0.95rem; }
.toolbar .btn-danger { flex: 1 1 100%; }

/* ---------------- Griglia giocatori ---------------- */
.players-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.player-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: opacity 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.player-name {
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  border: 1px dashed transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: #f8fafc;
  color: var(--text);
  width: 100%;
  min-height: 48px;
}
.player-name:hover { border-color: var(--border); }
.player-name:focus-visible { outline: 3px solid var(--primary); outline-offset: 1px; background: #fff; }

.player-status {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--plus);
  text-align: center;
}

.player-lives {
  font-size: 3.6rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.player-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-life {
  font-size: 1.7rem;
  font-weight: 800;
  min-height: 68px;
  border-radius: var(--radius);
}
.btn-minus { background: var(--minus-soft); color: var(--minus); }
.btn-minus:hover { background: #fecaca; }
.btn-plus  { background: var(--plus-soft); color: var(--plus); }
.btn-plus:hover  { background: #bbf7d0; }

/* --- Stato: attivo (default sopra) --- */
.player-card.active { border-color: var(--border); }

/* --- Stato: eliminato --- */
.player-card.eliminated {
  background: var(--eliminated-bg);
  border-color: #e2e8f0;
  opacity: 0.72;
}
.player-card.eliminated .player-status { color: var(--minus); }
.player-card.eliminated .player-lives { color: var(--muted); }

/* --- Stato: vincitore --- */
.player-card.winner {
  border-color: var(--winner);
  background: var(--winner-bg);
  box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.25), var(--shadow-lg);
  opacity: 1;
}
.player-card.winner .player-status { color: #b45309; }
.player-card.winner .player-lives { color: #b45309; }

/* ---------------- Cronologia ---------------- */
.history {
  margin-top: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.history h2 { margin: 0 0 10px; font-size: 1.1rem; }
.history-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.history-list li { font-size: 0.92rem; color: var(--text); }
.history-list .history-empty { list-style: none; margin-left: -20px; color: var(--muted); font-style: italic; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   Responsive: tablet e desktop -> griglia a piu colonne
   ============================================================ */
@media (min-width: 560px) {
  .players-grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar .btn-danger { flex: 1 1 auto; }
}

@media (min-width: 900px) {
  .players-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1200px) {
  .players-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
