:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b6f76;
  --line: #e2ddd2;
  --accent: #b4232a;      /* rosso Udine */
  --accent-dark: #8e1b21;
  --gold: #c9a227;
  --piedi: #6b7280;
  --bici: #16a34a;
  --bus: #dc2626;
  --nera: #111827;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(31, 35, 40, 0.12);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); }
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0 0 .5rem; }
h1 { font-size: 2.4rem; letter-spacing: -.02em; }
h1 span { color: var(--accent); }
h2 { font-size: 1.2rem; margin-top: 1.2rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 1.2rem; }

.screen.center { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; width: 100%; }
.home-card { max-width: 400px; display: flex; flex-direction: column; gap: 10px; }
.lobby-card { max-width: 460px; }
.board-card { max-width: 900px; overflow-x: auto; }
.tagline { color: var(--muted); margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, monospace; }

label { font-weight: 600; font-size: .9rem; }
input, select, button { font: inherit; border-radius: 8px; }
input, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); background: #fff; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { padding: 10px 16px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; }
button:hover { background: #f8f6f1; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.link { border: 0; background: none; color: var(--accent); padding: 6px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 8px; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; text-align: center; }
.divider { text-align: center; color: var(--muted); font-size: .85rem; margin: 8px 0 0; border-top: 1px solid var(--line); }
.divider span { position: relative; top: -.7em; background: var(--card); padding: 0 8px; }
.error { color: var(--accent); min-height: 1.2em; margin: 4px 0; font-size: .9rem; }

/* Lobby */
.room-code { font-size: 3rem; font-weight: 800; letter-spacing: .25em; color: var(--accent); }
.players { list-style: none; padding: 0; margin: 0 0 16px; }
.players li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.players .badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); }
.players .badge.mrx { background: var(--nera); color: #fff; }
.players .off { opacity: .5; }
#lobby-host { display: flex; flex-direction: column; gap: 8px; }

/* Partita */
.screen.game { display: grid; grid-template-columns: 1fr 340px; height: 100%; }
#map { height: 100%; min-height: 300px; background: #ddd; }
#map .leaflet-tile-pane { filter: grayscale(.7) brightness(1.06) contrast(.9); }
.panel { background: var(--card); padding: 16px; overflow-y: auto; border-left: 1px solid var(--line); }
.status { font-weight: 700; font-size: 1.05rem; padding: 12px; border-radius: 8px; background: var(--bg); }
.status.your-turn { background: var(--accent); color: #fff; }
.role { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tickets { display: flex; gap: 6px; flex-wrap: wrap; }
.ticket { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 6px; color: #fff; font-size: .8rem; font-weight: 700; }
.ticket.piedi { background: var(--piedi); }
.ticket.bici { background: var(--bici); }
.ticket.bus { background: var(--bus); }
.ticket.nera { background: var(--nera); }
.ticket.empty { opacity: .35; }

.log { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.log .cell { border: 1px solid var(--line); border-radius: 6px; padding: 4px 2px; text-align: center; font-size: .7rem; min-height: 44px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.log .cell .n { color: var(--muted); }
.log .cell.reveal { border-color: var(--gold); background: #fbf6e3; }
.log .cell.current { outline: 2px solid var(--accent); }
.log .cell .t { display: block; color: #fff; border-radius: 4px; margin: 0 3px; padding: 1px 0; font-weight: 700; font-size: .65rem; }
.log .cell .t.piedi { background: var(--piedi); }
.log .cell .t.bici { background: var(--bici); }
.log .cell .t.bus { background: var(--bus); }
.log .cell .t.nera { background: var(--nera); }
.log .cell .where { font-weight: 700; }

.detectives { list-style: none; margin: 0; padding: 0; }
.detectives li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 18px 1fr; gap: 4px 8px; align-items: center; }
.detectives .dot { width: 14px; height: 14px; border-radius: 50%; }
.detectives .meta { grid-column: 2; font-size: .8rem; color: var(--muted); }
.detectives .tickets { grid-column: 2; }
.detectives .done { opacity: .55; }

.piece-picker { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.piece-picker button.active { outline: 2px solid var(--accent); }

.legend { margin-top: 16px; font-size: .85rem; }
.legend ul { list-style: none; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.sw { width: 24px; height: 4px; border-radius: 2px; display: inline-block; }
.sw.piedi { background: var(--piedi); } .sw.bici { background: var(--bici); } .sw.bus { background: var(--bus); height: 6px; } .sw.nera { background: var(--nera); }

/* Nodi e pedine sulla mappa */
.node, .piece { position: absolute; transform: translate(-50%, -50%); }
#map.far .node { width: 19px; height: 19px; font-size: 9px; border-width: 1.5px; }
#map.far .node.bus-stop { border-width: 2.5px; }
#map.far .piece { width: 24px; height: 24px; font-size: 11px; border-width: 2px; }
.node { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid #374151; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #111; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.node.bus-stop { border-color: var(--bus); border-width: 3px; }
.node.reachable { background: #fde68a; border-color: var(--accent); cursor: pointer; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.2); } }
.piece { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 13px; box-shadow: 0 2px 6px rgba(0,0,0,.45); }
.piece.mrx { background: var(--nera); }
.piece.ghost { background: rgba(17,24,39,.35); border-style: dashed; color: #111; }
.piece.selected { outline: 3px solid var(--gold); }
.move-popup { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.move-popup strong { font-size: .95rem; }
.move-popup button { color: #fff; border: 0; }
.move-popup button.piedi { background: var(--piedi); }
.move-popup button.bici { background: var(--bici); }
.move-popup button.bus { background: var(--bus); }
.move-popup button.nera { background: var(--nera); }

/* Fine partita */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 1000; }
.end-card { max-width: 420px; text-align: center; }
.end-card h2 { font-size: 1.6rem; }
.end-card .row { justify-content: center; margin-top: 12px; }

/* Classifiche */
.table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.table tr.me td { background: #fbf6e3; font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--nera); color: #fff; padding: 10px 18px; border-radius: 99px; z-index: 2000; box-shadow: var(--shadow); }

@media (max-width: 760px) {
  .screen.game { grid-template-columns: 1fr; grid-template-rows: 58vh auto; height: auto; min-height: 100%; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .card { padding: 20px; }
}
