:root {
  --bg: #0b0e14;
  --panel: #161c28;
  --panel2: #1d2533;
  --accent: #ffd24a;
  --accent2: #4fa3ff;
  --danger: #ff5a5a;
  --ok: #5ad469;
  --text: #e8edf4;
  --muted: #8a94a6;
  --border: #283246;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
  user-select: none;
}

/* Анимированный фон */
#bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 15% 20%, rgba(79, 163, 255, 0.14), transparent 38%),
    radial-gradient(circle at 85% 75%, rgba(255, 210, 74, 0.12), transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(90, 212, 105, 0.06), transparent 55%),
    var(--bg);
  background-size: 200% 200%;
  animation: bgshift 18s ease-in-out infinite;
}
@keyframes bgshift {
  0%, 100% { background-position: 0% 0%, 100% 100%, 50% 50%; }
  50% { background-position: 30% 20%, 70% 80%, 40% 60%; }
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  overflow-y: auto;
}
.hidden { display: none !important; }

/* Лого */
.logo {
  font-size: 54px;
  font-weight: 900;
  letter-spacing: 3px;
  line-height: 0.92;
  text-align: center;
  text-shadow: 0 0 24px rgba(255, 210, 74, 0.25);
  animation: logopulse 3.5s ease-in-out infinite;
}
.logo span { color: var(--accent); }
.logo.big { font-size: 76px; }
@keyframes logopulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.tagline { color: var(--muted); text-align: center; margin: 14px 0 22px; font-size: 15px; line-height: 1.5; }

/* Карточки */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  animation: rise 0.35s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.auth-card { width: min(420px, 92vw); text-align: center; }
.card h3 { margin-bottom: 12px; font-size: 16px; }

/* Поля и кнопки */
input[type='text'], input[type='password'] {
  width: 100%;
  background: #0e131b;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent2); }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #1a1300;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.97); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-ghost:hover { background: var(--panel2); border-color: var(--accent2); }
.btn-ghost.small { padding: 7px 12px; font-size: 13px; }

.big-btn { width: min(360px, 90vw); font-size: 20px; padding: 16px; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1;
  background: var(--panel2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  font-weight: 600;
}
.tab.active { color: var(--text); border-color: var(--accent); background: #232c3c; }

#guest-btn { width: 100%; margin-top: 10px; }
.error-msg { color: var(--danger); min-height: 18px; margin-top: 12px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Меню */
.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
}
.user-badge { display: flex; flex-direction: column; gap: 2px; }
#user-name { font-weight: 800; font-size: 16px; }

.menu-actions { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.action-card { width: 240px; }
#customize-btn {
  width: min(340px, 90vw);
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(135deg, rgba(196, 107, 255, 0.18), rgba(79, 163, 255, 0.18));
  border: 1px solid #3a4458;
  border-radius: 12px;
  transition: transform 0.08s, border-color 0.15s, filter 0.15s;
}
#customize-btn:hover { border-color: var(--accent2); filter: brightness(1.12); }
#customize-btn:active { transform: scale(0.97); }

/* Экран кастомизации */
.custom-card { width: min(420px, 92vw); text-align: center; }
.custom-card h2 { margin-bottom: 16px; }
#custom-preview {
  background: #11161f;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}
.custom-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.custom-controls label {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
}
.custom-controls input[type='color'] {
  width: 40px; height: 28px; border: none; background: none; cursor: pointer; padding: 0;
}
.custom-buttons { display: flex; gap: 10px; margin-bottom: 12px; }
.custom-buttons button { flex: 1; }

.rooms-card { width: min(620px, 94vw); }
.rooms-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.rooms-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.room-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
}
.room-row .rname { flex: 1; font-weight: 600; }
.room-row .rmeta { color: var(--muted); font-size: 13px; }
.room-row .tag {
  font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: #2a3344; color: var(--muted);
}
.room-row .tag.live { background: rgba(90,212,105,0.18); color: var(--ok); }
.empty-note { color: var(--muted); text-align: center; padding: 16px; }

/* Лобби */
.lobby-wrap { width: min(820px, 96vw); display: flex; flex-direction: column; gap: 16px; }
.lobby-header { display: flex; justify-content: space-between; align-items: center; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 680px) { .lobby-grid { grid-template-columns: 1fr; } }

.player-list { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.player-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
}
.color-dot { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.tank-preview { width: 30px; height: 30px; flex: none; background: #0e131b; border: 1px solid var(--border); border-radius: 6px; }
.player-row .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-host { font-size: 11px; color: var(--accent); border: 1px solid var(--accent); border-radius: 20px; padding: 1px 7px; }
.badge-bot { font-size: 11px; color: var(--accent2); border: 1px solid var(--accent2); border-radius: 20px; padding: 1px 7px; }
.badge-guest { font-size: 11px; color: var(--muted); }
.kick-btn { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 16px; line-height: 1; }
.kick-btn:hover { transform: scale(1.2); }

.bot-controls { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.settings-list { display: flex; flex-direction: column; gap: 14px; }
.setting { }
.setting-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; }
.setting-top b { color: var(--accent); }
input[type='range'] { width: 100%; accent-color: var(--accent); cursor: pointer; }
input[type='range']:disabled { opacity: 0.5; cursor: default; }
.switch-row { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 14px; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* Чат лобби */
.chat-card { grid-column: 1 / -1; display: flex; flex-direction: column; }
.chat-messages {
  height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #0e131b;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.4;
}
.chat-msg { word-break: break-word; }
.chat-sys { color: var(--accent); font-style: italic; text-align: center; opacity: 0.9; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { margin-bottom: 0; }
.chat-form button { flex: none; width: 44px; font-size: 18px; }

/* Кнопка старта во время отсчёта */
#start-btn:disabled { opacity: 0.85; cursor: default; }
.big-btn { align-self: center; }
#lobby-note { text-align: center; }

/* Игра */
#game-screen { padding: 0; }
#canvas {
  background: #11161f;
  border-radius: 10px;
  box-shadow: 0 0 0 2px var(--border), 0 20px 50px rgba(0, 0, 0, 0.6);
  max-width: 100%;
  max-height: 100%;
}
#hud { position: absolute; inset: 0; pointer-events: none; }
#scoreboard {
  position: absolute; top: 16px; left: 16px;
  background: rgba(15, 19, 27, 0.82);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  min-width: 180px;
  backdrop-filter: blur(4px);
}
.sb-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.sb-dot { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.sb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-name.me { font-weight: 800; }
.sb-bot { font-size: 10px; color: var(--accent2); }
.sb-score { font-weight: 800; color: var(--accent); }
.sb-dead { opacity: 0.4; }

#round-banner {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 19, 27, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 40px;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  white-space: nowrap;
  animation: rise 0.25s ease;
}
#round-banner small { display: block; margin-top: 8px; font-size: 14px; font-weight: 500; color: var(--muted); }

#countdown-big {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 140px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 40px rgba(255, 210, 74, 0.5), 0 6px 20px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
#countdown-big.pop { animation: cdpop 0.9s ease-out; }
@keyframes cdpop {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0.92; }
}

.sb-head { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }

#game-leave-btn { position: absolute; top: 14px; right: 64px; pointer-events: auto; }
#stop-btn { position: absolute; top: 14px; right: 148px; pointer-events: auto; }

#mute-btn {
  position: fixed; top: 14px; right: 14px; z-index: 50;
  width: 40px; height: 40px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
#mute-btn:hover { border-color: var(--accent); }

/* Оверлей переподключения */
#reconnect-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 16, 0.88);
  backdrop-filter: blur(6px);
}
.reconnect-box {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 40px;
  max-width: 360px;
}
.reconnect-box h2 { margin: 16px 0 8px; }
.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== Кнопки меню в ряд ====== */
.menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 4px auto 0;
  width: min(720px, 92vw);
}
.menu-row .btn-ghost { flex: 1 1 200px; }
#catalog-btn, #editor-btn {
  font-weight: 700;
  border: 1px solid #3a4458;
  border-radius: 12px;
  padding: 13px;
}
#catalog-btn:hover { border-color: var(--accent2); filter: brightness(1.12); }
#editor-btn:hover { border-color: #5ad469; filter: brightness(1.12); }

