@font-face {
  font-family: 'Rubik';
  font-weight: 800;
  font-display: swap;
  src: url('../assets/fonts/rubik-cyrillic-800-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Rubik';
  font-weight: 800;
  font-display: swap;
  src: url('../assets/fonts/rubik-latin-800-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191-2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;
  --panel: rgba(28, 20, 44, 0.86);
  --panel-glass: rgba(28, 20, 44, 0.74);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #fff6ff;
  --muted: #cbbfe0;
  --accent: #ffcf3f;
  --accent-dark: #c98a00;
  --danger: #ff5050;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #b9a6f2;
  color: var(--text);
  font-family: 'Rubik', system-ui, sans-serif;
  font-weight: 800;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

canvas#game { position: fixed; inset: 0; display: block; cursor: crosshair; }

/* Заставка меню и загрузки: сгенерированный арт, медленно «дышит». */
#splash {
  position: fixed;
  inset: -3%;
  background: #1b0f2e url('../assets/img/splash-wide.jpg') center / cover no-repeat;
  animation: splash-drift 28s ease-in-out infinite alternate;
}
#splash-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1.2s ease;
}
#splash-video.ready { opacity: 1; }
#splash.live { animation: none; }
#splash::after {
  content: '';
  position: absolute;
  z-index: 1;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(20, 8, 40, 0.15) 0%, rgba(20, 8, 40, 0.55) 70%, rgba(10, 4, 20, 0.85) 100%);
}
@media (orientation: portrait) {
  #splash { background-image: url('../assets/img/splash-tall.jpg'); }
}
@keyframes splash-drift {
  from { transform: scale(1) translate(0, 0); }
  to { transform: scale(1.06) translate(-1%, -1%); }
}
@media (prefers-reduced-motion: reduce) { #splash { animation: none; } }
body.playing #splash { display: none; }
.screen:not(#pause):not(#gameover):not(#generating) { background: transparent; }

.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* --- Экраны ---------------------------------------------------------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  padding: 16px;
  background: rgba(30, 16, 60, 0.35);
  z-index: 20;
  overflow-y: auto;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 20px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  max-width: 100%;
  margin: auto;
}
.panel.wide { width: 720px; }
.panel h2 { margin: 0 0 12px; font-size: 26px; }
.panel p { color: var(--muted); }

.logo {
  margin: 0 0 18px;
  font-size: clamp(30px, 6vw, 52px);
  line-height: 1;
  color: #ffb3c7;
  text-shadow: 0 4px 0 #8c3550, 0 8px 18px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.logo-img {
  display: block;
  width: min(420px, 82%);
  height: auto;
  margin: -6px auto 0;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
  animation: logo-in 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both, logo-bob 4s ease-in-out 0.7s infinite;
}
#loading .logo-img { width: min(460px, 86%); }
@keyframes logo-in { from { transform: scale(0.6) rotate(-4deg); opacity: 0; } }
@keyframes logo-bob { 50% { transform: translateY(-4px) rotate(-0.6deg); } }
@media (prefers-reduced-motion: reduce) { .logo-img { animation: none; } }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; text-align: left; }
.grid > section { min-width: 0; }
.grid h2 { font-size: 16px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 10px; }

.team-row, .opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}
.opt { justify-content: space-between; }
.team-toggle { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.swatch { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35); }

select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px 8px;
}
input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--accent); }

.panel button {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 16px;
}
.panel button:hover { background: rgba(255, 255, 255, 0.2); }
.panel button.big {
  font-size: 24px;
  padding: 14px;
  background: var(--accent);
  color: #3b2400;
  box-shadow: 0 5px 0 var(--accent-dark);
  margin-top: 18px;
}
.panel button.big:hover { filter: brightness(1.07); }
.panel button.big:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-dark); }

.help { margin-top: 16px; text-align: left; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; color: var(--text); }
.help ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.7; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.15);
  color: var(--text);
  text-align: center;
  font-family: inherit;
}

