* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: #f7f1e4;
  font-family: Nunito, "Trebuchet MS", sans-serif;
  background: #07090f;
}

#app {
  min-height: 100%;
  height: 100%;
  display: grid;
  place-items: stretch;
  position: relative;
  overflow: hidden;
}

/* —— Full-bleed splash art —— */
.splash {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #1a2e22;
}

.splash-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 28%;
  display: block;
  transform: scale(1.08);
  animation: splash-ken 28s ease-in-out infinite alternate;
  filter: saturate(1.08) contrast(1.04);
}

@keyframes splash-ken {
  from { transform: scale(1.06) translate3d(0, 0, 0); }
  to { transform: scale(1.14) translate3d(-1.5%, -1%, 0); }
}

.splash-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(8, 14, 10, 0.55) 0%, rgba(8, 14, 10, 0.12) 28%, rgba(8, 14, 10, 0.2) 55%, rgba(6, 10, 8, 0.88) 100%),
    radial-gradient(ellipse 70% 55% at 50% 35%, transparent 30%, rgba(0, 0, 0, 0.35) 100%);
}

.splash::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255, 240, 180, 0.5), transparent),
    radial-gradient(1px 1px at 30% 60%, rgba(255, 220, 120, 0.35), transparent),
    radial-gradient(1px 1px at 70% 30%, rgba(200, 255, 200, 0.3), transparent),
    radial-gradient(1px 1px at 85% 70%, rgba(255, 200, 255, 0.35), transparent),
    radial-gradient(1px 1px at 50% 80%, rgba(255, 255, 255, 0.25), transparent);
  animation: sparkle-drift 18s linear infinite;
  opacity: 0.7;
}

@keyframes sparkle-drift {
  from { transform: translateY(0); }
  to { transform: translateY(-40px); }
}

#app.playing .splash,
#app.playing #menu {
  display: none !important;
}

/* —— Menu over art —— */
.splash-menu {
  position: relative;
  z-index: 10;
  min-height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(20px, 4vh, 40px) clamp(16px, 4vw, 36px) clamp(18px, 3vh, 28px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  pointer-events: auto;
  animation: menu-in 0.85s ease-out both;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.brand {
  margin: 0;
  text-align: center;
  position: relative;
  isolation: isolate;
  padding: 10px 18px 6px;
}

.brand::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: min(92vw, 520px);
  height: 70%;
  background: radial-gradient(ellipse at center, rgba(4, 6, 8, 0.75) 0%, rgba(4, 6, 8, 0.4) 55%, transparent 78%);
  z-index: -1;
  pointer-events: none;
}

.brand-title {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.06em;
  line-height: 0.92;
  font-family: Unbounded, Nunito, sans-serif;
  font-weight: 900;
  text-transform: uppercase;
}

.brand-line {
  display: block;
  paint-order: stroke fill;
  -webkit-text-stroke: 0.08em #0a0806;
}

.brand-line--baba {
  font-size: clamp(2.6rem, 10vw, 4.2rem);
  letter-spacing: 0.1em;
  color: #ffe08a;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.85);
}

.brand-line--toma {
  font-size: clamp(3.2rem, 12vw, 5.2rem);
  letter-spacing: 0.04em;
  color: #ff3b2e;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.85);
}

.subtitle {
  margin: 14px 0 0;
  color: #f4efe2;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.95), 0 0 12px rgba(0, 0, 0, 0.8);
}

.menu-actions {
  position: relative;
  z-index: 2;
  width: min(420px, 100%);
  margin: 0 auto;
  padding: 16px 16px 14px;
  background: rgba(10, 16, 12, 0.72);
  border: 1.5px solid rgba(240, 196, 90, 0.45);
  border-radius: 6px;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.player-pick {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

button {
  appearance: none;
  border: 2px solid #e8b84a;
  background: #2f5c44;
  color: #fff6d6;
  font: inherit;
  font-weight: 800;
  padding: 12px 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

button:hover {
  background: #3d7a58;
}

button:active {
  transform: translateY(1px);
}

.controls-help {
  text-align: left;
  font-size: 0.86rem;
  line-height: 1.5;
  color: #d7e0d6;
  border-top: 1px solid rgba(240, 196, 90, 0.22);
  padding: 10px 2px 0;
}

.controls-help .muted {
  margin-top: 6px;
  color: #9aab9c;
  font-size: 0.78rem;
}

.panel {
  width: min(520px, 100%);
  background: linear-gradient(180deg, rgba(36, 58, 48, 0.92) 0%, rgba(18, 32, 26, 0.96) 100%);
  border: 2px solid rgba(240, 196, 90, 0.55);
  border-radius: 4px;
  padding: 28px 24px;
  text-align: center;
}

h2 {
  margin: 0 0 10px;
  font-family: Unbounded, Nunito, sans-serif;
  color: #f0c24a;
}

#game {
  display: block;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  background: #0a0c14;
  border: none;
  border-radius: 0;
  pointer-events: none;
}

#game:not(.hidden) {
  pointer-events: auto;
}

#app.playing {
  padding: 0;
  overflow: hidden;
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  width: auto;
  margin: 0;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  font-weight: 800;
  text-shadow: 0 1px 3px #000, 0 0 8px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.35) 0%, transparent 100%);
}

#hud > * {
  pointer-events: auto;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.btn-hud {
  padding: 8px 12px;
  font-size: 0.85rem;
  background: rgba(47, 92, 68, 0.92);
}

#scores {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
}

