* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, #1e1b4b 0%, #070b18 70%);
  color: #f1f5f9;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 1rem;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.game-shell {
  width: min(820px, 100%);
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 14px;
  padding: 0.9rem 1.1rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  padding-bottom: 0.7rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 0.9rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
  font-variant-numeric: tabular-nums;
}

.stat {
  color: #94a3b8;
}

.stat strong {
  color: #f8fafc;
  margin-left: 0.2rem;
}

.lives {
  color: #fb7185;
  letter-spacing: 2px;
}

.controls {
  display: flex;
  gap: 0.5rem;
}

.btn {
  background: #6366f1;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn:hover {
  background: #4f46e5;
}

.btn:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: #334155;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-big {
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
}

.btn-touch-only {
  display: none;
}

@media (pointer: coarse) {
  .btn-touch-only {
    display: inline-block;
  }
}

.stage {
  position: relative;
}

canvas {
  width: 100%;
  display: block;
  background: #070b18;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  cursor: pointer;
  touch-action: none;
}

.powerups {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  pointer-events: none;
}

.powerup {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 118px;
  padding: 0.22rem 0.5rem;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--pu-color);
  box-shadow: 0 0 10px color-mix(in srgb, var(--pu-color) 45%, transparent);
  font-size: 0.74rem;
}

.powerup-icon {
  display: grid;
  place-items: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: var(--pu-color);
  color: #0b1120;
  font-weight: 800;
  font-size: 0.7rem;
}

.powerup-body {
  flex: 1;
}

.powerup-label {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
}

.powerup-bar {
  height: 4px;
  margin-top: 3px;
  border-radius: 2px;
  background: rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.powerup-fill {
  height: 100%;
  width: 100%;
  background: var(--pu-color);
}

.toasts {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  pointer-events: none;
  z-index: 4;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: min(300px, 80vw);
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  background: rgba(30, 27, 75, 0.94);
  border: 1px solid #fbbf24;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.35);
  animation: toast-life 3.2s ease forwards;
}

.toast-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: #fbbf24;
  color: #1e1b4b;
  font-weight: 800;
}

.toast-title {
  font-weight: 700;
  font-size: 0.82rem;
  color: #fde68a;
}

.toast-desc {
  font-size: 0.74rem;
  color: #cbd5e1;
}

@keyframes toast-life {
  0% {
    opacity: 0;
    transform: translateX(24px);
  }
  10%,
  85% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(24px);
  }
}

.menu {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 0.6rem;
  padding: 1rem;
  overflow-y: auto;
  text-align: center;
  background: rgba(7, 11, 24, 0.9);
  border-radius: 10px;
}

.menu > * {
  flex-shrink: 0;
}

@media (max-height: 520px) {
  body {
    padding: 0.3rem;
  }
}

.menu-title {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  background: linear-gradient(90deg, #fbbf24, #f472b6, #818cf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.menu-sub,
.diff-info,
.menu-best {
  color: #94a3b8;
  font-size: 0.88rem;
}

.menu-best strong {
  color: #fde68a;
}

.difficulty {
  display: inline-flex;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.diff-btn {
  padding: 0.5rem 1.1rem;
  background: transparent;
  color: #cbd5e1;
  border: none;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.diff-btn + .diff-btn {
  border-left: 1px solid rgba(148, 163, 184, 0.35);
}

.diff-btn.active {
  background: #6366f1;
  color: #ffffff;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

.howto {
  width: min(520px, 100%);
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.7);
  font-size: 0.82rem;
  line-height: 1.5;
}

.howto h2,
.badges-wrap h2 {
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: #e2e8f0;
}

.howto ul {
  padding-left: 1.1rem;
}

.howto kbd {
  padding: 0 0.3rem;
  border-radius: 4px;
  background: #334155;
  font-size: 0.75rem;
}

.c-star { color: #fbbf24; }
.c-meteor { color: #f87171; }
.c-shield { color: #34d399; }
.c-speed { color: #38bdf8; }
.c-double { color: #f472b6; }
.c-slow { color: #a78bfa; }

.badges-wrap {
  width: min(520px, 100%);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #64748b;
  font-size: 0.74rem;
  opacity: 0.7;
}

.badge i {
  font-style: normal;
  font-weight: 800;
}

.badge small {
  display: none;
}

.badge.unlocked {
  opacity: 1;
  color: #fde68a;
  border-color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
}

.rotate-hint {
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: 0.5rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: rgba(30, 27, 75, 0.96);
  border: 1px solid #818cf8;
  font-size: 0.8rem;
}

.rotate-actions {
  display: flex;
  gap: 0.4rem;
}

.tips {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: 0.7rem;
  font-size: 0.78rem;
  color: #94a3b8;
}

@media (max-width: 640px) {
  body {
    padding: 0.4rem;
  }

  .game-shell {
    padding: 0.6rem 0.65rem;
    border-radius: 10px;
  }

  .hud {
    font-size: 0.82rem;
  }

  .tips {
    font-size: 0.72rem;
  }

  .btn {
    padding: 0.5rem 0.8rem;
  }
}

.game-shell.compact {
  padding: 0.4rem 0.6rem;
}

.game-shell.compact .hud {
  padding-bottom: 0.35rem;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
}

.game-shell.compact .tips,
.game-shell.compact .menu-sub,
.game-shell.compact .badges-wrap {
  display: none;
}

.game-shell.compact .menu {
  gap: 0.4rem;
  padding: 0.5rem;
}

.game-shell.compact .menu-title {
  font-size: 1.4rem;
}

.game-shell.compact .btn-big {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}