/* ====== Каталог карт ====== */
#catalog-screen, #editor-screen { justify-content: flex-start; }
.catalog-wrap { width: min(1100px, 96vw); margin: 24px auto; }
.catalog-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.catalog-header h2 { margin: 0; flex: 0 0 auto; }
.catalog-tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.catalog-tools input { width: 240px; }
.catalog-tools input, .catalog-tools select {
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 12px;
}
.map-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 220 / 130;
  background: #0c1118;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.map-meta { display: flex; flex-direction: column; gap: 2px; }
.map-title { font-weight: 800; font-size: 15px; }
.map-author { color: var(--muted); font-size: 13px; }
.map-plays { color: var(--accent2); font-size: 13px; font-weight: 600; }
.map-pick { width: 100%; }
.map-del { width: 100%; color: #ff8f8f; border-color: #5a2c2c; }
.map-del:hover { border-color: #ff5a5a; }

/* Карточка карты в лобби */
.map-card-lobby {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.map-card-lobby .map-thumb { width: 200px; aspect-ratio: 200 / 120; }
.map-card-lobby .map-meta { flex: 1; }
.map-card-lobby #lobby-map-btn { margin-left: auto; }

/* ====== Редактор карт ====== */
.editor-wrap {
  width: min(1100px, 98vw);
  margin: 16px auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
.editor-toolbar select {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.tool-group { display: inline-flex; gap: 4px; }
.tool-btn {
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.tool-btn:hover { border-color: var(--accent2); }
.tool-btn.active { background: var(--accent); border-color: var(--accent); color: #06101e; font-weight: 700; }
.ed-bg-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.ed-bg-label input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
.editor-stage {
  display: flex;
  justify-content: center;
  background: #0c1118;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
}
#editor-canvas {
  width: 100%;
  max-width: 960px;
  height: auto;
  aspect-ratio: 960 / 600;
  background: #11161f;
  border-radius: 8px;
  cursor: crosshair;
  touch-action: none;
}
.editor-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.editor-save { display: inline-flex; gap: 8px; margin-left: auto; }
.editor-save input {
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  width: 220px;
}
.editor-hint { text-align: center; }
