@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Unbounded:wght@500;700&display=swap");

html {
  -webkit-text-size-adjust: 100%;
}

:root {
  --bg: #0e1118;
  --panel: #1a2030;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #6ee7b7;
  --mark: #60a5fa;
  --vova: #fbbf24;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(ellipse 120% 80% at 50% 0%, #1e293b 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
}

#wrap {
  max-width: 100%;
  width: min(100%, 960px);
}

.hud {
  margin-bottom: 0.75rem;
}

.hud-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.label {
  width: 7.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.bar {
  flex: 1;
  max-width: 280px;
  height: 8px;
  background: #2a3144;
  border-radius: 4px;
  overflow: hidden;
}

.bar .fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transition: transform 0.15s ease-out;
}

.bar .fill.mark {
  background: linear-gradient(90deg, #3b82f6, var(--mark));
}

.bar .fill.vova {
  background: linear-gradient(90deg, #d97706, var(--vova));
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.scene-wrap {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.canvas-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 960 / 540;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 24px 48px rgba(0, 0, 0, 0.45);
  background: #111827;
}

.canvas-shell #game {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

/* Сенсор: брусчатка — только во время боя на телефоне / тач-экране */
.touch-controls {
  display: none;
  margin-top: 0.65rem;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

@media (max-width: 900px) {
  body.game-active .touch-controls:not([hidden]) {
    display: block;
  }
}

@media (pointer: coarse) {
  body.game-active .touch-controls:not([hidden]) {
    display: block;
  }
}

@media (min-width: 901px) and (pointer: fine) {
  body.game-active .touch-controls {
    display: none !important;
  }
}

.touch-controls-inner {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr 1.2fr;
  gap: 6px;
  padding: 10px 8px 12px;
  border-radius: 10px;
  background-color: #3d3530;
  background-image:
    linear-gradient(335deg, rgba(0, 0, 0, 0.14) 23px, transparent 23px),
    linear-gradient(155deg, rgba(0, 0, 0, 0.12) 23px, transparent 23px),
    linear-gradient(335deg, rgba(255, 255, 255, 0.04) 23px, transparent 23px),
    linear-gradient(155deg, rgba(255, 255, 255, 0.03) 23px, transparent 23px),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 11px,
      rgba(0, 0, 0, 0.18) 11px,
      rgba(0, 0, 0, 0.18) 12px
    );
  background-size: 58px 58px;
  background-position:
    0 0,
    29px 0,
    29px -29px,
    0 29px,
    0 0;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.06),
    inset 0 -3px 8px rgba(0, 0, 0, 0.35),
    0 4px 14px rgba(0, 0, 0, 0.4);
}

.touch-brick {
  position: relative;
  min-height: 48px;
  padding: 0.4rem 0.35rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: #e7e5e4;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  background: linear-gradient(180deg, #6b5b52 0%, #4a3f3a 48%, #3a322e 52%, #2d2825 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    0 2px 0 #1a1614,
    0 4px 8px rgba(0, 0, 0, 0.35);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.touch-brick:active,
.touch-brick.touch-brick--pressed {
  transform: translateY(2px);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.45),
    0 1px 0 #1a1614;
}

.touch-brick--move .touch-brick-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.touch-brick--attack {
  color: #fef3c7;
  background: linear-gradient(180deg, #7c6a5c 0%, #5c4d44 50%, #453c37 100%);
}

.touch-brick--block {
  color: #d1fae5;
  background: linear-gradient(180deg, #5a6358 0%, #3d453c 50%, #2f352e 100%);
}

.touch-brick-label {
  display: block;
  letter-spacing: 0.04em;
}

@media (max-width: 400px) {
  .touch-controls-inner {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .touch-brick--move {
    min-height: 52px;
  }
}

/* Заставка */
.splash-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.5s ease;
  overflow: hidden;
  background:
    radial-gradient(ellipse 90% 75% at 50% 38%, rgba(30, 27, 48, 0.88) 0%, rgba(8, 10, 18, 0.94) 55%, rgba(4, 6, 12, 0.97) 100%),
    linear-gradient(165deg, rgba(251, 191, 36, 0.09) 0%, transparent 42%);
}

.splash-overlay.visible {
  opacity: 1;
}

.splash-overlay[hidden] {
  display: none !important;
}

.splash-inner {
  text-align: center;
  padding: 1.25rem 1.5rem 1.75rem;
  max-width: 540px;
  animation: splashReveal 0.85s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes splashReveal {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.splash-eyebrow {
  margin: 0 0 0.65rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.95;
}

.splash-title {
  margin: 0 0 0.5rem;
  font-family: "Unbounded", sans-serif;
  font-weight: 700;
  font-size: clamp(1.45rem, 4.6vw, 2.4rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
}

.splash-title .splash-accent {
  background: linear-gradient(120deg, #fde68a 0%, #fbbf24 35%, #f59e0b 70%, #34d399 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 2px 14px rgba(251, 191, 36, 0.35));
}

.splash-subtitle {
  margin: 0 0 1.35rem;
  font-size: 0.88rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.splash-btn {
  margin-top: 0.25rem;
  min-width: 9rem;
}

.splash-hint {
  margin: 1rem 0 0;
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  opacity: 0.75;
}

body.splash-active .hud {
  opacity: 0.18;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

body.dialogue-active .hud {
  opacity: 0.22;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

/* Диалог поверх той же сцены, что и бой: реплики как речь героев */
.scene-dialogue {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  background: linear-gradient(
    180deg,
    rgba(8, 11, 20, 0.5) 0%,
    rgba(8, 11, 20, 0.22) 38%,
    rgba(8, 11, 20, 0.05) 72%,
    transparent 100%
  );
}

.scene-dialogue.visible {
  opacity: 1;
  pointer-events: auto;
}

.scene-tagline {
  position: absolute;
  top: 0.55rem;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-family: "Unbounded", sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  pointer-events: none;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}

.speech-anchor {
  position: absolute;
  width: min(42%, 380px);
  pointer-events: none;
}

/* Пузыри в верхней зоне сцены — нижний край (включая хвост) выше голов героев (~63% от верха канваса) */
.speech-anchor--mark {
  left: 2.5%;
  bottom: 52%;
}

.speech-anchor--vova {
  right: 2.5%;
  bottom: 52%;
}

.speech-bubble {
  padding: 0.65rem 0.85rem 0.75rem;
  min-height: 4.25rem;
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--text);
  background: rgba(26, 32, 48, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  position: relative;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease,
    border-color 0.3s ease;
}

.speech-bubble:not(.speaking) {
  opacity: 0.42;
  transform: scale(0.98);
}

.speech-bubble.speaking {
  opacity: 1;
  transform: scale(1);
}

.speech-bubble--mark {
  border-color: rgba(96, 165, 250, 0.45);
}

.speech-bubble--mark.speaking {
  box-shadow:
    0 10px 32px rgba(0, 0, 0, 0.45),
    0 0 24px rgba(96, 165, 250, 0.2);
}

.speech-bubble--vova {
  border-color: rgba(251, 191, 36, 0.4);
}

.speech-bubble--vova.speaking {
  box-shadow:
    0 10px 32px rgba(0, 0, 0, 0.45),
    0 0 24px rgba(251, 191, 36, 0.18);
}

.speech-who {
  display: block;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.35rem;
}

.speech-bubble--mark .speech-who {
  color: var(--mark);
}

.speech-bubble--vova .speech-who {
  color: var(--vova);
}

.speech-line {
  margin: 0;
  min-height: 2.6em;
}

.speech-bubble:not(.speaking) .speech-line:empty::after {
  content: "…";
  color: var(--muted);
  opacity: 0.45;
}

.scene-dialogue-actions {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: auto;
}

/* Короткий хвост вниз — не доходит до персонажей */
.speech-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(26, 32, 48, 0.92);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2));
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 16, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.dialogue-box {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 1.75rem 2rem;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.dialogue-box.small {
  max-width: 400px;
  text-align: center;
}

.btn {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  padding: 0.65rem 1.75rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(135deg, #34d399, #059669);
  color: #052e1f;
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

#gameover h2 {
  font-family: "Unbounded", sans-serif;
  margin-top: 0;
}

#go-text {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .hud-row {
    flex-wrap: wrap;
  }

  .bar {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .label {
    width: auto;
    min-width: 5rem;
  }

  .hint {
    font-size: 0.62rem;
    line-height: 1.45;
  }

  .speech-anchor {
    width: 46%;
  }

  .speech-anchor--mark {
    left: 1%;
    bottom: 50%;
  }

  .speech-anchor--vova {
    right: 1%;
    bottom: 50%;
  }

  .speech-bubble {
    font-size: 0.78rem;
    min-height: 3.5rem;
  }
}
