/* I Traditori — il castello di notte.
   Verde pino per le stanze di pietra, luce di candela per gli accenti,
   rosso sangue solo per i Traditori, pergamena per le lettere e il testo. */
:root {
  --bg: #0e1915;
  --bg-2: #13211c;
  --surface: #182a23;
  --surface-2: #1f342c;
  --line: #2b443a;
  --line-2: #3d5c4f;
  --text: #f0e6cf;
  --text-2: #cfc5ad;
  --muted: #8fa69b;
  --candle: #ebb85e;
  --candle-2: #f6d594;
  --candle-ink: #2a1d07;
  --candle-glow: rgba(235, 184, 94, 0.16);
  --blood: #a8261f;
  --blood-2: #e0574a;
  --blood-bg: #2b1211;
  --parchment: #eadbb8;
  --parchment-2: #dcc89c;
  --parchment-ink: #3a2a16;
  --wax: #9e1c17;
  --ok: #62b882;
  --ice: #8cc8f0;
  --team-rosso: #d2452f;
  --team-blu: #4489d4;
  --team-verde: #49a86c;

  --display: 'Grenze Gotisch', Georgia, 'Times New Roman', serif;
  --sans: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --gap: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(100% 55% at 50% -12%, var(--candle-glow), transparent 62%) fixed,
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; }
h2 { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.005em; }
h3 { font-size: 1rem; font-weight: 800; color: var(--text-2); margin: 18px 0 8px; }
p { margin: 6px 0; }
small, .muted { color: var(--muted); }
a { color: var(--candle); }
b, strong { font-weight: 800; }
.display { font-family: var(--display); font-weight: 800; letter-spacing: 0.01em; }
:focus-visible { outline: 3px solid var(--candle); outline-offset: 2px; border-radius: 6px; }

.ic { width: 1.15em; height: 1.15em; flex: none; display: inline-block; vertical-align: -0.2em; }

