/* =========================================================================
   Sillaba per Sillaba — style.css
   Tema Training Cognitivo. Usato sia dall'autore (index.html) sia dal
   player (play.html).
   ========================================================================= */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&family=Atkinson+Hyperlegible:wght@400;700&display=swap');

:root {
  --tc-blue: #0C6895;
  --tc-blue-dark: #084c6e;
  --tc-cyan: #4DB7E0;
  --tc-orange: #E8731B;
  --tc-green: #2e9e5b;
  --tc-red: #d8413a;
  --ink: #26323a;
  --muted: #6b7a85;
  --line: #e2eaf0;
  --bg: #f1f6f9;
  --card: #ffffff;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(12, 104, 149, .10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Poppins', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.wrap { max-width: 940px; margin: 0 auto; padding: 0 16px 48px; }

/* ----------------------------- Header -------------------------------- */
.appbar {
  background: linear-gradient(90deg, var(--tc-blue) 0%, var(--tc-cyan) 100%);
  color: #fff;
}
.appbar__inner {
  max-width: 940px; margin: 0 auto; padding: 18px 16px;
  display: flex; align-items: center; gap: 12px;
}
.appbar__logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: rgba(255, 255, 255, .18);
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
  flex: none;
}
.appbar__title { font-size: 20px; font-weight: 600; margin: 0; }
.appbar__sub { font-size: 13px; opacity: .9; margin: 0; }

/* ------------------------------ Card --------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-top: 24px;
}
.card__title {
  margin: 0 0 4px; font-size: 22px; font-weight: 700; color: var(--tc-blue);
}
.card__hint { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

/* ------------------------------ Form --------------------------------- */
.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }
.field__note { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.field__note a { color: var(--tc-blue); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  font-family: inherit; font-size: 15px;
  color: var(--ink);
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--tc-cyan);
  box-shadow: 0 0 0 3px rgba(77, 183, 224, .25);
}
textarea { resize: vertical; min-height: 96px; }
.is-upper-input { text-transform: uppercase; }

.row-inline { display: flex; gap: 10px; align-items: stretch; }
.row-inline select { flex: 1; }

/* Toggle (checkbox) */
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle__track {
  width: 46px; height: 26px; border-radius: 999px; background: #cdd9e1;
  position: relative; transition: background .2s; flex: none;
}
.toggle__track::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.toggle input:checked + .toggle__track { background: var(--tc-blue); }
.toggle input:checked + .toggle__track::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle__track { box-shadow: 0 0 0 3px rgba(77, 183, 224, .35); }

