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

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: #0E1117;
  color: #F1F5F9;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, #131926 0%, #0E1117 70%);
}

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

/* Minimalist top HUD */
#hud {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) calc(env(safe-area-inset-right, 0px) + 18px) 8px calc(env(safe-area-inset-left, 0px) + 18px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}

.hud-scores {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-block {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #64748B;
}

.score-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #F8FAFC;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.best-block {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.best-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #475569;
}

.best-value {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #94A3B8;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(22, 27, 38, 0.78);
  color: #CBD5E1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.12s ease, background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(30, 41, 59, 0.92);
  color: #F8FAFC;
  border-color: rgba(148, 163, 184, 0.35);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn[aria-pressed="true"] {
  color: #FF4D6D;
  border-color: rgba(255, 77, 109, 0.35);
}

/* First-run hint */
.hint-banner {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 380px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(22, 27, 38, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #CBD5E1;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  z-index: 12;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.hint-banner.fade-out {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}

/* Overlays & Modals */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 15, 0.74);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 30;
  animation: fadeIn 0.2s ease-out;
}

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

.modal-card {
  width: 100%;
  max-width: 320px;
  background: #161B26;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 20px;
  padding: 24px 22px;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
  animation: popIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.gameover-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #FF4D5A;
  background: rgba(255, 77, 90, 0.12);
  border: 1px solid rgba(255, 77, 90, 0.28);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

.modal-title {
  font-size: 24px;
  font-weight: 800;
  color: #F8FAFC;
  margin-bottom: 6px;
}

.modal-subtitle {
  font-size: 14px;
  color: #94A3B8;
  margin-bottom: 20px;
}

.new-best-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #0E1117;
  background: linear-gradient(135deg, #FDE047, #F59E0B);
  padding: 4px 12px;
  border-radius: 999px;
  margin: 4px 0 14px;
}

.gameover-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 20px;
}

.stat-box {
  background: rgba(14, 17, 23, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 14px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #64748B;
}

.stat-number {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #F8FAFC;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, background-color 0.15s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, #38BDF8, #0EA5E9);
  color: #0B1120;
  box-shadow: 0 8px 20px rgba(56, 189, 248, 0.25);
}

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

.btn-secondary {
  background: rgba(148, 163, 184, 0.14);
  color: #E2E8F0;
}

.btn-secondary:hover {
  background: rgba(148, 163, 184, 0.22);
}

.btn-danger {
  background: #FF4D6D;
  color: #FFFFFF;
}

.btn-danger:hover {
  filter: brightness(1.06);
}

.hidden {
  display: none !important;
}
