:root {
  --bg: #0b0f1a;
  --bg-2: #121829;
  --card: #161d31;
  --line: #26304a;
  --text: #e7ecf5;
  --muted: #8b97b3;
  --accent: #4f8cff;
  --accent-2: #22d3a6;
  --danger: #ff5d6c;
  --bonus: #22c55e;
  --malus: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1a2440 0%, var(--bg) 55%);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 26, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { color: var(--text); font-weight: 700; letter-spacing: 0.3px; display: inline-flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 13px;
}
nav { display: flex; align-items: center; gap: 18px; }
nav a { color: var(--muted); font-weight: 500; }
nav a:hover { color: var(--text); text-decoration: none; }
/* Il form di logout non deve influire sul layout: il bottone "Esci" si allinea
   come gli altri link della nav (desktop e, con stretch, nel menu mobile). */
.topbar nav form.inline { display: contents; }
.topbar nav .linklike { font-weight: 500; }
.btn-nav {
  background: var(--accent);
  color: #061225 !important;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
}
.btn-nav:hover { text-decoration: none; filter: brightness(1.08); }

main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 28px 22px 60px; }

footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  padding: 18px;
  font-size: 13px;
}

/* ---- Hero / home ---- */
.hero { text-align: center; padding: 40px 0 30px; }
.hero h1 { font-size: 42px; margin: 0 0 12px; background: linear-gradient(135deg, #fff, #9fc0ff); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.lead { color: var(--muted); font-size: 18px; max-width: 620px; margin: 0 auto 26px; }
.cta-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 40px; }
.how .card h3 { margin: 0 0 6px; }
.how .card p { color: var(--muted); margin: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #061225;
  border: none;
  padding: 11px 20px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.linklike { background: none; border: none; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.linklike:hover { color: var(--text); text-decoration: underline; }
.linklike.danger { color: var(--danger); }
.inline { display: inline; }

/* ---- Cards / forms ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.narrow { max-width: 420px; margin: 20px auto; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
input, select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 9px;
  font: inherit;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

h1 { font-size: 28px; margin-top: 0; }

/* ---- Flash ---- */
.flash { padding: 12px 14px; border-radius: 9px; margin: 12px 0; font-size: 14px; }
.flash-error { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.4); color: #ffb4bb; }
.flash-ok { background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.4); color: #a7f3c9; }

/* ---- Venue grid ---- */
.venue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 8px 0 18px; }
.venue {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 10px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}
.venue:hover { border-color: var(--accent); }
.venue.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; background: #16203a; }
.venue input { position: absolute; top: 8px; left: 8px; width: 18px; height: 18px; accent-color: var(--accent); }
.venue-logo { width: 56px; height: 56px; object-fit: contain; border-radius: 8px; background: #fff; padding: 4px; }
.venue-name { font-size: 13px; line-height: 1.3; }
#counter { font-weight: 700; }
#counter.ok { color: var(--bonus); }
#counter.over { color: var(--malus); }

.own-venue {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-2);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 14px;
}

/* ---- Tables ---- */
.board { width: 100%; border-collapse: collapse; margin-top: 10px; }
.board th, .board td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.board th { color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; }
.board .num { text-align: right; }
.board tr.me { background: rgba(79, 140, 255, 0.08); }
.rank { font-weight: 700; color: var(--muted); }
.score { font-weight: 800; font-size: 16px; }
.pos { color: var(--bonus); }
.neg { color: var(--malus); }
.team-cell { display: flex; flex-direction: column; }
.mini-logos { display: flex; gap: 4px; flex-wrap: wrap; }
.mini-logo { width: 26px; height: 26px; object-fit: contain; border-radius: 5px; background: #fff; padding: 2px; }

/* ---- Admin ---- */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 16px 0 30px; }
@media (max-width: 760px) { .admin-grid { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
legend { color: var(--muted); padding: 0 6px; font-size: 13px; }
.rule-list { display: flex; flex-direction: column; gap: 8px; }
.rule {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  cursor: pointer;
}
.rule input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.rule-desc { font-size: 14px; line-height: 1.4; }
.rule-pts { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rule.bonus .rule-pts { color: var(--bonus); }
.rule.malus .rule-pts { color: var(--malus); }
/* Evidenzia chiaramente la regola selezionata (utile su smartphone) */
.rule.bonus:has(input:checked) { border-color: var(--bonus); box-shadow: 0 0 0 1px var(--bonus) inset; background: rgba(34, 197, 94, 0.1); }
.rule.malus:has(input:checked) { border-color: var(--malus); box-shadow: 0 0 0 1px var(--malus) inset; background: rgba(239, 68, 68, 0.1); }

/* ---- Wizard admin: registra evento (tastoni) ---- */
.wizard-title { margin: 4px 0 2px; }
.wizard-chosen {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.rule-section-title { font-weight: 700; margin: 16px 0 6px; }
.rule-section-title.bonus { color: var(--bonus); }
.rule-section-title.malus { color: var(--malus); }

.tap-grid { display: grid; gap: 10px; margin: 10px 0 8px; }
.tap-grid.unis { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.tap-grid.rules { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.tapbtn {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-2);
  cursor: pointer;
}
.tapbtn input { position: absolute; opacity: 0; width: 0; height: 0; }
/* Sedi: solo nome, tastoni centrati */
.tap-grid.unis .tapbtn { align-items: center; text-align: center; justify-content: center; min-height: 64px; }
.tap-grid.unis .tapbtn-name { font-weight: 600; }
.tapbtn-logo { width: 48px; height: 48px; object-fit: contain; background: #fff; border-radius: 8px; padding: 4px; }
.tapbtn-name { font-size: 13px; line-height: 1.3; }
/* Regole: punti grandi + descrizione */
.tap-grid.rules .tapbtn { min-height: 88px; }
.tapbtn-pts { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.tapbtn-desc { font-size: 13px; line-height: 1.35; }
.tap-bonus .tapbtn-pts { color: var(--bonus); }
.tap-malus .tapbtn-pts { color: var(--malus); }

/* Stato selezionato ben visibile */
.tapbtn:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.tap-bonus:has(input:checked) { border-color: var(--bonus); box-shadow: 0 0 0 2px var(--bonus) inset; background: rgba(34, 197, 94, 0.1); }
.tap-malus:has(input:checked) { border-color: var(--malus); box-shadow: 0 0 0 2px var(--malus) inset; background: rgba(239, 68, 68, 0.1); }

.btn-big { width: 100%; padding: 15px; font-size: 16px; margin-top: 10px; }

/* ---- Standings / dettaglio università ---- */
.uni-link { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 500; }
.uni-link:hover { color: var(--accent); text-decoration: none; }
.uni-link .mini-logo { width: 30px; height: 30px; }
.uni-header { display: flex; align-items: center; gap: 16px; margin: 14px 0 22px; }
.uni-header-logo { width: 72px; height: 72px; object-fit: contain; background: #fff; border-radius: 10px; padding: 6px; flex: none; }
.uni-header h1 { margin: 0; }
.uni-total { font-weight: 800; font-size: 20px; margin-top: 4px; }
.event-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.event-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.event-item.bonus { border-left: 3px solid var(--bonus); }
.event-item.malus { border-left: 3px solid var(--malus); }
.event-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.event-desc { font-size: 14px; line-height: 1.4; }
.event-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; white-space: nowrap; flex: none; }
.event-pts { font-weight: 800; font-size: 16px; }

/* ---- Regolamento ---- */
.steps { counter-reset: step; list-style: none; margin: 20px 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.steps li {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 14px 54px;
  line-height: 1.5;
}
.steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 14px;
  top: 14px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a;
  font-weight: 800;
  display: grid;
  place-items: center;
  font-size: 14px;
}
.callout {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 16px 0;
}
.callout h3 { margin: 0 0 6px; }
.callout p { margin: 0; color: var(--text); line-height: 1.55; }

/* ---- Regole pubbliche ---- */
.rules-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 18px; }
@media (max-width: 760px) { .rules-cols { grid-template-columns: 1fr; } }
.rules-cols h3 { margin: 0 0 10px; }
.rule-public-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rule-public {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}
.rule-public.bonus { border-left: 3px solid var(--bonus); }
.rule-public.malus { border-left: 3px solid var(--malus); }
.rule-public .rule-desc { font-size: 14px; line-height: 1.4; }
.rule-public .rule-pts { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rule-public.bonus .rule-pts { color: var(--bonus); }
.rule-public.malus .rule-pts { color: var(--malus); }

.rename-form { display: flex; gap: 6px; align-items: center; }
.rename-form input[type="text"] { min-width: 120px; padding: 6px 8px; font-size: 14px; }
.btn-mini {
  background: var(--accent);
  color: #061225;
  border: none;
  padding: 6px 10px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-mini:hover { filter: brightness(1.08); }

.badge-admin {
  display: inline-block;
  background: rgba(79, 140, 255, 0.15);
  border: 1px solid rgba(79, 140, 255, 0.5);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ---- Tabelle scrollabili su mobile ---- */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* =========================================================
   RESPONSIVE — smartphone
   ========================================================= */
@media (max-width: 640px) {
  main { padding: 18px 14px 48px; }

  /* Topbar: brand sopra, nav che va a capo sotto */
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px 10px; }
  .brand { font-size: 15px; }
  nav {
    width: 100%;
    gap: 6px 14px;
    flex-wrap: wrap;
    justify-content: flex-start;
    row-gap: 6px;
  }
  nav a { font-size: 14px; }
  .btn-nav { padding: 6px 12px; }

  /* Hero */
  .hero { padding: 24px 0 18px; }
  .hero h1 { font-size: 32px; }
  .lead { font-size: 16px; }
  .cta-row { gap: 10px; }
  .btn { padding: 11px 18px; }

  h1 { font-size: 24px; }

  /* Griglia sedi: più colonne strette, loghi più piccoli */
  .venue-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .venue { padding: 12px 6px; }
  .venue-logo { width: 46px; height: 46px; }
  .venue-name { font-size: 12px; }
  .venue input { width: 16px; height: 16px; top: 6px; left: 6px; }

  /* Tabelle: padding ridotto, non vanno a capo (scroll orizzontale via wrapper) */
  .board { font-size: 14px; }
  .board th, .board td { padding: 8px 8px; }
  .board th { font-size: 11px; }
  .mini-logo { width: 22px; height: 22px; }
  .score { font-size: 15px; }

  /* Regolamento */
  .steps li { padding: 12px 14px 12px 46px; }
  .steps li::before { left: 12px; top: 12px; width: 24px; height: 24px; }
  .callout { padding: 14px 14px; }

  /* Form auth più compatti */
  .narrow { margin: 8px auto; }
}

/* Schermi molto stretti */
@media (max-width: 360px) {
  .venue-grid { grid-template-columns: repeat(2, 1fr); }
  nav { gap: 6px 10px; }
  nav a { font-size: 13px; }
}

/* ---- Hamburger menu (mobile) ---- */
.nav-burger { display: none; }

@media (max-width: 640px) {
  .nav-burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    margin-left: auto;
    width: 44px;
    height: 40px;
    padding: 10px 9px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--bg-2);
    cursor: pointer;
  }
  .nav-burger span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
  }

  /* Nav a tendina: nascosta finché non si apre il menu */
  .topbar nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    margin-top: 8px;
  }
  .nav-toggle:checked ~ nav { display: flex; }

  .topbar nav a {
    display: block;
    width: 100%;
    margin: 0;
  }
  .topbar nav a,
  .topbar nav .linklike {
    padding: 13px 12px;
    border-radius: 8px;
    font-size: 16px;
    text-align: left;
  }
  .topbar nav a:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
  .topbar nav .linklike { width: 100%; }
  .topbar nav .btn-nav { background: var(--accent); color: #061225 !important; text-align: center; }

  /* Icona -> X quando aperto */
  .nav-toggle:checked ~ .nav-burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle:checked ~ .nav-burger span:nth-child(2) { opacity: 0; }
  .nav-toggle:checked ~ .nav-burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
}
