:root {
  --carta: #fbf7ef;
  --carta-2: #f3ead8;
  --inchiostro: #2b2118;
  --muto: #6f6253;
  --bordo: #e0d3bb;
  --accento: #8c3b1f;
  --accento-2: #b8860b;
  --ok: #2e7d32;
  --errore: #b3261e;
  --scheda: #ffffff;
  --ombra: 0 2px 10px rgba(60, 40, 20, .08);
  --raggio: 12px;
  --preistoria: #7a5c3e;
  --antica: #a0522d;
  --medioevo: #4b5d8a;
  --moderna: #2f7d6d;
  --contemporanea: #8a3b6e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --carta: #1c1915; --carta-2: #26221c; --inchiostro: #efe6d6; --muto: #b0a491; --bordo: #3b342a;
    --accento: #e08a5f; --accento-2: #e0b44a; --scheda: #24201b; --ombra: 0 2px 10px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--carta); color: var(--inchiostro);
  font: 17px/1.6 Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}
a { color: var(--accento); }
h1, h2, h3, h4 { font-family: "Segoe UI", system-ui, -apple-system, sans-serif; line-height: 1.25; }
img { max-width: 100%; height: auto; }
.muto { color: var(--muto); }
.piccolo { font-size: .85em; }
.inline { display: inline; }

/* ---------- testata */
.testata {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--inchiostro); color: var(--carta);
  font-family: "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) { .testata { background: #0f0d0b; } }
