:root {
  --sfondo: #f2f2f5;
  --superficie: #ffffff;
  --superficie-2: #f7f7f9;
  --testo: #16161a;
  --testo-2: #5d5d66;
  --bordo: #e2e2e8;
  --accento: #e53935;
  --si: #2e9e47;
  --si-sfondo: #2e9e47;
  --no: #e53935;
  --medio: #e6a100;
  --ombra: 0 1px 2px rgba(0,0,0,.06);
  --barra-h: 56px;
  --schede-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sfondo: #0f0f11; --superficie: #1c1c1f; --superficie-2: #232327; --testo: #f1f1f3;
    --testo-2: #a3a3ad; --bordo: #2e2e33; --ombra: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --sfondo: #0f0f11; --superficie: #1c1c1f; --superficie-2: #232327; --testo: #f1f1f3;
  --testo-2: #a3a3ad; --bordo: #2e2e33; --ombra: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--sfondo); color: var(--testo);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }

/* Barra superiore */
.barra {
  position: sticky; top: 0; z-index: 10; min-height: var(--barra-h);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 14px 20px 12px;
  background: var(--superficie); border-bottom: 1px solid var(--bordo);
}
.barra h1 { font-size: 19px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--accento); min-width: 0; flex: 1; }
.logo[hidden] { display: none; }
/* nelle pagine principali il titolo va sotto il logo */
.logo:not([hidden]) ~ h1 { flex-basis: 100%; font-size: 18px; text-align: center; }
.barra:has(.logo:not([hidden])) { justify-content: center; }
.logo { flex: none; display: inline-flex; flex-direction: column; align-items: stretch; gap: 3px; text-decoration: none; }
.logo img { height: 20px; width: auto; display: block; }
/* payoff come testo vero: resta nitido e leggibile anche piccolo */
.payoff {
  font-size: 7.5px; font-weight: 500; letter-spacing: .2em; text-transform: uppercase; line-height: 1;
  color: var(--testo); text-align: center; white-space: nowrap;
  width: 0; min-width: 100%; text-indent: .2em; /* compensa lo spazio dopo l'ultima lettera */
}
/* logo con testo nero sul tema chiaro, bianco sul tema scuro */
.logo-scuro { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-chiaro { display: none !important; }
  :root:not([data-theme="light"]) .logo-scuro { display: block !important; }
}
:root[data-theme="dark"] .logo-chiaro { display: none !important; }
:root[data-theme="dark"] .logo-scuro { display: block !important; }
@media (max-width: 420px) { .barra { padding: 12px 16px 10px; } .barra h1, .logo:not([hidden]) ~ h1 { font-size: 17px; } }
.indietro {
  display: inline-flex; align-items: center; gap: 2px; justify-self: start;
  border: 1px solid var(--bordo); background: var(--superficie-2); color: var(--accento);
  border-radius: 999px; padding: 4px 12px 4px 8px; font-size: 15px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.indietro b { font-size: 24px; line-height: 1; margin-top: -3px; }
.indietro:hover { border-color: var(--accento); }
.indietro[hidden] { display: none; }
/* pagine interne: Indietro a sinistra, titolo centrato */
.barra.interna { display: grid; grid-template-columns: 1fr minmax(0, auto) 1fr; }
.barra.interna h1 { grid-column: 2; text-align: center; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(var(--schede-h) + 24px); outline: none; }
.caricamento { text-align: center; color: var(--testo-2); padding: 48px 0; }

/* Barra schede in basso */
.schede {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: var(--schede-h);
  display: flex; justify-content: center; background: var(--superficie); border-top: 1px solid var(--bordo);
  padding-bottom: env(safe-area-inset-bottom);
}
.schede a {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 13px; color: var(--testo-2); border-top: 2px solid transparent;
}
.schede a svg { width: 22px; height: 22px; }
.schede a.attiva { color: var(--accento); border-top-color: var(--accento); }

/* Selettore Smartphone / Tablet */
.tipo {
  display: flex; gap: 4px; padding: 4px; margin: 0 auto 16px; max-width: 420px;
  background: var(--superficie); border: 1px solid var(--bordo); border-radius: 14px;
}
.tipo button {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 12px; border: 0; border-radius: 10px; background: none; cursor: pointer;
  font-weight: 600; color: var(--testo-2);
}
.tipo button svg { width: 20px; height: 20px; }
.tipo button.attivo { background: var(--accento); color: #fff; }

/* Contatore a semicerchio */
.contatore { text-align: center; margin: 4px 0 8px; }
.contatore svg { width: 220px; max-width: 70%; display: block; margin: 0 auto; }
.contatore .num { font-size: 40px; font-weight: 700; color: var(--si); margin-top: -46px; }
.contatore .lab { color: var(--testo-2); font-size: 15px; }
.intro { text-align: center; color: var(--testo-2); margin: 12px auto 16px; max-width: 520px; }

/* Ricerca */
.ricerca-box {
  margin-bottom: 14px; border-radius: 12px;
  /* resta visibile sotto la barra superiore quando si scorre (e fa da riferimento per la x) */
  position: sticky; top: calc(var(--barra-alto, 56px) + 8px); z-index: 5;
  box-shadow: 0 0 0 8px var(--sfondo);
}
.ricerca {
  width: 100%; padding: 12px 46px 12px 14px; border-radius: 12px; border: 1px solid var(--bordo);
  background: var(--superficie); outline: none; display: block;
  -webkit-appearance: none; appearance: none;
}
/* la x del browser la nascondo: c'è la nostra, rossa */
.ricerca::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.svuota {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; padding: 8px; border: 0; border-radius: 50%; background: none;
  color: var(--accento); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.svuota svg { width: 20px; height: 20px; }
.svuota:hover { background: var(--superficie-2); }
.ricerca:placeholder-shown + .svuota { display: none; }
/* smartphone, mentre si scrive nella ricerca (classe messa da app.js): niente schede in basso e spazio
   sotto i risultati, così il campo può salire in cima anche quando i risultati sono pochi */
body.cercando .schede { display: none; }
body.cercando main { padding-bottom: 100vh; }
.ricerca:focus { border-color: var(--accento); }

/* Liste */
.lista { background: var(--superficie); border-radius: 14px; overflow: hidden; box-shadow: var(--ombra); margin-bottom: 18px; }
.riga {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--bordo);
  min-height: 52px;
}
.lista .riga:last-child { border-bottom: 0; }
a.riga:hover { background: var(--superficie-2); }
.riga .nome { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.riga .sotto { color: var(--testo-2); font-size: 15px; }
.riga .freccia { color: var(--testo-2); }
.miniatura { width: 36px; height: 48px; object-fit: contain; flex: none; }
.titolo-sezione { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--testo-2); margin: 18px 4px 8px; }
.vuoto { padding: 24px; text-align: center; color: var(--testo-2); }

.perc {
  min-width: 54px; text-align: center; padding: 3px 8px; border-radius: 999px; font-size: 15px; font-weight: 600; color: #fff;
}
.conteggio { color: var(--si); font-size: 15px; margin-left: 6px; }

.pallini { display: flex; gap: 5px; flex: none; }
.pallino {
  width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; line-height: 1; flex: none;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--no);
}
.pallino.si { background: var(--si); }

/* Scheda dispositivo */
.esito {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: 12px;
  margin-bottom: 8px; color: #fff; font-weight: 700; text-transform: uppercase; font-size: 15px; letter-spacing: .03em;
  background: var(--no);
}
.esito.si { background: var(--si); }
.esito svg { width: 24px; height: 24px; flex: none; }
.esito small { display: block; text-transform: none; font-weight: 400; letter-spacing: 0; opacity: .92; font-size: 15px; margin-top: 2px; }
.foto-grande { background: #fff; border-radius: 14px; padding: 16px; margin: 14px 0; text-align: center; }
.foto-grande img { max-height: 220px; max-width: 100%; }
.specifiche .riga { align-items: flex-start; }
.specifiche .chiave { width: 40%; flex: none; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--testo-2); padding-top: 2px; }
.specifiche .valore { flex: 1; text-align: right; white-space: pre-line; word-break: break-word; }

/* Schede prodotto */
.prodotto { background: var(--superficie); border-radius: 14px; padding: 18px; box-shadow: var(--ombra); margin-bottom: 14px; }
.prodotto h2 { margin: 0 0 6px; font-size: 22px; }
.prodotto-foto { background: #fff; border-radius: 10px; margin: 0 0 14px; padding: 12px; text-align: center; }
.prodotto-foto img { max-width: 100%; max-height: 260px; display: inline-block; }
.prodotto p { color: var(--testo-2); margin: 0 0 10px; }
.prodotto ul { margin: 0 0 14px; padding-left: 20px; }
.prodotto li { margin: 4px 0; }
.etichetta { display: inline-block; font-size: 14px; padding: 2px 8px; border-radius: 999px; background: var(--medio); color: #000; margin-bottom: 8px; }
.pulsanti { display: flex; flex-wrap: wrap; gap: 8px; }
.pulsante {
  display: inline-block; padding: 10px 16px; border-radius: 10px; background: var(--accento); color: #fff;
  font-weight: 600; border: 0; cursor: pointer;
}
.pulsante.secondario { background: var(--superficie-2); color: var(--testo); border: 1px solid var(--bordo); }

/* Confronta */
.filtri { background: var(--superficie); border-radius: 14px; padding: 14px; box-shadow: var(--ombra); margin-bottom: 14px; }
.filtri label { display: block; font-size: 15px; color: var(--testo-2); margin-bottom: 6px; }
.segmenti { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.segmenti button {
  flex: 1; min-width: 90px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--bordo);
  background: var(--superficie-2); cursor: pointer;
}
.segmenti button.attivo { background: var(--accento); border-color: var(--accento); color: #fff; }
.prezzi { display: flex; gap: 10px; align-items: center; }
.prezzi input[type=range] { flex: 1; accent-color: var(--accento); }
.prezzi output { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
.spunta { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 16px; }
.spunta input { accent-color: var(--accento); }
.risultati { color: var(--testo-2); font-size: 15px; margin: 0 4px 8px; }

/* Griglia marchi */
.griglia { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tessera {
  background: var(--superficie); border-radius: 14px; padding: 14px; box-shadow: var(--ombra);
  display: flex; flex-direction: column; gap: 4px;
}
.tessera:hover { outline: 2px solid var(--accento); }
.tessera strong { font-size: 18px; }
.tessera span { font-size: 14px; color: var(--testo-2); }

/* Impostazioni */
.campo { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.campo select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--bordo); background: var(--superficie-2); }
.legenda { display: flex; flex-wrap: wrap; gap: 12px; font-size: 15px; color: var(--testo-2); margin: 0 4px 12px; }
.legenda > span { display: inline-flex; align-items: center; gap: 6px; }
.legenda .pallino { width: 24px; height: 24px; font-size: 11px; }
.piede { text-align: center; color: var(--testo-2); font-size: 14px; margin-top: 24px; }

.schede a span { max-width: 100%; overflow: hidden; text-align: center; line-height: 1.15; padding: 0 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@media (max-width: 420px) {
  .schede a { font-size: 12px; }
  .specifiche .chiave { width: 45%; }
}

/* Confronta */
button.riga { width: 100%; background: none; border-width: 0 0 1px; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.vuoto svg { width: 40px; height: 40px; opacity: .5; }
.confronto { margin-top: 12px; }
.c-valori { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 6px; }
.c-etichetta { font-size: 14px; color: var(--testo-2); margin: 10px 4px 4px; }
.cella {
  background: var(--superficie); border-radius: 10px; padding: 8px 10px; font-size: 16px;
  overflow-wrap: anywhere; white-space: pre-line; position: relative;
}
.cella small { display: block; font-size: 14px; color: var(--testo-2); margin-top: 4px; white-space: normal; }
.cella.oltre { color: var(--no); font-weight: 700; }
.cella .trattino { color: var(--testo-2); }
.cella.testa { text-align: center; padding: 10px 8px 12px; white-space: normal; }
.cella:has(.c-esito) { white-space: normal; }
.cella.testa a { color: inherit; text-decoration: none; display: block; }
.c-foto { display: grid; place-items: center; height: 110px; background: #fff; border-radius: 8px; margin-bottom: 8px; }
.c-foto img { max-height: 96px; max-width: 90%; }
.c-nome { font-weight: 600; font-size: 16px; }
.togli {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: var(--sfondo); color: var(--testo); font-size: 20px; line-height: 1; cursor: pointer; z-index: 1;
}
.c-esito {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--no); color: #fff; font-weight: 700; font-size: 15px; line-height: 1;
}
.c-esito.si { background: var(--si); }
.pulsante svg { width: 18px; height: 18px; flex: none; }
.pulsante:has(svg) { display: inline-flex; align-items: center; gap: 8px; }

/* Confronta: righe con valori uguali / diversi */
:root { --uguale: #2e9d5b; --diverso: #e0a100; }
.c-valori.uguali .cella { box-shadow: inset 3px 0 0 var(--uguale); background: color-mix(in srgb, var(--uguale) 9%, var(--superficie)); }
.c-valori.diversi .cella { box-shadow: inset 3px 0 0 var(--diverso); background: color-mix(in srgb, var(--diverso) 12%, var(--superficie)); }
.c-legenda { margin: 12px 4px 0; }
.c-campione { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
.c-campione.uguali { background: color-mix(in srgb, var(--uguale) 35%, var(--superficie)); border-left: 3px solid var(--uguale); }
.c-campione.diversi { background: color-mix(in srgb, var(--diverso) 40%, var(--superficie)); border-left: 3px solid var(--diverso); }

/* Custodie */
.intro { color: var(--testo-2); margin: 4px auto 14px; max-width: 520px; text-align: center; }
.custodie { display: grid; gap: 10px; margin-bottom: 18px; }
.custodia {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px 12px 12px;
  background: var(--superficie); border-radius: 14px; box-shadow: var(--ombra);
}
.custodia:hover { outline: 2px solid var(--accento); }
.custodia-foto { flex: none; width: 110px; height: 84px; background: #fff; border-radius: 10px; display: grid; place-items: center; }
.custodia-foto img { max-width: 94%; max-height: 90%; }
.custodia-testo { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.custodia-testo strong { font-size: 19px; }
.custodia-testo > span:last-child { color: var(--testo-2); font-size: 15px; }
.custodia .etichetta { margin: 0; }
.custodia .freccia { color: var(--testo-2); font-size: 22px; }

/* Esito compatibilità nelle liste */
.badge {
  flex: none; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: #fff;
  white-space: nowrap; background: var(--no);
}
.badge.si { background: var(--si); }

/* Specifiche apribili nella scheda dispositivo */
.apribile { margin-bottom: 18px; }
.apribile summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--superficie); border-radius: 14px; box-shadow: var(--ombra);
  font-weight: 600;
}
.apribile summary::-webkit-details-marker { display: none; }
.apribile summary::after { content: '›'; font-size: 22px; line-height: 1; color: var(--testo-2); transition: transform .2s; }
.apribile[open] summary::after { transform: rotate(90deg); }
.apribile[open] summary { border-radius: 14px 14px 0 0; border-bottom: 1px solid var(--bordo); }
.apribile .lista { border-radius: 0 0 14px 14px; margin-bottom: 0; }

/* Nota sul prezzo dentro le specifiche */
.nota-prezzo { margin: 0; padding: 10px 14px 12px; font-size: 14px; color: var(--testo-2); }

/* Tabella comparativa delle custodie (pagina smartphone) */
.confronto-custodie { background: var(--superficie); border-radius: 14px; padding: 14px; box-shadow: var(--ombra); margin-bottom: 18px; }
.ct-prodotti { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.ct-prodotto {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; font-size: 15px; font-weight: 600;
  padding: 10px; border: 1px solid var(--bordo); border-radius: 12px;
}
.ct-prodotto:hover { border-color: var(--accento); }
.ct-foto { width: 100%; height: 110px; background: #fff; border-radius: 8px; display: grid; place-items: center; }
.ct-foto img { max-width: 90%; max-height: 96px; }
.ct-tabella { width: 100%; border-collapse: collapse; table-layout: fixed; }
.ct-tabella th, .ct-tabella td { padding: 10px 8px; vertical-align: middle; }
.ct-tabella tbody th { text-align: left; font-weight: 700; font-size: 16px; width: 36%; }
.ct-tabella td { text-align: center; }
.ct-tabella thead th { font-size: 17px; padding-bottom: 8px; border-bottom: 3px solid var(--testo); }
.ct-tabella thead th:first-child { border-bottom: 0; }
.ct-tabella thead th.ct-col0 { border-bottom-color: var(--accento); }
.ct-tabella tbody tr:nth-child(odd) { background: var(--superficie-2); }
.ct-tabella small { display: block; font-size: 13px; color: var(--testo-2); }
.ct-prezzo { font-weight: 700; font-size: 17px; white-space: nowrap; }
.ct-testo { font-weight: 600; }
.ct-si, .ct-no { display: inline-block; width: 24px; height: 24px; vertical-align: middle; }
.ct-si svg, .ct-no svg { width: 100%; height: 100%; display: block; }
.ct-si { color: var(--testo); }
.ct-no { color: var(--testo-2); opacity: .7; }
.ct-azioni { text-align: center; margin: 14px 0 0; }
@media (max-width: 420px) {
  .confronto-custodie { padding: 10px; }
  .ct-tabella th, .ct-tabella td { padding: 9px 4px; }
  .ct-tabella tbody th { font-size: 14px; }
  .ct-tabella thead th { font-size: 15px; }
  .ct-prezzo { font-size: 15px; }
}

/* Prezzo pieno barrato quando c'è uno sconto */
.ct-pieno { display: block; font-size: 14px; color: var(--testo-2); white-space: nowrap; }
.ct-prezzo.sconto { color: var(--accento); }

/* Link "Scopri di più" sotto ogni colonna della tabella custodie */
.ct-tabella tr.ct-link { background: none !important; }
.ct-link td { padding-top: 14px; }
.ct-link a { color: var(--accento); font-weight: 600; font-size: 15px; white-space: nowrap; }

/* Tabella custodie: i nomi delle custodie restano in alto mentre si scorre */
.ct-tabella { border-collapse: separate; border-spacing: 0; }
.ct-tabella thead th {
  position: sticky; top: var(--barra-alto, 56px); z-index: 3;
  background: var(--superficie); padding-top: 10px;
}

/* --- Carbonarm (aggiunto da strumenti/carbonarm.py) --- */
.logo img { height: 46px; }
