/* =========================================================
   Stile comune della piattaforma: colori, bottoni, finestre,
   area adulti. Ogni gioco aggiunge solo il proprio stile.
   ========================================================= */

/* Palette calma, basso contrasto di sfondo, alto contrasto sul testo */
:root {
  --bg: #eef3f1;
  --panel: #ffffff;
  --ink: #22302c;
  --muted: #5d6e69;
  --line: #cfdcd7;
  --slot: #e2ebe7;
  --accent: #3f7f6e;
  --accent-ink: #ffffff;
  --good: #2f8a5b;
  --warn: #b5762a;
  --calm: #6f8fb8;
  --radius: 14px;
  --t: 220ms;
}
body.high-contrast {
  --bg: #ffffff; --panel: #ffffff; --ink: #000000; --muted: #222;
  --line: #000000; --slot: #f0f0f0; --accent: #003b8e;
}
body.dark {
  --bg: #1b2321; --panel: #253030; --ink: #eef4f2; --muted: #a9bab5;
  --line: #3b4a47; --slot: #2c3836; --accent: #7fc4b0; --accent-ink: #10201c;
}
/* Colori dei grafici: validati per daltonismo (impulsiva / regolare / esitazione / linea) */
:root { --viz-fast: #eb6834; --viz-ok: #1baf7a; --viz-slow: #2a78d6; --viz-line: #2a78d6; }
body.dark { --viz-fast: #d95926; --viz-ok: #199e70; --viz-slow: #3987e5; --viz-line: #3987e5; }
body.reduce-motion { --t: 0ms; }
@media (prefers-reduced-motion: reduce) { :root { --t: 0ms; } }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "Atkinson Hyperlegible", system-ui, sans-serif;
  font-size: 18px; line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.screen { display: none; }
.screen.active { display: flex; }
.app { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; flex-direction: column; gap: 12px; min-height: 100vh; }

/* ---------- Home e preparazione ---------- */
.menu h1 { font-size: 34px; margin: 8px 0 0; text-align: center; }
.menu .sub { text-align: center; color: var(--muted); margin: 0 0 6px; }
.box { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; }
.box h2 { font-size: 20px; margin: 0 0 10px; }
.name-input { width: 100%; font: inherit; min-height: 52px; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); }

.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.game-card {
  border: 3px solid var(--line); border-radius: var(--radius); background: var(--bg);
  padding: 14px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left;
}
.game-card:hover, .game-card:focus-visible { border-color: var(--accent); }
.game-card .em { font-size: 40px; line-height: 1; }
.game-card b { font-size: 20px; }
.game-card small { color: var(--muted); font-size: 15px; }

.setup-head { display: flex; align-items: center; gap: 12px; }
.setup-head .em { font-size: 44px; }
.setup-head h1 { font-size: 28px; margin: 0; text-align: left; }
.setup-head p { margin: 2px 0 0; color: var(--muted); }

.diffs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.diff { border: 3px solid var(--line); border-radius: var(--radius); background: var(--bg); padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.diff .em { font-size: 34px; }
.diff b { font-size: 18px; }
.diff small { color: var(--muted); font-size: 14px; }
.diff[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.menu-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn.play { font-size: 24px; min-height: 64px; padding: 10px 40px; }
.adult-btn { align-self: center; margin-top: 6px; position: relative; overflow: hidden; border: 2px solid var(--line); background: transparent; border-radius: 99px; padding: 8px 16px; color: var(--muted); font-size: 15px; touch-action: none; }
.adult-btn i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---------- Fine partita ---------- */
.fine-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.fine-stat { background: var(--bg); border-radius: 12px; padding: 12px 8px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.fine-stat .em { font-size: 30px; }
.fine-stat b { font-size: 30px; }
.fine-stat span:last-child { font-size: 15px; color: var(--muted); }
.fine-msg { text-align: center; margin: 12px 0 0; font-size: 18px; }
.moods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mood { border: 3px solid var(--line); border-radius: var(--radius); background: var(--bg); padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 16px; }
.mood .em { font-size: 44px; line-height: 1; }
.mood[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.fine-mood { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 18px; }

/* ---------- Gioco delle emozioni (prima e dopo la partita) ---------- */
:root { --z-verde: #d5ecd9; --z-gialla: #f6e8b4; --z-rossa: #f4cdc9; --z-blu: #d0ddf2; }
body.dark { --z-verde: #2f4a37; --z-gialla: #4d4425; --z-rossa: #503030; --z-blu: #2c3a52; }
.emo-overlay { z-index: 15; }
.emo-dialog { max-width: 560px; text-align: center; }
.emo-mascot { display: flex; align-items: flex-end; gap: 10px; text-align: left; margin-bottom: 10px; }
.emo-tarta { font-size: 52px; line-height: 1; animation: emo-bob 2.4s ease-in-out infinite; }
.emo-bubble { position: relative; background: var(--bg); border: 2px solid var(--line); border-radius: 16px; padding: 10px 14px; font-size: 19px; flex: 1; }
.emo-bubble::before { content: ""; position: absolute; left: -10px; bottom: 14px; border: 8px solid transparent; border-right-color: var(--line); }
.emo-ricordo { color: var(--muted); font-size: 15px; margin: 4px 0 10px; }
.emo-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.emo-face {
  border: 2px solid rgba(0,0,0,.12); border-radius: 14px; padding: 8px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 13px; color: var(--ink); animation: emo-in calc(var(--t) * 1.8) ease both; animation-delay: calc(var(--n) * 40ms);
}
.emo-face .em { font-size: 38px; line-height: 1.1; transition: transform var(--t); }
.emo-face:hover .em, .emo-face:focus-visible .em { transform: scale(1.15) rotate(-6deg); }
.z-verde { background: var(--z-verde); } .z-gialla { background: var(--z-gialla); } .z-rossa { background: var(--z-rossa); } .z-blu { background: var(--z-blu); }
.emo-big { width: 110px; height: 110px; margin: 6px auto 12px; border-radius: 50%; display: grid; place-items: center; font-size: 64px; animation: pop calc(var(--t) * 1.6) ease; }
.emo-int { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-items: end; }
.emo-int button { border: 2px solid var(--line); background: var(--bg); border-radius: 14px; padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 16px; min-height: 110px; justify-content: flex-end; }
.emo-dot { width: var(--s); height: var(--s); border-radius: 50%; background: var(--calm); opacity: .8; }
.emo-skip { margin-top: 12px; border: none; background: none; color: var(--muted); text-decoration: underline; font-size: 15px; min-height: 44px; }
@keyframes emo-in { from { transform: translateY(10px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes emo-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
body.reduce-motion .emo-tarta, body.reduce-motion .emo-face, body.reduce-motion .emo-big { animation: none; }
@media (max-width: 520px) {
  .emo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .emo-face { flex-direction: row; justify-content: flex-start; gap: 8px; padding: 6px 10px; font-size: 16px; }
  .emo-face .em { font-size: 30px; }
}

/* ---------- Barra in alto durante il gioco ---------- */
.top { display: flex; align-items: center; gap: 10px; }
.goal { flex: 1; background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.goal-label { font-size: 15px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 12px; background: var(--slot); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width var(--t) ease; }
.timebar { display: none; align-items: center; gap: 6px; margin-top: 6px; font-size: 14px; color: var(--muted); }
.timebar.on { display: flex; }
.timebar .bar { flex: 1; margin: 0; height: 8px; }
.timebar .bar > i { background: var(--calm); transition: width 500ms linear; }
.icon-btn { width: 52px; height: 52px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--panel); font-size: 24px; display: grid; place-items: center; flex: none; }
.game-area { display: flex; flex-direction: column; gap: 12px; flex: 1; }

/* ---------- Carte/tessere: colore + numero + simbolo (mai solo colore) ---------- */
.card {
  height: 60px; border-radius: 10px; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-weight: 700; font-size: 22px; color: #1d2624; flex: none;
  border: 2px solid rgba(0,0,0,.18); box-shadow: 0 2px 0 rgba(0,0,0,.12);
  transition: transform var(--t) ease;
}
.card .sym { font-size: 18px; }
.card.pop { animation: pop calc(var(--t) * 1.6) ease; }
.card.drop { animation: drop var(--t) ease; }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes drop { from { transform: translateY(-14px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.shake { animation: shake calc(var(--t) * 1.2) ease; }

/* ---------- Strumenti e messaggi ---------- */
.tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tool { min-height: 52px; padding: 6px 14px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 8px; }
.tool[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, var(--panel)); }
.tool:disabled { opacity: .45; cursor: default; }
.tool small { color: var(--muted); }
.stars { font-weight: 700; }
.msg { min-height: 26px; text-align: center; color: var(--muted); font-size: 17px; }

/* ---------- Area adulti ---------- */
.report { user-select: text; }
.report h1 { font-size: 26px; margin: 4px 0; }
.note { font-size: 14px; color: var(--muted); }
.report select { font: inherit; min-height: 44px; width: 100%; border-radius: 10px; border: 2px solid var(--line); background: var(--panel); color: var(--ink); padding: 4px 8px; }
.report-filters { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.area h2 { display: flex; align-items: center; gap: 8px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.metric { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.metric .v { font-size: 22px; font-weight: 700; }
.metric .l { font-size: 14px; color: var(--muted); }
.read { font-size: 14px; color: var(--muted); margin: 10px 0 0; }
.chart { width: 100%; height: 150px; display: block; margin-top: 8px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; background: var(--c); vertical-align: -1px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }

/* ---------- Finestre ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,30,28,.45); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.overlay.open { display: flex; }
.dialog { background: var(--panel); color: var(--ink); border-radius: 20px; padding: 22px; max-width: 460px; width: 100%; max-height: 90vh; overflow: auto; }
.dialog h2 { margin: 0 0 10px; font-size: 26px; }
.dialog p { margin: 8px 0; }
.btn { min-height: 52px; padding: 10px 18px; border-radius: var(--radius); border: 2px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.step { display: flex; gap: 12px; align-items: center; margin: 10px 0; }
.step .n { flex: none; width: 34px; height: 34px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; }
.setting { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.setting select { font: inherit; min-height: 40px; border-radius: 8px; border: 2px solid var(--line); background: var(--panel); color: var(--ink); }
.switch { width: 58px; height: 34px; border-radius: 99px; border: 2px solid var(--line); background: var(--slot); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 99px; background: var(--muted); transition: left var(--t); }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { left: 27px; background: #fff; }
.breathe { width: 120px; height: 120px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 30%, transparent); margin: 16px auto; animation: breathe 8s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(.7); } 50% { transform: scale(1); } }
body.reduce-motion .breathe { animation: none; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .card { height: 50px; font-size: 17px; gap: 0; flex-direction: column; line-height: 1; overflow: hidden; }
  .card .sym { font-size: 13px; }
  .tool { padding: 6px 10px; }
  .settings-grid { grid-template-columns: 1fr; }
  .diff .em { font-size: 28px; }
  .report-filters { grid-template-columns: 1fr; }
}
.umore-riga { margin: 0 0 10px; font-size: 16px; }
/* i risultati si vedono solo dopo che il bambino ha scelto come si sente */
.attesa-umore > *:not(h1) { visibility: hidden; }

/* ---------- Impostazioni ---------- */
.set-list { display: flex; flex-direction: column; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.set-row:last-child { border-bottom: none; }
.set-row .set-label { display: flex; flex-direction: column; gap: 2px; flex: 1 1 200px; }
.set-row .set-label small { color: var(--muted); font-size: 14px; }
/* scelte a bottoni grandi invece dei menu a tendina: più facili da toccare */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { min-height: 44px; padding: 6px 12px; border-radius: 99px; border: 2px solid var(--line); background: var(--bg); font-size: 15px; }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.set-locked .set-list { opacity: .5; }
.set-locked .set-list button { pointer-events: none; }
.set-box-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.set-box-head h2 { margin: 0; }
.set-box-head .adult-btn { margin: 0; }

/* ---------- Pausa con durata ---------- */
.pause-timer { margin: 4px 0 8px; text-align: center; }
.pause-timer .bar > i { background: var(--calm); transition: width 300ms linear; }
.pause-timer p { margin: 6px 0 0; font-size: 18px; }
.pause-timer.done p { font-weight: 700; color: var(--good); }

/* ---------- Tempo massimo di gioco ---------- */
.limit-chip { align-self: center; background: var(--panel); border: 2px solid var(--calm); border-radius: 99px; padding: 6px 14px; font-size: 16px; }

/* ---------- Grandezza del testo ---------- */
body.testo-grande .app, body.testo-grande .dialog { zoom: 1.12; }
body.testo-molto .app, body.testo-molto .dialog { zoom: 1.25; }
.set-ctrl { display: flex; align-items: center; gap: 8px; }
.set-ctrl .btn { min-height: 44px; padding: 6px 12px; font-size: 15px; }
#setupOpts { display: flex; flex-direction: column; gap: 12px; }
.setup-note { margin: -4px 0 10px; }

/* ---------- Lettura ad alta voce (BETA): bottoni 🔊 ---------- */
.speak { border: 2px solid var(--line); background: var(--panel); border-radius: 99px; width: 44px; height: 44px; font-size: 20px; display: inline-grid; place-items: center; padding: 0; flex: none; vertical-align: middle; }
.speak[hidden] { display: none; }
.msg { display: flex; align-items: center; justify-content: center; gap: 8px; }
.dialog { position: relative; }
.speak-corner { position: absolute; top: 14px; right: 14px; }
.dialog:has(> .speak-corner) > h2 { padding-right: 54px; }
.emo-bubble .speak { float: right; margin: -4px -6px 4px 8px; width: 40px; height: 40px; font-size: 18px; }
.beta { font-size: 11px; font-weight: 700; background: var(--calm); color: #fff; border-radius: 99px; padding: 2px 7px; margin-left: 6px; vertical-align: 2px; }

/* ---------- Tutorial visivo ---------- */
.tut-dialog { text-align: center; max-width: 480px; }
.tut-stage { position: relative; height: 210px; background: var(--bg); border-radius: var(--radius); overflow: hidden; }
.tut-pezzo { position: absolute; margin: 0; transition: left 700ms ease, top 700ms ease, opacity 300ms ease, transform 300ms ease; }
.tut-salto .tut-pezzo, body.reduce-motion .tut-pezzo { transition: none; }
@media (prefers-reduced-motion: reduce) { .tut-pezzo { transition: none; } }
.tut-casella { background: var(--slot); border: 2px dashed var(--line); border-radius: 12px; }
.tut-em { font-size: 42px; line-height: 1; z-index: 3; }
.tut-dorso { background: var(--accent); background-image: radial-gradient(circle at 50% 50%, rgba(255,255,255,.22) 18%, transparent 19%); background-size: 18px 18px; border-radius: 10px; border: 2px solid rgba(0,0,0,.18); }
.tut-faccia { display: grid; place-items: center; border-radius: 10px; border: 2px solid rgba(0,0,0,.18); font-size: 36px; z-index: 1; }
.tut-testo { font-size: 24px; font-weight: 700; margin: 14px 0 10px; }
.tut-dots { display: flex; gap: 8px; justify-content: center; }
.tut-dots i { width: 12px; height: 12px; border-radius: 99px; background: var(--line); }
.tut-dots i.on { background: var(--accent); }
.tut-row { justify-content: center; }
.tut-row .btn[hidden], .emo-skip[hidden] { display: none; }
.speak-corner { z-index: 5; }