.progress { height: 12px; background: rgba(0, 0, 0, 0.35); border-radius: 6px; overflow: hidden; width: 260px; margin: 0 auto; }
#loading-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* --- HUD ------------------------------------------------------------- */

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud .weapon { pointer-events: auto; }

#timer {
  position: absolute;
  top: 12px;
  left: 12px;
  min-width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}
#timer.urgent { color: var(--danger); animation: pulse 0.5s infinite alternate; }
#timer.retreat { color: #7dff8a; }
@keyframes pulse { to { transform: scale(1.08); } }

#wind {
  position: absolute;
  top: 12px;
  right: 108px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 14px;
}
#wind img { width: 22px; height: 22px; }
.wind-bar { display: flex; width: 150px; height: 12px; background: rgba(0, 0, 0, 0.4); border-radius: 6px; overflow: hidden; }
.wind-bar .half { flex: 1; display: flex; }
.wind-bar .left { justify-content: flex-end; border-right: 2px solid rgba(255, 255, 255, 0.5); }
#wind-left, #wind-right { height: 100%; background: linear-gradient(90deg, #7ad7ff, #3d8bff); transition: width 0.4s; }
#wind-left { background: linear-gradient(270deg, #7ad7ff, #3d8bff); }

#hud-buttons { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; }

/* Звук и установка в углу меню: в игре звук включается кнопкой в HUD. */
#corner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 25;
  display: flex;
  gap: 8px;
}
#corner button {
  height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  font-size: 19px;
  line-height: 1;
}
#corner #btn-install, #corner #btn-update { font-size: 15px; color: var(--accent); }
#corner #btn-update { background: #3a2a10; border-color: var(--accent); }
.app-version { margin: 10px 0 0; font-size: 11px; color: var(--muted); opacity: 0.6; text-align: center; }
body.playing #corner, body.playing #install-hint { display: none; }
#install-hint {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 25;
  max-width: min(300px, calc(100vw - 24px));
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #1c142c;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  border: 2px solid var(--panel-border);
  font-size: 14px;
  line-height: 1.4;
}
#hud-buttons button {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  font-size: 18px;
}

#banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  text-shadow: 0 3px 0 #1b1220, 0 0 14px rgba(0, 0, 0, 0.5);
}
#banner b { display: block; font-size: clamp(26px, 5vw, 44px); }
#banner span { font-size: 18px; color: var(--text); }
#banner.show { animation: banner 2.2s ease-out forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -20px) scale(0.8); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  20% { transform: translate(-50%, 0) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

#toast {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 12px;
  background: var(--panel);
  font-size: 15px;
  opacity: 0;
  transition: opacity 0.25s;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

#teams {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 8px 10px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  min-width: 190px;
}
.team { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 2px 0; opacity: 0.85; }
.team.current { opacity: 1; }
.team.current .tname::before { content: '▸ '; }
.team.out { opacity: 0.35; text-decoration: line-through; }
.team small { font-size: 10px; color: var(--muted); }
.tname { width: 92px; white-space: nowrap; }
.tbar { flex: 1; height: 10px; background: rgba(0, 0, 0, 0.4); border-radius: 5px; overflow: hidden; min-width: 70px; }
.tfill { display: block; height: 100%; transition: width 0.6s; }