.logo { color: var(--carta); font-weight: 700; text-decoration: none; font-size: 1.15rem; }
.menu { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; }
.menu a { color: #e9dcc4; text-decoration: none; padding: .35rem .7rem; border-radius: 8px; }
.menu a:hover, .menu a.attivo { background: rgba(255,255,255,.12); color: #fff; }
.profilo-mini { display: flex; gap: .5rem; align-items: center; color: var(--carta); text-decoration: none; }
.profilo-testo { display: flex; flex-direction: column; min-width: 120px; font-size: .85rem; }
.grado-icona { font-size: 1.8rem; }
.barra-xp { display: block; height: 6px; background: rgba(128,128,128,.3); border-radius: 4px; overflow: hidden; margin: 3px 0; }
.barra-xp span { display: block; height: 100%; background: linear-gradient(90deg, var(--accento-2), var(--accento)); }
.barra-xp.grande { height: 12px; }

.contenuto { max-width: 1100px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.pagina-mappa .contenuto { max-width: 1500px; }
.piede { text-align: center; font-size: .8rem; color: var(--muto); padding: 1.5rem 1rem; border-top: 1px solid var(--bordo); }

/* ---------- componenti */
.scheda { background: var(--scheda); border: 1px solid var(--bordo); border-radius: var(--raggio); padding: 1.2rem; box-shadow: var(--ombra); }
.modulo-stretto { max-width: 460px; margin: 1rem auto; }
form label { display: block; margin: .7rem 0; font-family: "Segoe UI", system-ui, sans-serif; font-size: .95rem; }
form label.check { display: flex; gap: .5rem; align-items: center; }
input, select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--bordo); border-radius: 8px;
  background: var(--carta); color: var(--inchiostro); font: inherit; font-size: .95rem;
}
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 90px; }
.bottone {
  display: inline-block; background: var(--accento); color: #fff; border: 0; border-radius: 10px;
  padding: .6rem 1.1rem; font: 600 .95rem "Segoe UI", system-ui, sans-serif; cursor: pointer; text-decoration: none;
}
.bottone:hover { filter: brightness(1.1); }
.bottone.secondario { background: transparent; color: var(--accento); border: 2px solid var(--accento); }
.bottone.piccolo { padding: .3rem .7rem; font-size: .85rem; }
.bottone.pericolo { background: var(--errore); }
button.link { background: none; border: 0; color: var(--accento); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.avviso { padding: .7rem 1rem; border-radius: 10px; margin: .6rem 0; border: 1px solid var(--bordo); background: var(--scheda); font-family: "Segoe UI", system-ui, sans-serif; }
.avviso-errore { border-color: var(--errore); color: var(--errore); }
.avviso-ok { border-color: var(--ok); }
.avviso-xp, .avviso-badge { border-color: var(--accento-2); background: linear-gradient(90deg, rgba(184,134,11,.15), transparent); }
.etichetta { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; background: var(--carta-2); border: 1px solid var(--bordo); border-radius: 6px; padding: 0 .4rem; margin-left: .4rem; color: var(--muto); }
.briciole { font-size: .9rem; color: var(--muto); font-family: "Segoe UI", system-ui, sans-serif; }
.tabella { width: 100%; border-collapse: collapse; background: var(--scheda); font-family: "Segoe UI", system-ui, sans-serif; font-size: .92rem; }
.tabella th, .tabella td { padding: .5rem .6rem; border-bottom: 1px solid var(--bordo); text-align: left; vertical-align: top; }
.tabella th { background: var(--carta-2); }
.scorri { overflow-x: auto; }
.banner-anteprima { background: var(--accento-2); color: #000; text-align: center; padding: .4rem; font-family: "Segoe UI", system-ui, sans-serif; font-size: .9rem; }
.barra-anteprima { display: flex; justify-content: flex-end; }
.barra-anteprima label { display: flex; gap: .5rem; align-items: center; margin: 0; }
.barra-anteprima select { width: auto; }

/* ---------- home */
.hero { text-align: center; padding: 3rem 1rem; }
.hero h1 { font-size: clamp(1.8rem, 5vw, 3rem); }
.griglia-home { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.grado-scheda { text-align: center; }
.grado-grande { font-size: 3.5rem; }
.medaglie { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.medaglie li { display: flex; flex-direction: column; align-items: center; width: 92px; text-align: center; font-size: .78rem; font-family: "Segoe UI", system-ui, sans-serif; }
.medaglie li span { font-size: 2rem; }
.medaglie li.non-ottenuta { opacity: .35; filter: grayscale(1); }

/* ---------- linea del tempo */
.timeline { list-style: none; padding: 0 0 0 1.5rem; border-left: 4px solid var(--bordo); margin-left: .5rem; }
.tappa { position: relative; margin: 0 0 .8rem; }
.tappa::before { content: ""; position: absolute; left: -2.05rem; top: .9rem; width: 16px; height: 16px; border-radius: 50%; background: var(--bordo); border: 3px solid var(--carta); }
.tappa-superato::before { background: var(--ok); }
.tappa-aperto::before { background: var(--accento-2); }
.tappa a { display: grid; grid-template-columns: auto 1fr; column-gap: .7rem; text-decoration: none; color: inherit; background: var(--scheda); border: 1px solid var(--bordo); border-radius: 10px; padding: .6rem .9rem; }
.tappa a:hover { border-color: var(--accento); }
.tappa-bloccato a { opacity: .55; cursor: not-allowed; }
.tappa-icona { grid-row: span 3; font-size: 1.4rem; align-self: center; }
.tappa-anni { font-size: .78rem; color: var(--muto); font-family: "Segoe UI", system-ui, sans-serif; }
.tappa-progresso { font-size: .8rem; color: var(--muto); }

/* ---------- capitoli */
.titolo-era { border-bottom: 3px solid currentColor; padding-bottom: .3rem; margin-top: 2rem; }
.era-preistoria.titolo-era { color: var(--preistoria); }
.era-antica.titolo-era { color: var(--antica); }
.era-medioevo.titolo-era { color: var(--medioevo); }
.era-moderna.titolo-era { color: var(--moderna); }
.era-contemporanea.titolo-era { color: var(--contemporanea); }
.griglia-capitoli { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.carta-capitolo { display: flex; flex-direction: column; background: var(--scheda); border: 1px solid var(--bordo); border-radius: var(--raggio); overflow: hidden; color: inherit; text-decoration: none; box-shadow: var(--ombra); transition: transform .15s; }
.carta-capitolo:hover { transform: translateY(-3px); }
.carta-capitolo.bloccato { filter: grayscale(.9); opacity: .6; cursor: not-allowed; }
.carta-capitolo.superato { border-color: var(--ok); }
.copertina { position: relative; height: 140px; background: var(--carta-2) center/cover no-repeat; }
.crediti-copertina { position: absolute; right: 0; bottom: 0; max-width: 100%; padding: 1px 6px; background: rgba(0,0,0,.55); color: #fff; font: 10px/1.4 "Segoe UI", system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crediti-copertina:empty { display: none; }
.copertina-capitolo { margin: 0; }
.copertina-capitolo figcaption, .pannello-fig figcaption { font-size: .75rem; color: var(--muto); margin-top: .2rem; }
.pannello-fig { margin: .5rem 0; }
.licenza-testo { font-size: .8rem; color: var(--muto); }
.carta-corpo { padding: .8rem 1rem 1rem; }
.carta-corpo h3 { margin: .2rem 0; font-size: 1.05rem; }
.carta-corpo p { margin: .3rem 0 .6rem; font-size: .9rem; color: var(--muto); }
.testata-capitolo { display: grid; grid-template-columns: minmax(0, 320px) 1fr; gap: 1.5rem; align-items: start; }
.testata-capitolo img { border-radius: var(--raggio); box-shadow: var(--ombra); }
.testata-capitolo h1 { margin: .2rem 0; }
.sottotitolo { font-style: italic; color: var(--muto); }
@media (max-width: 700px) { .testata-capitolo { grid-template-columns: 1fr; } }
.elenco-lezioni { padding-left: 1.4rem; }
.elenco-lezioni li { margin: .4rem 0; }
.elenco-lezioni a { text-decoration: none; }
.elenco-lezioni li.letta a { color: var(--muto); }

/* ---------- lezione */
.lezione { max-width: 780px; margin: 0 auto; }
.lezione h1 { font-size: 2rem; margin-bottom: 0; }
.lezione figure { margin: 1rem 0; }
.lezione figure img { border-radius: 8px; display: block; }
.lezione figure.principale img { width: 100%; max-height: 420px; object-fit: cover; }
.lezione figure.laterale { float: right; width: 42%; margin: .3rem 0 1rem 1.2rem; }
@media (max-width: 640px) { .lezione figure.laterale { float: none; width: 100%; margin: 1rem 0; } }
figcaption { font-size: .82rem; color: var(--muto); margin-top: .3rem; }
.fonte-img { font-size: .75rem; }
.lezione .intro { font-size: 1.07rem; }
.livello-medie .intro { font-size: 1.15rem; line-height: 1.75; }
.sezione { border-top: 1px solid var(--bordo); padding: .3rem 0; clear: both; }
.sezione summary { cursor: pointer; list-style: none; }
.sezione summary::-webkit-details-marker { display: none; }
.sezione summary h2 { display: inline; font-size: 1.35rem; }
.sezione summary::before { content: "▸ "; color: var(--accento); }
.sezione[open] summary::before { content: "▾ "; }
.sezione h4 { margin: 1.2rem 0 .3rem; }
.galleria { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.galleria img { aspect-ratio: 4/3; object-fit: cover; width: 100%; }
.attribuzione { clear: both; font-size: .82rem; color: var(--muto); border-top: 1px dashed var(--bordo); padding-top: .8rem; margin-top: 2rem; }
.nota-docente { background: var(--carta-2); border-left: 4px solid var(--accento-2); padding: .8rem 1rem; border-radius: 6px; margin: 1rem 0; }
.nav-lezione { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; max-width: 780px; margin: 2rem auto 0; }

/* ---------- quiz */
.quiz { max-width: 780px; }
.domanda { border: 1px solid var(--bordo); border-radius: var(--raggio); background: var(--scheda); margin: 0 0 1rem; padding: 1rem 1.2rem; }
.domanda legend { font-weight: 600; padding: 0 .3rem; font-family: "Segoe UI", system-ui, sans-serif; }
.domanda .num { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accento); color: #fff; font-size: .85rem; margin-right: .3rem; }
.difficolta { color: var(--accento-2); font-size: .8rem; margin-left: .3rem; }
.opzione { display: flex; gap: .6rem; align-items: flex-start; padding: .45rem .6rem; border-radius: 8px; cursor: pointer; margin: .2rem 0; }
.opzione:hover { background: var(--carta-2); }
.opzione input { margin-top: .35rem; }
.risultato { text-align: center; max-width: 520px; }
.risultato.ok { border-color: var(--ok); }
.punteggio-grande { font: 700 3.5rem "Segoe UI", system-ui, sans-serif; color: var(--accento); }
.risultato.ok .punteggio-grande { color: var(--ok); }
.esito { font-weight: 600; }
.correzione li { margin-bottom: 1rem; padding: .6rem .8rem; border-radius: 8px; background: var(--scheda); border-left: 4px solid var(--ok); }
.correzione li.sbagliata { border-left-color: var(--errore); }
.correzione .testo { font-weight: 600; margin: 0 0 .3rem; }
.correzione p { margin: .2rem 0; }
.spiegazione { color: var(--muto); font-size: .92rem; }

/* ---------- mappa */
.mappa-layout { display: grid; grid-template-columns: 1fr 380px; gap: 1rem; }
@media (max-width: 960px) { .mappa-layout { grid-template-columns: 1fr; } }
.mappa-colonna { min-width: 0; }
#mappa.mare { background: #b9d3e0; }
#mappa { height: 68vh; min-height: 420px; border-radius: var(--raggio); border: 1px solid var(--bordo); box-shadow: var(--ombra); background: #aad3df; }
.mappa-controlli { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.mappa-controlli input[type=range] { flex: 1; min-width: 160px; padding: 0; accent-color: var(--accento); }
.mappa-controlli select { width: auto; max-width: 260px; }
.etichetta-anno { font: 700 1.3rem "Segoe UI", system-ui, sans-serif; min-width: 130px; text-align: center; color: var(--accento); }
.etichetta-anno.caricamento { opacity: .5; }
.pannello { background: var(--scheda); border: 1px solid var(--bordo); border-radius: var(--raggio); padding: 1rem 1.2rem; max-height: calc(68vh + 3rem); overflow-y: auto; box-shadow: var(--ombra); }
.pannello h2 { margin: .2rem 0; }
.pannello-img { display: block; width: 100%; max-height: 240px; object-fit: contain; background: var(--carta-2); border-radius: 8px; }
.sopratitolo { font: 600 .78rem "Segoe UI", system-ui, sans-serif; text-transform: uppercase; letter-spacing: .05em; color: var(--accento-2); margin: 0; }
.temi { display: flex; flex-wrap: wrap; gap: .4rem; }
.tema { border: 1px solid var(--bordo); background: var(--carta); color: var(--inchiostro); border-radius: 20px; padding: .35rem .75rem; cursor: pointer; font: .85rem "Segoe UI", system-ui, sans-serif; }
.tema:hover, .tema.attivo { background: var(--accento); color: #fff; border-color: var(--accento); }
.voci { padding-left: 1.1rem; }
.voci li { margin-bottom: .5rem; }
.riquadro { background: var(--carta-2); border-radius: 8px; padding: .7rem; margin: .8rem 0; }
.nome-citta { background: rgba(255,255,255,.85); border: 0; box-shadow: none; font: 600 11px "Segoe UI", system-ui, sans-serif; padding: 0 4px; }
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--inchiostro); color: var(--carta); padding: .8rem 1.2rem; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.3); z-index: 2000; font-family: "Segoe UI", system-ui, sans-serif; }
.leaflet-container { font-family: "Segoe UI", system-ui, sans-serif; }
/* mappa MapLibre */
#mappa.maplibregl-map { background: #b9d3e0; font-family: "Segoe UI", system-ui, sans-serif; }
.mappa-controlli .bottone.piccolo { min-width: 2.4rem; }
.form-anno { display: flex; gap: .4rem; align-items: center; margin: 0; }
.form-anno label { font: .9rem "Segoe UI", system-ui, sans-serif; }
.form-anno input { width: 6.5rem; }
.spunta { display: inline-flex; gap: .35rem; align-items: center; font: .9rem "Segoe UI", system-ui, sans-serif; cursor: pointer; }
.spunta input { width: auto; }
.citta { display: flex; align-items: center; gap: 3px; background: none; border: 0; padding: 0; cursor: pointer; }
.citta .punto { width: 10px; height: 10px; border-radius: 50%; background: #f5deb3; border: 1.5px solid #222; flex: none; }
.citta-1 .punto { width: 14px; height: 14px; background: #b8860b; }
.citta .nome-citta { display: none; border-radius: 3px; color: #222; white-space: nowrap; }
.citta.con-nome .nome-citta { display: inline; }
.citta:hover .nome-citta { display: inline; background: #fff; }
.popup-nome .maplibregl-popup-content { padding: .35rem .6rem; font: .85rem "Segoe UI", system-ui, sans-serif; pointer-events: none; }
.popup-nome { pointer-events: none; }

/* ---------- classifica / profilo / admin */
.podio td:first-child { font-size: 1.3rem; }
.riga-io { background: rgba(184,134,11,.15); }
.admin-menu { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.admin-menu a { padding: .35rem .8rem; border: 1px solid var(--bordo); border-radius: 8px; text-decoration: none; background: var(--scheda); font-family: "Segoe UI", system-ui, sans-serif; font-size: .9rem; }
.admin-menu a.attivo { background: var(--accento); color: #fff; border-color: var(--accento); }
.griglia-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0 1rem; }
.griglia-form .largo { grid-column: 1 / -1; }
.aiuto { display: block; font-size: .78rem; color: var(--muto); }
.filtri { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filtri label { margin: 0; }
.azioni { white-space: nowrap; }
.azioni form { display: inline; }
.livelli-tabella input, .livelli-tabella select { min-width: 70px; }

/* ---------- editor testi */
.editor-testo { min-height: 60vh; font: 13px/1.5 Consolas, "Courier New", monospace; }
.stato-ok { color: var(--ok); font-weight: 600; }
.stato-ko { color: var(--errore); font-weight: 600; }

/* ---------- mappe piccole (lezioni e verifiche) */
.mini-mappa { height: 300px; border-radius: 10px; border: 1px solid var(--bordo); background: #aad3df; }
.mini-mappa.mare { background: #b9d3e0; }
.mini-mappa.quiz { height: 380px; cursor: crosshair; }
.mini-mappa.risultato { height: 260px; margin: .5rem 0; }
.mini-mappa-box { margin: 1.2rem 0; clear: both; }
.mini-mappa-box figcaption { font-size: .88rem; }
.mini-mappa-errore { padding: 1rem; color: var(--muto); }
.consegna { margin: .2rem 0 .6rem; color: var(--muto); font-size: .92rem; }
.ordine-domanda, .abbinamento-domanda { display: flex; flex-direction: column; gap: .5rem; }
.riga-ordine { display: flex; gap: .7rem; align-items: center; margin: 0; }
.riga-ordine select { width: 5rem; flex: none; }
.riga-abbinamento { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: .7rem; align-items: center; margin: 0; }
@media (max-width: 560px) { .riga-abbinamento { grid-template-columns: 1fr; gap: .2rem; } }
.lezioni-collegate { padding-left: 1.1rem; }
.lezioni-collegate li { margin-bottom: .3rem; }