/* ----------------------------- Buttons ------------------------------- */
.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: inherit; font-weight: 600; font-size: 15px;
  color: #fff; background: var(--tc-blue);
  padding: 12px 22px; border-radius: 999px;
  transition: transform .08s, box-shadow .15s, background .15s, opacity .15s;
  box-shadow: 0 6px 16px rgba(12, 104, 149, .25);
}
.btn:hover { background: var(--tc-blue-dark); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(77, 183, 224, .6); outline-offset: 2px; }
.btn--accent { background: var(--tc-orange); box-shadow: 0 6px 16px rgba(232, 115, 27, .25); }
.btn--accent:hover { background: #c9610e; }
.btn--ghost {
  background: transparent; color: var(--tc-blue);
  box-shadow: none; border: 1px solid var(--line);
}
.btn--ghost:hover { background: #eef5f9; }
.btn--sm { padding: 7px 14px; font-size: 13px; }
.btn--block { width: 100%; }

.actions-bar { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }

.error-msg { color: var(--tc-red); font-weight: 600; margin: 12px 0 0; }
.hidden { display: none !important; }

/* ----------------------------- Share box ----------------------------- */
.share { margin-top: 20px; padding: 18px; border: 1px dashed var(--tc-cyan);
  border-radius: 12px; background: #f3fafd; }
.share__row { display: flex; gap: 10px; margin-top: 8px; }
.share__row input { font-family: ui-monospace, monospace; font-size: 13px; }
.share__meta { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* ============================== GIOCO ================================= */
.game { margin-top: 8px; }

.game__top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px;
}
.game__progress { display: flex; flex-wrap: wrap; gap: 8px; }
.dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #d4dee5; border: 2px solid #c2d0d9;
  transition: background .2s, border-color .2s, transform .2s;
}
.dot--active { background: var(--tc-cyan); border-color: var(--tc-blue); transform: scale(1.15); }
.dot--ok { background: var(--tc-green); border-color: var(--tc-green); }
.dot--ko { background: var(--tc-red); border-color: var(--tc-red); }

.game__feedback { text-align: center; min-height: 28px; font-weight: 600; font-size: 18px; margin: 0 0 8px; }
.game__feedback.is-green { color: var(--tc-green); }
.game__feedback.is-red { color: var(--tc-red); }

.game__word {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 6px;
  min-height: 120px; align-items: center;
  font-size: 56px; font-weight: 600; letter-spacing: 2px;
  color: var(--ink);
}
.game__word.is-green { color: var(--tc-green); }
.game__word.is-red { color: var(--tc-red); }
.sillaba { transition: opacity .12s linear; }
.game__word.is-upper, .game__guess.is-upper { text-transform: uppercase; }

.game__inputrow { display: flex; gap: 10px; max-width: 560px; margin: 12px auto 0; }
.game__guess {
  flex: 1; font-size: 30px; text-align: center;
  border: none; border-bottom: 2px solid var(--line); border-radius: 0;
  background: transparent; padding: 6px 4px;
}
.game__guess:focus { box-shadow: none; border-bottom-color: var(--tc-cyan); }
.game__confirm { flex: none; }

.game__actions { display: flex; justify-content: center; margin-top: 22px; }
.game__next { opacity: 0; pointer-events: none; transition: opacity .2s; }
.game__next.is-on { opacity: 1; pointer-events: auto; }

/* ---------------------------- Risultati ------------------------------ */
.results { text-align: center; }
.results__score { color: var(--tc-blue); font-size: 24px; margin: 6px 0 18px; }
.bar { background: #e4edf2; border-radius: 999px; height: 26px; overflow: hidden; max-width: 560px; margin: 0 auto 24px; }
.bar__fill {
  width: 0; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--tc-blue), var(--tc-cyan));
  color: #fff; font-size: 13px; font-weight: 600; line-height: 26px;
  text-align: right; padding-right: 10px; transition: width .8s ease;
}
.results__tablewrap { overflow-x: auto; }
.results__table { width: 100%; max-width: 560px; margin: 0 auto; border-collapse: collapse; text-align: left; }
.results__table th, .results__table td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.results__table th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.row--ok .cell-esito { color: var(--tc-green); }
.row--ko .cell-esito { color: var(--tc-red); }
.cell-esito { font-size: 20px; text-align: center; }
.results__actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 26px; }

/* ----------------------------- Player -------------------------------- */
.player-card { text-align: center; }
.player-start__title { font-size: 24px; color: var(--tc-blue); margin: 8px 0; }
.player-start__hint { color: var(--muted); margin: 0 0 22px; }

/* --------------------- Opzioni avanzate / validazione ---------------- */
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }

.advanced {
  margin: 8px 0 18px; border: 1px solid var(--line); border-radius: 12px;
  background: #fafcfe; padding: 0 16px;
}
.advanced > summary {
  cursor: pointer; font-weight: 600; color: var(--tc-blue);
  padding: 14px 4px; list-style: none;
}
.advanced > summary::before { content: '▸ '; }
.advanced[open] > summary::before { content: '▾ '; }
.advanced .grid2 { padding-bottom: 8px; }

.validate { margin: 8px 0 0; font-size: 13px; font-weight: 600; min-height: 18px; }
.validate--ok { color: var(--tc-green); }
.validate--warn { color: var(--tc-orange); }