.hud-player {
  color: var(--c, #fff);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.hud-player b {
  font-weight: 800;
}

.hud-player i {
  font-style: normal;
  opacity: 0.9;
  font-size: 0.92rem;
}

.hud-player {
  text-shadow: 0 1px 3px #000, 0 0 10px rgba(0, 0, 0, 0.7);
}

#scores {
  font-size: 1.25rem;
  line-height: 1;
}

.hearts-full {
  color: #ff3b4a;
  letter-spacing: 1px;
}

.heart-empty {
  color: rgba(255, 255, 255, 0.22);
  letter-spacing: 1px;
}

.hud-boss {
  color: #ffb0c8;
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: min(92vw, 720px);
}

.hud-boss-hp {
  font-size: 0.62rem;
  letter-spacing: 0;
  line-height: 1.15;
  max-width: min(70vw, 560px);
  word-break: break-all;
}

.overlay-panel {
  position: fixed;
  z-index: 5;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: none;
}

#overlay,
#pause {
  z-index: 5;
}

.pause-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .splash-art {
    object-position: 48% 22%;
  }

  .menu-actions {
    width: 100%;
  }
}

@media (min-width: 900px) {
  .splash-art {
    object-position: 50% 22%;
  }

  .splash-menu {
    justify-content: space-between;
  }

  .menu-actions {
    margin-left: 0;
    margin-right: auto;
  }
}

