:root {
  --bg: #12151c;
  --panel: #1c2130;
  --panel-2: #242b3d;
  --text: #e8ecf5;
  --muted: #8d97b0;
  --accent: #ffcc33;
  --accent-2: #4caf50;
  --danger: #e0484c;
  --border: #303849;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body { overflow: hidden; background: linear-gradient(#000 0%, #02052a 45%, #0a1d7a 100%) fixed; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: normal; font-size: 0.85em; }
.error { color: var(--danger); min-height: 1.2em; margin: 0.4em 0; }
.hint { color: var(--muted); font-size: 0.9em; }

.screen {
  position: absolute;
  inset: 0;
  overflow: auto;
  overflow-x: hidden; /* phones: nothing may push the page sideways */
  z-index: 1;
}
#screen-game { z-index: 2; background: #000; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  min-width: 0;
  padding: 0.8rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { margin: 0; font-size: 1.4rem; }
.conn { color: var(--muted); font-size: 0.9rem; }

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
}

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


.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem 1.4rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.panel h2 {
  margin: 0.2rem 0 0.8rem;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.panel h2 + h2, .panel .row + h2, .panel .hint + h2 { margin-top: 1.4rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  color: var(--muted);
  flex: 1;
}

input, select, button {
  font: inherit;
  color: var(--text);
}

input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  width: 100%;
}

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

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #1a1400; border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { background: var(--danger); border-color: transparent; }
button.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.row > label { margin-bottom: 0.8rem; }
.row input { width: auto; flex: 1; }

.code { font-size: 1.3rem; letter-spacing: 0.2em; background: var(--panel-2); padding: 0.3rem 0.7rem; border-radius: 8px; }
.code-input { text-transform: uppercase; letter-spacing: 0.2em; max-width: 9rem; }

.room-list, .player-list { list-style: none; padding: 0; margin: 0 0 0.8rem; }

.room-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.4rem;
  background: var(--panel-2);
}

.room-list .name { font-weight: 600; }
.room-list .meta { color: var(--muted); font-size: 0.85rem; }
.room-list .empty { color: var(--muted); padding: 0.6rem; border: 1px dashed var(--border); border-radius: 8px; text-align: center; }

.player-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: var(--panel-2);
  margin-bottom: 0.35rem;
}

.player-list .swatch { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.player-list .tag { margin-left: auto; font-size: 0.8rem; color: var(--muted); }
.player-list .tag.ready { color: var(--accent-2); }

.map-preview {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #6fa8dc;
  image-rendering: pixelated;
  margin-bottom: 0.8rem;
}

.chat-log {
  height: 160px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.6rem;
  font-size: 0.9rem;
}

.chat-log .from { color: var(--accent); font-weight: 600; margin-right: 0.3rem; }

/* ---------- game ---------- */

#screen-game { overflow: hidden; background: #000; }

#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#hud { position: absolute; inset: 0; pointer-events: none; font-size: 0.9rem; }
#hud > * { pointer-events: none; }

.hud-teams {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-team {
  display: grid;
  grid-template-columns: minmax(150px, max-content) auto 140px; /* avatar + name + icons, live worm count, the bar */
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.45);
  padding: 3px 8px;
  border-radius: 6px;
  border-left: 4px solid transparent;
}

.hud-team.active { outline: 2px solid var(--accent); }
.hud-team.mine .name::after { content: " (ty)"; color: var(--muted); }
.hud-team.dead { opacity: 0.45; }
.hud-team .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-team .bar { height: 10px; background: rgba(255, 255, 255, 0.15); border-radius: 5px; overflow: hidden; }
.hud-team .bar > div { height: 100%; transition: width 0.3s; }

.hud-center {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 18px;
  border-radius: 8px;
}

#hud-timer { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
#hud-timer.warn { color: var(--danger); }
#hud-phase { font-size: 0.8rem; color: var(--muted); }
.hud-sd { font-weight: 800; color: #ff4040; letter-spacing: 0.08em; font-size: 0.85rem; animation: sdblink 1s steps(2) infinite; }
@keyframes sdblink { 50% { opacity: 0.35; } }

.hud-wind {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.45);
  padding: 6px 10px;
  border-radius: 8px;
}

.hud-wind .label { color: var(--muted); font-size: 0.8rem; }
.wind-bar { position: relative; width: 160px; height: 12px; background: rgba(255, 255, 255, 0.15); border-radius: 6px; overflow: hidden; }
.wind-bar::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, 0.5); }
#wind-fill { position: absolute; top: 0; bottom: 0; background: var(--accent); transition: left 0.3s, width 0.3s; }