#bottom {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: min(calc(100vw - 460px), 920px);
}
body.touch #bottom { max-width: calc(100vw - 24px); }
body.touch #weapons { flex-wrap: nowrap; }
@media (max-width: 900px) { #bottom { max-width: calc(100vw - 24px); bottom: 70px; } }
#weapon-info {
  padding: 4px 12px;
  border-radius: 10px;
  background: var(--panel);
  font-size: 14px;
  display: flex;
  gap: 10px;
  align-items: baseline;
  white-space: nowrap;
}
#weapon-info .hint { color: var(--muted); font-size: 12px; }
#weapon-info { pointer-events: auto; }
.fuse { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); font-size: 12px; }
.fuse button {
  min-width: 28px;
  height: 26px;
  border: none;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 13px;
  touch-action: manipulation;
}
.fuse button.on { background: var(--accent); color: #3b2400; }
#weapon-toggle { display: none; }
#weapons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  padding: 5px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  overflow-x: auto;
  max-width: 100%;
}
#weapons.locked { opacity: 0.6; }
#weapons.locked .weapon { pointer-events: none; }
.weapon {
  position: relative;
  width: 40px;
  height: 40px;
  flex: none;
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  padding: 6px;
}
.weapon img { width: 100%; height: 100%; display: block; }
.weapon:hover { background: rgba(255, 255, 255, 0.18); }
.weapon.selected { border-color: var(--accent); background: rgba(255, 207, 63, 0.25); }
.weapon.empty { opacity: 0.25; }
.weapon .ammo {
  position: absolute;
  right: 2px;
  bottom: 0;
  font-size: 11px;
  color: var(--accent);
  text-shadow: 0 1px 2px #000;
}

/* --- Сенсорное управление ------------------------------------------- */

#touch { display: none; }
body.touch #touch { display: block; }
body.touch #teams { bottom: auto; top: 86px; left: 12px; min-width: 150px; padding: 6px 8px; }
body.touch #bottom { bottom: 8px; }
.pad { position: absolute; bottom: 100px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: auto; }
.pad .row { display: flex; gap: 46px; }
.left-pad { left: 14px; }
.right-pad { right: 14px; align-items: flex-end; }
.pad button {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid var(--panel-border);
  background: var(--panel);
  font-size: 20px;
  touch-action: none;
}
.pad button.down { background: rgba(255, 207, 63, 0.5); }
.pad button.small { width: 44px; height: 44px; font-size: 18px; }
.pad button.fire { width: 84px; height: 84px; background: rgba(220, 50, 50, 0.85); font-size: 15px; }

@media (max-width: 720px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .opt { flex-wrap: wrap; }
  #opt-nick { flex: 1; width: auto; }
  .panel { padding: 18px 16px; }
  #wind { right: 104px; padding: 6px 8px; }
  .wind-bar { width: 90px; }
  .weapon { width: 38px; height: 38px; padding: 5px; }
  #weapon-info .hint { display: none; }
}
@media (max-height: 520px) {
  .panel { padding: 14px 18px; }
  .logo { font-size: 30px; margin-bottom: 10px; }
  .logo-img { width: min(230px, 50%); }
  .team-row, .opt { padding: 4px 10px; margin-bottom: 4px; }
  .panel button.big { margin-top: 10px; padding: 10px; font-size: 20px; }
  .pad { bottom: 76px; }
  .pad button { width: 46px; height: 46px; }
  .pad button.fire { width: 68px; height: 68px; }
}

/* --- Онлайн ---------------------------------------------------------- */

