* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #07111f;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  color: white;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

button {
  font-family: inherit;
}

.game-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 12%, rgba(251, 191, 36, 0.16), transparent 34%),
    radial-gradient(circle at 15% 82%, rgba(59, 130, 246, 0.18), transparent 30%),
    linear-gradient(180deg, #14213d 0%, #111827 46%, #020617 100%);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* Верхний интерфейс */
.hud {
  position: absolute;
  z-index: 5;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  pointer-events: none;
}

.hud-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 7px;
  align-items: stretch;
}

.hud-card,
.hp-card,
.status-text {
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background: rgba(15, 23, 42, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  image-rendering: pixelated;
}

.hud-card {
  min-width: 0;
  padding: 7px 8px;
  border-radius: 4px;
}

.hud-card .label {
  display: block;
  margin-bottom: 2px;
  font-size: 8px;
  line-height: 1;
  color: #cbd5e1;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.hud-card strong {
  display: block;
  font-size: 13px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gold-card strong {
  color: #facc15;
}

.mini-button {
  pointer-events: auto;
  border: 0;
  border-radius: 4px;
  padding: 0 12px;
  min-height: 43px;
  color: #f8fafc;
  font-weight: 800;
  font-size: 10px;
  letter-spacing: 1px;
  background:
    linear-gradient(180deg, rgba(30, 41, 59, 0.98), rgba(15, 23, 42, 0.98));
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.status-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 7px;
}

.status-row .status-text {
  flex: 1;
  margin: 0;
}

.log-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 14px;
  background: linear-gradient(180deg, rgba(127, 29, 29, 0.85), rgba(69, 10, 10, 0.9));
  border-color: rgba(239, 68, 68, 0.4);
}

.log-button.has-errors {
  animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.mini-button:active,
.upgrade-button:active,
.start-button:active,
.hero-switch-btn:active,
.log-btn:active {
  transform: scale(0.96);
}

.hp-card {
  margin-top: 7px;
  padding: 8px;
  border-radius: 4px;
}

.hp-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 9px;
  color: #e2e8f0;
  letter-spacing: 1px;
}

.hp-info strong {
  color: #f8fafc;
}

.hp-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 0;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.08);
}

.hp-fill {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: linear-gradient(90deg, #ef4444, #f97316, #facc15);
  transition: width 0.18s linear;
  image-rendering: pixelated;
}

.status-text {
  display: inline-block;
  max-width: 100%;
  padding: 7px 10px;
  border-radius: 0;
  font-size: 9px;
  color: #e5e7eb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.5px;
}

/* Индикатор способности */
.ability-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid rgba(250, 204, 21, 0.25);
  font-size: 9px;
  color: #fde68a;
  width: fit-content;
  pointer-events: none;
  letter-spacing: 0.5px;
}

.ability-indicator.hidden {
  display: none;
}

.ability-indicator.ready {
  border-color: rgba(34, 197, 94, 0.6);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.3);
}

/* ПАНЕЛЬ ПЕРЕКЛЮЧЕНИЯ ГЕРОЕВ */
.hero-switcher {
  position: absolute;
  z-index: 6;
  left: 10px;
  right: 10px;
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 74px);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  pointer-events: none;
}

.hero-switcher.hidden {
  display: none;
}

