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

html {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: #0a0a1a;
  touch-action: manipulation;
}

body {
  background: #0a0a1a;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Exo 2', 'Segoe UI', sans-serif;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body.mobile-game,
body.telegram-miniapp,
body.base-miniapp {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  padding:
    max(env(safe-area-inset-top), var(--safe-top, 0px))
    max(env(safe-area-inset-right), 0px)
    max(env(safe-area-inset-bottom), var(--safe-bottom, 0px))
    max(env(safe-area-inset-left), 0px);
}

body.base-miniapp {
  padding: 0;
}

#app {
  position: relative;
  box-shadow:
    0 0 60px rgba(0, 255, 136, 0.15),
    0 0 120px rgba(255, 50, 100, 0.1);
  border: 3px solid #1a1a3a;
  border-radius: 4px;
  flex-shrink: 0;
}

body.mobile-game #app,
body.telegram-miniapp #app,
body.base-miniapp #app {
  width: 100%;
  height: 100%;
  max-width: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0d1b2a;
  cursor: pointer;
  touch-action: none;
}

body.mobile-game #game,
body.telegram-miniapp #game,
body.base-miniapp #game {
  max-width: none;
  height: auto;
}

#ui-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#name-overlay {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translate(-50%, -50%);
  width: min(420px, 88%);
  padding: 18px 20px;
  background: rgba(0, 0, 0, 0.82);
  border: 2px solid #00ff88;
  border-radius: 4px;
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.2);
  text-align: center;
  z-index: 5;
  pointer-events: auto;
}

#name-overlay label {
  display: block;
  color: #00ff88;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 12px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

#name-overlay input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #1a1a3a;
  border-radius: 4px;
  background: #111;
  color: #fff;
  font: 800 1.25rem 'Exo 2', 'Segoe UI', sans-serif;
  text-align: center;
  outline: none;
  touch-action: auto;
  -webkit-user-select: text;
  user-select: text;
}

#name-overlay input:focus {
  border-color: #ffd700;
}

#name-overlay p {
  margin-top: 12px;
  color: #ccc;
  font-size: 0.85rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

@media (orientation: portrait) and (max-width: 900px) {
  body.mobile-game #app,
  body.telegram-miniapp #app,
  body.base-miniapp #app {
    width: 100%;
    height: 100%;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  body.mobile-game,
  body.telegram-miniapp,
  body.base-miniapp {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 12px;
  z-index: 8;
  pointer-events: none;
}

#touch-controls button {
  pointer-events: auto;
  min-width: 64px;
  height: 54px;
  padding: 0 14px;
  border: 2px solid #00ff88;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #00ff88;
  font: 800 1.15rem 'Exo 2', 'Segoe UI', sans-serif;
  box-shadow: 0 0 18px rgba(0, 255, 136, 0.18);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#touch-controls button:active {
  transform: scale(0.95);
  background: rgba(0, 255, 136, 0.18);
}

#touch-action {
  min-width: 72px;
  color: #ffd700;
  border-color: #ffd700;
}

#touch-controls.select-mode {
  bottom: calc(118px + env(safe-area-inset-bottom, 0px));
}

#base-char-picker {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  z-index: 12;
  padding: 8px 0 6px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88), rgba(0, 0, 0, 0.45));
  pointer-events: auto;
}

.char-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 6px 18vw 10px;
  touch-action: pan-x;
}

.char-scroll::-webkit-scrollbar {
  display: none;
}

.char-card {
  flex: 0 0 auto;
  width: 88px;
  scroll-snap-align: center;
  border: 2px solid #444;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.65);
  padding: 8px 6px 10px;
  color: #fff;
  text-align: center;
  touch-action: manipulation;
}

.char-card.active {
  border-color: #00ff88;
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.35);
  transform: scale(1.06);
}

.char-card img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto 6px;
}

.char-card-name {
  display: block;
  font: 700 0.62rem 'Exo 2', 'Segoe UI', sans-serif;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

#touch-zone-left,
#touch-zone-right {
  position: fixed;
  top: 18%;
  bottom: 32%;
  width: 18vw;
  max-width: 90px;
  z-index: 11;
  pointer-events: auto;
}

#touch-zone-left {
  left: 0;
  background: linear-gradient(to right, rgba(0, 255, 136, 0.12), transparent);
}

#touch-zone-right {
  right: 0;
  background: linear-gradient(to left, rgba(0, 255, 136, 0.12), transparent);
}

#touch-zone-left::after,
#touch-zone-right::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font: 800 2rem 'Exo 2', sans-serif;
  color: rgba(0, 255, 136, 0.75);
  text-shadow: 0 0 12px rgba(0, 255, 136, 0.4);
}

#touch-zone-left::after {
  content: '◀';
  left: 12px;
}

#touch-zone-right::after {
  content: '▶';
  right: 12px;
}

#base-fullscreen-btn {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  z-index: 15;
  width: 42px;
  height: 42px;
  border: 2px solid #00ff88;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: #00ff88;
  font-size: 1.2rem;
  touch-action: manipulation;
}