/* ------------------------------ QR ----------------------------------- */
.share__qr { display: flex; gap: 18px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.share__qr canvas {
  width: 168px; height: 168px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; padding: 6px;
}

/* ----------------------- Conto alla rovescia ------------------------- */
.countdown { font-size: 84px; font-weight: 700; color: var(--tc-cyan); }
.countdown--pop { animation: cd-pop .35s ease; }
@keyframes cd-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* --------------- Caratteri ad alta leggibilità / dimensioni ----------- */
.fnt-hl .game__word, .fnt-hl .game__guess { font-family: 'Atkinson Hyperlegible', 'Poppins', sans-serif; }
.fnt-mono .game__word, .fnt-mono .game__guess { font-family: ui-monospace, 'Courier New', monospace; letter-spacing: 4px; }
.sz-g .game__word { font-size: 72px; }
.sz-xg .game__word { font-size: 92px; }
.sz-g .game__guess { font-size: 36px; }
.sz-xg .game__guess { font-size: 42px; }

/* ----------------------------- Risultati extra ----------------------- */
.results__sub { color: var(--muted); margin: -10px 0 18px; }
.results__meta { color: var(--muted); font-size: 13px; }
.cell-time { text-align: right; color: var(--muted); white-space: nowrap; }
.print-only { display: none; }

/* --------------------------- Responsive ------------------------------ */
@media (max-width: 700px) {
  .grid2 { grid-template-columns: 1fr; }
  .game__word { font-size: 40px; min-height: 90px; }
  .game__guess { font-size: 24px; }
  .sz-g .game__word { font-size: 52px; }
  .sz-xg .game__word { font-size: 60px; }
  .card { padding: 18px; }
  .countdown { font-size: 60px; }
}

/* ----------------------- Setup a due colonne ------------------------- */
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin-top: 12px; }
.setup-col { min-width: 0; padding: 4px 0; }
.setup-col:first-child { padding-right: 32px; border-right: 1px solid var(--line); }
.setup-col:last-child { padding-left: 32px; }

.col-title { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 18px; font-weight: 700; color: var(--tc-blue); }
.col-num {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: var(--tc-blue); color: #fff; font-size: 14px;
  display: grid; place-items: center;
}
.col-hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

#stimoli { min-height: 200px; }
.field__foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.field__foot .validate { margin: 0; }
.field__foot-actions { display: flex; align-items: center; gap: 16px; }

/* righe parametro: etichetta a sinistra, controllo a destra */
.prow { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.prow:last-child { border-bottom: none; }
.prow > label, .prow__lbl { margin: 0; font-weight: 600; font-size: 14px; }
.prow .ctl { width: 170px; flex: none; }
.prow .ctl-sm { width: 110px; flex: none; }

.setup-actions {
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
  margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line);
}
.btn--lg { padding: 14px 28px; font-size: 16px; }

@media (max-width: 760px) {
  .setup-grid { grid-template-columns: 1fr; }
  .setup-col:first-child { padding-right: 0; border-right: none; }
  .setup-col:last-child { padding-left: 0; border-top: 1px solid var(--line); margin-top: 8px; padding-top: 18px; }
  #stimoli { min-height: 120px; }
}

/* --------------------------- Modale (share) -------------------------- */
.modal {
  border: none; padding: 0; background: transparent;
  max-width: 520px; width: calc(100% - 32px);
}
.modal::backdrop { background: rgba(8, 40, 60, .55); backdrop-filter: blur(3px); }
.modal[open] { animation: modal-in .18s ease; }
@keyframes modal-in { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal__card { background: #fff; border-radius: 20px; padding: 28px; position: relative; box-shadow: 0 30px 80px rgba(8, 76, 110, .35); }
.modal__close {
  position: absolute; top: 12px; right: 14px; border: none; background: transparent;
  font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px;
}
.modal__close:hover { color: var(--ink); }
.modal__title { margin: 0 0 8px; color: var(--tc-blue); font-size: 22px; }
.modal__text { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.modal__actions { display: flex; justify-content: flex-end; margin-top: 22px; }

/* ------------------- Accessibilità: meno animazioni ------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .bar__fill { transition: none !important; }
}

/* ------------------------------- Stampa ------------------------------ */
@media print {
  .appbar, .no-print, .advanced, .share { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; margin: 0; padding: 0; }
  .print-only { display: block; }
  .bar { border: 1px solid #ccc; }
  .results__table th, .results__table td { border-color: #ccc; }
}