.hero-switch-btn {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 58px;
  padding: 6px 4px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  color: white;
  background: linear-gradient(180deg, rgba(51, 65, 85, 0.7), rgba(15, 23, 42, 0.85));
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: all 0.18s linear;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

.hero-switch-btn.active {
  border-color: var(--hero-color, #facc15);
  box-shadow:
    0 0 0 2px var(--hero-color, #facc15),
    0 10px 24px var(--hero-color-soft, rgba(250, 204, 21, 0.35));
  transform: translateY(-2px);
}

.hero-switch-btn[data-hero-index="0"] { --hero-color: #f59e0b; --hero-color-soft: rgba(245, 158, 11, 0.35); }
.hero-switch-btn[data-hero-index="1"] { --hero-color: #a855f7; --hero-color-soft: rgba(168, 85, 247, 0.35); }
.hero-switch-btn[data-hero-index="2"] { --hero-color: #3b82f6; --hero-color-soft: rgba(59, 130, 246, 0.35); }

.hero-switch-icon {
  font-size: 22px;
  line-height: 1;
  image-rendering: pixelated;
}

.hero-switch-name {
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.5px;
}

.hero-switch-cd {
  font-size: 8px;
  color: #cbd5e1;
  line-height: 1;
  min-height: 10px;
}

.hero-switch-btn.active .hero-switch-cd {
  color: #fef3c7;
}

.hero-switch-cd.ready {
  color: #86efac !important;
  font-weight: 700;
}

/* Нижняя панель прокачки */
.upgrade-panel {
  position: absolute;
  z-index: 6;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  pointer-events: none;
}

.upgrade-button {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 58px;
  padding: 8px 7px;
  border: 0;
  border-radius: 4px;
  color: white;
  background:
    linear-gradient(180deg, rgba(51, 65, 85, 0.88), rgba(15, 23, 42, 0.94));
  border: 2px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.upgrade-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 0;
  background: rgba(250, 204, 21, 0.14);
}

.upgrade-button b {
  display: block;
  font-size: 10px;
  line-height: 1.1;
  letter-spacing: 0.5px;
}

.upgrade-button small {
  display: block;
  margin-top: 2px;
  font-size: 8px;
  line-height: 1.1;
  color: #cbd5e1;
}

/* Стартовое окно */
.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 50% 35%, rgba(250, 204, 21, 0.18), transparent 32%),
    rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(430px, 100%);
  padding: 24px 20px 20px;
  text-align: center;
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(30, 41, 59, 0.95), rgba(2, 6, 23, 0.96));
  border: 2px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.logo-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  font-size: 34px;
  border-radius: 4px;
  background:
    radial-gradient(circle at 35% 25%, #fef3c7, #f59e0b 45%, #92400e 100%);
  box-shadow: 0 0 35px rgba(245, 158, 11, 0.42);
  image-rendering: pixelated;
}

.overlay-card h1 {
  margin: 0;
  font-size: clamp(18px, 5vw, 28px);
  line-height: 1.3;
  letter-spacing: 1px;
}

.overlay-card p {
  margin: 12px auto 18px;
  max-width: 320px;
  color: #cbd5e1;
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0.5px;
}

.start-button {
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 4px;
  color: #111827;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #fde68a, #f59e0b);
  box-shadow:
    0 16px 32px rgba(245, 158, 11, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* ПАНЕЛЬ ЛОГОВ */
.log-panel {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.log-panel.hidden {
  display: none;
}

.log-card {
  width: min(640px, 100%);
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  border-radius: 4px;
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border: 2px solid rgba(239, 68, 68, 0.3);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.log-header h2 {
  margin: 0;
  font-size: 14px;
  color: #fca5a5;
  letter-spacing: 1px;
}

.log-buttons {
  display: flex;
  gap: 6px;
}

.log-btn {
  border: 0;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 700;
  color: white;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.5px;
}

.copy-btn {
  background: linear-gradient(180deg, #22c55e, #15803d);
}

.clear-btn {
  background: linear-gradient(180deg, #64748b, #334155);
}

.close-btn {
  background: linear-gradient(180deg, #ef4444, #991b1b);
  padding: 8px 10px;
}

.log-content {
  flex: 1;
  min-height: 200px;
  max-height: 60dvh;
  overflow-y: auto;
  margin: 0;
  padding: 12px;
  border-radius: 0;
  background: #020617;
  border: 2px solid rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}

.log-content::-webkit-scrollbar {
  width: 8px;
}

.log-content::-webkit-scrollbar-track {
  background: #0f172a;
}

.log-content::-webkit-scrollbar-thumb {
  background: #475569;
}

.log-hint {
  margin: 10px 0 0;
  font-size: 9px;
  color: #94a3b8;
  text-align: center;
  letter-spacing: 0.5px;
}

/* Маленькие телефоны */
@media (max-width: 370px) {
  .hud-row {
    grid-template-columns: 1fr 1fr auto;
  }

  .gold-card {
    display: none;
  }

  .upgrade-button {
    gap: 4px;
    min-height: 54px;
    padding: 7px 5px;
  }

  .upgrade-icon {
    width: 24px;
    height: 24px;
    font-size: 14px;
  }

  .upgrade-button b {
    font-size: 9px;
  }

  .upgrade-button small {
    font-size: 8px;
  }

  .hero-switch-btn {
    min-height: 52px;
  }

  .hero-switch-icon {
    font-size: 20px;
  }

  .hero-switch-name {
    font-size: 8px;
  }

  .log-btn {
    padding: 6px 8px;
    font-size: 9px;
  }
}

/* Компьютер */
@media (min-width: 700px) {
  .hud {
    left: 18px;
    right: auto;
    width: 460px;
  }

  .upgrade-panel {
    left: 50%;
    right: auto;
    width: min(560px, calc(100vw - 36px));
    transform: translateX(-50%);
  }

  .hero-switcher {
    left: 50%;
    right: auto;
    width: min(420px, calc(100vw - 36px));
    transform: translateX(-50%);
  }
}