:root {
  --bg: #05050c;
  --panel: rgba(7, 10, 20, 0.85);
  --line: rgba(255, 255, 255, 0.15);
  --text: #f5f7ff;
  --accent: #f25f5c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 20% 10%, #1b1f39 0%, #070812 35%, #040409 100%);
  color: var(--text);
  font-family: "Consolas", "Courier New", monospace;
}

canvas#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.panel {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  backdrop-filter: blur(3px);
  transition: background 140ms ease, border-color 140ms ease;
}

.panel.near-top {
  background: rgba(6, 10, 20, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
}

.chat-dock {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: min(340px, calc(100vw - 28px));
  background: rgba(6, 10, 20, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  backdrop-filter: blur(3px);
  z-index: 12;
  padding: 8px;
  display: grid;
  gap: 8px;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.chat-toggle {
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
}

.chat-messages {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 200px;
  overflow: auto;
  display: grid;
  gap: 5px;
}

.chat-item {
  font-size: 12px;
  line-height: 1.25;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 5px 6px;
  word-break: break-word;
}

.chat-item strong {
  color: #ffd28f;
}

.chat-form {
  display: flex;
  gap: 6px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 9px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-family: inherit;
}

.chat-form button {
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  background: linear-gradient(90deg, #e63946, #f4a261);
  color: #fff;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}

.hud-top,
.hud-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  transition: opacity 140ms ease;
}

.game-switch-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  line-height: 1;
}

.game-switch-btn:hover {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.16);
}

.panel.near-top .hud-top {
  opacity: 0.2;
}

.hud-bottom {
  margin-top: 8px;
  opacity: 0.9;
}

.bombs-danger {
  color: #ff4d4d;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 20;
}

.card,
.stats-card {
  width: min(92vw, 760px);
  background: rgba(11, 13, 24, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.card.compact {
  width: min(92vw, 420px);
  text-align: center;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-bottom: 8px;
}

#joinForm {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-family: inherit;
}

.join-row button {
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-family: inherit;
  color: white;
  background: linear-gradient(90deg, #e63946, #f4a261);
  cursor: pointer;
}

.avatar-picker {
  display: grid;
  gap: 8px;
}

.color-picker {
  display: grid;
  gap: 8px;
}

.avatar-title {
  font-size: 12px;
  opacity: 0.85;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.avatar-option {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 4px;
  cursor: pointer;
}

.avatar-option:hover {
  border-color: rgba(255, 255, 255, 0.45);
}

.avatar-option.selected {
  border-color: #f4a261;
  box-shadow: inset 0 0 0 1px rgba(244, 162, 97, 0.8);
  background: rgba(244, 162, 97, 0.15);
}

.avatar-preview {
  image-rendering: pixelated;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 6px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
}

.color-option {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: var(--swatch-color, #ffffff);
  cursor: pointer;
}

.color-option:hover {
  border-color: rgba(255, 255, 255, 0.48);
}

.color-option.selected {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45) inset;
}

.error {
  margin-top: 8px;
  min-height: 18px;
  color: #ff6b6b;
}

.hint {
  margin-top: 10px;
  opacity: 0.75;
  font-size: 12px;
}

.switch-row {
  margin-top: 8px;
}

.palette-dock {
  position: fixed;
  left: 14px;
  bottom: 14px;
  width: min(460px, calc(100vw - 28px));
  background: rgba(6, 10, 20, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  backdrop-filter: blur(3px);
  z-index: 12;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.palette-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.palette-export-btn {
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.palette-export-btn:hover {
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.14);
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}

.palette-option {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: var(--swatch-color, #000000);
  cursor: pointer;
}

.palette-option:hover {
  border-color: rgba(255, 255, 255, 0.46);
}

.palette-option.selected {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4) inset;
}

.stats-card {
  max-height: 94vh;
  overflow: auto;
}

#statsTitle {
  font-size: 32px;
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-align: center;
}

#statsDuration,
#statsCountdown {
  text-align: center;
  margin-bottom: 12px;
}

#statsMiniMap {
  display: block;
  width: min(100%, 420px);
  height: auto;
  margin: 0 auto 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: #0a0c15;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
}

th,
td {
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 6px;
  text-align: center;
  font-size: 13px;
}

.explosions {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 12px;
}

#explosionList {
  margin: 8px 0 0;
  padding-left: 18px;
  max-height: 150px;
  overflow: auto;
  line-height: 1.3;
}

.hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .panel {
    font-size: 12px;
    padding: 8px 10px;
  }

  .hud-top,
  .hud-bottom {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  #statsTitle {
    font-size: 24px;
  }

  .join-row {
    flex-direction: column;
  }

  .avatar-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .color-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .chat-dock {
    bottom: 10px;
    right: 10px;
    width: calc(100vw - 20px);
  }

  .palette-dock {
    left: 10px;
    bottom: 138px;
    width: calc(100vw - 20px);
  }

  .palette-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .chat-messages {
    max-height: 120px;
  }
}