.tabs { display: flex; gap: 6px; margin: -4px 0 16px; padding: 4px; background: rgba(0, 0, 0, 0.25); border-radius: 12px; }
.panel .tabs button { margin: 0; flex: 1; padding: 8px 10px; font-size: 15px; background: transparent; color: var(--muted); }
.panel .tabs button.active { background: rgba(255, 255, 255, 0.14); color: var(--text); }
#pane-online .big { margin: 6px 0 16px; }
#pane-local .big { margin-top: 12px; }
.panel button.inline { width: auto; margin: 0; padding: 6px 12px; font-size: 14px; background: rgba(255, 207, 63, 0.9); color: #3b2400; white-space: nowrap; }
.opt select, .opt input { min-width: 0; }
#opt-friend-mode, #opt-code { flex: 1; }
input[type='text'] {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 5px 8px;
  width: 150px;
  -webkit-user-select: text;
  user-select: text;
}
#opt-code { text-transform: uppercase; letter-spacing: 0.15em; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.4; }
.code {
  font-size: 44px;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin: 4px 0;
  -webkit-user-select: text;
  user-select: text;
  font-variant-numeric: tabular-nums;
}
#net-wait .panel { min-width: min(420px, 100%); }
#net-wait p { line-height: 1.5; }
.dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #5fe36c; box-shadow: 0 0 6px #5fe36c; vertical-align: 1px; }

.screen > .panel { background: var(--panel-glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }

/* --- Телефоны и планшеты ---------------------------------------------- */

html, body, button, canvas { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
button, select, input { touch-action: manipulation; }

/* Вырезы и закруглённые углы экрана. */
#timer { top: calc(12px + env(safe-area-inset-top, 0px)); left: calc(12px + env(safe-area-inset-left, 0px)); }
#hud-buttons { top: calc(12px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); }
#wind { top: calc(12px + env(safe-area-inset-top, 0px)); }
#teams { left: calc(12px + env(safe-area-inset-left, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
#bottom { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.left-pad { left: calc(14px + env(safe-area-inset-left, 0px)); }
.right-pad { right: calc(14px + env(safe-area-inset-right, 0px)); }
body.touch #hud-buttons { right: calc(12px + env(safe-area-inset-right, 0px)); }
body.touch #wind { right: calc(158px + env(safe-area-inset-right, 0px)); }

/* Оружие на сенсорном экране: кнопка с текущим оружием открывает сетку. */
body.touch #weapon-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  padding: 8px 14px 8px 10px;
  border-radius: 14px;
  border: 2px solid var(--panel-border);
  background: var(--panel);
  font-size: 15px;
}
body.touch #weapon-toggle img { width: 28px; height: 28px; }
body.touch #weapons {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 420px);
  max-height: 60vh;
  overflow-y: auto;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 10px;
}
body.touch #bottom.open #weapons { display: flex; }
body.touch .weapon { width: 56px; height: 56px; padding: 9px; }
body.touch .weapon .ammo { font-size: 13px; }
body.touch #weapon-info { font-size: 13px; padding: 4px 10px; }
body.touch .fuse button { min-width: 34px; height: 32px; font-size: 15px; }
body.touch #bottom { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 260px); }
.pad { bottom: calc(110px + env(safe-area-inset-bottom, 0px)); }

/* Планшеты: кнопки крупнее, места больше. */
@media (min-width: 900px) and (min-height: 600px) {
  body.touch .pad button { width: 68px; height: 68px; font-size: 24px; }
  body.touch .pad .row { gap: 60px; }
  body.touch .pad button.fire { width: 104px; height: 104px; font-size: 18px; }
  body.touch .pad button.small { width: 54px; height: 54px; }
}

/* Телефон вертикально: управление внизу, оружие по центру над ним. */
@media (orientation: portrait) and (max-width: 600px) {
  body.touch .pad { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  body.touch #bottom { bottom: calc(210px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 24px); }
  body.touch #wind { top: calc(86px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); }
  body.touch #teams { top: calc(86px + env(safe-area-inset-top, 0px)); }
}

/* Телефон горизонтально: экран низкий — кнопки ниже и компактнее. */
@media (max-height: 500px) and (orientation: landscape) {
  body.touch .pad { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); gap: 4px; }
  body.touch .pad .row { gap: 40px; }
  body.touch .pad button { width: 48px; height: 48px; font-size: 18px; }
  body.touch .pad button.small { width: 42px; height: 42px; }
  body.touch .pad button.fire { width: 74px; height: 74px; font-size: 14px; }
  body.touch #teams { top: calc(80px + env(safe-area-inset-top, 0px)); }
}

/* На узком экране панель меню во всю ширину: опускаем её под кнопку звука. */
@media (max-width: 760px) {
  #menu, #net-wait { padding-top: calc(64px + env(safe-area-inset-top, 0px)); }
}

/* Реклама за вознаграждение (только в сборке для игровых площадок). */
#hud-buttons #btn-reward { background: #3a2a10; border-color: var(--accent); animation: reward-pulse 1.6s ease-in-out infinite; }
@keyframes reward-pulse { 50% { transform: scale(1.08); } }
#btn-bonus { background: #3a2a10; color: var(--accent); border: 2px solid var(--accent); }
@media (prefers-reduced-motion: reduce) { #hud-buttons #btn-reward { animation: none; } }
