:root {
  --bg: #08080f;
  --panel: rgba(7, 10, 24, 0.78);
  --panel-strong: rgba(8, 9, 22, 0.96);
  --cyan: #00f5ff;
  --magenta: #ff006e;
  --yellow: #ffe600;
  --green: #00ff88;
  --ink: #f7fbff;
  --muted: #b8c2d9;
  --line: rgba(255, 255, 255, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
}

body::after {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.032) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 48%, transparent 40%, rgba(0, 0, 0, 0.34));
  mix-blend-mode: overlay;
  opacity: 0.28;
  content: "";
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 18%, rgba(0, 245, 255, 0.22), transparent 30%),
    radial-gradient(circle at 80% 72%, rgba(255, 0, 110, 0.16), transparent 32%),
    linear-gradient(145deg, #050713 0%, #101020 48%, #06141a 100%);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.back-link {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid rgba(0, 245, 255, 0.36);
  border-radius: 8px;
  background: rgba(6, 7, 18, 0.78);
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  backdrop-filter: blur(14px);
  box-shadow: 0 0 28px rgba(0, 245, 255, 0.18);
}

.hud {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, auto));
  gap: 8px;
}

.hud-chip,
.chain-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.3);
}

.hud-chip {
  min-width: 72px;
  padding: 9px 10px;
  text-align: center;
}

.hud-chip span,
.chain-label span,
.best-row span,
.score-label,
.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
}

.hud-chip strong,
.chain-label strong,
.best-row strong,
.score-value,
.stat-value {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-family: Orbitron, sans-serif;
}

.hud-chip strong {
  font-size: clamp(0.9rem, 2vw, 1.15rem);
}

.chain-panel {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 12;
  width: min(292px, calc(100vw - 150px));
  padding: 10px;
}

.chain-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chain-label strong {
  color: var(--yellow);
  font-size: 0.78rem;
}

.chain-track {
  height: 9px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.chain-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--magenta), var(--yellow), var(--green));
  box-shadow: 0 0 18px rgba(255, 230, 0, 0.4);
  transition: width 80ms linear;
}

.action-button {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 13;
  width: 112px;
  height: 54px;
  border: 1px solid rgba(255, 230, 0, 0.58);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--yellow), var(--cyan), var(--green));
  color: #040710;
  font: 800 0.74rem Orbitron, sans-serif;
  box-shadow: 0 0 30px rgba(0, 245, 255, 0.28);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.action-button.active {
  filter: brightness(1.18);
  transform: translateY(1px) scale(0.98);
}

.status-line {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 11;
  width: min(520px, calc(100vw - 350px));
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.76rem, 2vw, 0.95rem);
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.72);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 76px 18px 24px;
  background: rgba(3, 4, 12, 0.43);
  backdrop-filter: blur(7px);
}

.panel {
  width: min(560px, 100%);
  padding: clamp(22px, 5vw, 34px);
  border: 1px solid rgba(0, 245, 255, 0.24);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel-strong), rgba(8, 8, 20, 0.92));
  box-shadow: 0 0 34px rgba(0, 245, 255, 0.18), 0 30px 90px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.title,
.over-title {
  margin: 0;
  color: var(--cyan);
  font-family: Orbitron, sans-serif;
  font-size: clamp(2.25rem, 9vw, 4.1rem);
  font-weight: 800;
  line-height: 0.95;
  text-shadow: 0 0 22px rgba(0, 245, 255, 0.42), 0 0 42px rgba(255, 0, 110, 0.22);
}

.over-title {
  color: var(--magenta);
  font-size: clamp(2rem, 8vw, 3.4rem);
  text-shadow: 0 0 22px rgba(255, 0, 110, 0.45);
}

.subtitle,
.over-game-name,
.hint,
.share-feedback {
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.subtitle,
.over-game-name {
  color: var(--yellow);
  font-size: 0.86rem;
}

.best-row,
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 22px 0;
}

.stats {
  grid-template-columns: repeat(3, 1fr);
}

.best-row > div,
.stats > div,
.score-block {
  min-width: 0;
  padding: 13px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.best-row strong,
.stat-value {
  font-size: clamp(1.2rem, 5vw, 1.95rem);
}

.score-block {
  margin-top: 20px;
}

.score-value {
  color: var(--green);
  font-size: clamp(2.2rem, 11vw, 4rem);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: #02040a;
  font: 800 0.82rem Orbitron, sans-serif;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--yellow), var(--cyan));
  box-shadow: 0 0 30px rgba(0, 245, 255, 0.28);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--magenta), #7b4dff);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .hud {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    top: max(58px, env(safe-area-inset-top));
    grid-template-columns: repeat(4, 1fr);
  }

  .hud-chip {
    min-width: 0;
    padding: 8px 5px;
  }

  .hud-chip span {
    font-size: 0.48rem;
  }

  .hud-chip strong {
    font-size: 0.88rem;
  }

  .chain-panel {
    width: calc(100vw - 150px);
  }

  .status-line {
    top: max(110px, calc(env(safe-area-inset-top) + 112px));
    bottom: auto;
    width: calc(100vw - 28px);
    font-size: 0.78rem;
  }

  .back-link {
    font-size: 0.76rem;
  }
}

@media (max-width: 430px) {
  .button-row {
    grid-template-columns: 1fr;
  }

  .best-row,
  .stats {
    gap: 8px;
  }

  .panel {
    padding: 22px 14px;
  }

  .action-button {
    width: 104px;
  }
}
