@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Nunito:wght@400;500;600;700;800&display=swap');

/* =========================================================
   Olimpiadi Verdiane — Design System
   Stile: minimal pulito · base grigia + accento blu
   Font: Fredoka / Nunito
   NB: i nomi --rose-* sono mantenuti per comodità ma ora
       valgono la scala neutra (50-300) e l'accento blu (400-700).
   ========================================================= */
:root {
    /* Scala neutra (grigi) */
    --rose-50:  #f1f5f9;   /* sfondi/hover chiarissimi */
    --rose-100: #e2e8f0;   /* tracce barre, righe tabella, bordi tenui */
    --rose-200: #cbd5e1;   /* bordi input e controlli */
    --rose-300: #94a3b8;
    /* Scala accento (blu) */
    --rose-400: #60a5fa;
    --rose-500: #3b82f6;
    --rose-600: #2563eb;   /* primario */
    --rose-700: #1d4ed8;
    --rose-900: #1e293b;   /* slate scuro per i titoli */
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --amber-400:#fbbf24;

    /* Token semantici */
    --primary:      var(--rose-600);
    --primary-700:  var(--rose-700);
    --accent:       #0ea5e9;
    --surface:      #ffffff;
    --surface-2:    #f1f5f9;
    --ink:          #1e293b;   /* testo principale (slate, AA su bianco) */
    --ink-soft:     #475569;   /* testo secondario */
    --muted:        #94a3b8;
    --line:         #e2e8f0;
    --ok:           #16a34a;
    --err:          #dc2626;

    /* Forma & profondità */
    --r-sm: 12px;
    --r:    18px;
    --r-lg: 26px;
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, .06);
    --shadow:    0 14px 36px rgba(15, 23, 42, .12);
    --shadow-lg: 0 24px 60px rgba(15, 23, 42, .16);

    /* Motion */
    --ease: cubic-bezier(.22, 1, .36, 1);
    --dur: 220ms;

    --space: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: 'Nunito', system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, legend, .brand, .kpi-num, .rank-pos {
    font-family: 'Fredoka', sans-serif;
    letter-spacing: -.01em;
}

