/* CONQUISTA — stile "sala operativa" a fosfori ambra */
:root {
  --ink: #0a1a20;
  --table: #0f2a33;
  --panel: #123540;
  --line: #235563;
  --amber: #ffb347;
  --amber-dim: #a8743a;
  --signal: #ff4d3d;
  --sea: #5cc8ff;
  --paper: #efe4c8;
  --muted: #8fb0b3;
  --pixel: "Press Start 2P", "Courier New", monospace;
  --body: "VT323", "Lucida Console", monospace;
  --radius: 2px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(ellipse at 50% 0%, #15404c 0%, transparent 60%),
    var(--ink);
  color: var(--paper);
  font-family: var(--body);
  font-size: 21px;
  line-height: 1.25;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px dashed var(--amber); outline-offset: 3px; }

/* ---------- barra superiore */
.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 2px solid var(--line);
  background: rgba(10, 26, 32, 0.85);
}
.brand { font-family: var(--pixel); font-size: 13px; color: var(--amber); letter-spacing: 1px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.me-tag { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.me-tag img, .me-tag .mini-flag { width: 26px; height: 26px; }
.net { width: 10px; height: 10px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 8px var(--signal); }
.net.on { background: #9bd770; box-shadow: 0 0 8px #9bd770; }

main { height: calc(100% - 52px); }

.screen { display: none; height: 100%; overflow: auto; padding: 28px 20px; }
.screen.active { display: block; }
#screen-game.active { padding: 0; overflow: hidden; }

/* ---------- elementi comuni */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--table));
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
}
.panel.tight { padding: 12px 14px; }

h2, h3 { font-family: var(--pixel); font-weight: 400; margin: 0 0 14px; color: var(--amber); }
h2 { font-size: 13px; line-height: 1.6; }
h3 { font-size: 10px; line-height: 1.6; margin-bottom: 10px; }
.gap { margin-top: 22px; }
.muted { color: var(--muted); }
.center { text-align: center; }

