:root {
  --bg: #070a12;
  --panel: rgba(12, 17, 30, 0.9);
  --panel-edge: rgba(255, 255, 255, 0.1);
  --text: #eef2fa;
  --muted: #9aa8c2;
  --accent: #ff8a2b;
  --accent-2: #ffc233;
  --danger: #ff5a4a;
  --good: #8dff9a;
  --font: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --display: 'Arial Black', 'Segoe UI Black', Impact, 'Helvetica Neue', sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #1a2236, var(--bg) 70%);
  color: var(--text);
  font-family: var(--font);
}

body {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.6);
}

/* --- Overlay screens ------------------------------------------------------------------------ */

#ui {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: 16px;
}

#ui > * {
  pointer-events: auto;
}

#ui.dim {
  background: rgba(4, 6, 12, 0.45);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  padding: 22px 26px;
  width: min(640px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: pop 0.18s ease-out;
}

.panel.narrow {
  width: min(380px, 100%);
}

.panel.wide {
  width: min(960px, 100%);
}

.panel.banner {
  width: min(560px, 100%);
}

@keyframes pop {
  from {
    transform: scale(0.96);
    opacity: 0;
  }
}

.panel h2 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: 26px;
  letter-spacing: 0.5px;
}

.panel h3 {
  margin: 14px 0 8px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.panel p {
  line-height: 1.45;
}

.hint,
.fineprint {
  color: var(--muted);
  font-size: 14px;
}

.fineprint {
  font-size: 12px;
  text-align: center;
  margin-bottom: 0;
}

.title-panel {
  width: min(520px, 100%);
  text-align: center;
  background: rgba(10, 14, 26, 0.8);
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.9;
  margin: 4px 0 10px;
  font-family: var(--display);
  filter: drop-shadow(0 4px 14px rgba(255, 110, 30, 0.45));
}

.logo-top {
  font-size: clamp(38px, 8vw, 62px);
  letter-spacing: 3px;
  background: linear-gradient(180deg, #fff3b0 0%, #ffc233 35%, #ff6a1f 70%, #b8261a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-bottom {
  font-size: clamp(26px, 5.4vw, 42px);
  letter-spacing: 14px;
  margin-left: 14px;
  color: #dfe6f3;
  text-shadow: 0 2px 0 #394056;
}

.tagline {
  color: #c8d3e8;
  margin: 6px 0 18px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.menu .row > * {
  flex: 1;
}

.row.end {
  justify-content: flex-end;
  margin-top: 16px;
}

.spacer {
  flex: 1;
}

/* --- Controls ------------------------------------------------------------------------------- */

.btn {
  font: 600 15px var(--font);
  color: var(--text);
  background: linear-gradient(180deg, #2b3550, #1d2438);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: transform 0.06s, filter 0.12s, background 0.12s;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.18);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.btn.primary {
  background: linear-gradient(180deg, #ff9d3d, #e8531f);
  border-color: rgba(255, 200, 120, 0.5);
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.btn.danger {
  background: linear-gradient(180deg, #a23a34, #74231f);
}

.btn.big {
  font-size: 18px;
  padding: 13px 18px;
}

.btn.small {
  font-size: 13px;
  padding: 5px 10px;
}

.btn.icon {
  padding: 6px 10px;
}

input,
select,
textarea {
  font: 15px var(--font);
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 8px 10px;
  user-select: text;
  -webkit-user-select: text;
}

select option {
  background: #1a2032;
}

label {
  color: var(--muted);
  font-size: 14px;
}

/* --- Lineup --------------------------------------------------------------------------------- */

.lineup {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lineup-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lineup-row .name-input {
  flex: 1;
  min-width: 0;
}

.lineup-row .type-select {
  width: 150px;
}

.color-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  cursor: pointer;
  flex: none;
}

.add-tank {
  align-self: flex-start;
}

.chip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: middle;
}

/* --- Tables --------------------------------------------------------------------------------- */

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.results tr.first td {
  color: var(--accent-2);
  font-weight: 700;
}

td.money {
  color: var(--good);
  font-variant-numeric: tabular-nums;
}

.keys th {
  color: var(--accent-2);
  text-transform: none;
  font-size: 14px;
  letter-spacing: 0;
  white-space: nowrap;
}

.help-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 18px;
}

.scroll {
  max-height: 46vh;
  overflow: auto;
}

@media (max-width: 760px) {
  .help-grid {
    grid-template-columns: 1fr;
  }
}

/* --- Toasts --------------------------------------------------------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 20;
}

.toast {
  background: rgba(10, 14, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  animation: pop 0.2s ease-out;
  max-width: 90vw;
}

.toast.error {
  border-color: rgba(255, 90, 74, 0.6);
}

/* --- Forms ---------------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
}

.field.indent {
  margin-left: 28px;
}

.field-label {
  color: var(--muted);
  font-size: 14px;
}

.wide-input {
  width: 100%;
}

.radio {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  color: var(--text);
}

.radio input {
  margin-top: 3px;
}

.radio span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.radio small {
  color: var(--muted);
  font-size: 13px;
}

.advanced {
  margin: 10px 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
}

.code-input {
  font: 800 30px var(--display);
  letter-spacing: 10px;
  text-transform: uppercase;
  text-align: center;
  padding: 10px;
}

.status {
  min-height: 1.4em;
  color: var(--accent-2);
  font-size: 14px;
}

.status.error {
  color: var(--danger);
}

.settings-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 14px;
  align-items: center;
}

.settings-grid select,
.settings-grid .range {
  width: 100%;
}

.settings-grid input[type='checkbox'] {
  width: 20px;
  height: 20px;
  justify-self: start;
}

.range {
  display: flex;
  gap: 10px;
  align-items: center;
}

.range input {
  flex: 1;
}

.setting-value {
  color: var(--text);
  font-size: 14px;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 10px auto;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Lobby ---------------------------------------------------------------------------------- */

.lobby-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.code-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.room-code {
  font: 800 36px var(--display);
  letter-spacing: 8px;
  color: var(--accent-2);
  user-select: all;
  -webkit-user-select: all;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
}

@media (max-width: 760px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.lobby-players {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lobby-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.lobby-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
}

.badge.host {
  background: rgba(255, 138, 43, 0.25);
  color: #ffc28a;
}

.badge.ai {
  background: rgba(120, 160, 255, 0.2);
  color: #b9cbff;
}

.badge.you {
  background: rgba(141, 255, 154, 0.18);
  color: var(--good);
}

/* --- Chat ----------------------------------------------------------------------------------- */

.chat {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: min(380px, calc(100vw - 24px));
  z-index: 15;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat.open,
.chat.pinned {
  pointer-events: auto;
}

.chat-log {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
}

.chat-line {
  background: rgba(8, 12, 22, 0.72);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 13px;
  line-height: 1.35;
  transition: opacity 0.6s;
  word-wrap: break-word;
  user-select: text;
  -webkit-user-select: text;
}

.chat-line.faded {
  opacity: 0;
}

.chat-line.system {
  color: var(--muted);
  font-style: italic;
}

.chat-name {
  font-weight: 700;
}

.chat-input {
  width: 100%;
  background: rgba(8, 12, 22, 0.9);
}

/* --- Shop ----------------------------------------------------------------------------------- */

.shop-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.shop-purse {
  text-align: right;
}

.shop-who {
  font-weight: 700;
  font-size: 16px;
}

.shop-cash {
  font: 800 28px var(--display);
  color: var(--good);
}

.shop-body {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 18px;
  max-height: calc(100vh - 230px);
  overflow: auto;
}

@media (max-width: 860px) {
  .shop-body {
    grid-template-columns: 1fr;
  }
}

.shop-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.shop-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto 38px auto auto;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
}

.shop-row:hover {
  background: rgba(255, 255, 255, 0.07);
}

.shop-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}

.shop-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.shop-name strong {
  font-size: 14px;
}

.shop-name small {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shop-price {
  font-size: 13px;
  color: #ffe2a8;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.shop-owned {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent-2);
  text-align: right;
}

.shop-ready {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ready-pill {
  font-size: 13px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.ready-pill.ready {
  background: rgba(141, 255, 154, 0.16);
  color: var(--good);
}

#settings-screen .settings-grid {
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 7px 14px;
}

#settings-screen .settings-grid select {
  padding: 6px 8px;
}

@media (max-width: 760px) {
  #settings-screen .settings-grid {
    grid-template-columns: auto minmax(0, 1fr);
  }
}

#settings-screen {
  width: min(820px, 100%);
}

/* --- Touch controls ------------------------------------------------------------------------- */

.touch {
  position: fixed;
  inset: auto 0 0 0;
  pointer-events: none;
  z-index: 12;
  padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.touch-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
  pointer-events: none;
}

.touch-group {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px;
  border-radius: 14px;
  background: rgba(8, 12, 22, 0.55);
  pointer-events: auto;
}

.touch-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 0 4px;
}

.touch-btn {
  min-width: 46px;
  height: 46px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(40, 50, 76, 0.85);
  color: #fff;
  font: 700 20px var(--font);
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-btn:active {
  background: rgba(80, 96, 136, 0.95);
}

.touch-btn.small {
  font-size: 13px;
  padding: 0 10px;
}

.touch-btn.fire {
  min-width: 96px;
  height: 58px;
  font: 800 20px var(--display);
  letter-spacing: 1px;
  background: linear-gradient(180deg, #ff9d3d, #e8531f);
  border-color: rgba(255, 200, 120, 0.6);
  pointer-events: auto;
}

.touch-btn.menu {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  min-width: 42px;
  height: 42px;
  font-size: 20px;
  background: rgba(8, 12, 22, 0.6);
}

.touch-weapon {
  min-width: 110px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

button.touch-weapon {
  height: 46px;
  padding: 0 8px;
  border-radius: 11px;
  border: 1px dashed rgba(255, 255, 255, 0.28);
  background: rgba(8, 12, 22, 0.35);
  color: #fff;
  font-family: var(--font);
  pointer-events: auto;
  touch-action: none;
}

button.touch-weapon::after {
  content: ' ▾';
  color: var(--accent-2);
}

/* --- Weapons & items menu ------------------------------------------------------------------- */

.arsenal {
  position: fixed;
  z-index: 16;
}

.arsenal-panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 10px 14px 14px;
  overflow: auto;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: pop 0.14s ease-out;
}

.arsenal-head {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
}

.arsenal-panel h3 {
  margin: 10px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.arsenal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 6px;
}

.arsenal-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.arsenal-weapons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.arsenal-weapon {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: 600 13px var(--font);
  text-align: left;
  cursor: pointer;
}

.arsenal-weapon:hover {
  background: rgba(255, 255, 255, 0.09);
}

.arsenal-weapon.selected {
  border-color: var(--accent-2);
  background: rgba(255, 194, 51, 0.14);
}

.arsenal-weapon-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arsenal-count {
  font-weight: 700;
  font-size: 12px;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.arsenal-items {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.arsenal-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
}

.arsenal-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.arsenal-name strong {
  font-size: 13px;
}

.arsenal-name small {
  color: var(--muted);
  font-size: 12px;
}

.arsenal-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(141, 255, 154, 0.16);
  color: var(--good);
}

.arsenal-drive-buttons {
  display: flex;
  gap: 4px;
}

.arsenal-drive {
  min-width: 40px;
  touch-action: none;
}

.arsenal-zone {
  position: relative;
  display: block;
  height: 6px;
  margin: 7px 6px 3px;
  border-radius: 3px;
  background: rgba(141, 255, 154, 0.3);
}

.arsenal-zone-tank {
  position: absolute;
  top: -3px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

.arsenal-hint {
  margin: 6px 0 0;
  font-size: 12px;
}

@media (max-width: 420px) {
  .arsenal-weapons {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .touch-btn {
    min-width: 40px;
    height: 40px;
    font-size: 17px;
  }
  button.touch-weapon {
    height: 40px;
  }
  .touch-weapon {
    min-width: 80px;
  }
  .touch-label {
    display: none;
  }
}

.touch-bar {
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: nowrap;
}

.touch-cluster {
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.touch-cluster.left {
  align-items: flex-start;
}

.touch-cluster.right {
  align-items: flex-end;
}

.touch-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

@media (max-height: 520px) {
  .touch-btn {
    min-width: 38px;
    height: 38px;
    font-size: 16px;
  }
  button.touch-weapon {
    height: 38px;
  }
  .touch-btn.fire {
    min-width: 78px;
    height: 46px;
    font-size: 17px;
  }
  .touch-btn.small {
    font-size: 12px;
    padding: 0 8px;
  }
  .touch-label {
    display: none;
  }
  .touch-weapon {
    min-width: 84px;
    font-size: 12px;
  }
  .panel {
    padding: 14px 18px;
  }
  .panel h2 {
    font-size: 21px;
    margin-bottom: 8px;
  }
  .logo-top {
    font-size: 34px;
  }
  .logo-bottom {
    font-size: 22px;
  }
  .tagline {
    margin: 2px 0 10px;
    font-size: 13px;
  }
  .btn.big {
    font-size: 16px;
    padding: 9px 14px;
  }
  .menu {
    gap: 7px;
  }
  .fineprint {
    display: none;
  }
}

.lobby .settings-grid {
  gap: 5px 12px;
}

.lobby .settings-grid select {
  padding: 5px 8px;
  font-size: 14px;
}

.lobby .row.end {
  margin-top: 10px;
}
