:root {
  --sky-top: #4cc3f0;
  --sky-bot: #9ee7ff;
  --sand: #f6d999;
  --accent: #ff7a59;
  --accent-2: #ffd23f;
  --ink: #123;
  --panel: rgba(255, 255, 255, 0.92);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bot));
  overflow: hidden;
  /* запрет двойного тап-зума на телефонах (прокрутка и панорама остаются) */
  touch-action: manipulation;
}

/* в игре отключаем все жесты браузера полностью */
#screen-game.active,
#screen-game.active * {
  touch-action: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* ТОТЕМЫ по бокам (декор как в оригинале) */
.totem {
  position: fixed;
  bottom: 0;
  height: 86vh;
  width: auto;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.2));
}
.totem.left { left: 0; }
.totem.right { right: 0; }
@media (max-width: 1300px) { .totem { display: none; } }

/* TOPBAR */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
}
.logo {
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.logo span { color: var(--accent-2); }
.logo small {
  font-size: 12px;
  font-weight: 700;
  opacity: 0.8;
  margin-left: 4px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.conn {
  font-size: 13px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  background: #fff;
}
.conn.offline { color: #b00; }
.conn.online { color: #0a7; }
.ping {
  font-size: 13px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  background: #fff;
  color: #0a7;
}
.ping.hidden { display: none; }
.ping.warn { color: #d98200; }
.ping.bad { color: #b00; }

/* SCREENS */
.screen {
  flex: 1;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 0;        /* позволяет flex-детям ужиматься под низкие экраны */
  overflow-y: auto;     /* меню прокручивается на маленьких устройствах */
}
.screen.active { display: flex; }

.panel {
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 36px;
  width: min(560px, 94vw);
  backdrop-filter: blur(4px);
}
.panel.center { text-align: center; }

h1 { font-size: 28px; margin-bottom: 6px; }
h2 { font-size: 24px; margin: 14px 0 6px; }
.subtitle { color: #456; margin-bottom: 18px; }

.field { display: block; margin-bottom: 18px; }
.field span { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #cfe7f2;
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus { border-color: var(--accent); }

.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  font-weight: 800;
  font-size: 16px;
  padding: 13px 22px;
  border-radius: 12px;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  box-shadow: 0 6px 0 #d85a3c;
}
.btn.primary:hover { background: #ff8c6e; }
.btn.secondary {
  background: #3a86ff;
  color: #fff;
  width: 100%;
  box-shadow: 0 6px 0 #1a5fd4;
  margin-top: 10px;
}
.btn.secondary:hover { background: #5fa0ff; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 2px solid #cfe7f2;
  margin-top: 18px;
}

.controls-help {
  margin-top: 24px;
  border-top: 1px dashed #cdd;
  padding-top: 16px;
}
.controls-help h3 { font-size: 15px; margin-bottom: 8px; }
.controls-help ul { list-style: none; display: grid; gap: 6px; }
.controls-help li { font-size: 14px; color: #345; }
.hint { margin-top: 12px; font-size: 13px; color: #678; font-style: italic; }
kbd {
  background: #fff;
  border: 1px solid #bcd;
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 7px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
}

/* SELECT (персонаж/мяч) */
.select-block { margin-bottom: 18px; }
.sel-label { display: block; font-weight: 700; font-size: 14px; margin: 10px 0 6px; }
.sel-label b { color: var(--accent); }
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.thumb-grid.ball { grid-template-columns: repeat(8, 1fr); max-width: 280px; }
.thumb {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: #eaf6fc center/82% no-repeat;
  border: 2px solid #cfe7f2;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.12s, box-shadow 0.12s;
}
.thumb:hover { transform: translateY(-2px); border-color: #9fd4ea; }
.thumb.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; background-color: #fff3ee; }

/* SPINNER */
.spinner {
  width: 54px;
  height: 54px;
  margin: 0 auto 8px;
  border: 6px solid #cfe7f2;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* GAME — полноэкранный слой, поле растягивается на весь вьюпорт */
#screen-game.active {
  position: fixed;
  inset: 0;
  z-index: 5;
  padding: 0;
  overflow: hidden;
}

#hud {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 22px;
  background: var(--panel);
  padding: 8px 26px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.score-box { display: flex; align-items: center; gap: 12px; }
.score-box.right { flex-direction: row; }
.pname { font-weight: 700; font-size: 15px; color: #345; min-width: 80px; }
.score-box.left .pname { text-align: right; }
.pscore {
  font-weight: 900;
  font-size: 30px;
  color: var(--accent);
  min-width: 30px;
  text-align: center;
}
.vs { font-weight: 900; font-size: 26px; color: #678; }

#canvas-wrap {
  position: relative;
  /* ширину выставляет fitGame() в client.js; это запасное значение до первого расчёта */
  width: min(100vw, 133.33vh);
  aspect-ratio: 1280 / 960;
  overflow: hidden;
}
#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* SEARCH BANNER (режим разминки) */
.search-banner {
  position: absolute;
  top: 84px; /* под плавающим HUD */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 30, 50, 0.62);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}
.search-banner.hidden { display: none; }
.search-banner .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
.btn-mini {
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
}
.btn-mini:hover { background: #ff8c6e; }

/* СЕНСОРНОЕ УПРАВЛЕНИЕ */
#touch-controls.hidden { display: none; }
.touch-btn {
  position: fixed;
  transform: translate(-50%, -50%);
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.55);
  color: #fff;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn.pressed { background: rgba(255, 255, 255, 0.45); }
.touch-btn .tb-label {
  display: none;
  pointer-events: none;
  font-size: 12px;
}
#touch-controls.editing .tb-label { display: block; }
#touch-controls.editing .touch-btn {
  border-style: dashed;
  border-color: var(--accent-2);
  background: rgba(255, 210, 63, 0.18);
}
#touch-controls.editing .touch-btn.sel {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 122, 89, 0.55);
}

.touch-gear {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 8;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.88);
  font-size: 22px;
  box-shadow: var(--shadow);
}
.touch-gear.hidden { display: none; }

.touch-edit-panel {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 94vw;
  background: rgba(10, 30, 50, 0.78);
  color: #fff;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
}
.touch-edit-panel.hidden { display: none; }
.btn-mini.warn { background: #d33; }
.btn-mini.warn:hover { background: #e55; }

/* OVERLAY */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 30, 50, 0.45);
  color: #fff;
  text-align: center;
}
.overlay.hidden { display: none; }
#overlay-content { display: grid; gap: 16px; justify-items: center; }
.big-count {
  font-size: 96px;
  font-weight: 900;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}
.result-title { font-size: 44px; font-weight: 900; }
.result-sub { font-size: 18px; opacity: 0.9; }
.overlay .btn.primary { width: auto; padding: 13px 30px; }