.btn-online {
  position: relative;
  z-index: 3;
  width: 100%;
  margin-bottom: 12px;
  background: linear-gradient(180deg, #4a3080 0%, #2a1850 100%);
  border-color: #b080ff;
  box-shadow: 0 0 20px rgba(176, 128, 255, 0.25);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.btn-online:hover {
  background: linear-gradient(180deg, #5a40a0 0%, #3a2870 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 24px rgba(176, 128, 255, 0.4);
}

.btn-online:active {
  transform: translateY(0);
}

.btn-start {
  background: linear-gradient(180deg, #34b85a 0%, #1a8040 100%);
  border-color: #7ef0a0;
  font-size: 1.2rem;
  padding: 16px 20px;
  font-weight: 900;
  box-shadow: 0 0 24px rgba(80, 220, 120, 0.35);
  animation: start-glow 2s ease-in-out infinite;
}

@keyframes start-glow {
  0%, 100% { box-shadow: 0 0 18px rgba(80, 220, 120, 0.3); }
  50% { box-shadow: 0 0 32px rgba(120, 255, 160, 0.55); }
}

.btn-start.hidden {
  display: none;
}

.btn-start:not(:disabled):hover {
  background: linear-gradient(180deg, #42cc6a 0%, #229650 100%);
}

.btn-start:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: linear-gradient(180deg, #2a5a3a 0%, #1a4030 100%);
  border-color: #4a8060;
}

#lobby,
#online-browse,
#hero-pick {
  z-index: 20;
  max-width: min(480px, 94vw);
  pointer-events: auto;
}

#lobby .lobby-actions button,
#hero-pick button,
#online-browse button {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

.lobby-subtitle {
  margin: 16px 0 8px;
  font-size: 0.95rem;
  color: #f0c24a;
  text-align: left;
}

.online-active-list {
  display: grid;
  gap: 8px;
  max-height: min(36vh, 240px);
  overflow-y: auto;
  margin-bottom: 12px;
  text-align: left;
}

.lobby-game-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  text-align: left;
  padding: 12px 14px;
  width: 100%;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(176, 128, 255, 0.45);
  color: inherit;
  font: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.lobby-game-row:hover {
  background: rgba(60, 40, 90, 0.45);
  border-color: rgba(200, 160, 255, 0.7);
  transform: translateX(3px);
}

.lobby-game-host {
  font-weight: 800;
}

.lobby-game-meta {
  grid-column: 1;
  font-size: 0.82rem;
  color: #b8c8b8;
}

.lobby-game-join {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  font-size: 0.85rem;
  color: #c8a0ff;
}

.lobby-empty {
  margin: 0 0 12px;
  text-align: center;
}

.lobby-code-details {
  text-align: left;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.lobby-code-details summary {
  cursor: pointer;
  color: #d7e0d6;
  margin-bottom: 8px;
}

.lobby-back {
  width: 100%;
  background: rgba(40, 40, 50, 0.8);
}

.hero-pick-grid {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.hero-pick-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 12px 14px;
  transition: transform 0.12s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.hero-pick-btn:not(:disabled):not(.taken):hover {
  transform: scale(1.02);
  box-shadow: 0 0 16px rgba(176, 128, 255, 0.35);
  border-color: #c8a0ff;
}

.hero-pick-icon {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hero-pick-label {
  font-weight: 800;
  font-size: 1.05rem;
}

.hero-pick-btn.selected {
  background: #4a3080;
  border-color: #d0a0ff;
  box-shadow: 0 0 0 2px rgba(200, 160, 255, 0.35);
}

.hero-pick-btn.taken,
.hero-pick-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}


.lobby-status {
  font-size: 1.05rem;
  margin: 0 0 8px;
  color: #ffe8a0;
}

.lobby-room {
  font-family: Unbounded, Nunito, sans-serif;
  font-size: 1.1rem;
  margin: 0 0 12px;
  word-break: break-all;
}

.lobby-slots {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.lobby-slot {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 4px;
  border: 1px solid rgba(240, 196, 90, 0.25);
  background: rgba(0, 0, 0, 0.25);
}

.lobby-slot-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.lobby-slot-icon--dim {
  opacity: 0.35;
}

.lobby-slot--filled {
  border-color: rgba(120, 255, 160, 0.45);
  background: rgba(40, 80, 50, 0.35);
}

.lobby-slot--empty {
  opacity: 0.65;
}

.lobby-slot-num {
  font-weight: 900;
  color: #f0c24a;
}

.lobby-slot-hero {
  font-weight: 800;
}

.lobby-slot-name,
.lobby-slot-wait {
  grid-column: 2 / 4;
  font-size: 0.85rem;
  color: #b8c8b8;
}

.lobby-slot-ok {
  color: #6f8;
  font-weight: 900;
}

.lobby-actions {
  display: grid;
  gap: 8px;
}

.lobby-label {
  display: block;
  text-align: left;
  margin-bottom: 10px;
  font-weight: 700;
}

.lobby-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 2px solid rgba(240, 196, 90, 0.45);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff6d6;
  font: inherit;
}

.lobby-hint {
  margin: 12px 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
}

/* —— Touch controls (multi-touch) —— */
.touch-controls {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-controls.is-active .touch-zone {
  pointer-events: auto;
}

.touch-zone {
  position: absolute;
  pointer-events: none;
  touch-action: none;
  -webkit-touch-callout: none;
}

.touch-zone--move {
  left: 0;
  bottom: 0;
  width: min(52vw, 260px);
  height: min(52vw, 260px);
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(8px, env(safe-area-inset-left));
}

.touch-zone--actions {
  right: 0;
  bottom: 0;
  display: flex;
  gap: 22px;
  padding: 16px 14px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-right: max(10px, env(safe-area-inset-right));
  align-items: flex-end;
  touch-action: none;
  pointer-events: none; /* клики только по кнопкам, не по пустоте между ними */
}

.touch-zone--actions .touch-btn {
  pointer-events: auto;
  position: relative;
  touch-action: none;
}

.touch-zone--actions .touch-btn::before {
  content: "";
  position: absolute;
  inset: -22px;
  border-radius: 50%;
}

@media (orientation: landscape) and (max-height: 500px) {
  .touch-zone--move {
    width: min(44vh, 190px);
    height: min(44vh, 190px);
    padding: 6px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .touch-zone--actions {
    gap: 14px;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .touch-btn {
    width: clamp(56px, 14vh, 72px);
    height: clamp(56px, 14vh, 72px);
  }
}

.touch-joy-base {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.35);
  touch-action: none;
}

.touch-joy-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44%;
  height: 44%;
  margin: 0;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 240, 200, 0.35);
  border: 2px solid rgba(255, 220, 140, 0.55);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.touch-btn {
  width: clamp(64px, 16vw, 84px);
  height: clamp(64px, 16vw, 84px);
  border-radius: 50%;
  padding: 0;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  line-height: 1;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.08s ease;
}

.touch-btn--jump {
  background: rgba(80, 180, 120, 0.35);
  border-color: rgba(160, 255, 200, 0.45);
}

.touch-btn--fire {
  background: rgba(200, 80, 40, 0.4);
  border-color: rgba(255, 160, 80, 0.55);
  font-size: clamp(1rem, 3.5vw, 1.35rem);
}

.touch-btn.is-pressed,
.touch-btn:active {
  transform: scale(0.92);
  filter: brightness(1.25);
}

