/* На html/body намеренно нет overflow/touch-action: иначе в мобильных Chromium корневым
 * скроллером становится html и страница перестаёт листаться одним пальцем. */
html, body {
  margin: 0; padding: 0; background: #0e1a2b; color: #eaf2ff;
  font-family: 'Segoe UI', Arial, sans-serif;
}
html.touch { -webkit-tap-highlight-color: transparent; }
html.touch.ingame, html.touch.ingame body { overscroll-behavior: none; }
html.touch #screen-game, html.touch #screen-game * { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#app { display: flex; flex-direction: column; align-items: center; padding: 18px; max-width: 920px; margin: 0 auto; position: relative; min-height: 100vh; min-height: 100dvh; box-sizing: border-box; overflow-x: clip; }
h1.title { margin: 0 0 18px 0; font-size: 30px; letter-spacing: 2px; text-align: center; }
.panel { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.panel[hidden] { display: none; }
[hidden] { display: none !important; }
.menuBtn {
  width: 320px; padding: 16px; font-size: 17px; border-radius: 10px; border: none;
  background: #274363; color: #eaf2ff; cursor: pointer; font-weight: 700; letter-spacing: 0.5px;
}
.menuBtn.primary { background: #4aa8ff; color: #06121f; }
.menuBtn.primary:hover { background: #6fbcff; }
.menuBtn:hover { background: #33587f; }
.menuBtn:disabled { opacity: 0.45; cursor: default; }
.menuBtn.ghost { background: transparent; border: 1px solid #3a5a80; color: #a9c2e0; font-weight: 500; width: 200px; }
.menuBtn.ghost.wide { width: 320px; }
.menuBtn, .menuBtn.ghost, .menuBtn.ghost.wide { max-width: 90vw; }
.menuBtn.ghost:hover { background: #16283f; }
.linkBtn { background: none; border: none; color: #4aa8ff; cursor: pointer; font-size: 13px; text-decoration: underline; padding: 0 4px; }
.subtitle { color: #a9c2e0; font-size: 14px; text-align: center; max-width: 560px; }
.who { font-size: 14px; color: #a9c2e0; }
.stub-box {
  background: #16283f; border: 1px solid #3a5a80; border-radius: 10px; padding: 22px 30px;
  text-align: center; max-width: 420px; width: 100%; box-sizing: border-box;
}
.stub-code { font-size: 26px; letter-spacing: 3px; color: #ffd166; margin: 10px 0; font-weight: 700; }
.stub-code.inline { display: inline; margin: 0; font-size: 22px; }
.stub-note { font-size: 12px; color: #ff9d9d; margin-top: 10px; min-height: 14px; }
.stub-box input, #nickInput {
  width: 100%; box-sizing: border-box; padding: 10px; font-size: 16px; text-align: center;
  letter-spacing: 2px; border-radius: 6px; border: 1px solid #3a5a80; background: #0e1a2b; color: #eaf2ff; margin: 8px 0;
}
.searching { font-size: 16px; }
.modeGrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; width: 100%; max-width: 460px; }
.modeGrid.small { grid-template-columns: repeat(4, 1fr); }
.modeGrid.small .modeCard { padding: 12px 6px; font-size: 15px; }
.modeCard {
  padding: 22px 10px; border-radius: 10px; border: 2px solid #3a5a80; background: #16283f;
  color: #eaf2ff; font-size: 17px; font-weight: 700; cursor: pointer; text-align: center;
}
.modeCard:hover { border-color: #4aa8ff; }
.modeCard.selected { border-color: #4aa8ff; background: #1c3a58; }

.cardGrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; width: 100%; }
.heroCard, .mapCard {
  padding: 14px; border-radius: 10px; border: 2px solid #3a5a80; background: #16283f;
  cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 6px;
}
.heroCard:hover, .mapCard:hover { border-color: #4aa8ff; }
.heroCard.selected, .mapCard.selected { border-color: #4aa8ff; background: #1c3a58; }
.heroName { font-weight: 700; font-size: 15px; }
.heroDesc { font-size: 12px; color: #a9c2e0; line-height: 1.4; }
.heroSwatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #0b1622; }
/* компактная карточка бойца: строка «цвет · имя · i», описание — в .heroInfo под сеткой */
.heroCard { flex-direction: row; align-items: center; gap: 10px; padding: 8px 10px; min-width: 0; }
.heroCard .heroName { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heroCard .heroSwatch { width: 26px; height: 26px; flex: none; }
.heroInfoBtn { width: 28px; height: 28px; border-radius: 50%; border: 1px solid #3a5a80; background: #0e1a2b; color: #a9c2e0; font: italic 700 14px Georgia, 'Times New Roman', serif; cursor: pointer; flex: none; padding: 0; line-height: 1; }
.heroInfoBtn:hover { border-color: #4aa8ff; color: #eaf2ff; }
.heroInfo { background: #16283f; border: 1px solid #3a5a80; border-radius: 8px; padding: 8px 12px; font-size: 12px; color: #a9c2e0; line-height: 1.4; width: 100%; max-width: 560px; box-sizing: border-box; }
.heroInfo b { color: #eaf2ff; }
.navRow { display: flex; gap: 12px; margin-top: 4px; flex-wrap: wrap; justify-content: center; }

/* сегментированный переключатель (сложность ботов) */
.segRow { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.segBtn { padding: 8px 16px; border-radius: 8px; border: 1px solid #3a5a80; background: #0e1a2b; color: #a9c2e0; font: 600 14px 'Segoe UI', Arial, sans-serif; cursor: pointer; }
.segBtn:hover { border-color: #4aa8ff; }
.segBtn.selected { border-color: #4aa8ff; background: #1c3a58; color: #eaf2ff; }
html.touch .segBtn { min-height: 44px; }

/* настройки */
.settingsBox { background: #16283f; border: 1px solid #3a5a80; border-radius: 10px; padding: 8px 18px; width: 100%; max-width: 460px; box-sizing: border-box; }
.setRow { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid #23405f; font-size: 15px; cursor: pointer; }
.setRow:last-child { border-bottom: none; }
.setRow small { display: block; color: #a9c2e0; font-size: 12px; margin-top: 3px; line-height: 1.35; }
.setRow input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: #4aa8ff; }
.setRow select { background: #0e1a2b; color: #eaf2ff; border: 1px solid #3a5a80; border-radius: 6px; padding: 6px 8px; font-size: 14px; flex: none; }

/* лобби */
.lobbyHead { text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.lobbyResult { background: #16283f; border: 1px solid #3a5a80; border-radius: 8px; padding: 8px 16px; font-weight: 700; color: #ffd166; }
.lobbyConfig { display: flex; gap: 18px; align-items: center; font-size: 14px; color: #a9c2e0; }
.lobbyConfig select { background: #16283f; color: #eaf2ff; border: 1px solid #3a5a80; border-radius: 6px; padding: 4px 8px; font-size: 14px; }
.teamsGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; width: 100%; max-width: 620px; }
.teamCol { display: flex; flex-direction: column; gap: 6px; }
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot {
  border: 2px dashed #3a5a80; border-radius: 8px; padding: 10px 12px; font-size: 14px; min-height: 20px;
  display: flex; justify-content: space-between; align-items: center; cursor: pointer; background: #0f1e31;
}
.slot:hover { border-color: #4aa8ff; }
.slot.taken { border-style: solid; background: #16283f; cursor: default; }
.slot.me { border-color: #ffe066; }
.slot .role { color: #a9c2e0; font-size: 12px; }
.slot .off { color: #ff9d9d; font-size: 11px; }
.slot .host { color: #ffd166; font-size: 11px; margin-left: 6px; }
.slot .kick { background: none; border: 1px solid #ff5b5b; color: #ff9d9d; border-radius: 4px; cursor: pointer; font-size: 11px; padding: 2px 6px; }
.slot .botHint { color: #6f89a8; font-size: 12px; }
.teamlabel { font-weight: 700; margin-bottom: 3px; }
.teamlabel.a { color: #4aa8ff; }
.teamlabel.b { color: #ff5b5b; }

/* игра */
#hint { font-size: 13px; color: #a9c2e0; margin-bottom: 4px; text-align: center; max-width: 900px; }
#abilityHint { font-size: 12px; color: #ffd166; margin-bottom: 10px; text-align: center; max-width: 900px; min-height: 16px; }
#topGameBar { display:flex; justify-content:space-between; align-items:center; width:100%; max-width:900px; margin-bottom:6px; }
#topGameBar button { background:#16283f; border:1px solid #3a5a80; color:#cfe2fb; padding:6px 14px; border-radius:6px; cursor:pointer; font-size:12px; }
#topGameBar button:hover { background:#274363; }
#netStat { font-size: 12px; color: #a9c2e0; font-variant-numeric: tabular-nums; white-space: nowrap; }
#netStat.bad { color: #ff6b6b; font-weight: 600; }
#matchTimer { width: 70px; text-align: right; font-variant-numeric: tabular-nums; color: #a9c2e0; font-size: 14px; }
#topGameBar #fsBtn { font-size: 15px; padding: 4px 10px; margin-left: 8px; }
#gameWrap { width: 100%; display: flex; flex-direction: column; align-items: center; position: relative; }
#stage { position: relative; max-width: 100%; aspect-ratio: 900 / 560; }
canvas {
  background: linear-gradient(180deg,#dfeeff 0%, #c3ddf7 100%);
  border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.45); cursor: crosshair; display: block; max-width: 100%; height: 100%; width: 100%;
}
#overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  flex-direction: column; background: rgba(5,10,20,0.72); border-radius: 10px; gap: 10px;
}
#overlay h2 { font-size: 34px; margin: 0 0 6px 0; }
#overlaySub { color: #a9c2e0; font-size: 14px; margin-bottom: 8px; }
#overlay .ovRow { display: flex; gap: 10px; }
#overlay button {
  padding: 10px 22px; font-size: 15px; border: none; border-radius: 8px;
  background: #4aa8ff; color: #06121f; font-weight: 700; cursor: pointer;
}
#overlay button.secondary { background: #274363; color: #eaf2ff; }
#overlay button:hover { filter: brightness(1.15); }
#reconnectOverlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5,10,20,0.6); border-radius: 10px; font-size: 16px; }
#bottomRow { display: flex; justify-content: space-between; width: 100%; max-width: 900px; margin-top: 8px; font-size: 12px; align-items: flex-start; box-sizing: border-box; }
.pips { display: flex; gap: 4px; }
.pip { width: 14px; height: 14px; border-radius: 3px; background: #294159; border: 1px solid #4b6a8a; }
.pip.on.a { background: #4aa8ff; }
.pip.on.b { background: #ff5b5b; }
.charrow { display:flex; gap:14px; margin-bottom:4px; align-items:center; }
.charrow.right { justify-content: flex-end; }
.charname { font-size:11px; color:#9fb8d6; min-width:110px; }
.charname.me { color: #ffe066; }
.charname.bot { color: #6f89a8; }
#abilityBox { text-align:center; min-width: 190px; }
#abilityBtn { padding: 8px 18px; font-size: 13px; border-radius: 8px; border: 1px solid #7a5cff; background: #2a2050; color: #e6d9ff; cursor: pointer; font-weight: 700; }
#abilityBtn:disabled { opacity: 0.4; cursor: default; }
#abilityCd { font-size: 11px; color: #b7a6ff; margin-top: 4px; }
#reloadHud { font-size: 11px; color: #ffcf5b; margin-top: 2px; font-weight: 600; }

/* сенсорное управление */
#touchLayer { position: absolute; inset: 0; z-index: 4; touch-action: none; overflow: hidden; }
#touchLayer .zone { position: absolute; top: 0; bottom: 0; left: 0; width: 50%; touch-action: none; }
#touchLayer .zone.right { left: 50%; }
#touchLayer .zoneHint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 12px; color: rgba(234,242,255,0.55); letter-spacing: 1px; text-transform: uppercase; opacity: 0; transition: opacity 0.4s; pointer-events: none; white-space: nowrap; }
#touchLayer.showZones .zone { background: rgba(74,168,255,0.06); box-shadow: inset 0 0 0 1px rgba(74,168,255,0.25); }
#touchLayer.showZones .zoneHint { opacity: 1; }
#touchLayer .stick { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,255,255,0.10); border: 2px solid rgba(255,255,255,0.35); pointer-events: none; }
#touchLayer .stick .knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; background: rgba(255,255,255,0.75); box-shadow: 0 2px 8px rgba(0,0,0,0.35); will-change: transform; }
#touchLayer .stick.mini { width: 100px; height: 100px; margin: -50px 0 0 -50px; border-color: rgba(183,166,255,0.6); }
#touchLayer .stick.mini .knob { background: rgba(183,166,255,0.9); }
#touchAbility { position: absolute; right: 18px; bottom: 96px; width: 64px; height: 64px; border-radius: 50%; border: 2px solid #7a5cff; background: rgba(42,32,80,0.85); color: #e6d9ff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; touch-action: none; padding: 0; z-index: 5; }
#touchAbility.off { opacity: 0.35; }
#touchAbility.ready { box-shadow: 0 0 16px rgba(122,92,255,0.8); }
#touchAbility.armed { background: rgba(122,92,255,0.9); color: #fff; }
#touchAbilityIcon { font-size: 22px; line-height: 1; }
#touchAbilityCd { font-size: 10px; line-height: 1; color: #b7a6ff; min-height: 10px; }

/* сенсорный режим: игровой экран во весь вьюпорт, HUD поверх полей, меню под палец */
html.touch .menuBtn, html.touch .modeCard, html.touch .heroCard, html.touch .mapCard, html.touch .slot { min-height: 44px; }
html.touch canvas { cursor: default; }
html.touch .heroCard:not(.selected):hover, html.touch .mapCard:not(.selected):hover, html.touch .modeCard:not(.selected):hover { border-color: #3a5a80; background: #16283f; }
html.touch .menuBtn:hover { background: #274363; }
html.touch .menuBtn.primary:hover { background: #4aa8ff; }
html.touch .menuBtn.ghost:hover { background: transparent; }
html.touch.ingame #app { padding: 0; max-width: none; min-height: 100vh; min-height: 100dvh; height: 100vh; height: 100dvh; overflow: hidden; }
html.touch.ingame h1.title, html.touch.ingame .footer, html.touch.ingame #soundToggle, html.touch.ingame #connState, html.touch.ingame #abilityHint, html.touch.ingame #abilityBox { display: none; }
html.touch.ingame #drainBanner { margin: 0; border-radius: 0; font-size: 11px; padding: 4px 8px; }
html.touch.ingame #screen-game { gap: 0; flex: 1; min-height: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); box-sizing: border-box; }
html.touch.ingame #topGameBar { max-width: none; margin: 0; padding: 4px 10px; box-sizing: border-box; height: 36px; flex: none; }
html.touch.ingame #topGameBar button { padding: 4px 10px; font-size: 12px; }
html.touch.ingame #hint { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 8px; }
html.touch.ingame #gameWrap { flex: 1; min-height: 0; width: 100%; }
html.touch.ingame #stage { border-radius: 0; }
html.touch.ingame canvas { border-radius: 6px; box-shadow: none; }
html.touch.ingame #overlay, html.touch.ingame #reconnectOverlay { border-radius: 6px; }
html.touch.ingame #overlay { z-index: 6; }
html.touch.ingame #overlay h2 { font-size: 26px; }
html.touch.ingame .charname { min-width: 0; }
html.touch.ingame .pip { width: 11px; height: 11px; }
/* ландшафт: арена по высоте, поля по бокам под стики и HUD */
@media (orientation: landscape) {
  html.touch.ingame #gameWrap { flex-direction: row; justify-content: center; align-items: stretch; }
  html.touch.ingame #stage { height: 100%; width: auto; max-width: 100%; }
  html.touch.ingame #bottomRow { position: absolute; inset: 0; margin: 0; max-width: none; pointer-events: none; padding: 8px 10px; box-sizing: border-box; }
  html.touch.ingame #hudA, html.touch.ingame #hudB { max-width: 24%; }
}
/* портрет: арена сверху по ширине, HUD под ней, стики в оставшемся месте */
@media (orientation: portrait) {
  html.touch.ingame #gameWrap { flex-direction: column; }
  html.touch.ingame #stage { width: 100%; height: auto; flex: none; }
  html.touch.ingame #bottomRow { margin: 6px 8px 0; width: auto; align-self: stretch; flex: none; }
  html.touch.ingame #touchLayer { position: absolute; top: 0; }
  html.touch.ingame #touchAbility { bottom: 24px; }
}
/* телефон в ландшафте: экраны меню без заголовка, чтобы не прокручивать */
@media (orientation: landscape) and (max-height: 450px) {
  html.touch h1.title { display: none; }
  html.touch #app { padding: 8px 12px; }
  html.touch .panel { gap: 8px; }
  html.touch .subtitle { font-size: 12px; }
  html.touch .menuBtn { padding: 10px; font-size: 15px; }
  html.touch .cardGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
}
/* узкие экраны меню (телефон в портрете) */
@media (max-width: 600px) {
  #app { padding: 12px; }
  h1.title { font-size: 24px; margin-bottom: 12px; }
  .cardGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .heroCard { padding: 8px 8px; gap: 8px; }
  .heroCard .heroName { font-size: 13px; }
  .subtitle { font-size: 13px; }
  .teamsGrid { grid-template-columns: 1fr; gap: 12px; }
  .lobbyConfig { flex-wrap: wrap; justify-content: center; gap: 10px; }
  .stub-box { padding: 16px; }
  #bottomRow { flex-wrap: wrap; gap: 8px; }
}
#soundToggle { position:absolute; top:10px; right:10px; background:#16283f; border:1px solid #3a5a80; color:#cfe2fb; padding:5px 10px; border-radius:6px; cursor:pointer; font-size:14px; z-index:5; }
#connState { position:absolute; top:14px; left:14px; font-size: 14px; color: #6f89a8; z-index: 5; }
#connState.on { color: #7CFFB2; }
#connState.off { color: #ff5b5b; }
#drainBanner { background: #3a2f10; border: 1px solid #ffd166; color: #ffd166; border-radius: 8px; padding: 8px 14px; font-size: 13px; margin-bottom: 12px; text-align: center; }
#toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: #16283f; border: 1px solid #ff5b5b; color: #ffd6d6; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 10; max-width: 80vw; text-align: center; }
.footer { margin-top: auto; padding-top: 24px; font-size: 11px; color: #4b6a8a; }

/* Отсчёт перед стартом матча: крупная цифра поверх арены, кликов не перехватывает. */
#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
  font-size: clamp(64px, 18vmin, 160px);
  font-weight: 800;
  color: #ffe066;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  animation: cdPulse 1s ease-out infinite;
}
@keyframes cdPulse {
  0% { transform: scale(1.25); opacity: 0.2; }
  35% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
