* { box-sizing: border-box; }
:root { --oro: #ffcf1f; --testo: #1b2a3a; --cella: 40px; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column; color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(120% 90% at 50% 0%, #1b3a9c, #0d1b4d 70%) fixed;
  -webkit-user-select: none; user-select: none;
}
main { flex: 1; padding: 12px; width: 100%; max-width: 760px; margin: 0 auto; }
main:has(#gioco:not([hidden])) { max-width: none; }
footer { text-align: center; font-size: 13px; padding: 8px; color: #b9c7ff; background: rgba(0, 0, 0, .25); }
[hidden] { display: none !important; }

.pannello {
  background: linear-gradient(180deg, #fffdf6, #f6efdc); color: var(--testo);
  border-radius: 22px; padding: 18px 22px 22px; border: 4px solid #fff;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .45), inset 0 0 0 3px #e8d9a8;
}
img.logo { display: block; width: 84px; height: 84px; margin: 0 auto; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .35)); }
/* Titolo in rilievo: lettere con sfumatura lucida e ombra sotto, in due colori */
h1 { text-align: center; font: 800 2.7rem Verdana, "Trebuchet MS", sans-serif; letter-spacing: .01em; margin: 6px 0 12px; filter: drop-shadow(0 3px 0 rgba(10, 30, 90, .55)) drop-shadow(0 6px 6px rgba(0, 0, 0, .25)); }
h1 span { background: linear-gradient(180deg, #8dbdff 0%, #3b78e8 45%, #1d3f9e 100%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
h1 span.due { background-image: linear-gradient(180deg, #ffe27a 0%, #ffb21f 45%, #e06a00 100%); }
h2 { text-align: center; margin: 0 0 12px; color: #c0392b; }
label { display: block; font-size: 1.4rem; margin: 14px 0; font-weight: 700; }
select {
  font-size: 1.4rem; padding: 10px; margin-top: 6px; width: 100%; border-radius: 12px;
  border: 3px solid #1d4fc4; background: #fff; color: var(--testo); font-family: inherit;
}
input[type=range] { width: 100%; height: 44px; accent-color: #2358d4; }

button {
  font-family: inherit; font-size: 1.25rem; font-weight: 700; min-height: 52px; padding: 8px 22px;
  border-radius: 14px; border: 0; color: #fff; cursor: pointer; touch-action: manipulation;
  background: linear-gradient(180deg, #4f8cff, #2358d4); box-shadow: 0 5px 0 #173a94, 0 8px 12px rgba(0, 0, 0, .3);
  transition: transform .08s, box-shadow .08s;
}
button:active { transform: translateY(4px); box-shadow: 0 1px 0 #173a94, 0 3px 6px rgba(0, 0, 0, .3); }
button.grande {
  width: 100%; font-size: 1.8rem; min-height: 70px; margin-top: 14px;
  background: linear-gradient(180deg, #ffb347, #ff7a00); box-shadow: 0 6px 0 #b34f00, 0 10px 16px rgba(0, 0, 0, .3);
}
button.grande:active { box-shadow: 0 1px 0 #b34f00; }
button.chiaro { background: #fff; color: #1d4fc4; border: 3px solid #1d4fc4; box-shadow: 0 4px 0 #9fb6ee; }
button.grande.chiaro { background: #fff; color: #1d4fc4; box-shadow: 0 6px 0 #9fb6ee; }
button.piccolo { min-height: 44px; padding: 4px 14px; font-size: 1.05rem; }

.livelli { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
button.livello {
  display: block; text-align: left; font-size: 1.6rem; background: #fff; color: #1d4fc4;
  border: 4px solid #9fb6ee; box-shadow: 0 4px 0 #9fb6ee; min-height: 70px;
}
button.livello small { display: block; font-size: 1rem; font-weight: 400; color: #456; }
button.livello.scelto { border-color: #ff7a00; background: #fff4e0; box-shadow: 0 4px 0 #b34f00; }

/* Gioco */
.barra { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
#contatore { margin-left: auto; font-size: 1.5rem; font-weight: 700; color: var(--oro); }
.campo { display: flex; gap: 14px; align-items: flex-start; justify-content: center; }
#areagriglia { flex: 0 0 auto; }
#griglia {
  display: grid; touch-action: none; cursor: pointer; background: linear-gradient(180deg, #4a5160, #2b303b); border: 5px solid #1b1f27; border-radius: 12px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .5), inset 0 2px 0 rgba(255, 255, 255, .15);
  grid-template-columns: repeat(var(--n), var(--cella)); grid-auto-rows: var(--cella); position: relative;
}
/* Ogni cella è un tasto di macchina da scrivere: bordo cromato, faccia chiara, spessore; si abbassa quando è premuto */
.c {
  position: relative; isolation: isolate; display: flex; align-items: center; justify-content: center; color: #1b1b1b; font-weight: 700;
  font-family: "Courier New", Courier, "Trebuchet MS", monospace; font-size: calc(var(--cella) * .6); line-height: 1;
  --f1: #ffffff; --f2: #e6e0cf; --d: calc(var(--cella) * .07);
}
.c::before {
  content: ""; position: absolute; inset: 8%; z-index: -1; border-radius: 50%;
  background: radial-gradient(circle at 36% 28%, var(--f1) 0%, var(--f2) 72%);
  box-shadow: 0 0 0 calc(var(--cella) * .045) #aeb4bf, 0 0 0 calc(var(--cella) * .075) #5c626e,
    0 var(--d) 0 calc(var(--cella) * .075) #14171d, 0 calc(var(--d) * 1.6) calc(var(--cella) * .08) calc(var(--cella) * .06) rgba(0, 0, 0, .45),
    inset 0 calc(var(--cella) * -.05) 0 rgba(0, 0, 0, .13);
  transition: transform .06s, box-shadow .06s, background .1s;
}
.c.sel, .c.errata, .c.trovata { transform: none; }
.c.sel::before, .c.errata::before, .c.trovata::before {
  transform: translateY(calc(var(--d) * .8));
  box-shadow: 0 0 0 calc(var(--cella) * .045) #aeb4bf, 0 0 0 calc(var(--cella) * .075) #5c626e,
    0 calc(var(--d) * .25) 0 calc(var(--cella) * .075) #14171d, inset 0 calc(var(--cella) * .05) calc(var(--cella) * .05) rgba(0, 0, 0, .25);
}
.c.sel { --f1: #fff3a0; --f2: #ffd93b; }
.c.errata { --f1: #ffd0c8; --f2: #ff9a8a; }
.p0 { --f1: #c9f5d0; --f2: #7fd48f; } .p1 { --f1: #d2ebff; --f2: #78b9f5; } .p2 { --f1: #ffe0ee; --f2: #f59cc4; } .p3 { --f1: #fff0b8; --f2: #f2c94c; }
.p4 { --f1: #e8d8ff; --f2: #b794f0; } .p5 { --f1: #ffe0c2; --f2: #f5a05c; } .p6 { --f1: #cdf5ee; --f2: #6fd3c2; } .p7 { --f1: #f4f4c2; --f2: #cfcf5e; }
#elenco { flex: 0 0 auto; width: 270px; max-height: calc(100vh - 110px); overflow: auto; padding: 14px 16px; }
#elenco ul { list-style: none; margin: 0; padding: 0; columns: var(--colonne, 1); column-gap: 14px; }
#elenco li { font-size: 1.25rem; font-weight: 700; padding: 3px 4px; break-inside: avoid; }
#elenco li.fatta { text-decoration: line-through; color: #8a9aa8; }

.velo { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.velo .pannello { max-width: 420px; width: 100%; }

body.impila .campo { flex-direction: column; align-items: center; }
body.impila #elenco { width: 100%; max-height: none; }
#elenco.fitta li { font-size: 1rem; padding: 2px 4px; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* Aiuti BES (classi sul body) */
.aiuti { margin-top: 12px; }
.aiuti summary { font-size: 1.3rem; font-weight: 700; color: #1d4fc4; cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.riga { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; margin: 8px 0; }
.riga input { width: 28px; height: 28px; flex: none; }
.c.ini { --f1: #ffd6e6; --f2: #f48fb8; }
.c.aiuto { --f1: #fff3a0; --f2: #ffd93b; }
.c.aiuto::before { box-shadow: 0 0 0 calc(var(--cella) * .09) #e0457b, 0 var(--d) 0 calc(var(--cella) * .09) #14171d; }
#elenco li { cursor: pointer; }
body.bes-grande #elenco li { font-size: 1.7rem; padding: 6px 4px; }
body.bes-carattere .c, body.bes-carattere #elenco li { font-family: Verdana, Arial, sans-serif; }
body.bes-carattere #elenco li { letter-spacing: .06em; }
body.bes-contrasto { background: #fff; color: #000; }
body.bes-contrasto footer { background: #eee; color: #000; }
body.bes-contrasto .pannello { background: #fff; border: 3px solid #000; box-shadow: none; }
body.bes-contrasto button, body.bes-contrasto button.grande { background: #fff; color: #000; border: 3px solid #000; box-shadow: none; }
body.bes-contrasto button.livello.scelto { background: #000; color: #fff; }
body.bes-contrasto button.livello.scelto small { color: #fff; }
body.bes-contrasto h1, body.bes-contrasto h1 span, body.bes-contrasto h2 { color: #000; text-shadow: none; filter: none; background: none; -webkit-text-fill-color: #000; }
body.bes-contrasto #contatore { color: #000; }
body.bes-contrasto #griglia { border-color: #000; }
body.bes-contrasto #griglia { background: #fff; }
body.bes-contrasto .c { font-family: Verdana, Arial, sans-serif; font-weight: 800; }
body.bes-contrasto .c::before { inset: 4%; border-radius: 22%; background: #fff; box-shadow: inset 0 0 0 2px #000; transform: none; }
body.bes-contrasto .c.trovata::before { background: #ddd; box-shadow: inset 0 0 0 2px #000; }
body.bes-contrasto .c.trovata { text-decoration: underline; }
body.bes-contrasto .c.sel::before, body.bes-contrasto .c.aiuto::before { background: #000; box-shadow: none; }
body.bes-contrasto .c.sel { color: #fff; }
body.bes-contrasto .c.ini::before { box-shadow: inset 0 0 0 4px #000; }
body.bes-calmo .c::before { transition: none; }
body.bes-calmo button { transition: none; }

/* Squadre */
.modo { display: flex; gap: 10px; margin-bottom: 6px; }
.modo button { flex: 1; font-size: 1.2rem; }
.modo button.attivo { background: #ffb347; color: #fff; border-color: #b34f00; box-shadow: 0 4px 0 #b34f00; }
#punteggi { display: flex; gap: 8px; margin-left: 8px; flex-wrap: wrap; }
.sq { display: inline-flex; align-items: center; gap: 6px; background: #fff; color: var(--testo); border: 4px solid var(--c); border-radius: 14px; padding: 2px 12px 2px 4px; font-weight: 700; font-size: 1.15rem; opacity: .7; }
.sq img { width: 40px; height: 40px; object-fit: contain; }
.sq b { font-size: 1.4rem; }
.sq.turno { opacity: 1; box-shadow: 0 0 0 4px var(--c), 0 6px 14px rgba(0,0,0,.4); transform: scale(1.06); }
#turno { position: fixed; left: 50%; top: 30%; transform: translateX(-50%); z-index: 70; background: var(--c); color: #fff; font-size: 2.4rem; font-weight: 800; padding: 14px 34px; border-radius: 22px; border: 4px solid #fff; box-shadow: 0 10px 30px rgba(0,0,0,.5); text-align: center; pointer-events: none; }
.q0 { --f1: #d2e0ff; --f2: #6f9bff; } .q1 { --f1: #ffd6d6; --f2: #f27a7a; } .q2 { --f1: #cff5dd; --f2: #5cd08c; } .q3 { --f1: #fff0b8; --f2: #f2c94c; }
body.bes-contrasto .sq { border-color: #000; }
body.bes-contrasto .modo button.attivo { background: #000; color: #fff; }

/* Le mie parole */
textarea { width: 100%; font-size: 1.2rem; padding: 10px; border-radius: 10px; border: 3px solid #9ab; font-family: inherit; user-select: text; -webkit-user-select: text; margin: 6px 0; }
input[type=text] { font-size: 1.2rem; padding: 10px; border-radius: 10px; border: 3px solid #9ab; width: 100%; font-family: inherit; user-select: text; -webkit-user-select: text; }
.nota { font-size: 1rem; color: #456; margin: 6px 0; }
.foto { font-size: 1.05rem; min-height: 44px; padding: 8px 14px; border-radius: 10px; border: 3px solid #1d4fc4; color: #1d4fc4; background: #fff; cursor: pointer; display: inline-flex; align-items: center; font-weight: 700; margin: 0; }
.riga2 { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
#listeSalvate { list-style: none; margin: 6px 0 0; padding: 0; }
#listeSalvate li { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; font-weight: 700; padding: 4px 0; }
#listeSalvate li span { flex: 1; }
#listeSalvate button { min-height: 40px; padding: 2px 12px; font-size: 1rem; background: #d94a3a; box-shadow: 0 3px 0 #8f2a1e; }
body.bes-contrasto #listeSalvate button { background: #fff; }

/* Stampa: foglio A4 con la griglia e le parole, poi la pagina delle soluzioni */
@page { size: A4; margin: 12mm; }
#foglio { display: none; }
@media print {
  body > *:not(#foglio) { display: none !important; }
  body { background: #fff !important; color: #000; display: block; min-height: 0; }
  #foglio { display: block !important; }
  #foglio[hidden] { display: block !important; }
  .pag { page-break-after: always; text-align: center; color: #000; font-family: "Trebuchet MS", Verdana, sans-serif; }
  .pag:last-child { page-break-after: auto; }
  .pag h1 { font-size: 22pt; margin: 0 0 4mm; color: #000; text-shadow: none; }
  .pag h2 { font-size: 14pt; margin: 6mm 0 2mm; color: #000; text-align: center; }
  .gs { border-collapse: collapse; margin: 0 auto; border: 0.6mm solid #000; }
  .gs td { width: var(--cs); height: var(--cs); padding: 0; text-align: center; vertical-align: middle; font-weight: 800; font-size: calc(var(--cs) * .6); line-height: 1; }
  .gs td.s { background: #bbb; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pag ul { list-style: none; margin: 0; padding: 0; columns: 4; column-gap: 8mm; text-align: left; font-size: 12pt; font-weight: 700; }
  .pag li { padding: 1mm 0; break-inside: avoid; }
  .pag li::before { content: "\2610  "; }
  .pag.sol li::before { content: ""; }
  .pag .cr { font-size: 9pt; margin-top: 6mm; color: #444; }
}

/* Effetti: onda sulle lettere della parola, striscione, festa finale e coppa */
/* La parola trovata salta a onda, cambia colore passando per tutto l'arcobaleno, brilla (breve: poi resta del suo colore) */
.c.onda { z-index: 3; animation: salta .55s cubic-bezier(.3, 1.6, .5, 1) var(--dl, 0s) both, arcobaleno 2.4s linear var(--dl, 0s) both; }
@keyframes salta { 0% { transform: none; } 35% { transform: translateY(-32%) scale(1.3); } 100% { transform: none; } }
@keyframes arcobaleno {
  0% { filter: hue-rotate(0deg) brightness(1.1) drop-shadow(0 0 0 rgba(255, 255, 255, 0)); }
  20% { filter: hue-rotate(72deg) brightness(1.4) drop-shadow(0 0 6px #fff); }
  40% { filter: hue-rotate(144deg) brightness(1.15) drop-shadow(0 0 3px #fff); }
  60% { filter: hue-rotate(216deg) brightness(1.4) drop-shadow(0 0 6px #fff); }
  80% { filter: hue-rotate(288deg) brightness(1.15) drop-shadow(0 0 3px #fff); }
  100% { filter: hue-rotate(360deg) brightness(1) drop-shadow(0 0 0 rgba(255, 255, 255, 0)); }
}
.c.festa { animation: festaTasto 1.3s ease-in-out 3; animation-delay: var(--d, 0s); }
@keyframes festaTasto { 0%, 100% { filter: none; transform: none; z-index: 1; } 50% { filter: brightness(1.3) drop-shadow(0 0 5px #fff3a0); transform: scale(1.12); z-index: 3; } }
#parolaTrovata {
  position: fixed; left: 50%; top: 14%; transform: translateX(-50%); z-index: 70; pointer-events: none; text-align: center;
  background: linear-gradient(180deg, #ffe066, #ffb000); color: #3a2400; font-size: clamp(1.6rem, 4.2vw, 3rem); font-weight: 800; letter-spacing: .04em;
  padding: 10px 32px; border-radius: 22px; border: 4px solid #fff; box-shadow: 0 10px 28px rgba(0, 0, 0, .5), 0 5px 0 #b87a00;
  animation: bannerP 1.6s ease-out both; max-width: 92vw;
}
@keyframes bannerP { 0% { opacity: 0; transform: translate(-50%, -24px) scale(.6); } 18%, 78% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -10px) scale(1); } }
.coppa { text-align: center; border: 5px solid var(--oro); animation: entra .6s cubic-bezier(.2, 1.4, .4, 1); }
.coppa .trofeo { font-size: 4.5rem; line-height: 1; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .35)); }
.coppa .stelle { font-size: 2.4rem; color: var(--oro); text-shadow: 0 3px 0 #b8860b; letter-spacing: .2em; }
@keyframes entra { from { transform: scale(.3) rotate(-8deg); opacity: 0; } }
body.bes-calmo .c.onda, body.bes-calmo .c.festa, body.bes-calmo #parolaTrovata, body.bes-calmo .coppa { animation: none; }
@media (prefers-reduced-motion: reduce) { .c.onda, .c.festa, #parolaTrovata, .coppa { animation: none; } }

/* Telefono: tasti grandi abbastanza da toccare; la griglia scorre col dito, la parola si indica toccando prima e ultima lettera */
.soloTel { display: none; }
body { overflow-x: hidden; }
.barra { flex-wrap: wrap; }
body.telefono .soloTel { display: inline-flex; align-items: center; }
body.telefono main { padding: 8px; }
body.telefono .barra { gap: 6px; }
body.telefono .barra button { min-height: 40px; padding: 2px 10px; font-size: .95rem; }
body.telefono #contatore { font-size: 1.25rem; }
body.telefono #punteggi { order: 5; width: 100%; margin-left: 0; }
body.telefono #areagriglia { overflow: auto; max-height: 64vh; max-width: calc(100vw - 16px); -webkit-overflow-scrolling: touch; border-radius: 12px; }
body.telefono #griglia { touch-action: pan-x pan-y; width: max-content; }
body.telefono #elenco { padding: 10px 12px; }
body.telefono #elenco li { font-size: 1.05rem; }
body.telefono #parolaTrovata { top: 9%; font-size: clamp(1.1rem, 5.2vw, 1.8rem); padding: 6px 16px; white-space: nowrap; }
body.telefono #turno { font-size: 1.5rem; padding: 10px 18px; }
body.telefono h1 { font-size: 2rem; }
body.telefono p.suggerimento { display: block; margin: 0 0 6px; font-size: .95rem; color: #dbe4ff; text-align: center; }
.c.mira::before { box-shadow: 0 0 0 calc(var(--cella) * .045) #aeb4bf, 0 0 0 calc(var(--cella) * .1) #4db8ff, 0 var(--d) 0 calc(var(--cella) * .1) #14171d; }
body.bes-contrasto .c.mira::before { box-shadow: inset 0 0 0 3px #000; }

/* Parole bonus: parole vere trovate fuori elenco */
#bonus { font-size: 1.2rem; font-weight: 700; color: #bff3ff; background: rgba(255, 255, 255, .12); border-radius: 12px; padding: 4px 12px; }
.c.bonusc:not(.trovata) { --f1: #e9fbff; --f2: #7fdcf0; }
.c.bonusc:not(.trovata)::before {
  transform: translateY(calc(var(--d) * .8));
  box-shadow: 0 0 0 calc(var(--cella) * .045) #aeb4bf, 0 0 0 calc(var(--cella) * .075) #5c626e,
    0 calc(var(--d) * .25) 0 calc(var(--cella) * .075) #14171d, inset 0 calc(var(--cella) * .05) calc(var(--cella) * .05) rgba(0, 0, 0, .25);
}
#parolaTrovata.bonus { background: linear-gradient(180deg, #bff3ff, #4cc9e8); color: #06323d; box-shadow: 0 10px 28px rgba(0, 0, 0, .5), 0 5px 0 #1f8aa3; }

#punti { font-size: 1.2rem; font-weight: 700; color: #fff3a0; background: rgba(255, 255, 255, .12); border-radius: 12px; padding: 4px 12px; }
#fineRec a { color: #1d4fc4; font-weight: 800; }