.hud-messages {
  position: absolute;
  left: 12px;
  bottom: 96px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 40vw;
}

.hud-messages .msg {
  background: rgba(0, 0, 0, 0.55);
  padding: 4px 10px;
  border-radius: 6px;
  animation: fade 6s forwards;
}

@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

.hud-status {
  position: absolute;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 204, 51, 0.7);
  pointer-events: auto !important;
  cursor: pointer;
  white-space: nowrap;
}

#status-weapon { font-weight: 700; font-size: 1rem; color: var(--accent); }

.weapon-panel {
  position: absolute;
  right: 12px;
  top: 60px;
  bottom: 70px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px;
  background: rgba(10, 12, 20, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  pointer-events: auto !important;
}

.weapon-row { display: flex; gap: 3px; align-items: stretch; }
.weapon-row .group { width: 26px; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; color: var(--muted); }

.weapon {
  pointer-events: auto;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  width: 138px;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  cursor: pointer;
  user-select: none;
}

.weapon:hover { border-color: rgba(255, 255, 255, 0.4); }
.weapon.selected { border-color: var(--accent); background: rgba(80, 60, 0, 0.7); }
.weapon.empty { opacity: 0.3; cursor: default; }
.weapon .wtext { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.weapon .wname { font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wicon { width: 28px; height: 28px; flex: none; image-rendering: pixelated; }
.status-icon { display: inline-flex; align-items: center; }
.status-icon .wicon { width: 32px; height: 32px; }
.weapon .ammo { font-size: 0.68rem; color: var(--accent); }
.weapon .cd { width: 100%; height: 3px; background: rgba(255,255,255,0.2); border-radius: 2px; overflow: hidden; }
.weapon .cd > div { height: 100%; background: var(--danger); }

#game-canvas.targeting { cursor: crosshair; }

.hud-help {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.75rem;
  white-space: nowrap;
}

.game-over {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.game-over h2 { font-size: 2.4rem; margin: 0 0 0.5rem; text-shadow: 0 2px 8px #000; }

.game-chat { position: absolute; right: 12px; bottom: 12px; width: 320px; pointer-events: auto !important; }
#game-chat-log { max-height: 160px; overflow: hidden; font-size: 0.85rem; text-shadow: 0 1px 2px #000; }
#game-chat-log .from { color: var(--accent); font-weight: 600; margin-right: 0.3rem; }
#game-chat-form input { pointer-events: auto; background: rgba(0, 0, 0, 0.7); }

.modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal .panel { width: min(420px, 90vw); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.toast.ok { background: var(--accent-2); }

/* ---------- touch controls ---------- */

#screen-game, #game-canvas { touch-action: none; -webkit-user-select: none; user-select: none; }

.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none !important;
}

.tc-left, .tc-right {
  position: absolute;
  bottom: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.tc-left { left: 14px; }
.tc-right { right: 14px; align-items: flex-end; }
.tc-row { display: flex; gap: 8px; }

.tc-btn {
  pointer-events: auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tc-btn.small { width: 46px; height: 46px; font-size: 0.85rem; }
.tc-btn.fire { width: 84px; height: 84px; background: rgba(224, 72, 76, 0.55); border-color: rgba(255, 255, 255, 0.6); }
.tc-btn:active, .tc-btn.held { background: rgba(255, 204, 51, 0.6); color: #1a1400; }

@media (max-width: 700px) {
  .hud-help { display: none; }
  .hud-team { grid-template-columns: 80px 90px; }
  .game-chat { width: 200px; bottom: auto; top: 60px; }
  .weapon-panel { left: 12px; right: 12px; top: 56px; bottom: 180px; }
  .hud-status { bottom: 8px; font-size: 0.85rem; }
}

/* ---------- main menu (Worms Armageddon style) ---------- */

#screen-menu { overflow: hidden; background: transparent; }
/* The twinkling sky sits behind every screen but the game itself. */
#menu-bg { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; pointer-events: none; }

.menu-layout {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 100%;
  padding: 0.6rem 1rem 0.8rem;
  box-sizing: border-box;
}

.wa-logo { text-align: center; font-family: 'Luckiest Guy', Impact, 'Arial Black', sans-serif; line-height: 0.9; margin-top: 0.4rem; }
.logo-worms {
  font-size: clamp(2rem, 5vw, 3.4rem);
  letter-spacing: 0.08em;
  color: #e3161b;
  -webkit-text-stroke: 1.5px #3a0000;
  text-shadow: 3px 3px 0 #2a0000, 0 0 18px rgba(255, 40, 40, 0.5);
  transform: rotate(-2deg);
}
.logo-online {
  font-size: clamp(3rem, 8vw, 5.4rem);
  letter-spacing: 0.06em;
  background: linear-gradient(#fff3a0 0%, #ffd23f 40%, #ff8a00 75%, #d43a00 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(3px 4px 0 #3a1400) drop-shadow(0 8px 12px rgba(0,0,0,0.8));
}

.wa-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(200px, 300px));
  gap: 14px 16px;
  margin: 0.8rem 0 0.4rem;
}

.wa-tile {
  position: relative;
  padding: 0;
  border: 4px solid;
  border-color: #e6e6e6 #5c5c5c #5c5c5c #e6e6e6;
  outline: 2px solid #1c1c1c;
  background: #000;
  cursor: pointer;
  overflow: hidden;
  aspect-ratio: 8 / 5;
  box-shadow: 0 10px 22px rgba(0,0,0,0.7);
  transition: transform 0.1s, filter 0.1s;
}
.wa-tile canvas { display: block; width: 100%; height: 100%; }
.wa-tile:hover, .wa-tile:focus-visible { transform: scale(1.03); filter: brightness(1.12); border-color: #fff #8a8a8a #8a8a8a #fff; z-index: 1; }
.wa-tile:active { transform: scale(0.99); filter: brightness(0.95); }
.wa-caption {
  position: absolute;
  right: 6px;
  bottom: 4px;
  font-family: 'Luckiest Guy', Impact, 'Arial Black', sans-serif;
  font-size: 1rem;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  pointer-events: none;
}

.wa-hint { min-height: 1.6em; color: #33e0ff; font: 700 1.05rem 'Trebuchet MS', Verdana, sans-serif; text-shadow: 1px 1px 0 #000; text-align: center; }

.wa-footer { width: 100%; display: flex; align-items: center; justify-content: center; gap: 1.2rem; }
#menu-conn { color: #9aa3b8; font-size: 0.8rem; }

.wa-btn {
  font: 700 1rem 'Trebuchet MS', Verdana, sans-serif;
  color: #d8d8d8;
  background: linear-gradient(#3b3b3b, #1a1a1a);
  border: 3px solid;
  border-color: #cfcfcf #4a4a4a #4a4a4a #cfcfcf;
  outline: 1px solid #000;
  border-radius: 0;
  padding: 0.35rem 1.6rem;
  min-width: 140px;
  cursor: pointer;
  text-shadow: 1px 1px 0 #000;
}
.wa-btn:hover { color: #fff; filter: brightness(1.25); }
.wa-btn:active { border-color: #4a4a4a #cfcfcf #cfcfcf #4a4a4a; }

/* sub-screens: the dark red W:A options background */
.screen.sub { background: linear-gradient(rgba(0, 0, 0, 0.2) 0%, rgba(32, 0, 0, 0.7) 40%, rgba(74, 0, 0, 0.8) 100%); }
.wa-bar { background: transparent; border-bottom: none; justify-content: space-between; }
.wa-bar h1 { font: 700 1.6rem 'Trebuchet MS', Verdana, sans-serif; color: #c9c9c9; text-shadow: 1px 1px 0 #000; }

.wa-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem 1.6rem;
  max-width: 1080px;
  margin: 1rem auto 2rem;
  padding: 0 1.2rem;
}

.wa-group {
  margin: 0;
  padding: 0.8rem 1rem 1rem;
  border: 2px solid;
  border-color: #6a6a6a #2a2a2a #2a2a2a #6a6a6a;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-start;
}
.wa-group legend { padding: 0 0.6rem; font: 700 1.25rem 'Trebuchet MS', Verdana, sans-serif; color: #c9c9c9; text-shadow: 1px 1px 0 #000; }
.wa-field { width: 100%; color: #c9c9c9; font-weight: 700; font-family: 'Trebuchet MS', Verdana, sans-serif; }
.wa-field input, .wa-field select { background: #111; border: 2px solid; border-color: #4a4a4a #9a9a9a #9a9a9a #4a4a4a; border-radius: 0; color: #d8d8d8; font: 700 1.1rem 'Trebuchet MS', Verdana, sans-serif; }
.wa-pic { border: 3px solid; border-color: #e6e6e6 #5c5c5c #5c5c5c #e6e6e6; outline: 1px solid #000; background: #000; width: 260px; height: 130px; }
.wa-pic.clickable { cursor: pointer; }
.wa-note { color: #9aa3b8; font-size: 0.85rem; margin: 0; }
.wa-audio { display: flex; gap: 1rem; align-items: stretch; }
.wa-volume { writing-mode: vertical-lr; direction: rtl; width: 24px; height: 130px; accent-color: #f5a08c; }
.wa-ok { justify-self: end; align-self: end; min-width: 220px; font-size: 1.2rem; padding: 0.7rem 1.6rem; }
#options-hint { grid-column: 1; text-align: left; align-self: end; }

.screen.sub .map-card, .screen.sub .arsenal-item, .screen.sub .help-panel { background: rgba(0,0,0,0.45); border-color: #4a4a4a; }
.screen.sub .arsenal-group h2 { color: #f5a08c; }
.screen.sub .help-panel { border: 2px solid; border-color: #6a6a6a #2a2a2a #2a2a2a #6a6a6a; border-radius: 0; }
.screen.sub .help-panel h2 { color: #c9c9c9; font-family: 'Trebuchet MS', Verdana, sans-serif; }
.screen.sub .keys td:first-child { color: #f5a08c; }

.map-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.8rem;
  padding: 0 1.5rem 2rem;
  max-width: 1300px;
  margin: 0 auto;
}
.map-card { border: 1px solid var(--border); border-radius: 4px; overflow: hidden; cursor: pointer; transition: transform 0.1s, border-color 0.1s; }
.map-card:hover { transform: translateY(-3px); border-color: #f5a08c; }
.map-card .thumb { height: 90px; background: #1b2140; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.map-card img, .map-card canvas { width: 100%; height: 100%; object-fit: cover; mix-blend-mode: screen; image-rendering: auto; }
.map-card canvas { mix-blend-mode: normal; }
.map-card .name { padding: 0.4rem 0.6rem 0.1rem; font-weight: 600; }
.map-card .desc { padding: 0 0.6rem 0.5rem; color: var(--muted); font-size: 0.8rem; }

.arsenal-list { max-width: 1100px; margin: 0 auto 2rem; padding: 0 1.5rem; }
.arsenal-group { margin-bottom: 1rem; }
.arsenal-group h2 { font-size: 0.95rem; margin: 0.6rem 0 0.4rem; }
.arsenal-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.5rem; }
.arsenal-item { display: flex; gap: 0.6rem; align-items: center; border: 1px solid; border-radius: 4px; padding: 0.4rem 0.6rem; }
.arsenal-item canvas { width: 40px; height: 40px; flex: none; }
.arsenal-item .n { font-weight: 600; font-size: 0.9rem; }
.arsenal-item .d { color: var(--muted); font-size: 0.75rem; }

.help-panel { max-width: 720px; margin: 1.5rem auto; }
.help-panel p { color: #d5dbe8; line-height: 1.5; }
.keys { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.keys td { padding: 0.3rem 0.5rem; border-bottom: 1px solid #3a3a3a; vertical-align: top; }
.keys td:first-child { white-space: nowrap; font-weight: 600; width: 34%; }

@media (max-width: 760px) {
  .topbar { padding-left: max(0.8rem, env(safe-area-inset-left)); padding-right: max(0.8rem, env(safe-area-inset-right)); }
  .topbar h1 { font-size: 1.15rem; min-width: 0; }
  .lobby-grid { padding: 0 0.7rem; margin: 0.8rem auto; gap: 0.8rem; }
  .panel { padding: 0.8rem 0.9rem; }
  .code { font-size: 1.05rem; letter-spacing: 0.12em; padding: 0.25rem 0.5rem; }
  .wa-tiles { grid-template-columns: repeat(2, minmax(140px, 1fr)); gap: 8px; width: 100%; }
  .wa-options { grid-template-columns: 1fr; }
  .logo-online { font-size: 2.6rem; }
}

/* ---------- voice ---------- */
.hud-voice {
  position: absolute;
  top: 48px;
  right: 12px;
  pointer-events: auto !important;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  color: #ddd;
  padding: 4px 10px;
  font-size: 0.85rem;
}
.hud-voice.on { background: rgba(76, 175, 80, 0.55); color: #fff; border-color: rgba(255,255,255,0.5); }
.hud-voice.pending { opacity: 0.7; }
#btn-voice-room.on, #btn-mic-room.on { background: var(--accent-2); color: #fff; border-color: transparent; }
/* The two voice buttons sit side by side under the wind gauge. */
.hud-voice-group { position: absolute; top: 48px; right: 12px; display: flex; gap: 6px; pointer-events: auto; }
.hud-voice-group .hud-voice { position: static; }
.player-list .tag.offline { color: var(--danger); }

/* ---- room: weapon scheme editor ---- */
.arsenal { border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; padding: 8px 10px 6px; margin: 4px 0; min-width: 0; }
.arsenal legend { padding: 0 6px; color: var(--muted); font-size: 0.8rem; }
.arsenal .hint { margin: 6px 0 0; font-size: 0.7rem; color: var(--muted); }
.ammo-grid { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ammo-cell { position: relative; width: 42px; height: 42px; padding: 0; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; background: rgba(0,0,0,0.35); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.ammo-cell .wicon { width: 32px; height: 32px; image-rendering: pixelated; }
.ammo-cell .count { position: absolute; right: 2px; bottom: 0; font-size: 0.7rem; font-weight: 700; color: var(--accent); text-shadow: 0 0 3px #000, 0 0 3px #000; }
.ammo-cell.inf .count { color: #7fd1ff; }
.ammo-cell.off { opacity: 0.35; }
.ammo-cell:not([disabled]):hover { border-color: rgba(255,255,255,0.6); }
.ammo-cell[disabled] { cursor: default; }

/* ---- accounts & persistent rooms ---- */
textarea { width: 100%; box-sizing: border-box; font: inherit; color: inherit; background: var(--panel-2, rgba(0,0,0,0.3)); border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; padding: 0.45rem 0.6rem; resize: vertical; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.auth-tabs { display: flex; gap: 0.4rem; margin: 0.2rem 0 0.6rem; }
.auth-tabs button.on { border-color: var(--accent); color: var(--accent); }
.auth-form button { margin-bottom: 0.6rem; }
.social { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.4rem 0 0.6rem; }
button.apple { background: #000; color: #fff; border-color: #444; font-weight: 600; width: 240px; }
label.check { display: flex; align-items: center; gap: 0.5rem; flex-direction: row; }
label.check input { width: auto; margin: 0; }
.map-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 2px 8px; max-height: 150px; overflow-y: auto; padding: 6px 8px; margin-bottom: 0.8rem; border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; background: rgba(0,0,0,0.25); }
.map-picks label { display: flex; align-items: center; gap: 0.35rem; margin: 0; font-size: 0.8rem; flex-direction: row; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-picks input { width: auto; margin: 0; }
.badge { display: inline-block; font-size: 0.7rem; padding: 0.05rem 0.4rem; border-radius: 999px; background: rgba(255, 213, 74, 0.2); color: var(--accent); margin-left: 0.3rem; vertical-align: middle; }
.room-list .desc { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; white-space: pre-wrap; }
.room-desc { margin: -0.4rem 0 0.8rem; color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; }

/* ---- lobby: room list first, creation on its own screen ---- */
.lobby-grid--rooms { grid-template-columns: minmax(260px, 1fr) 2fr; }
@media (max-width: 800px) { .lobby-grid--rooms { grid-template-columns: 1fr; } }
.row.space-between { justify-content: space-between; margin-bottom: 0.6rem; }
.row.space-between h2 { margin: 0; }
.panel.narrow { max-width: 560px; margin: 1.2rem auto; }

/* ---- voice: who is talking ---- */
.player-list li.speaking { box-shadow: inset 3px 0 0 #69f0ae; }
.player-list li.speaking .swatch { outline: 2px solid #69f0ae; }

/* ---- in-game quit button ---- */
.hud-quit.armed { background: rgba(211, 47, 47, 0.7); color: #fff; border-color: rgba(255,255,255,0.6); }

/* ---- lobby header worm ---- */
.logo-worm { width: 44px; height: 44px; vertical-align: middle; margin: -10px 4px -6px 0; image-rendering: pixelated; }

/* ---- favourite rooms ---- */
.room-list li { grid-template-columns: auto 1fr auto; }
.room-list .fav { font-size: 1.15rem; line-height: 1; padding: 0.15rem 0.35rem; background: transparent; border-color: transparent; color: var(--muted); }
.room-list .fav.on, #btn-fav-room.on { color: var(--accent); }
.room-list .fav:hover { border-color: var(--accent); color: var(--accent); }
.room-list li.mine { border-color: rgba(255, 213, 74, 0.45); }
.badge.private { background: rgba(255, 255, 255, 0.12); color: var(--muted); }

/* ---- chat timestamps ---- */
.chat-log .time { color: var(--muted); font-size: 0.72em; margin-right: 0.4rem; font-variant-numeric: tabular-nums; }

/* ---- avatars & profile ---- */
.avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; vertical-align: middle; background: rgba(255,255,255,0.08); }
.avatar-lg { width: 32px; height: 32px; margin-right: 0.3rem; }
.avatar-xl { width: 96px; height: 96px; border-radius: 12px; flex: none; }
.account-line { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.player-list li .avatar { margin-right: 0.35rem; }
.file-pick { display: inline-block; padding: 0.35rem 0.6rem; border: 1px solid rgba(255,255,255,0.25); border-radius: 8px; cursor: pointer; margin-bottom: 0.4rem; }
.file-pick input { display: none; }
#profile-form { width: min(440px, 92vw); }

.hud-team .avatar { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; vertical-align: -5px; margin-right: 4px; border: 1px solid rgba(255,255,255,0.35); }

/* ---- room settings dialog ---- */
#settings-form.panel { width: min(560px, 94vw); max-height: 90vh; overflow: auto; }
#live-settings { margin-top: 0.6rem; }

.ammo-cell.w0 { opacity: 0.35; }
.ammo-cell .count.weight { color: #ffd54a; }

/* Team play in the lobby: side headers with a join button; allies in the HUD. */
.player-list li.side-head { background: none; border-left: 3px solid; border-radius: 0; font-weight: 600; padding: 0.3rem 0.6rem; margin-top: 0.4rem; }
.player-list li.side-head .tag { margin-left: auto; font-weight: 400; }
.player-list .side-join { font-size: 0.8rem; padding: 0.15rem 0.55rem; }
.hud-team.ally { border-left-style: dashed; }

/* Live worm count next to the team name. */
.hud-team .alive { font-size: 0.75rem; color: #dfe4f5; opacity: 0.85; white-space: nowrap; }

/* Instant replay banner (the original's flashing "REPLAY") and the saved-replay control bar. */
.replay-banner {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  font-size: 2.6rem; font-weight: 900; letter-spacing: 0.25em; color: #ffe33d; text-shadow: 0 0 12px #000, 0 3px 0 #7a5a00;
  animation: replayblink 0.9s steps(2) infinite; pointer-events: none;
}
@keyframes replayblink { 50% { opacity: 0.25; } }
.replay-bar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.7rem;
  background: rgba(0, 0, 0, 0.7); border: 1px solid #555; border-radius: 10px; pointer-events: auto !important;
}
.replay-bar button { min-width: 2.2rem; }
.replay-bar button.on { background: var(--accent); color: #000; }
.replay-bar .track { width: min(40vw, 320px); height: 10px; background: rgba(255, 255, 255, 0.2); border-radius: 5px; cursor: pointer; overflow: hidden; }
.replay-bar .fill { height: 100%; background: #ffe33d; width: 0; }
.replay-bar .time { font-variant-numeric: tabular-nums; font-size: 0.85rem; }

/* Results of a finished match. */
.game-over-body { max-width: min(92vw, 720px); margin-bottom: 0.8rem; }
.awards { list-style: none; padding: 0; margin: 0 0 0.8rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; justify-content: center; }
.awards .icon { font-size: 1.2rem; }
.results { border-collapse: collapse; font-size: 0.85rem; background: rgba(0, 0, 0, 0.35); }
.results th, .results td { padding: 0.25rem 0.6rem; text-align: center; border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.results td:first-child, .results th:first-child { text-align: left; }
.results tr.won td { font-weight: 700; }

/* Lobby extras: kick buttons, spectators, replays, ranking, own maps. */
.player-list .kick { margin-left: 0.3rem; padding: 0 0.45rem; }
.player-list .kick.armed { background: var(--danger); color: #fff; }
.replay-list { list-style: none; padding: 0; margin: 0 0 0.8rem; max-height: 180px; overflow: auto; }
.replay-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.5rem; padding: 0.3rem 0.5rem; border-radius: 6px; background: var(--panel-2); margin-bottom: 0.3rem; font-size: 0.85rem; }
.replay-list li > span { min-width: 0; }
.replay-list .meta { color: var(--muted); font-size: 0.78rem; }
.replay-list button { margin-left: auto; }
.ranking-list { padding-left: 1.4rem; max-height: 60vh; overflow: auto; }
.ranking-list li { padding: 0.2rem 0; display: flex; gap: 0.5rem; align-items: center; }
.ranking-list .avatar { width: 22px; height: 22px; border-radius: 50%; }
.ranking-list .rating { margin-left: auto; font-weight: 700; }
.ranking-list .rec { color: var(--muted); font-size: 0.8rem; }
.map-upload { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: end; max-width: 1100px; margin: 0 auto 1rem; padding: 0.8rem 1.2rem; background: rgba(0,0,0,0.45); border: 1px solid #4a4a4a; }
.map-upload label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; }
.map-upload .muted { flex-basis: 100%; font-size: 0.78rem; }
.map-card .del { position: absolute; top: 4px; right: 4px; }
.map-card { position: relative; }
.map-card .badge { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,0.6); color: #ffe33d; font-size: 0.7rem; padding: 0.05rem 0.35rem; border-radius: 4px; }

/* Safe areas: the status bar, the notch and the home bar of phones (viewport-fit=cover, standalone PWA). */
.topbar { padding: calc(0.8rem + env(safe-area-inset-top)) max(1.5rem, env(safe-area-inset-right)) 0.8rem max(1.5rem, env(safe-area-inset-left)); }
.screen { padding-bottom: env(safe-area-inset-bottom); box-sizing: border-box; }
.menu-layout { padding: calc(0.6rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) calc(0.8rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
.modal { padding-top: env(safe-area-inset-top); }
.hud-teams { top: calc(12px + env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); }
.hud-center { top: calc(10px + env(safe-area-inset-top)); }
.hud-wind { top: calc(12px + env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
.hud-voice-group { top: calc(48px + env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
.weapon-panel { top: calc(60px + env(safe-area-inset-top)); }
.hud-status { bottom: calc(30px + env(safe-area-inset-bottom)); }
.hud-help { bottom: calc(8px + env(safe-area-inset-bottom)); }
.hud-messages { bottom: calc(96px + env(safe-area-inset-bottom)); }
.replay-bar { bottom: calc(14px + env(safe-area-inset-bottom)); }
.tc-left, .tc-right { bottom: calc(84px + env(safe-area-inset-bottom)); }
.tc-left { left: max(14px, env(safe-area-inset-left)); }
.tc-right { right: max(14px, env(safe-area-inset-right)); }

/* ---------- phones held sideways: little height, wide screen ---------- */
@media (max-height: 520px) {
  /* Menu keeps its look; when the browser's bars leave too little room it simply scrolls. */
  #screen-menu { overflow: auto; }
  .screen.sub .topbar h1, .topbar h1 { font-size: 1.1rem; }
  .topbar { padding: 0.3rem 0.8rem; }
  .panel { padding: 0.6rem 0.8rem; }
  .panel h2 { margin: 0.1rem 0 0.4rem; font-size: 0.95rem; }

  /* The match: a smaller HUD, controls tucked into the corners, no help line. */
  #hud { font-size: 0.8rem; }
  .hud-teams { top: calc(4px + env(safe-area-inset-top)); gap: 2px; transform: scale(0.78); transform-origin: top left; }
  .hud-center { top: calc(2px + env(safe-area-inset-top)); transform: translateX(-50%) scale(0.8); transform-origin: top center; }
  .hud-wind { top: calc(4px + env(safe-area-inset-top)); transform: scale(0.78); transform-origin: top right; }
  .hud-voice-group { top: calc(34px + env(safe-area-inset-top)); transform: scale(0.82); transform-origin: top right; }
  .hud-help { display: none; }
  .hud-status { bottom: calc(4px + env(safe-area-inset-bottom)); font-size: 0.78rem; padding: 2px 8px; }
  .hud-messages { bottom: calc(58px + env(safe-area-inset-bottom)); font-size: 0.78rem; gap: 2px; }
  .weapon-panel { top: 40px; bottom: 54px; left: 12px; right: 12px; }
  .game-chat { width: 220px; top: 40px; bottom: auto; }
  .game-over h2 { font-size: 1.5rem; }
  .game-over-body { max-height: 45vh; overflow: auto; }
  .results { font-size: 0.75rem; }
  .replay-bar { bottom: calc(4px + env(safe-area-inset-bottom)); transform: translateX(-50%) scale(0.85); }
  .replay-banner { top: 12%; font-size: 1.8rem; }
  .tc-left, .tc-right { bottom: calc(8px + env(safe-area-inset-bottom)); gap: 4px; }
  .tc-row { gap: 4px; }
  .tc-btn { width: 46px; height: 46px; font-size: 1rem; }
  .tc-btn.small { width: 38px; height: 38px; font-size: 0.75rem; }
  .tc-btn.fire { width: 62px; height: 62px; font-size: 0.9rem; }
}
