:root {
  --bg: #0a1020;
  --bg-2: #0f1830;
  --surface: #141f3a;
  --surface-2: #1b2848;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f4f6fb;
  --muted: #95a1bd;
  --beer: #fbbf24;
  --beer-deep: #f59e0b;
  --foam: #fff7e0;
  --live: #4ade80;
  --danger: #f43f5e;
  --versus: #fb7185;
  --info: #60a5fa;
  --radius: 16px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-score: "Anton", "Bebas Neue", Impact, "Arial Narrow", sans-serif;
  /* Titoli: sans-serif grassetto, maiuscole e minuscole normali */
  --font-title: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(120% 80% at 50% -10%, #1a2a55 0%, var(--bg) 60%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.45;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; -webkit-tap-highlight-color: transparent; }
a { color: var(--beer); }
[hidden] { display: none !important; }

.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 680px; }

/* --- Barra di navigazione --- */
.nav { position: sticky; top: 0; z-index: 20; background: rgba(10, 16, 32, 0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.nav .wrap { display: flex; align-items: center; gap: 16px; height: 56px; }
.nav .brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-family: var(--font-title); font-weight: 800; letter-spacing: -0.02em; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.nav .brand .brand-logo { height: 36px; width: auto; flex-shrink: 0; }
.nav .brand span { min-width: 0; }
@media (max-width: 480px) {
  .nav.many .brand span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
.nav .links { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav .links::-webkit-scrollbar { display: none; }
.nav .links a { color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; padding: 8px 10px; border-radius: 10px; white-space: nowrap; }
.nav .links a:hover, .nav .links a.on { color: var(--text); background: var(--surface); }

.foot { margin: 48px 0 24px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; }
.foot a { color: var(--muted); }

/* --- Tipografia --- */
.score { font-family: var(--font-score); font-weight: 400; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
h1.big { font-family: var(--font-title); font-weight: 800; letter-spacing: -0.02em; line-height: 1.08; font-size: clamp(30px, 6vw, 52px); }
h2.sec { font-family: var(--font-title); font-weight: 800; letter-spacing: -0.02em; font-size: 19px; color: var(--text); margin: 32px 0 12px; display: flex; align-items: center; gap: 10px; }
h2.sec .more { margin-left: auto; letter-spacing: 0; font-weight: 600; font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* --- Contenitori --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap-ok { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Pill di stato --- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.live { color: #052e14; background: var(--live); }
.pill.upcoming { color: #0b1d3a; background: var(--info); }
.pill.closed { color: var(--muted); }
.pill.draft { color: var(--beer); border: 1px dashed var(--beer); background: transparent; }
.pill.final { background: var(--surface-2); color: var(--text); }

.live-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); animation: live 2s infinite; flex-shrink: 0; }
.offline .live-dot { background: var(--danger); animation: none; }
@keyframes live {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
  70% { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.avatar { flex-shrink: 0; border-radius: 50%; background: var(--team, var(--surface-2)) center / cover no-repeat; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; overflow: hidden; width: 40px; height: 40px; font-size: 14px; }

/* --- Form e pulsanti --- */
input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], input[type=date], input[type=time], input[type=search], input:not([type]), textarea, select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; font-size: 16px; outline: none;
}
/* Icone del calendario e dell'orologio chiare sul fondo scuro */
input[type=datetime-local], input[type=date], input[type=time] { color-scheme: dark; }
input:focus, textarea:focus, select:focus { border-color: var(--beer); }
textarea { resize: vertical; min-height: 80px; }
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text); cursor: pointer; }
label.check input { width: 20px; height: 20px; accent-color: var(--beer); flex-shrink: 0; }
.form { display: flex; flex-direction: column; gap: 12px; }
.inline { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.inline > input, .inline > select { flex: 1 1 160px; min-width: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--beer); color: #1a1205; font-weight: 800; padding: 11px 16px; border-radius: 12px; font-size: 15px; white-space: nowrap; text-decoration: none; }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 10px; }
.btn.dark { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:active:not(:disabled) { transform: scale(0.97); }

/* --- Tab --- */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); margin: 16px 0; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .tabs a { padding: 10px 14px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; font-size: 15px; }
.tabs .on { color: var(--text); border-bottom-color: var(--beer); }
.tabs .badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }

/* --- Tabelle --- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 6px; border-bottom: 1px solid var(--line); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* --- Contenuti markdown --- */
.prose { line-height: 1.65; overflow-wrap: anywhere; }
.prose > * + * { margin-top: 0.8em; }
.prose h1, .prose h2, .prose h3 { line-height: 1.2; margin-top: 1.2em; }
.prose h1 { font-size: 1.6em; }
.prose h2 { font-size: 1.3em; }
.prose h3 { font-size: 1.1em; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose img { max-width: 100%; border-radius: 12px; }
.prose blockquote { border-left: 3px solid var(--beer); padding-left: 12px; color: var(--muted); }
.prose code { background: var(--bg-2); padding: 2px 6px; border-radius: 6px; font-size: 0.9em; }
.prose table { border-collapse: collapse; }
.prose td, .prose th { border: 1px solid var(--line); padding: 6px 10px; }

/* --- Partite --- */
.match { display: grid; grid-template-columns: minmax(0, 1fr) minmax(88px, 36%) minmax(0, 1fr); align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.match.live { border-color: rgba(74, 222, 128, 0.5); box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.2); }
.match .side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.match .side.away { flex-direction: row-reverse; text-align: right; }
.match .side .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .side.win .nm { color: var(--beer); }
.match .mid { text-align: center; min-width: 92px; }
.match .mid .sc { font-family: var(--font-score); font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.match .mid .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
@media (max-width: 480px) {
  .match .side, .match .side.away { flex-direction: column; text-align: center; gap: 4px; }
  .match .side .nm { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 14px; line-height: 1.2; }
}
.match .mlabel { grid-column: 1 / -1; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: -4px; }
.match .mid .meta.live { color: var(--live); font-weight: 800; }
.match-head { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; margin: 14px 2px 6px; }

.match .side.tbd .nm { color: var(--muted); font-weight: 600; font-style: italic; }
select.filter { margin: 4px 0 4px; }

/* --- Classifiche e tabellone --- */
.table.standings td, .table.standings th { padding-left: 5px; padding-right: 5px; }
@media (max-width: 480px) { .xs-hide { display: none; } .table.standings .avatar { display: none; } }
.bracket { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; }
.br-col { display: flex; flex-direction: column; justify-content: space-around; gap: 10px; min-width: 190px; flex: 1; }
.br-head { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.br-match { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.br-match.live { border-color: rgba(74, 222, 128, 0.6); }
.br-label { font-size: 11px; color: var(--muted); font-weight: 700; }
.br-team { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 14px; min-width: 0; }
.br-team.win { color: var(--beer); }
.br-team.tbd { color: var(--muted); font-weight: 600; font-style: italic; font-size: 13px; }
.br-team b { font-family: var(--font-score); font-weight: 400; font-size: 18px; }
@media (max-width: 560px) { .bracket { flex-direction: column; overflow: visible; } .br-col { min-width: 0; } }

/* --- Sfide --- */
.ch { background: linear-gradient(90deg, rgba(244, 63, 94, 0.18), var(--surface) 40%, var(--surface) 60%, rgba(244, 63, 94, 0.18)); border: 1px solid rgba(244, 63, 94, 0.4); border-radius: var(--radius); padding: 12px 14px; }
.ch.done { background: linear-gradient(90deg, rgba(251, 191, 36, 0.2), var(--surface)); border-color: rgba(251, 191, 36, 0.45); }
.ch .head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 800; color: var(--versus); text-transform: uppercase; letter-spacing: 0.06em; }
.ch.done .head { color: var(--beer); }
.ch .head .time { font-variant-numeric: tabular-nums; color: var(--text); }
.ch .vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 8px; }
.ch .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ch .side.b { flex-direction: row-reverse; text-align: right; }
.ch .side .avatar { width: 34px; height: 34px; font-size: 13px; }
.ch .side .nm { font-weight: 800; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch .pts { font-family: var(--font-score); font-size: 30px; color: var(--beer); display: flex; gap: 10px; align-items: baseline; }
.ch .pts small { font-family: var(--font-ui); font-size: 12px; color: var(--muted); font-weight: 800; }

.ch-tools { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.ch-beers { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }

/* --- Squadra: scheda pubblica, inquadratura foto, editor --- */
.sheet-head { height: 150px; border-radius: 14px; background: var(--team) center / cover no-repeat; }
.frame-stage { position: relative; align-self: center; touch-action: none; cursor: crosshair; line-height: 0; }
.frame-img { display: block; max-width: 100%; max-height: 48vh; border-radius: 12px; -webkit-user-select: none; user-select: none; }
.frame-dot { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.55), inset 0 0 0 2px rgba(0, 0, 0, 0.35); pointer-events: none; }
.frame-prevs { display: flex; gap: 14px; justify-content: center; align-items: flex-end; flex-wrap: wrap; }
.frame-p { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.frame-prev { background-size: cover; background-repeat: no-repeat; border: 1px solid var(--line); }
.frame-prev.round { width: 64px; height: 64px; border-radius: 50%; }
.frame-prev.wide { width: 120px; height: 78px; border-radius: 12px; }
.frame-prev.tall { width: 66px; height: 80px; border-radius: 10px; }
.team-ed-preview { display: flex; align-items: center; gap: 14px; }
.team-ed-card { flex: 1; min-width: 0; height: 84px; border-radius: 14px; background: var(--team) center / cover no-repeat; display: flex; align-items: flex-end; padding: 10px 12px; position: relative; overflow: hidden; }
.team-ed-card b { position: relative; font-size: 18px; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-ed-color { width: 48px; height: 40px; padding: 2px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); flex-shrink: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25); }
.pl-row { display: grid; grid-template-columns: 58px 1fr 1fr auto; gap: 6px; align-items: center; }
.pl-row input { padding: 9px 10px; }
@media (max-width: 480px) { .pl-row { grid-template-columns: 52px 1fr auto; } .pl-row .pl-role { grid-column: 2 / 3; grid-row: 2; } }

/* --- Copertina e locandina del torneo --- */
.cover { display: block; width: 100%; margin-top: 16px; padding: 0; border-radius: 18px; overflow: hidden; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45); }
.cover img { display: block; width: 100%; max-height: 380px; object-fit: cover; }
.poster-full { display: block; max-width: 100%; max-height: 74vh; margin: 0 auto; border-radius: 10px; }

/* --- Notifiche --- */
.toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(92vw, 440px); pointer-events: none; }
.toast-msg { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--beer); padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); font-weight: 600; animation: toast-in 0.25s ease-out; transition: opacity 0.4s, transform 0.4s; }
.toast-msg.error { border-left-color: var(--danger); }
.toast-msg.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* --- Finestra modale --- */
.modal-back { position: fixed; inset: 0; background: rgba(3, 6, 15, 0.7); z-index: 60; display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
.modal h3 { font-size: 18px; margin-bottom: 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@media (min-width: 640px) { .modal-back { align-items: center; } }