/* ---------------- intestazione del giocatore ---------------- */
.top {
  position: sticky; top: 0; z-index: 20;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 12px;
  background: linear-gradient(180deg, rgba(14, 25, 21, 0.98) 72%, rgba(14, 25, 21, 0));
}
.top-row { display: flex; align-items: center; gap: 10px; max-width: 560px; margin: 0 auto; }
.brand-mark { font-family: var(--display); font-weight: 800; font-size: 1.05rem; color: var(--candle); letter-spacing: 0.02em; }
.top-row .spacer { flex: 1 1 auto; }
.phase {
  font-family: var(--display); font-weight: 800; color: var(--text);
  font-size: 2.35rem; line-height: 1; max-width: 560px; margin: 8px auto 0;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; max-width: 560px; margin: 10px auto 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 0.88rem; font-weight: 600; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.chip b { color: var(--text); }
.chip.timer { background: var(--blood-bg); border-color: var(--blood); color: #fff; font-weight: 800; font-size: 1rem; }
.chip.timer.done { background: var(--blood); animation: pulse 1s infinite; }
.chip.team { color: #fff; border: 0; font-weight: 800; }
.chip.team.rosso { background: var(--team-rosso); }
.chip.team.blu { background: var(--team-blu); }
.chip.team.verde { background: var(--team-verde); }
@keyframes pulse { 50% { opacity: 0.55; } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text-2); font-weight: 700; font-size: 0.9rem; cursor: pointer;
}
.icon-btn:active { transform: translateY(1px); }

.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px calc(48px + var(--safe-b)); }

/* ---------------- superfici ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px; margin: var(--gap) 0;
}
.card.center { text-align: center; }
.card > h2 + p { margin-top: 8px; }

/* il riquadro "ora tocca a te": la cosa più importante sul telefono */
.now { border-color: var(--line-2); background: var(--surface-2); box-shadow: 0 0 0 1px rgba(235, 184, 94, 0.06), 0 18px 40px -24px rgba(0, 0, 0, 0.8); }
.how {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; padding: 12px 14px;
  border-radius: var(--r-sm); background: rgba(235, 184, 94, 0.08); color: var(--candle-2); font-size: 0.95rem;
}
.how .ic { color: var(--candle); margin-top: 2px; }

.announce {
  display: flex; gap: 12px; align-items: flex-start;
  border-radius: var(--r-md); padding: 14px 16px; margin: var(--gap) 0;
  background: var(--surface); border: 1px solid var(--line-2); font-weight: 600; font-size: 1.02rem;
}
.announce .ic { color: var(--candle); margin-top: 3px; }
.announce.dark { background: var(--blood-bg); border-color: var(--blood); }
.announce.dark .ic { color: var(--blood-2); }
.announce.gold { background: #2a2210; border-color: #6b5426; color: var(--candle-2); }
.announce.fresh { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(235, 184, 94, 0.7); } 100% { box-shadow: 0 0 0 20px rgba(235, 184, 94, 0); } }

/* ---------------- pulsanti ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 18px; border-radius: var(--r-md); border: 1px solid var(--line-2);
  background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 800; font-size: 1rem; text-align: center;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; transition: transform 0.06s;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--candle); color: var(--candle-ink); border-color: var(--candle); box-shadow: 0 10px 24px -14px rgba(235, 184, 94, 0.9); }
.btn.danger { background: var(--blood); border-color: var(--blood); color: #fff; }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; padding: 8px 12px; font-size: 0.9rem; border-radius: var(--r-sm); }
.btn.sel { border-color: var(--candle); background: #2c2614; color: var(--candle-2); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack > * + * { margin-top: 10px; }

input[type=text], input[type=number], input[type=password], textarea, select {
  width: 100%; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid var(--line-2);
  background: var(--bg-2); font-size: 17px; color: var(--text);
}
input::placeholder, textarea::placeholder { color: #6f8579; }
textarea { min-height: 150px; resize: vertical; font-size: 15px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--candle); outline-offset: 0; border-color: transparent; }
label.check { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; }
label.check input { width: 22px; height: 22px; accent-color: var(--candle); }

/* ---------------- ingresso ---------------- */
.join-hero { text-align: center; padding: 26px 18px 22px; }
.join-hero .seal-big { margin: 0 auto 14px; }
.join-hero h1 { font-family: var(--display); font-weight: 800; font-size: 2.6rem; color: var(--candle); }
.join-hero p { color: var(--text-2); }

/* ---------------- la lettera col sigillo (ruolo) ---------------- */
.letter {
  position: relative; margin: var(--gap) 0; border-radius: 8px 8px var(--r-lg) var(--r-lg);
  padding: 26px 20px 24px; text-align: center; color: var(--parchment-ink);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 255, 255, 0.35), transparent 60%),
    linear-gradient(180deg, var(--parchment), var(--parchment-2));
  box-shadow: 0 24px 50px -28px rgba(0, 0, 0, 0.9), inset 0 0 0 1px rgba(58, 42, 22, 0.18);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
  min-height: 210px; cursor: pointer;
}
.letter .cover { display: grid; justify-items: center; gap: 10px; }
.letter .cover p { margin: 0; font-weight: 600; color: #5a4526; }
.letter .cover .lead { font-weight: 800; font-size: 1.1rem; color: var(--parchment-ink); }
.letter .reveal { display: none; }
.letter.open .reveal { display: block; animation: unseal 0.18s ease-out; }
.letter.open .cover { display: none; }
@keyframes unseal { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }
.seal {
  width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 34% 30%, #d13a2f, var(--wax) 55%, #5e0f0b);
  box-shadow: 0 6px 14px -4px rgba(94, 15, 11, 0.7), inset 0 -3px 6px rgba(0, 0, 0, 0.35), inset 0 2px 3px rgba(255, 255, 255, 0.25);
  color: #f6d9a8; font-family: var(--display); font-weight: 800; font-size: 2.1rem;
}
.seal-big { width: 96px; height: 96px; font-size: 2.6rem; }
.role-name { font-family: var(--display); font-weight: 800; font-size: 3.2rem; line-height: 1; margin: 6px 0 8px; }
.role-name.traditore { color: var(--wax); }
.role-name.leale { color: #2f5a46; }
.letter .reveal p { color: #4a3820; font-weight: 600; }
.letter .reveal .allies { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(158, 28, 23, 0.1); color: var(--parchment-ink); }
.letter .hold-hint { display: inline-flex; gap: 8px; align-items: center; margin-top: 4px; padding: 6px 12px; border-radius: 999px; background: rgba(58, 42, 22, 0.1); font-size: 0.85rem; font-weight: 700; color: #5a4526; }

/* ---------------- liste e segni ---------------- */
.plist { list-style: none; padding: 0; margin: 0; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.plist li:last-child { border-bottom: 0; }
.plist .name { flex: 1 1 auto; font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #4a5a53; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(98, 184, 130, 0.18); }
.tdot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; flex: none; }
.tdot.rosso { background: var(--team-rosso); } .tdot.blu { background: var(--team-blu); } .tdot.verde { background: var(--team-verde); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.76rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.badge.trad { color: #ffb0a6; border-color: var(--blood); background: var(--blood-bg); }
.badge.leale { color: var(--candle-2); border-color: #6b5426; }
.badge.shield { color: var(--ice); border-color: #2f6390; }
.dead-name { text-decoration: line-through; color: var(--muted); }
.team-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: 0.88rem; color: #fff; }
.team-chip.rosso { background: var(--team-rosso); } .team-chip.blu { background: var(--team-blu); } .team-chip.verde { background: var(--team-verde); }

details.card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; font-weight: 800; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary .chev { margin-left: auto; transition: transform 0.15s; color: var(--muted); }
details.card[open] > summary .chev { transform: rotate(180deg); }
details.card[open] > summary { margin-bottom: 8px; }

/* ---------------- voto ---------------- */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.choice {
  min-height: 58px; padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--line-2);
  background: var(--bg-2); font-weight: 800; font-size: 1.02rem; cursor: pointer; text-align: center;
}
.choice.sel { border-color: var(--candle); background: var(--candle); color: var(--candle-ink); box-shadow: 0 0 0 3px rgba(235, 184, 94, .25); }
.choice.big { min-height: 84px; font-size: 1.3rem; }
.confirm-bar { margin-top: 14px; }
.tally { list-style: none; margin: 12px 0 0; padding: 0; }
.tally li { margin: 10px 0; font-weight: 700; }
.tally .n { color: var(--muted); font-weight: 600; margin-left: 6px; }
.bar { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--blood), var(--blood-2)); margin-top: 5px; }
.ballots { font-size: 0.9rem; color: var(--muted); columns: 2; column-gap: 18px; margin-top: 12px; }
.ballots div { break-inside: avoid; padding: 3px 0; }
.ballots b { color: var(--text-2); }
.progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--muted); font-weight: 600; font-size: 0.92rem; }
.progress .track { flex: 1 1 auto; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress .fill { height: 100%; background: var(--candle); border-radius: 3px; transition: width 0.3s; }

/* ---------------- quiz ---------------- */
.qtext { font-size: 1.3rem; font-weight: 800; line-height: 1.3; margin: 10px 0 14px; }
.qopts { display: grid; gap: 10px; }
.qopt {
  text-align: left; padding: 14px; border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--bg-2);
  font-weight: 700; cursor: pointer; display: flex; gap: 12px; align-items: center; min-height: 58px; width: 100%;
}
.qopt .k { width: 32px; height: 32px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; color: var(--candle); flex: none; }
.qopt.sel { border-color: var(--candle); }
.qopt.right { border-color: var(--ok); background: #143323; }
.qopt.right .k { background: var(--ok); color: #082414; }
.qopt.wrong { opacity: 0.5; }

/* ---------------- notte ---------------- */
.sigil {
  width: 220px; height: 220px; border-radius: 50%; margin: 18px auto; display: grid; place-items: center; text-align: center;
  padding: 30px; color: var(--muted); font-weight: 700; font-size: 0.98rem;
  background: radial-gradient(circle at 50% 40%, #233a31, #0f1b17 70%);
  border: 2px solid var(--line-2);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
  transition: transform 0.15s, box-shadow 0.2s, color 0.2s, border-color 0.2s;
}
.sigil .ic { width: 44px; height: 44px; color: var(--line-2); display: block; margin: 0 auto 8px; transition: color 0.2s; }
.sigil.pressed { transform: scale(0.96); color: var(--candle-2); border-color: var(--candle); box-shadow: 0 0 60px rgba(235, 184, 94, 0.3); }
.sigil.pressed .ic { color: var(--candle); }

/* ---------------- cifrario ---------------- */
.cipher-text {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 1.3rem; letter-spacing: 0.14em; line-height: 1.5;
  background: var(--bg-2); border: 1px solid var(--line); padding: 16px; border-radius: var(--r-md);
  word-break: break-word; text-align: center; color: var(--candle-2); margin-top: 12px;
}
.keytable { display: grid; grid-template-columns: repeat(13, 1fr); gap: 3px; font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; text-align: center; margin: 12px 0; }
.keytable div { background: var(--bg-2); border-radius: 6px; padding: 4px 0; line-height: 1.2; color: var(--text-2); }
.keytable b { color: var(--candle); display: block; }

/* ---------------- segreti ---------------- */
.secret { display: flex; gap: 10px; align-items: flex-start; background: #14232c; border: 1px solid #284556; border-radius: var(--r-sm); padding: 12px 14px; margin-top: 10px; }
.secret .ic { color: var(--ice); margin-top: 2px; }
.secret.shield { background: #12263a; border-color: #2f6390; }

/* ---------------- missione mostrata dal conduttore ---------------- */
.mission-text { white-space: pre-line; color: var(--text-2); margin-top: 10px; }

/* ---------------- fine ---------------- */
.winner { font-family: var(--display); font-weight: 800; font-size: 2.6rem; line-height: 1.05; text-align: center; color: var(--candle); margin: 6px 0 10px; }
.winner.traditori { color: var(--blood-2); }

/* ---------------- avvisi ---------------- */
#toast {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%); z-index: 80;
  background: var(--surface-2); border: 1px solid var(--candle); padding: 12px 18px; border-radius: var(--r-md);
  max-width: calc(100% - 32px); text-align: center; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity 0.2s;
  box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.9);
}
#toast.show { opacity: 1; }
#toast.err { border-color: var(--blood-2); }

.offline-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90; text-align: center; padding: 8px 12px;
  background: var(--blood); color: #fff; font-weight: 800; font-size: 0.9rem;
}

/* ---------------- tutorial ---------------- */
.sheet-back { position: fixed; inset: 0; z-index: 70; background: rgba(5, 10, 8, 0.78); display: grid; align-items: end; justify-items: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--bg-2);
  border: 1px solid var(--line-2); border-bottom: 0; border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 22px 20px calc(20px + var(--safe-b)); animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { font-size: 1.5rem; }
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.step-ico { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); color: var(--candle); flex: none; }
.step-ico .ic { width: 28px; height: 28px; }
.step-body { color: var(--text-2); }
.step-body li { margin: 8px 0; }
.step-body ul { padding-left: 20px; margin: 10px 0; }
.gesture { display: flex; gap: 12px; align-items: center; padding: 12px 14px; margin: 12px 0; border-radius: var(--r-sm); background: rgba(235, 184, 94, 0.08); color: var(--candle-2); font-weight: 700; }
.gesture .ic { width: 26px; height: 26px; color: var(--candle); }
.dots { display: flex; gap: 6px; justify-content: center; margin: 18px 0 14px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); }
.dots i.on { background: var(--candle); width: 22px; border-radius: 4px; }
.sheet-nav { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