.btn {
  font-family: var(--pixel);
  font-size: 11px;
  padding: 12px 16px;
  border: 2px solid var(--amber);
  background: transparent;
  color: var(--amber);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--amber-dim);
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:hover { background: rgba(255, 179, 71, 0.1); }
.btn:active { transform: translate(3px, 3px); box-shadow: none; }
.btn.primary { background: var(--amber); color: var(--ink); }
.btn.primary:hover { background: #ffc46e; }
.btn.ghost { border-color: var(--line); color: var(--muted); box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4); }
.btn.ghost:hover { color: var(--paper); border-color: var(--muted); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.danger { background: var(--signal); border-color: var(--signal); color: #fff; box-shadow: 3px 3px 0 #8f2218; }
.btn.danger:hover:not(:disabled) { background: #ff6a5c; }
.btn.big { font-size: 13px; padding: 16px; }
.small { font-size: 17px; }
.alert-text { color: #ffb0a8; }
.good-text { color: #9bd770; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { color: var(--muted); font-size: 19px; }
input:not([type="color"]):not([type="file"]), select {
  background: var(--ink);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 22px;
  width: 100%;
}
input:focus, select:focus { border-color: var(--amber); outline: none; }

/* ---------- profilo */
.hero { text-align: center; margin: 10px auto 26px; max-width: 720px; }
.title {
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(34px, 8vw, 76px);
  margin: 0 0 18px;
  color: var(--amber);
  text-shadow: 4px 4px 0 var(--signal), 8px 8px 0 rgba(0, 0, 0, 0.5);
  letter-spacing: 2px;
}
.title span { display: inline-block; animation: drop 0.5s steps(5) both; }
.title span:nth-child(2) { animation-delay: 0.15s; }
.title span:nth-child(3) { animation-delay: 0.3s; }
@keyframes drop { from { transform: translateY(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
.subtitle { color: var(--muted); max-width: 52ch; margin: 0 auto; }

.profile {
  max-width: 640px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 22px;
  align-items: start;
}
.profile .btn.wide { grid-column: 1 / -1; }
.flag-preview {
  width: 150px;
  height: 150px;
  border: 4px solid var(--amber);
  border-radius: 50%;
  background: var(--ink) center / cover no-repeat;
  display: grid;
  place-items: center;
  font-family: var(--pixel);
  font-size: 44px;
  box-shadow: 0 0 0 6px var(--ink), 0 0 0 8px var(--line);
}
.color-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input[type="color"] { width: 44px; height: 36px; border: 2px solid var(--line); background: var(--ink); padding: 2px; cursor: pointer; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; border: 2px solid var(--ink); outline: 1px solid var(--line); cursor: pointer; padding: 0; }
.swatch:hover { outline-color: var(--paper); }
.flag-row { display: flex; gap: 10px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------- lobby */
.lobby-grid, .room-grid {
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  align-items: start;
}
.room-list { display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
.room-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 8px 10px;
  border: 1px dashed var(--line);
}
.code { font-family: var(--pixel); font-size: 12px; color: var(--amber); }
.btn.small { padding: 8px 10px; font-size: 9px; }
.join-row { display: flex; gap: 10px; }
.join-row input { text-transform: uppercase; letter-spacing: 6px; font-family: var(--pixel); font-size: 14px; }

/* ---------- stanza */
.room-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.room-code { font-family: var(--pixel); font-size: 30px; color: var(--amber); letter-spacing: 6px; margin-top: 6px; }
.share-links { display: flex; flex-direction: column; gap: 4px; }
.share-links button {
  text-align: left;
  background: var(--ink);
  border: 1px solid var(--line);
  padding: 4px 10px;
  cursor: copy;
  color: var(--sea);
  word-break: break-all;
}
.share-links button:hover { border-color: var(--sea); }
.room-players { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 2px solid var(--pc, var(--line));
  background: var(--ink);
  min-width: 0;
}
.player-card .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-card small { display: block; color: var(--amber); font-size: 16px; }
.rules { margin: 6px 0 20px; padding-left: 22px; color: var(--muted); font-size: 19px; }
.rules li { margin-bottom: 6px; }
.rules b { color: var(--paper); font-weight: 400; }

.mini-flag {
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--pc, var(--line));
  background: var(--ink) center / cover no-repeat;
  display: grid;
  place-items: center;
  font-family: var(--pixel);
  color: var(--pc, var(--paper));
}

/* ---------- partita */
.game-layout { display: grid; grid-template-columns: 1fr 360px; height: 100%; }
.map-wrap { position: relative; min-width: 0; min-height: 0; background: var(--ink); }
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }

.hud {
  position: absolute;
  background: rgba(10, 26, 32, 0.82);
  border: 1px solid var(--line);
  padding: 6px 10px;
  pointer-events: none;
}
.hud-top { top: 10px; left: 10px; display: flex; gap: 16px; font-size: 20px; }
.hud-top #g-room { color: var(--amber); font-family: var(--pixel); font-size: 13px; align-self: center; letter-spacing: 2px; }
.hud-top #g-timer { color: var(--sea); }
.hud-hover { bottom: 10px; left: 10px; min-width: 220px; display: none; }
.hud-hover.show { display: block; }
.hud-hover b { color: var(--amber); font-weight: 400; }
.hint { margin: 8px 0 0; font-size: 17px; color: var(--muted); line-height: 1.15; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border-left: 2px solid var(--line);
  background: var(--table);
  min-height: 0;
}
.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.scoreboard { display: flex; flex-direction: column; gap: 4px; max-height: 22vh; overflow: auto; }
.score-row {
  display: grid;
  grid-template-columns: 14px auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 4px 6px;
  border-left: 4px solid var(--pc);
  background: rgba(0, 0, 0, 0.18);
}
.score-row.me { background: rgba(255, 179, 71, 0.08); }
.score-row.current { background: rgba(255, 179, 71, 0.2); box-shadow: inset 0 0 0 1px var(--amber); }
.score-row.current .turn-no { color: var(--ink); background: var(--amber); }
.turn-no { font-family: var(--pixel); font-size: 8px; color: var(--muted); text-align: center; line-height: 14px; }
.score-row.dead { opacity: 0.4; }
.score-row.dead .score-name span { text-decoration: line-through; }
.score-name { min-width: 0; }
.score-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-name small { color: var(--muted); font-size: 16px; }
.score-nums { text-align: right; font-size: 18px; line-height: 1.05; color: var(--muted); }
.score-nums b { color: var(--paper); font-weight: 400; }

.log { flex: 1; overflow: auto; font-size: 18px; display: flex; flex-direction: column; gap: 3px; }
.log div { padding-left: 8px; border-left: 2px solid var(--line); }
.log time { color: var(--muted); margin-right: 6px; }
.log .conquest { border-color: var(--amber); }
.log .defense { border-color: var(--sea); }
.log .alert { border-color: var(--signal); color: #ffb0a8; }
.log .bonus { border-color: #9bd770; color: #cdeeb3; }
.log .system { border-color: var(--paper); color: var(--amber); }
.log .warn { color: var(--muted); }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 26, 32, 0.72);
}
.overlay.hidden { display: none; }
.overlay-box { text-align: center; min-width: 320px; }
.winner { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 10px 0; font-size: 30px; }
.overlay-actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  border: 2px solid var(--signal);
  padding: 8px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive */
@media (max-width: 860px) {
  .lobby-grid, .room-grid { grid-template-columns: 1fr; }
  .profile { grid-template-columns: 1fr; justify-items: center; }
  .profile-fields { width: 100%; }
  .game-layout { grid-template-columns: 1fr; grid-template-rows: 62vh auto; height: auto; }
  #screen-game.active { overflow: auto; }
  .sidebar { border-left: 0; border-top: 2px solid var(--line); }
  .log { max-height: 30vh; }
}

@media (prefers-reduced-motion: reduce) {
  .title span { animation: none; }
  .btn, .toast { transition: none; }
}

/* ---------- pannello turno */
.turn-panel { border-color: var(--amber-dim); }
.turn-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.turn-who { display: flex; align-items: center; gap: 10px; font-size: 24px; min-width: 0; }
.turn-who small { display: block; font-family: var(--pixel); font-size: 8px; color: var(--muted); }
.turn-timer { font-family: var(--pixel); font-size: 13px; color: var(--sea); }
.turn-timer.low { color: var(--signal); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

.phases { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 0; margin: 10px 0; counter-reset: ph; }
.phases li {
  counter-increment: ph;
  font-family: var(--pixel);
  font-size: 7px;
  text-align: center;
  padding: 7px 2px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.phases li::before { content: counter(ph) ". "; }
.phases li.on { background: var(--amber); color: var(--ink); border-color: var(--amber); }
.phases li.done { color: var(--amber-dim); border-color: var(--amber-dim); }

.turn-body { display: flex; flex-direction: column; gap: 8px; }
.turn-body p { margin: 0; }
.turn-body .btn { margin-top: 2px; }
.big-num { font-family: var(--pixel); font-size: 20px; color: var(--amber); font-weight: 400; }
.pick-row { display: grid; grid-template-columns: 76px 1fr; gap: 6px; align-items: baseline; }
.pick-row b { font-weight: 400; color: var(--paper); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button {
  font-family: var(--pixel);
  font-size: 10px;
  padding: 10px 0;
  background: var(--ink);
  border: 2px solid var(--line);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 3px;
}
.seg button.on { border-color: var(--amber); color: var(--ink); background: var(--amber); }
.seg button:disabled { opacity: 0.3; cursor: not-allowed; }
.mini-die { width: 11px; height: 11px; background: var(--signal); border-radius: 2px; box-shadow: inset -2px -2px 0 rgba(0,0,0,0.3); }

.range-row { display: grid; grid-template-columns: 1fr 48px; gap: 10px; align-items: center; }
.range-row b { font-family: var(--pixel); font-size: 14px; color: var(--amber); font-weight: 400; text-align: right; }
input[type="range"] { accent-color: var(--amber); width: 100%; }

/* ---------- vassoio dei dadi */
.tray {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  min-width: 330px;
  background: rgba(10, 26, 32, 0.94);
  border: 2px solid var(--amber-dim);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.45);
  padding: 12px 16px;
}
.tray.hidden { display: none; }
.tray-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.tray-head .side { display: flex; align-items: center; gap: 8px; min-width: 0; line-height: 1; }
.tray-head .side.right { flex-direction: row-reverse; text-align: right; }
.tray-head .vs { font-family: var(--pixel); font-size: 8px; color: var(--muted); }
.mini-flag.neutral { background: #39402f; border-color: #c9cfb8; }

.tray-dice { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 8px; align-items: center; }
.dice-row { display: grid; grid-template-columns: 46px 40px 46px; align-items: center; justify-items: center; }
.glyph { font-family: var(--pixel); font-size: 12px; color: var(--muted); opacity: 0; }
.revealed .glyph { opacity: 1; }

.die {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 6px;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.3), 2px 2px 0 rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s;
}
.die i { width: 7px; height: 7px; border-radius: 50%; place-self: center; background: transparent; }
.die i.on { background: #fff; box-shadow: inset -1px -1px 0 rgba(0, 0, 0, 0.25); }
.die.att { background: #d7263d; }
.die.def { background: #1b64d6; }
.die.def.waiting { background: repeating-linear-gradient(45deg, #1b64d6 0 6px, #164fa8 6px 12px); opacity: 0.55; }
.die.empty { background: transparent; box-shadow: none; }
.die.rolling { animation: shake 0.14s steps(2) infinite; }
@keyframes shake { 0% { transform: rotate(-12deg) translateY(-2px); } 100% { transform: rotate(12deg) translateY(2px); } }
.revealed .die.lost { opacity: 0.35; position: relative; }
.revealed .die.lost::after {
  content: "";
  position: absolute;
  inset: 4px;
  background:
    linear-gradient(45deg, transparent 46%, rgba(255,255,255,0.7) 46% 54%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, rgba(255,255,255,0.7) 46% 54%, transparent 54%);
}
.tray-foot { text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.tray-foot .result { display: flex; gap: 22px; font-size: 22px; }
.tray-foot .result b { font-family: var(--pixel); font-size: 14px; color: var(--signal); font-weight: 400; }
#tray-countdown { font-family: var(--pixel); font-size: 10px; }

/* ---------- avviso di versione e latenza */
.version-warn {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 300;
  background: var(--signal);
  color: #fff;
  padding: 10px 16px;
  text-align: center;
  font-size: 20px;
  border-bottom: 2px solid #8f2218;
}
.version-warn.hidden { display: none; }
.version-warn b { font-family: var(--pixel); font-size: 11px; font-weight: 400; }
.brand small { font-size: 8px; color: var(--muted); margin-left: 6px; }
.lat { font-size: 17px; color: var(--muted); }
.lat.slow { color: var(--signal); }

/* ---------- comandi di zoom sulla mappa */
.zoom-box {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom-btn {
  width: 38px;
  height: 38px;
  font-family: var(--pixel);
  font-size: 13px;
  line-height: 1;
  background: rgba(10, 26, 32, 0.85);
  color: var(--amber);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}
.zoom-btn:hover { border-color: var(--amber); background: rgba(255, 179, 71, 0.12); }

/* ---------- carte territorio */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 8px;
  background: var(--ink);
  border: 2px solid var(--line);
  border-left-width: 6px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.card .sym { font-family: var(--pixel); font-size: 8px; color: var(--paper); }
.card small { color: var(--muted); font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.fante { border-left-color: #5cc8ff; }
.card.cavallo { border-left-color: #9bd770; }
.card.cannone { border-left-color: #ff6f59; }
.card.jolly { border-left-color: #ffe14d; }
.card.on { border-color: var(--amber); background: rgba(255, 179, 71, 0.16); }
.card:hover { border-color: var(--muted); }
.card.on:hover { border-color: var(--amber); }
#cards-foot { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }

/* ---------- legenda delle regioni */
.regions { display: flex; flex-direction: column; gap: 3px; }
.region-row {
  display: grid;
  grid-template-columns: 12px 1fr auto 22px;
  gap: 8px;
  align-items: center;
  font-size: 19px;
}
.region-row b { font-weight: 400; color: var(--amber); }
.swatch-dot { width: 12px; height: 12px; border-radius: 2px; display: block; }
.region-row .rname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phases.dim li { opacity: 0.45; }
