:root {
  --bg: #0a1620; --panel: #12222d; --panel2: #1b3140; --line: #2d4a5c; --text: #e9f1f4; --muted: #8fa9b6;
  --accent: #f2c744; --good: #5fd68a; --bad: #ff6b5a; --me: #4fc3f7;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding: var(--site-bar, 0px) max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left)); }
body.playing { overflow: hidden; padding: 0; }
.hidden { display: none !important; }
button, input, select { font: inherit; color: inherit; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 2px; max-width: 760px; margin: 0 auto; }
.top h1 { margin: 0; font-size: 1.25rem; letter-spacing: .02em; color: var(--accent); white-space: nowrap; }
.top-right { display: flex; align-items: center; gap: 6px; }
.langs { display: inline-flex; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: .85rem; cursor: pointer; }
.langs .chip:first-child { border-radius: 999px 0 0 999px; }
.langs .chip:last-child { border-radius: 0 999px 999px 0; border-left: 0; }
.chip.active { background: var(--accent); color: #1a1a10; border-color: var(--accent); font-weight: 700; }
.conn { max-width: 760px; margin: 0 auto 6px; background: #5b3b12; border: 1px solid #a2701f; border-radius: 8px; padding: 6px 10px; font-size: .9rem; position: relative; z-index: 30; }
main { max-width: 760px; margin: 0 auto; padding-bottom: 24px; }
.tagline { color: var(--muted); margin: 4px 2px 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 2px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .88rem; margin: 2px 0 8px; }
label { display: block; font-size: .88rem; color: var(--muted); margin: 6px 0 4px; }
input[type=text], input[type=password], input[type=email] { width: 100%; background: #07101a; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.row.join { margin-top: 10px; }
.row.join input { text-transform: uppercase; letter-spacing: .2em; text-align: center; font-weight: 700; }
.btn { background: var(--accent); color: #1c1a0c; border: 0; border-radius: 12px; padding: 12px 14px; font-weight: 700; cursor: pointer; min-height: 46px; margin-top: 4px; }
.btn.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.codebox { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.codebox span { font-size: 1.9rem; letter-spacing: .25em; font-weight: 800; color: var(--accent); flex: 1; }
.codebox .chip { flex: 0 0 auto; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 2147483001; display: flex; align-items: flex-end; justify-content: center; overflow-y: auto; padding: 12px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; width: 100%; max-width: 560px; margin: auto; display: grid; gap: 10px; }
.sheet h2, .sheet h3 { margin: 0; }
.sheet p { margin: 0; }
.sheet .hint { margin: 0; }
.sheet .big { font-size: 1.7rem; font-weight: 800; text-align: center; }
.sheet .big.win { color: var(--good); }
.sheet .big.lose { color: var(--bad); }
.sheet ul { margin: 0; padding-left: 1.1rem; display: grid; gap: 4px; font-size: .92rem; }
.sheet p b, .sheet li b { color: var(--accent); }
.sheet .btn { margin-top: 0; }
.error { color: var(--bad); min-height: 1.2em; font-size: .9rem; }
.stats { width: 100%; border-collapse: collapse; font-size: .92rem; }
.stats th, .stats td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 1px solid #0006; }
@media (min-width: 700px) { .overlay { align-items: center; } }

/* ───────── mappa e interfaccia di gioco ───────── */
#game { position: fixed; inset: 0; z-index: 10; background: var(--bg); user-select: none; -webkit-user-select: none; overflow: hidden; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: default; touch-action: none; }
#stage.attack { cursor: crosshair; }
#hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 58px; background: linear-gradient(#07101af0, #07101a00); pointer-events: none; }
#hud-top > * { pointer-events: auto; }
#hud-top .grow { flex: 1; pointer-events: none; }
.stat { display: inline-flex; align-items: center; gap: 6px; background: #0d1a24d9; border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; font-variant-numeric: tabular-nums; }
#board { display: flex; gap: 6px; flex-wrap: wrap; max-width: 62vw; }
.pl { display: inline-flex; align-items: center; gap: 5px; background: #0d1a24d9; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px 2px 8px; font-size: .82rem; white-space: nowrap; }
.pl.me { border-color: #fff8; }
.pl.dead { opacity: .45; text-decoration: line-through; }
.pl b { font-variant-numeric: tabular-nums; }
.pl small { color: var(--muted); font-variant-numeric: tabular-nums; }
.panel { background: #0d1a24ea; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; backdrop-filter: blur(3px); }
#hud-bottom { position: absolute; left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: flex-end; justify-content: space-between; pointer-events: none; }
#hud-bottom > * { pointer-events: auto; }
#info { min-width: 220px; max-width: 320px; font-size: .9rem; }
#info h3 { margin: 0 0 4px; font-size: 1rem; }
#info p { margin: 2px 0; color: var(--muted); }
#info p b { color: var(--text); }
#tools { display: grid; gap: 6px; max-width: 360px; }
.pcts { display: flex; gap: 4px; }
.pct { flex: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; font-weight: 700; cursor: pointer; min-width: 52px; }
.pct.on { background: var(--accent); color: #1a1a10; border-color: var(--accent); }
.row2 { display: flex; gap: 6px; flex-wrap: wrap; }
.row2 .chip.on { background: var(--accent); color: #1a1a10; border-color: var(--accent); font-weight: 700; }
#tools .hint { margin: 0; font-size: .78rem; }
#toasts { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; pointer-events: none; width: min(92vw, 460px); }
.toast { background: #0d1a24f0; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: .9rem; animation: fade 4.5s forwards; }
.toast.bad { border-color: var(--bad); }
.toast.good { border-color: var(--good); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#lobby { position: absolute; left: 10px; top: 58px; width: min(360px, calc(100vw - 20px)); max-height: calc(100% - 70px); overflow-y: auto; display: grid; gap: 8px; }
#lobby h2 { margin: 0; font-size: 1.1rem; }
#lobby .hint { margin: 0; }
.slot { display: flex; align-items: center; gap: 6px; background: var(--panel2); border-radius: 10px; padding: 6px 8px; font-size: .92rem; }
.slot .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot small { color: var(--muted); }
.slot .chip { padding: 2px 8px; }
.bots { display: flex; gap: 6px; flex-wrap: wrap; }
#lobby .btn { margin-top: 0; }

@media (max-width: 640px) {
  #hud-bottom { flex-direction: column; align-items: stretch; }
  #info { max-width: none; min-width: 0; }
  #tools { max-width: none; }
  #board { max-width: 100vw; }
  #hud-top { flex-wrap: wrap; padding-left: 10px; padding-top: calc(var(--site-bar, 0px) + 4px); }
  #lobby { top: auto; bottom: 10px; max-height: 58%; width: calc(100vw - 20px); }
  #hud-top .grow { display: none; }
}
