:root {
  --bg: #0e1812; --panel: #17261d; --panel2: #223a2b; --line: #3b6148; --text: #e9f2ea; --muted: #9db8a4;
  --accent: #f0c14a; --good: #7ddc7a; --bad: #ef7b6c; --blue: #4a86e8; --red: #e0503c;
}
* { 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)); }
.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; }
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; }
.card h3 { margin: 12px 0 4px; font-size: .95rem; color: var(--muted); font-weight: 600; }
.hint { color: var(--muted); font-size: .88rem; margin: 2px 0 8px; }
label { display: block; font-size: .88rem; color: var(--muted); margin: 6px 0 4px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; color: var(--text); }
input[type=text], input[type=password], input[type=email] { width: 100%; background: #0a130e; 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; }
.btn.big { font-size: 1.15rem; min-height: 56px; }
.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; }
.rooms, .seats { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.rooms .empty { color: var(--muted); font-size: .9rem; }
.rooms button { width: 100%; text-align: left; }
.codebox { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.codebox span { font-size: 2rem; letter-spacing: .25em; font-weight: 800; color: var(--accent); flex: 1; }
.codebox .btn { flex: 0 0 auto; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.team { background: #0f1c15; border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px 10px; }
.team.blue { border-color: var(--blue); }
.team.red { border-color: var(--red); }
.team h3 { margin: 2px 0 6px; font-size: 1rem; color: var(--text); }
.team .btn { width: 100%; min-height: 38px; padding: 6px; margin-top: 8px; }
.seats li { display: flex; align-items: center; gap: 8px; background: var(--panel2); border-radius: 10px; padding: 7px 9px; min-height: 36px; }
.seats .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seats .tag { color: var(--muted); font-size: .78rem; }
.seats button { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; cursor: pointer; }
#lobby-host { margin: 8px 0; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); 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: 520px; margin: auto; display: grid; gap: 10px; }
.sheet h2 { margin: 0; }
.sheet p { margin: 0; }
.error { color: var(--bad); min-height: 1.2em; font-size: .9rem; }
.sheet .hint { margin: 0; }
@media (min-width: 700px) { .overlay { align-items: center; } }

/* partita: il canvas occupa tutta la finestra sotto la barra del sito */
body.ingame { padding: 0; overflow: hidden; }
body.ingame .top, body.ingame .conn { display: none; }
body.ingame main { max-width: none; padding: 0; margin: 0; }
#game { position: fixed; inset: var(--site-bar, 0px) 0 0 0; }
#board { width: 100%; height: 100%; display: block; background: #0b140f; touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair; }
#game-top { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; }
.endcard { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(10, 20, 14, .92); border: 2px solid var(--accent); border-radius: 16px; padding: 16px 20px; min-width: min(92vw, 420px); text-align: center; }
.endcard h2 { margin: 0 0 8px; font-size: 1.6rem; color: var(--accent); }
.endcard table { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 8px 0; }
.endcard td, .endcard th { padding: 3px 6px; text-align: center; border-bottom: 1px solid var(--line); }
.endcard td:first-child, .endcard th:first-child { text-align: left; }
.endcard .b { color: #8fb4ff; } .endcard .r { color: #ff9b8a; }

/* comandi touch (solo dispositivi touch) */
.touch { display: none; position: absolute; inset: 0; pointer-events: none; }
@media (pointer: coarse) { .touch { display: block; } }
.touch .tb { pointer-events: auto; background: rgba(20, 40, 28, .62); border: 2px solid rgba(255,255,255,.35); border-radius: 14px; width: 56px; height: 56px; font-size: 1.3rem; color: #fff; touch-action: none; user-select: none; -webkit-user-select: none; }
.touch .tb.held { background: rgba(240, 193, 74, .75); color: #1a1a10; }
.t-left { position: absolute; left: 10px; bottom: 12px; display: grid; grid-template-columns: repeat(2, 56px); grid-template-rows: repeat(2, 56px); gap: 8px; }
.t-left [data-key=up] { order: 1; } .t-left [data-key=down] { order: 2; } .t-left [data-key=left] { order: 3; } .t-left [data-key=right] { order: 4; }
.t-right { position: absolute; right: 12px; bottom: 150px; display: flex; flex-direction: column; gap: 8px; }
.aimpad { position: absolute; right: 12px; bottom: 12px; width: 124px; height: 124px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(160, 40, 30, .28); pointer-events: auto; touch-action: none; }
.aimpad i { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(255, 120, 100, .7); }

.classbar { display: flex; flex-wrap: wrap; gap: 6px; }
.cbtn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: .85rem; cursor: pointer; font-weight: 600; }
.cbtn.on { background: var(--accent); color: #1a1a10; border-color: var(--accent); }
.cbtn.pending { outline: 2px dashed var(--accent); outline-offset: 1px; }
#game-top { align-items: flex-start; flex-wrap: wrap; max-width: calc(100% - 16px); }
#game-top .classbar { gap: 4px; }
#game-top .cbtn { padding: 4px 8px; font-size: .78rem; background: rgba(15, 28, 20, .82); }
#game-top .cbtn.on { background: var(--accent); }
@media (max-width: 760px) { #game-top .cbtn { font-size: .7rem; padding: 3px 6px; } }