/* ----- Sfondo grigio chiaro con bagliori tenui ----- */
.bg-fun {
    position: relative;
    min-height: 100dvh;
    background: #e8eef7; /* fallback */
    overflow-x: hidden;
}
/* Sfumatura grigio→blu, ancorata alla viewport (funziona anche su iOS) */
.bg-fun::before {
    content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background: linear-gradient(165deg, #f8fafc 0%, #e8eef7 45%, #d3e1f5 100%);
}
/* Bagliori tenui sopra la sfumatura */
.bg-fun::after {
    content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background:
        radial-gradient(340px 340px at calc(100% + 70px) -70px, rgba(147, 197, 253, .35), transparent 70%),
        radial-gradient(380px 380px at -90px calc(100% + 90px), rgba(148, 163, 184, .30), transparent 70%);
}

/* ----- Layout ----- */
.container { position: relative; z-index: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 20px 16px 40px; }
.container.narrow { max-width: 520px; }
.center-screen { min-height: 100dvh; display: flex; align-items: center; }
.center { text-align: center; }

/* Header sticky unico (topbar + subnav restano sempre allineate) */
.stickyhead { position: sticky; top: 0; z-index: 30; }
.stickyhead .topbar, .stickyhead .subnav { position: static; top: auto; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    padding-top: calc(14px + env(safe-area-inset-top));
    color: #fff;
    background: linear-gradient(120deg, #2563eb, #1d4ed8);
}
.stickyhead { box-shadow: 0 6px 20px rgba(15, 23, 42, .12); }
.topbar .brand { font-size: 1.15rem; font-weight: 700; white-space: nowrap; }
.topbar nav { display: flex; gap: 8px; flex: none; }
.topbar nav a {
    color: #fff; text-decoration: none; font-weight: 700; font-size: .92rem;
    padding: 8px 14px; border-radius: 999px; white-space: nowrap;
    background: rgba(255, 255, 255, .16);
    transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
/* Schermi stretti: header compatto, tutto su una riga */
@media (max-width: 480px) {
    .topbar { padding-left: 14px; padding-right: 14px; gap: 8px; }
    .topbar .brand { font-size: .98rem; }
    .topbar nav { gap: 6px; }
    .topbar nav a { padding: 7px 11px; font-size: .8rem; }
}
.topbar nav a:hover { background: rgba(255, 255, 255, .28); }
.topbar nav a:active { transform: scale(.96); }
.topbar nav a.muted { background: transparent; opacity: .85; }
.topbar nav a.muted:hover { background: rgba(255, 255, 255, .16); opacity: 1; }

.page-title {
    color: var(--ink); text-align: center; font-weight: 700;
    font-size: clamp(1.9rem, 8vw, 2.8rem); line-height: 1.1;
    margin: 22px 0 26px;
}

/* ----- Card ----- */
.card {
    position: relative; z-index: 1;
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    padding: 22px;
    margin-bottom: 18px;
}
.card h2 {
    margin: 0 0 16px; font-size: 1.2rem; font-weight: 600; color: var(--rose-900);
    display: flex; align-items: center; gap: 8px;
}

.grid-2 { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ----- Login ----- */
.login-card { text-align: center; width: 100%; padding: 34px 26px; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); }
.login-card .logo {
    width: 78px; height: 78px; margin: 0 auto 14px; display: grid; place-items: center;
    font-size: 2.4rem; border-radius: 22px;
    background: linear-gradient(150deg, var(--rose-400), var(--rose-600));
    box-shadow: var(--shadow);
}
.login-card h1 { margin: 4px 0 2px; font-size: 1.7rem; font-weight: 700; color: var(--rose-900); }

/* ----- KPI ----- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi {
    background: var(--surface); border-radius: var(--r);
    padding: 18px 14px; text-align: center; box-shadow: var(--shadow-sm);
    border: 1px solid var(--rose-100);
    transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.kpi-num {
    display: block; font-size: 2.3rem; font-weight: 700; line-height: 1;
    font-variant-numeric: tabular-nums;
    background: linear-gradient(150deg, var(--rose-500), var(--rose-700));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.kpi-lbl { display: block; font-size: .82rem; font-weight: 700; color: var(--ink-soft); margin-top: 6px; }

/* ----- Form ----- */
.block { border: none; padding: 0; margin: 0 0 26px; }
.block:last-of-type { margin-bottom: 8px; }
.block legend { font-size: 1.1rem; font-weight: 600; color: var(--rose-900); padding: 0; margin-bottom: 12px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .88rem; font-weight: 700; color: var(--ink-soft); margin-bottom: 7px; }
.field input[type=text],
.field input[type=password],
.combo input[type=text] {
    width: 100%; min-height: 52px; padding: 14px 16px;
    font: inherit; font-size: 1rem; color: var(--ink);
    border: 2px solid var(--line); border-radius: var(--r-sm);
    background: var(--surface-2); -webkit-appearance: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.field input::placeholder, .combo input::placeholder { color: var(--muted); }
.field input:focus, .combo input[type=text]:focus {
    outline: none; background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--rose-100);
}
.field input:disabled { opacity: .5; cursor: not-allowed; }

/* Segmented control (uomo/donna) */
.segmented {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    padding: 6px; background: var(--surface-2); border-radius: var(--r);
    border: 1px solid var(--line);
}
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmented label {
    min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 8px;
    border-radius: var(--r-sm); font-weight: 700; font-size: 1.02rem; color: var(--ink-soft);
    cursor: pointer; user-select: none;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform 120ms var(--ease), box-shadow var(--dur) var(--ease);
}
.segmented label:active { transform: scale(.97); }
.segmented input:checked + label {
    color: #fff; box-shadow: var(--shadow-sm);
    background: linear-gradient(150deg, var(--rose-500), var(--rose-600));
}
.segmented input:focus-visible + label { box-shadow: 0 0 0 4px var(--rose-200); }

/* Opzioni scelta */
.options { display: grid; gap: 10px; }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.opt span {
    position: relative; display: flex; align-items: center;
    min-height: 56px; padding: 14px 50px 14px 18px;
    border: 2px solid var(--line); border-radius: var(--r-sm);
    background: var(--surface-2);
    font-size: 1.08rem; font-weight: 700; color: var(--ink);
    cursor: pointer; user-select: none;
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform 120ms var(--ease);
}
.opt span:active { transform: scale(.985); }
.opt span::after {
    content: ""; position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
    width: 24px; height: 24px; border-radius: 50%;
    border: 2px solid var(--rose-200); background: #fff;
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.opt input:checked + span {
    border-color: var(--primary); background: var(--rose-50); color: var(--rose-700);
}
.opt input:checked + span::after {
    border-color: var(--primary); background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center/15px no-repeat;
}
.opt input:focus-visible + span { box-shadow: 0 0 0 4px var(--rose-100); }

/* Checkbox anonimo */
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 700; color: var(--ink); cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--primary); cursor: pointer; }

/* Combobox squadre */
.combo { position: relative; }
.combo #squadraSearch {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239b8088' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: 16px center; background-size: 20px;
    padding-left: 46px;
}
.combo-list {
    list-style: none; margin: 8px 0 0; padding: 6px;
    max-height: 260px; overflow-y: auto; -webkit-overflow-scrolling: touch;
    border: 2px solid var(--line); border-radius: var(--r-sm); background: #fff;
    position: absolute; left: 0; right: 0; z-index: 40; box-shadow: var(--shadow);
}
.combo-list li {
    padding: 14px; border-radius: 10px; cursor: pointer; min-height: 44px; display: flex; align-items: center;
    transition: background 120ms var(--ease);
}
.combo-list li:hover, .combo-list li.active { background: var(--rose-50); }
.combo-list li.none { color: var(--muted); font-style: italic; }
.combo-list li.combo-item { justify-content: space-between; gap: 12px; }
.combo-nome { font-weight: 700; color: var(--ink); }
.combo-opera {
    flex: none; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
    color: var(--rose-700); background: var(--rose-50);
    padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.combo-selected { margin: 10px 0 0; font-size: .9rem; font-weight: 700; color: var(--muted); }
.combo-selected.has { color: var(--rose-700); }

/* ----- Bottoni ----- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; border-radius: var(--r); padding: 15px 22px;
    font-family: 'Fredoka', sans-serif; font-size: 1.05rem; font-weight: 600;
    cursor: pointer; text-decoration: none; min-height: 52px;
    transition: transform 120ms var(--ease), box-shadow var(--dur) var(--ease), filter var(--dur) var(--ease);
}
.btn-primary {
    color: #fff; box-shadow: var(--shadow);
    background: linear-gradient(150deg, var(--rose-500), var(--rose-600));
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--rose-200), var(--shadow); }
.btn-block { width: 100%; }
.btn-big { min-height: 60px; font-size: 1.2rem; margin-top: 6px; }

/* ----- Alert / flash ----- */
.alert { padding: 13px 16px; border-radius: var(--r-sm); margin-bottom: 16px; font-weight: 700; }
.alert-error { background: #fee2e2; color: var(--err); border: 1px solid #fecaca; }

.flash {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    background: linear-gradient(150deg, #22c55e, var(--ok)); color: #fff;
    text-align: center; font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.1rem;
    border-radius: var(--r); box-shadow: var(--shadow);
    max-height: 0; opacity: 0; overflow: hidden;
    margin-bottom: 0; padding: 0 16px;
    transition: max-height var(--dur) var(--ease), opacity var(--dur) var(--ease),
                padding var(--dur) var(--ease), margin var(--dur) var(--ease);
}
.flash.show { max-height: 80px; opacity: 1; padding: 16px; margin-bottom: 16px; }

/* ----- Sottomenu sezioni (scrollspy) ----- */
.subnav {
    position: sticky; z-index: 25;
    top: calc(52px + env(safe-area-inset-top));
    display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: 10px 16px; scrollbar-width: none;
    background: #1d4ed8;
    border-top: 1px solid rgba(255, 255, 255, .12);
}
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
    flex: none; color: #fff; text-decoration: none; font-weight: 700; font-size: .9rem;
    padding: 8px 16px; border-radius: 999px; background: rgba(255, 255, 255, .14);
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.subnav a.active { background: #fff; color: var(--rose-700); }
section[id] { scroll-margin-top: 110px; }

/* ----- Legenda colori scelte ----- */
.card-soft {
    position: relative; z-index: 1; background: rgba(255, 255, 255, .92);
    border-radius: var(--r); padding: 12px 16px; margin-bottom: 16px;
    box-shadow: var(--shadow-sm); display: flex; flex-wrap: wrap; gap: 8px 16px;
}
.legend-chip { display: inline-flex; align-items: center; gap: 7px; font-size: .82rem; font-weight: 700; color: var(--ink); }
.legend-chip i { width: 14px; height: 14px; border-radius: 4px; flex: none; }

/* ----- Banner vincitore ----- */
.winner {
    display: flex; align-items: center; gap: 14px;
    background: linear-gradient(120deg, #2563eb, #1d4ed8);
    color: #fff; border-radius: var(--r-lg); padding: 18px 20px;
    margin-bottom: 16px; box-shadow: var(--shadow);
}
.winner-emoji { font-size: 2.2rem; line-height: 1; flex: none; }
.winner-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.winner-label { font-family: 'Fredoka', sans-serif; font-size: 1.3rem; font-weight: 600; }
.winner-label strong { font-weight: 700; }
.winner-pct { font-weight: 700; opacity: .9; margin-left: 4px; }
.winner-split { font-size: .92rem; opacity: .95; }
.winner-split b { font-weight: 800; }

/* ----- Barra preferenze impilata ----- */
.pref-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--rose-100); margin-top: 8px; }
.pref-bar span { height: 100%; transition: width var(--dur) var(--ease); }
.pref-bar.empty { opacity: .5; }

/* ----- Dettaglio numerico sotto la barra (leggibile su mobile, no tooltip) ----- */
.pref-detail { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-top: 8px; }
.pref-tag { display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; color: var(--ink-soft); }
.pref-tag i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.pref-tag b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 700; }
.pref-tag.is-top { color: var(--ink); font-weight: 700; }
.pref-tag.is-top b { color: var(--primary); }

/* ----- Classifica con corpo (opere / squadre) ----- */
.ranking2 { list-style: none; margin: 8px 0 0; padding: 0; }
.ranking2 li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; padding: 14px 0; border-bottom: 1px solid var(--rose-100); }
.ranking2 li:last-child { border-bottom: none; }
.ranking2 .rank-body { min-width: 0; }
.ranking2 .rank-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ranking2 .rank-name { font-weight: 700; color: var(--ink); }
.ranking2 .rank-val { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--rose-700); }
.ranking2 li.is-zero { opacity: .72; }
.rank-pos.pos-zero { background: var(--rose-200); color: var(--rose-700); }
/* podio: oro / argento / bronzo per i primi 3 (solo righe con voti) */
.ranking2 li:not(.is-zero):nth-child(1) .rank-pos { background: linear-gradient(150deg, #fcd34d, #f59e0b); }
.ranking2 li:not(.is-zero):nth-child(2) .rank-pos { background: linear-gradient(150deg, #e5e7eb, #9ca3af); }
.ranking2 li:not(.is-zero):nth-child(3) .rank-pos { background: linear-gradient(150deg, #fdba74, #ea580c); }

.opera-badge {
    display: inline-block; font-size: .66rem; font-weight: 800; letter-spacing: .02em;
    color: var(--rose-700); background: var(--rose-50); border: 1px solid var(--rose-100);
    padding: 2px 7px; border-radius: 999px; vertical-align: middle; white-space: nowrap;
}

/* ----- Ranking squadre ----- */
.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li {
    display: grid; grid-template-columns: 34px 1fr 56px; align-items: center; gap: 10px;
    padding: 12px 0; border-bottom: 1px solid var(--rose-100);
}
.ranking li:last-child { border-bottom: none; }
.rank-pos {
    width: 30px; height: 30px; display: grid; place-items: center;
    font-weight: 700; font-size: .95rem; color: #fff; border-radius: 50%;
    background: linear-gradient(150deg, var(--rose-400), var(--rose-600));
}
.ranking li:nth-child(1) .rank-pos { background: linear-gradient(150deg, #fcd34d, #f59e0b); }
.ranking li:nth-child(2) .rank-pos { background: linear-gradient(150deg, #d1d5db, #9ca3af); }
.ranking li:nth-child(3) .rank-pos { background: linear-gradient(150deg, #fdba74, #ea580c); }
.rank-name { font-weight: 700; color: var(--ink); }
.rank-bar { grid-column: 2 / -1; height: 9px; background: var(--rose-100); border-radius: 999px; overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--rose-400), var(--rose-600)); animation: grow 700ms var(--ease) both; }
.rank-val { grid-row: 1; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--rose-700); }
@keyframes grow { from { transform: scaleX(0); transform-origin: left; } }

/* ----- Tabella voti ----- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-sm); }
.votes { width: 100%; border-collapse: collapse; font-size: .94rem; }
.votes th, .votes td { padding: 11px 8px; text-align: left; border-bottom: 1px solid var(--rose-100); white-space: nowrap; }
.votes td.nowrap { white-space: nowrap; }
.votes td.cell-squadra { white-space: normal; min-width: 92px; }
.cell-squadra .sq-nome { display: block; font-weight: 700; }
.cell-squadra .sq-opera { display: block; font-size: .68rem; font-weight: 700; letter-spacing: .02em; color: var(--rose-600); }
.votes thead th {
    position: sticky; top: 0; background: var(--surface-2);
    font-family: 'Fredoka', sans-serif; font-size: .76rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft);
}
.votes tbody tr { transition: background 120ms var(--ease); }
.votes tbody tr:hover { background: var(--rose-50); }
.votes td.small { font-variant-numeric: tabular-nums; }
.tag { font-size: .68rem; font-weight: 800; background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }

/* ----- Util ----- */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
a { color: var(--primary); }
.topbar nav a, .subnav a { color: #fff; }
.login-card a, .card a { color: var(--rose-700); font-weight: 700; }
canvas { max-height: 260px; }

/* ----- Accessibilità: reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
    .bg-fun::before, .bg-fun::after { display: none; }
}
