:root {
  --bg: #04070d;
  --panel: rgba(10, 21, 34, 0.78);
  --border: #1b2c42;
  --text: #dbe7f5;
  --muted: #7c8ea6;
  --good: #39ff9e;
  --bad: #ff4d5e;
  --accent: #57d4ff;
  --warn: #ff8b3d;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at 50% 0%, #0d1c2e 0%, #04070d 65%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ------------------------------- HUD ---------------------------------- */
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.hud__cell {
  flex: 1 1 78px;
  min-width: 70px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.hud__label {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud__value {
  font-size: 17px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--good);
}

#combo.is-hot {
  color: var(--accent);
  text-shadow: 0 0 12px rgba(87, 212, 255, 0.75);
}

.hud__cell--timer {
  flex: 1 1 130px;
}

.pips {
  display: flex;
  gap: 4px;
  padding-top: 2px;
}

.pip {
  width: 15px;
  height: 15px;
  border-radius: 4px;
  background: #131d2b;
  border: 1px solid #26374d;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.pip--on {
  background: var(--good);
  border-color: transparent;
  box-shadow: 0 0 10px rgba(57, 255, 158, 0.65);
}

.timebar {
  margin-top: 3px;
  height: 4px;
  border-radius: 2px;
  background: #131d2b;
  overflow: hidden;
}

.timebar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: width 0.1s linear;
}

/* ------------------------------ СЦЕНА --------------------------------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, rgba(0, 0, 0, 0) 52%, rgba(0, 0, 0, 0.6) 100%);
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* --------------------------- ИНДИКАТОРЫ ------------------------------- */
.badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: #04221a;
  background: linear-gradient(90deg, var(--good), var(--accent));
  box-shadow: 0 0 22px rgba(57, 255, 158, 0.5);
  pointer-events: none;
  animation: badgePulse 1.1s ease-in-out infinite;
}

@keyframes badgePulse {
  50% {
    transform: translateX(-50%) scale(1.05);
  }
}

.wave-flash {
  position: absolute;
  top: 48px;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%) translateY(-8px);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 139, 61, 0.55);
  background: rgba(255, 139, 61, 0.14);
  color: #ffe3a3;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.wave-flash.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------------------- ОВЕРЛЕИ --------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  overflow: auto;
  text-align: center;
  background: rgba(4, 8, 14, 0.84);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.overlay__title {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(87, 212, 255, 0.45);
}

.overlay__title--end {
  font-size: 22px;
  color: var(--good);
  text-shadow: 0 0 24px rgba(57, 255, 158, 0.35);
}

.overlay__subtitle {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.overlay__hint {
  margin: 0;
  max-width: 460px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(87, 212, 255, 0.25);
  background: rgba(87, 212, 255, 0.08);
  color: #cfe3f5;
  font-size: 13px;
  line-height: 1.45;
}

.overlay__meta {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.overlay__reason {
  margin: 0;
  font-size: 13px;
  color: var(--warn);
}

.legend {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: #a9bed4;
}

.legend li {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.dot--good {
  background: var(--good);
  box-shadow: 0 0 10px rgba(57, 255, 158, 0.7);
}

.dot--bad {
  background: var(--bad);
  box-shadow: 0 0 10px rgba(255, 77, 94, 0.7);
}

.dot--zone {
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 12px rgba(255, 47, 109, 0.8);
  opacity: 0.7;
}

.result {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 240px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
}

.result__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
}

.result__row strong {
  font-size: 18px;
  color: var(--good);
  font-variant-numeric: tabular-nums;
}

.btn {
  margin-top: 4px;
  padding: 11px 24px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), var(--good));
  color: #04221a;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.foot {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ------------------------- МОБИЛЬНАЯ АДАПТАЦИЯ ------------------------ */
@media (max-width: 520px) {
  .app {
    padding: 6px;
    gap: 6px;
  }

  .hud__value {
    font-size: 15px;
  }

  .hud__cell {
    padding: 4px 7px;
  }

  .overlay {
    gap: 9px;
    padding: 14px;
  }

  .overlay__title {
    font-size: 20px;
  }

  .overlay__hint {
    font-size: 12px;
  }

  .legend {
    font-size: 11px;
  }

  .foot {
    display: none;
  }
}

@media (max-height: 560px) {
  .overlay {
    gap: 6px;
    padding: 10px;
  }

  .overlay__title {
    font-size: 18px;
  }

  .overlay__hint {
    font-size: 11px;
    padding: 7px 10px;
  }

  .legend,
  .overlay__subtitle {
    display: none;
  }

  .foot {
    display: none;
  }
}

/* ВАЖНО: правило ниже должно идти последним и перекрывать display у оверлеев */
.hidden {
  display: none !important;
}
