:root {
  --bg: #04090d;
  --panel: rgba(6, 16, 22, 0.88);
  --line: rgba(120, 220, 200, 0.28);
  --fg: #cfe9e4;
  --dim: #7da39d;
  --accent: #5ef2c8;
  --alert: #ff5a5a;
  --font: "Share Tech Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 14px; overflow: hidden; }
canvas#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.hidden { display: none !important; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 12px 14px; backdrop-filter: blur(3px); }
.panel.center { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(92vw, 420px); max-height: 94vh; overflow: auto; }
.panel.side { position: fixed; top: 14px; right: 14px; width: min(92vw, 390px); max-height: calc(100% - 28px); overflow: auto; }

h1 { margin: 0; letter-spacing: 6px; font-size: 34px; color: var(--accent); }
h1 span { color: var(--alert); margin-left: 4px; }
h2 { margin: 0 0 8px; font-size: 16px; letter-spacing: 2px; color: var(--accent); }
h3 { margin: 12px 0 6px; font-size: 12px; letter-spacing: 2px; color: var(--dim); text-transform: uppercase; }
.tag { margin: 2px 0 14px; color: var(--dim); }
.hint { color: var(--dim); font-size: 12px; margin: 8px 0; line-height: 1.5; }
.hint b { color: var(--fg); font-weight: normal; }

label { display: block; margin: 10px 0; color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
label.check { text-transform: none; letter-spacing: 0; color: var(--fg); font-size: 13px; }
input[type=text], input[type=password], input:not([type]), input[type=search], select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; background: #02070a; border: 1px solid var(--line);
  color: var(--fg); font: inherit; border-radius: 3px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
select { width: auto; margin: 0; padding: 4px 6px; font-size: 12px; }

button {
  font: inherit; color: var(--fg); background: rgba(94, 242, 200, 0.08); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 3px; cursor: pointer; transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: rgba(94, 242, 200, 0.2); border-color: var(--accent); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: rgba(94, 242, 200, 0.18); border-color: var(--accent); color: var(--accent); width: 100%; padding: 10px; letter-spacing: 2px; text-transform: uppercase; }
button.small { padding: 3px 8px; font-size: 12px; }
button.active { background: rgba(94, 242, 200, 0.35); border-color: var(--accent); color: #fff; }
button.danger { border-color: var(--alert); color: var(--alert); background: rgba(255, 90, 90, 0.1); }

/* Barra globale (lingua, suono, aiuto) */
#tools { position: fixed; top: 10px; left: 10px; z-index: 6; display: flex; gap: 4px; }
#tools button { background: var(--panel); }
#tools button.active { background: rgba(94, 242, 200, 0.35); }

/* Ingresso */
#join-howto { display: block; margin: 6px auto 0; }
#account-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 6px; min-height: 28px; }
#account-name { color: var(--accent); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#guest-note { margin-top: 0; }
.gamelist { list-style: none; margin: 4px 0 8px; padding: 0; font-size: 13px; }
.gamelist li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.gamelist .grow { flex: 1; min-width: 0; }
.gamelist .grow b { display: block; font-weight: normal; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gamelist small { color: var(--dim); font-size: 11.5px; line-height: 1.4; }
.gamelist .empty { color: var(--dim); border-top: 0; }
#screen-auth .row2 { display: flex; gap: 8px; }
#screen-auth .row2 button { flex: 1; letter-spacing: 1px; padding: 10px 6px; }
#screen-auth { z-index: 9; }
.error { color: #ffb0b0; background: rgba(255, 90, 90, 0.12); border: 1px solid var(--alert); border-radius: 3px; padding: 6px 10px; margin: 8px 0; font-size: 13px; }

/* Lobby */
#lobby-territories { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#lobby-territories button { text-align: left; border-left-width: 6px; font-size: 13px; padding: 6px 8px; }
#lobby-territories button small { display: block; color: var(--dim); font-size: 11px; }
#lobby-players { list-style: none; margin: 0; padding: 0; }
#lobby-players li { padding: 4px 0; display: flex; align-items: center; gap: 8px; }
#lobby-players .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lobby-players li .muted { font-size: 12px; white-space: nowrap; }
#lobby-bots { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.chip { width: 16px; height: 16px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; color: #04090d; font-weight: bold; font-size: 11px; line-height: 1; }
.muted { color: var(--dim); }

/* HUD */
#topbar { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line); padding: 6px 16px; border-radius: 4px; max-width: calc(100vw - 280px); }
#defcon-box { display: flex; align-items: center; gap: 10px; }
#defcon-box .lbl { letter-spacing: 3px; color: var(--dim); font-size: 12px; }
#defcon-num { font-size: 40px; line-height: 1; font-weight: bold; min-width: 30px; text-align: center; color: #fff; }
#defcon-num.d5 { color: #fff; } #defcon-num.d4 { color: #5ef2c8; } #defcon-num.d3 { color: #ffe066; } #defcon-num.d2 { color: #ff9f43; } #defcon-num.d1 { color: var(--alert); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .55; } }
#defcon-hint { font-size: 12px; color: var(--dim); max-width: 340px; line-height: 1.35; }
#defcon-hint.placement { color: #fff; }
#defcon-timer { font-size: 18px; color: var(--fg); }
#ready-btn { width: auto; padding: 6px 14px; }
#room-tag { color: var(--dim); font-size: 12px; }

#right-col { position: fixed; top: 10px; right: 10px; width: 270px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100% - 20px); overflow: auto; }
#scoreboard { font-size: 13px; }
#scoreboard .row { display: grid; grid-template-columns: 16px 1fr auto auto; gap: 8px; align-items: center; padding: 3px 0; }
#scoreboard .row.me { color: #fff; }
#scoreboard .head { color: var(--dim); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 4px; }
#scoreboard .sc { min-width: 54px; text-align: right; }
#scoreboard small { color: var(--dim); }

#toolbar { position: fixed; left: 10px; top: 52px; width: 224px; max-height: calc(100% - 200px); overflow: auto; }
#toolbar h3 { margin-top: 0; }
#toolbar button { display: block; width: 100%; text-align: left; margin-bottom: 6px; }
#toolbar button small { color: var(--dim); float: right; }
#toolbar p { margin: 4px 0 0; }
#toolbar .kv { color: var(--dim); font-size: 12px; margin-top: 4px; }
#toolbar .kv b { color: var(--fg); font-weight: normal; }
.coach { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12px; color: var(--dim); }
.coach li { padding: 2px 0 2px 18px; position: relative; line-height: 1.35; }
.coach li::before { content: "○"; position: absolute; left: 0; color: var(--dim); }
.coach li.done { color: var(--accent); }
.coach li.done::before { content: "✓"; color: var(--accent); }
.coach li.all { color: #fff; padding-left: 0; }
.coach li.all::before { content: ""; }

#unitpanel .btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#unitpanel .btns button { padding: 5px 9px; font-size: 13px; }
#unitpanel .kv { color: var(--dim); font-size: 12px; margin-top: 4px; }
#unitpanel .kv b { color: var(--fg); font-weight: normal; }

#log-wrap { position: fixed; left: 10px; bottom: 10px; width: min(46vw, 460px); pointer-events: none; }
#log { max-height: 110px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 12.5px; line-height: 1.45; text-shadow: 0 0 4px #000; }
#log .alert { color: var(--alert); } #log .warn { color: #ffb86b; } #log .chat b { font-weight: normal; }
#log .n { color: var(--dim); }
#chat { pointer-events: auto; margin-top: 6px; background: rgba(2, 7, 10, 0.7); }
#help { position: fixed; right: 10px; bottom: 10px; max-width: 400px; font-size: 11.5px; color: var(--dim); line-height: 1.6; }
#help b { color: var(--fg); font-weight: normal; }

#banner { position: fixed; top: 24%; left: 50%; transform: translateX(-50%); font-size: min(9vw, 76px); letter-spacing: 8px; font-weight: bold; text-shadow: 0 0 24px currentColor; pointer-events: none; animation: banner 3s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: translateX(-50%) scale(1.4); } 12% { opacity: 1; transform: translateX(-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }
#toast { position: fixed; bottom: 18%; left: 50%; transform: translateX(-50%); background: rgba(60, 10, 10, .92); border: 1px solid var(--alert); color: #ffd0d0; padding: 8px 16px; border-radius: 4px; pointer-events: none; max-width: 92vw; text-align: center; z-index: 9; }
#conn { position: fixed; top: 0; left: 0; right: 0; background: var(--alert); color: #000; text-align: center; padding: 6px; z-index: 10; }

/* Impostazioni di lobby */
#lobby-settings label span.inline, .inline { display: flex; gap: 6px; align-items: center; }
#lobby-settings select { width: 100%; margin-top: 4px; padding: 8px 10px; font-size: 13px; }
#lobby-settings input[type=datetime-local] { flex: 1; color-scheme: dark; }
input[type=datetime-local] { margin-top: 4px; padding: 8px 10px; background: #02070a; border: 1px solid var(--line); color: var(--fg); font: inherit; border-radius: 3px; }
.schedule { margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 3px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: 13px; }
#lobby-leave { display: block; margin: 10px 0 0; }

/* Coda di lancio e cronologia */
#queuepanel { font-size: 13px; }
#queuepanel .qrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; padding: 4px 0; border-top: 1px solid var(--line); }
#queuepanel .qrow small { grid-column: 1; color: #ffe066; }
#queuepanel .qrow.no-shooter small { color: var(--alert); }
#queuepanel .qrow.reload small { color: #fff; }
#queuepanel .qrow button { grid-column: 2; grid-row: 1 / span 2; }
#queuepanel > button { margin-top: 8px; }
#btn-feed { position: relative; background: transparent; font-size: 16px; padding: 2px 8px; }
.badge { position: absolute; top: -6px; right: -6px; min-width: 16px; padding: 0 4px; border-radius: 8px; background: var(--alert); color: #fff; font-size: 11px; line-height: 16px; text-align: center; }
#feedpanel { position: fixed; top: 60px; right: 292px; width: min(92vw, 360px); max-height: 60vh; overflow: auto; z-index: 5; }
#feed-list ul { list-style: none; margin: 0; padding: 0; font-size: 12.5px; line-height: 1.5; }
#feed-list li { padding: 3px 0; border-top: 1px solid var(--line); }
#feed-list li time { color: var(--dim); margin-right: 6px; }
#feed-list li.fresh { color: #fff; }
#feed-list li.boom, #feed-list li.launch { color: #ffb86b; }
#feed-list li.destroyed { color: var(--alert); }

/* Come si gioca */
#howto { width: min(94vw, 640px); z-index: 8; }
#howto-body h3 { color: var(--accent); margin: 14px 0 4px; }
#howto-body p, #howto-body li { line-height: 1.55; font-size: 13px; }
#howto-body ul { margin: 4px 0; padding-left: 18px; }
#howto-body b { color: #fff; font-weight: normal; }
#howto .check { margin: 12px 0 8px; }

/* Fine partita */
#screen-end { width: min(94vw, 560px); }
#end-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
#end-table th { color: var(--dim); font-weight: normal; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; text-align: right; padding: 4px; }
#end-table td { padding: 5px 4px; text-align: right; border-top: 1px solid var(--line); }
#end-table th:first-child, #end-table td:first-child { text-align: left; }
#end-winner { font-size: 18px; margin: 4px 0 8px; }
#end-view { display: block; margin: 10px auto 0; }

/* Touch: bersagli più grandi */
@media (pointer: coarse) {
  button { min-height: 40px; }
  button.small { min-height: 34px; padding: 4px 10px; }
  select { min-height: 34px; }
}

@media (max-width: 800px) {
  html, body { font-size: 13px; }
  #help { display: none; }
  #room-tag { display: none; }
  #topbar { top: 52px; gap: 8px; padding: 4px 10px; max-width: calc(100vw - 20px); }
  #defcon-num { font-size: 30px; }
  #defcon-hint { display: none; }
  #defcon-timer { font-size: 14px; }
  #right-col { top: 112px; width: 176px; max-height: 38vh; }
  #scoreboard { font-size: 11.5px; }
  #toolbar { top: 112px; width: 150px; padding: 8px; max-height: 40vh; }
  #toolbar h3 { font-size: 10px; letter-spacing: 1px; }
  #toolbar button { padding: 5px 7px; font-size: 12px; }
  #log-wrap { width: calc(100vw - 20px); bottom: 6px; }
  #log { max-height: 64px; font-size: 11.5px; }
  .panel.side { top: 52px; right: 8px; left: 8px; width: auto; max-height: calc(100% - 60px); }
  #unitpanel { position: fixed; left: 10px; right: 10px; bottom: 100px; width: auto; }
  #right-col #unitpanel { position: fixed; }
  #feedpanel { top: 112px; right: 8px; left: 8px; width: auto; }
  h1 { font-size: 28px; letter-spacing: 4px; }
}

/* Home: partite in lobby in primo piano, sopra lo sfondo con la partita finta */
.lobbies-head { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.lobbies-head h3 { flex: 1; margin: 0; }
.lobbies-head .primary { width: auto; padding: 6px 14px; }
.lobbylist { max-height: 30vh; overflow: auto; margin-bottom: 12px; }
#screen-join { background: rgba(4, 9, 13, 0.82); }
.ingame { margin: 0 0 10px; color: var(--dim); font-size: 12.5px; }
.ingame b { color: var(--fg); }
.home-actions { margin: 8px 0 4px; }
.home-actions button { width: 100%; }
.havecode { margin: 8px 0; }
.havecode summary { cursor: pointer; color: var(--dim); font-size: 12.5px; margin-bottom: 6px; }
.home-actions { display: flex; gap: 8px; }
.home-actions button { flex: 1; letter-spacing: 1px; padding: 10px 6px; font-size: 12px; }
button.primary.alt { background: transparent; border-color: var(--line); color: var(--fg); }

/* Contatore armi in evidenza (colonna sinistra) */
.arsenal { display: flex; gap: 8px; margin-bottom: 8px; }
.arsenal > div { flex: 1; text-align: center; border: 1px solid var(--accent); border-radius: 4px; padding: 6px 4px; background: rgba(94, 242, 200, 0.08); }
.arsenal b { display: block; font-size: 30px; line-height: 1.1; color: var(--accent); }
.arsenal span { font-size: 10.5px; color: var(--dim); letter-spacing: 1px; text-transform: uppercase; }
/* Invito alle notifiche */
#notify-nudge { position: fixed; top: 86px; left: 50%; transform: translateX(-50%); width: min(92vw, 320px); z-index: 12; box-shadow: 0 0 24px rgba(0, 0, 0, .7); }
#notify-nudge .bell { font-size: 34px; text-align: center; animation: ring 1.4s ease-in-out infinite; transform-origin: 50% 0; }
#notify-nudge .row2 { display: flex; gap: 8px; }
#notify-nudge .row2 .primary { flex: 1; }
@keyframes ring { 0%, 60%, 100% { transform: rotate(0); } 10%, 30%, 50% { transform: rotate(14deg); } 20%, 40% { transform: rotate(-14deg); } }
#tools button.pulse { animation: pulse 1s ease-in-out infinite; border-color: var(--accent); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(94, 242, 200, .35); } }
@media (prefers-reduced-motion: reduce) { #notify-nudge .bell, #tools button.pulse { animation: none; } }
#topbar #btn-menu { margin-right: 4px; }
