/* УКАЗЫВАЕМ НА ЛОКАЛЬНЫЙ ФАЙЛ ШРИФТА */
@font-face {
  font-family: 'BattleCityFont'; /* Присваиваем шрифту собственное имя */
  src: url('../fonts/1.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: black;
}

body {
  display: flex;
  flex-direction: column;
}

#main {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

canvas {
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#help {
  display: none;
}

#tg-only-message {
  display: none;
  width: 100%;
  text-align: center;
  color: #ccc;
  font-family: Arial, sans-serif;
  font-size: 18px;
  align-self: center;
}

/* --- Стили сенсорного управления --- */

#touch-controls {
  display: flex;
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  z-index: 100;
  box-sizing: border-box;
}

#touch-controls.layout-swapped {
  flex-direction: row-reverse;
}

#d-pad, #action-buttons {
  pointer-events: auto;
}

#d-pad {
  display: grid;
  height: 100%;
  width: 45%;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 2px;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.3));
}

#d-pad .touch-button {
  background: linear-gradient(145deg, #5e5e5e, #3a3a3a);
  border: 1px solid #2f2f2f;
  box-shadow: inset 0 2px 1px rgba(255,255,255,0.1), inset 0 -1px 1px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
}

#touch-up { border-radius: 8px 8px 0 0; }
#touch-down { border-radius: 0 0 8px 8px; }
#touch-left { border-radius: 8px 0 0 8px; }
#touch-right { border-radius: 0 8px 8px 0; }

#d-pad .touch-button::before {
  content: '';
  width: 0;
  height: 0;
  border-style: solid;
  opacity: 0.8;
  transition: all 0.1s ease;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}
#touch-up::before { border-width: 0 10px 16px 10px; border-color: transparent transparent #cfcfcf transparent; }
#touch-down::before { border-width: 16px 10px 0 10px; border-color: #cfcfcf transparent transparent transparent; }
#touch-left::before { border-width: 10px 16px 10px 0; border-color: transparent #cfcfcf transparent transparent; }
#touch-right::before { border-width: 10px 0 10px 16px; border-color: transparent transparent transparent #cfcfcf; }

#d-pad .touch-button:active {
  transform: scale(0.95);
  background: linear-gradient(145deg, #3a3a3a, #505050);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.6);
}

#touch-a, #touch-b {
  position: relative;
  border-radius: 50%;
  box-sizing: border-box;
  box-shadow: 0 8px 10px rgba(0,0,0,0.3), inset 0 2px 1px rgba(255,255,255,0.3);
  transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
  font-family: Arial, sans-serif;
  font-weight: bold;
  font-size: 24px;
  text-shadow: 0 2px 3px rgba(0,0,0,0.4);
}

#touch-a::before, #touch-b::before {
  content: attr(data-label);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -webkit-transform: translate(-50%, -50%);
  color: white;
}

#touch-a::after, #touch-b::after {
  content: '';
  position: absolute;
  top: 5%; left: 10%;
  width: 80%; height: 40%;
  border-radius: 50%;
  background: linear-gradient(to bottom, rgba(255,255,255,0.4), rgba(255,255,255,0.0));
  transition: opacity 0.1s ease-out;
}

#touch-a {
  background: radial-gradient(circle at 50% 40%, #ff5252, #c62828);
}
#touch-b {
  background: radial-gradient(circle at 50% 40%, #ffeb3b, #f9a825);
}

#touch-a:active {
  transform: scale(0.95) translateY(2px);
  box-shadow: 0 0 25px 5px rgba(255, 82, 82, 0.7), inset 0 4px 8px rgba(0,0,0,0.6);
}
#touch-b:active {
  transform: scale(0.95) translateY(2px);
  box-shadow: 0 0 25px 5px rgba(255, 235, 59, 0.7), inset 0 4px 8px rgba(0,0,0,0.6);
}
#touch-a:active::after, #touch-b:active::after {
  opacity: 0;
}

/* --- Расположение --- */
#touch-controls {
  flex: 0 0 auto;
  height: 25vh;
  min-height: 150px;
  width: 100%;
  background-color: #282828;
  border-top: 1px solid #444;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
}
#action-buttons {
  display: flex;
  height: 100%;
  width: 45%;
  justify-content: space-around;
  align-items: center;
  gap: 15px;
}
#touch-b, #touch-a {
  width: 38%;
  height: auto;
  aspect-ratio: 1 / 1;
}

@media (orientation: landscape) {
  body { flex-direction: row; }
  #main { width: 100%; height: 100%; }
  #touch-controls {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    padding: 4vh;
    background-color: transparent;
    pointer-events: none;
    align-items: flex-end;
  }
  #d-pad { width: 28vh; height: 28vh; }
  #action-buttons { width: 32vh; height: 16vh; }
  #touch-b, #touch-a {
    width: 13vh;
    height: 13vh;
    padding-bottom: 0;
    font-size: 3vh;
  }
}

#touch-up { grid-column: 2; grid-row: 1; }
#touch-down { grid-column: 2; grid-row: 3; }
#touch-left { grid-column: 1; grid-row: 2; }
#touch-right { grid-column: 3; grid-row: 2; }