:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #e9edf3;
  --text: #1b2430;
  --text-muted: #6b7688;
  --border: #d8dee8;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --gold: #e0a32e;
  --danger: #d64545;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161b22;
    --surface: #1e242e;
    --surface-2: #262d39;
    --text: #e8ecf2;
    --text-muted: #98a2b3;
    --border: #333c4a;
    --accent: #4a86f7;
    --gold: #f0bc52;
    --danger: #f06767;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
}

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ---------- login ---------- */

#login { align-items: center; justify-content: center; padding: 24px; }

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 26px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-icon { font-size: 44px; line-height: 1; }
.login-box h1 { margin: 12px 0 6px; font-size: 1.5rem; }
.muted { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 20px; }

/* ---------- struttura ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content {
  flex: 1;
  padding: 16px 14px calc(24px + env(safe-area-inset-bottom));
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- controlli ---------- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 14px;
  transition: opacity 0.15s ease;
}

button:active { opacity: 0.7; }

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 600;
}

button.big { padding: 15px; font-size: 1.02rem; width: 100%; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 6px 10px;
  color: var(--text-muted);
}

input, select {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.error { color: var(--danger); font-size: 0.88rem; margin: 0 0 12px; }

label.field { display: block; font-size: 0.88rem; color: var(--text-muted); margin-bottom: 5px; }

label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 0.95rem;
}

label.check input { width: auto; margin: 0; }

/* ---------- lista partite ---------- */

#games { display: flex; flex-direction: column; gap: 10px; }

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-card .info { flex: 1; min-width: 0; }
.game-card .name { font-weight: 600; margin-bottom: 3px; }
.game-card .meta { font-size: 0.85rem; color: var(--text-muted); }
.game-card .chevron { color: var(--text-muted); font-size: 1.3rem; }

.empty { text-align: center; color: var(--text-muted); padding: 36px 12px; }

/* ---------- classifica ---------- */

#standings { display: flex; flex-direction: column; gap: 8px; }

.stand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 15px;
}

.stand-row.leader { border-color: var(--gold); }
.stand-row.out { opacity: 0.5; }

.stand-row .pos {
  width: 26px;
  text-align: center;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.stand-row.leader .pos { color: var(--gold); }
.stand-row .who { flex: 1; min-width: 0; }
.stand-row .who .n { font-weight: 600; }
.stand-row .who .t { font-size: 0.8rem; color: var(--text-muted); }
.stand-row .pts { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- tabella punteggi ---------- */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#score-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }

#score-table th, #score-table td {
  padding: 11px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#score-table thead th {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface);
}

#score-table .rlabel { text-align: left; color: var(--text-muted); font-size: 0.85rem; }
#score-table td.cell { cursor: pointer; min-width: 58px; }
#score-table tfoot td { font-weight: 700; border-bottom: none; background: var(--surface-2); }
#score-table tfoot .rlabel { color: var(--text); }

/* ---------- modale ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

@media (min-width: 560px) { .modal { align-items: center; padding: 20px; } }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 440px;
  max-height: 88dvh;
  overflow-y: auto;
}

@media (min-width: 560px) { .modal-box { border-radius: var(--radius); } }

.modal-box h2 { margin: 0 0 16px; font-size: 1.15rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button { flex: 1; padding: 13px; }

.row-input { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.row-input .who { flex: 1; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.row-input input { width: 92px; margin: 0; text-align: center; }

.player-edit { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.player-edit input { margin: 0; }
.player-edit select { margin: 0; width: auto; flex-shrink: 0; }

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 15px 4px;
}

.menu-item:last-child { border-bottom: none; }
