/* sito/gioca/app.css — l'app di gioco di Verandia. Dentro Telegram prende i colori del tema dell'utente
   (le variabili --tg-theme-* che mette telegram-web-app.js); fuori, i suoi. Pensata per il telefono. */
:root {
  --f-fondo: #f2f0eb; --f-carta: #ffffff; --f-testo: #1b1f2a; --f-tenue: #6b6f7b; --f-accento: #14213d; --f-su-accento: #ffffff;
  --f-link: #1f4fbf; --f-bordo: rgba(20, 33, 61, 0.12); --f-ombra: 0 1px 2px rgba(20, 33, 61, .06), 0 6px 20px rgba(20, 33, 61, .06);
  --oro: #e0a91b; --rosso: #c0392b; --verde: #1e8e5a; --giallo-fondo: #fff6dc; --rosso-fondo: #fdecea;
  --fondo: var(--tg-theme-secondary-bg-color, var(--f-fondo));
  --carta: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--f-carta)));
  --testo: var(--tg-theme-text-color, var(--f-testo));
  --tenue: var(--tg-theme-hint-color, var(--f-tenue));
  --accento: var(--tg-theme-button-color, var(--f-accento));
  --su-accento: var(--tg-theme-button-text-color, var(--f-su-accento));
  --link: var(--tg-theme-link-color, var(--f-link));
  --bordo: var(--f-bordo);
  --raggio: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --f-fondo: #0f1320; --f-carta: #181d2c; --f-testo: #e9ecf4; --f-tenue: #9aa3b5; --f-accento: #f2c14e; --f-su-accento: #14213d;
    --f-link: #8fb4ff; --f-bordo: rgba(233, 236, 244, 0.12); --f-ombra: 0 1px 2px rgba(0, 0, 0, .3);
    --giallo-fondo: #3a3014; --rosso-fondo: #3b1c1a;
  }
}
:root[data-theme="dark"] {
  --f-fondo: #0f1320; --f-carta: #181d2c; --f-testo: #e9ecf4; --f-tenue: #9aa3b5; --f-accento: #f2c14e; --f-su-accento: #14213d;
  --f-link: #8fb4ff; --f-bordo: rgba(233, 236, 244, 0.12); --f-ombra: 0 1px 2px rgba(0, 0, 0, .3);
  --giallo-fondo: #3a3014; --rosso-fondo: #3b1c1a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--fondo); color: var(--testo);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- la testata ---- */
.testa {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--carta); border-bottom: 1px solid var(--bordo);
}
.testa-chi { display: flex; align-items: center; gap: 10px; min-width: 0; }
.testa-colore { width: 10px; height: 36px; border-radius: 6px; background: var(--accento); flex: none; }
.testa-nome { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.testa-ruolo { color: var(--tenue); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pa { flex: none; font-weight: 700; background: var(--fondo); border: 1px solid var(--bordo); border-radius: 999px; padding: 6px 12px; font-variant-numeric: tabular-nums; }

/* ---- la vista ---- */
.vista { flex: 1; padding: 16px; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.vista.chat-aperta { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--tenue); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.nota { color: var(--tenue); font-size: 14px; }
.caricamento { display: grid; place-items: center; min-height: 40vh; }
.ruota { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--bordo); border-top-color: var(--accento); animation: gira 0.8s linear infinite; display: inline-block; }
.ruota.piccola { width: 16px; height: 16px; border-width: 2px; vertical-align: -3px; margin-right: 6px; }
@keyframes gira { to { transform: rotate(360deg); } }

.carta { background: var(--carta); border: 1px solid var(--bordo); border-radius: var(--raggio); padding: 14px; margin-bottom: 12px; box-shadow: var(--f-ombra); }
.carta.cliccabile { cursor: pointer; }
.carta.cliccabile:active { transform: scale(.995); }
.riga { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.riga + .riga { margin-top: 8px; }
.etichetta { font-size: 13px; color: var(--tenue); }
.titolo-carta { font-weight: 700; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--fondo); border: 1px solid var(--bordo); white-space: nowrap; }
.pill.rossa { background: var(--rosso-fondo); color: var(--rosso); border-color: transparent; }
.pill.verde { color: var(--verde); }
.banda { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.banda.gialla { background: var(--giallo-fondo); }
.banda.rossa { background: var(--rosso-fondo); }

/* l'orologio a spicchi */
.orologio { display: inline-flex; gap: 4px; }
.orologio i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accento); display: inline-block; }
.orologio i.pieno { background: var(--accento); }

/* ---- i moduli ---- */
label.campo { display: block; margin: 12px 0; }
label.campo > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--bordo); background: var(--fondo); border-radius: 12px; padding: 12px; outline: none; font-size: 16px;
}
textarea { min-height: 110px; resize: vertical; }
textarea.grande { min-height: 220px; }
input:focus, select:focus, textarea:focus { border-color: var(--accento); }
.interruttore { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.interruttore input { width: 22px; height: 22px; accent-color: var(--accento); }
.manca { border-color: var(--rosso) !important; }

.bottone {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--bordo); background: var(--carta); font-weight: 700; cursor: pointer; text-decoration: none; color: var(--testo);
}
.bottone.primo { background: var(--accento); color: var(--su-accento); border-color: transparent; }
.bottone.pieno { width: 100%; }
.bottone.piccolo { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.bottone:disabled { opacity: .5; cursor: default; }
.bottone:active:not(:disabled) { transform: translateY(1px); }
.bottoni { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.bottoni > .bottone { flex: 1 1 auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip { border: 1px solid var(--bordo); background: var(--carta); border-radius: 999px; padding: 8px 12px; font-size: 14px; cursor: pointer; }

/* ---- l'elenco delle azioni ---- */
details.categoria { background: var(--carta); border: 1px solid var(--bordo); border-radius: var(--raggio); margin-bottom: 8px; overflow: hidden; }
details.categoria summary { list-style: none; padding: 14px; font-weight: 700; cursor: pointer; display: flex; justify-content: space-between; }
details.categoria summary::-webkit-details-marker { display: none; }
details.categoria[open] summary { border-bottom: 1px solid var(--bordo); }
.azione { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--bordo); background: none; text-align: left; cursor: pointer; }
.azione:last-child { border-bottom: 0; }

/* ---- gli articoli dell'editor ---- */
.articolo { border: 1px solid var(--bordo); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: var(--fondo); }
.articolo .riga input { font-weight: 600; }
.articolo .n { white-space: nowrap; font-size: 14px; }
.articolo textarea { min-height: 90px; margin-top: 8px; background: var(--carta); }
ul.lista { margin: 6px 0 0; padding-left: 18px; }
ul.lista li { margin: 4px 0; }

/* ---- la chat con il bot ---- */
.chat { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 92%; background: var(--carta); border: 1px solid var(--bordo); border-radius: 14px 14px 14px 4px; padding: 10px 12px; overflow-wrap: anywhere; }
.msg.mio { align-self: flex-end; background: var(--accento); color: var(--su-accento); border-radius: 14px 14px 4px 14px; border-color: transparent; }
.msg.avviso-bot { align-self: center; font-size: 13px; color: var(--tenue); background: transparent; border: 0; }
.msg pre, .msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; white-space: pre-wrap; }
.msg blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--bordo); }
.msg .allegato { display: block; margin-top: 8px; }
.msg .allegato img { max-width: 100%; border-radius: 10px; display: block; }
.msg-tasti { display: grid; gap: 6px; margin-top: 8px; }
.msg-tasti .fila { display: flex; gap: 6px; }
.msg-tasti button, .msg-tasti a { flex: 1; min-height: 40px; border-radius: 10px; border: 1px solid var(--bordo); background: var(--fondo); font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px 8px; text-align: center; text-decoration: none; color: var(--link); }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 6;
  background: var(--carta); border-top: 1px solid var(--bordo); padding: 8px 12px;
}
.composer form { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; }
.composer textarea { min-height: 44px; max-height: 140px; height: 44px; padding: 10px 12px; }
.composer .bottone { min-height: 44px; }

/* ---- le schede in basso ---- */
.schede {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex; justify-content: center;
  background: var(--carta); border-top: 1px solid var(--bordo); padding-bottom: env(safe-area-inset-bottom);
}
.schede button { position: relative; flex: 1; max-width: 144px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; border: 0; background: none; color: var(--tenue); font-size: 11px; font-weight: 600; cursor: pointer; }
.schede .ico { font-size: 22px; line-height: 1.1; filter: grayscale(.6); opacity: .8; }
.schede button.attiva { color: var(--accento); }
.schede button.attiva .ico { filter: none; opacity: 1; }
.pallino { position: absolute; top: 6px; right: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: var(--rosso); }

.avviso {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 9; max-width: 688px; margin: 0 auto;
  background: var(--testo); color: var(--carta); border-radius: 12px; padding: 12px 14px; font-size: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}

/* ---- l'accesso fuori da Telegram ---- */
.accesso { min-height: 80vh; display: grid; place-items: center; text-align: center; }
.accesso .stemma { width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 18px; background: #14213d; display: grid; place-items: center; color: #f2c14e; font-weight: 800; font-size: 34px; }

@media (min-width: 760px) {
  .vista { padding: 24px; padding-bottom: 100px; }
}
