/* Animal Stack: Tower Physics Balancing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0c1222;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #fff;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0284c7;
}

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

/* --- Top HUD --- */
#game-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 20;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.hud-center {
  display: flex;
  align-items: center;
  pointer-events: auto;
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hud-pill .label {
  color: #94a3b8;
  font-size: 10px;
  letter-spacing: 0.5px;
}

.hud-pill .value {
  color: #fff;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

.level-pill .value {
  color: #38bdf8;
}

.height-pill .value {
  color: #4ade80;
}

.score-pill .value {
  color: #facc15;
  font-size: 15px;
}

/* Combo Pill */
.combo-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.6);
  animation: bounce 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.combo-pill.hidden {
  display: none;
}

@keyframes bounce {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.icon-btn {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.icon-btn:hover {
  background: rgba(30, 41, 59, 0.9);
}

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

/* Floating Rating Feedback */
.hit-rating {
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 25;
  animation: popUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.hit-rating.perfect {
  color: #fde047;
}

.hit-rating.good {
  color: #38bdf8;
}

.hit-rating.wobbly {
  color: #fb923c;
}

.hit-rating.hidden {
  display: none;
}

@keyframes popUp {
  0% { transform: translate(-50%, -30%) scale(0.7); opacity: 0; }
  40% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(1); opacity: 0; }
}

/* Bottom Drop Bar */
#drop-bar {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  z-index: 20;
}

.drop-btn {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border: none;
  outline: none;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 14px 42px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(34, 197, 94, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  transition: transform 0.1s, box-shadow 0.15s;
}

.drop-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(34, 197, 94, 0.7);
}

.drop-btn:active {
  transform: translateY(2px) scale(0.96);
}

.drop-icon {
  font-size: 18px;
}

/* --- Overlays & Modals --- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.card {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 32px;
  width: 90%;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7), 0 0 40px rgba(56, 189, 248, 0.15);
}

.card-badge {
  display: inline-block;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 4px 14px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.defeat-badge {
  display: inline-block;
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 4px 14px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.victory-ribbon {
  display: inline-block;
  background: linear-gradient(90deg, #4ade80, #38bdf8);
  color: #0f172a;
  padding: 4px 18px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1.5px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #fff;
  margin-bottom: 8px;
}

.card-subtitle {
  font-size: 14px;
  color: #94a3b8;
  margin-bottom: 24px;
}

.instructions-box {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 24px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.instruction-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
  line-height: 1.4;
  color: #cbd5e1;
}

.instruction-row .row-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.instruction-row strong {
  color: #fff;
}

.checkpoint-notice {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 18px 0;
  font-size: 13px;
  color: #7dd3fc;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0 28px 0;
}

.stat-box {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-box.highlight {
  border-color: rgba(74, 222, 128, 0.4);
  background: rgba(74, 222, 128, 0.1);
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
}

.stat-box.highlight .stat-value {
  color: #4ade80;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  border: none;
  outline: none;
  color: #fff;
  padding: 14px 20px;
  border-radius: 9999px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  transition: transform 0.1s, box-shadow 0.15s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.6);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  outline: none;
  color: #cbd5e1;
  padding: 12px 20px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
  transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

/* Tutorial Hint */
.tutorial-hint {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 9999px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #facc15;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 25;
  transition: opacity 0.4s ease, transform 0.4s ease;
  animation: floatHint 2s infinite ease-in-out;
}

.tutorial-hint.fade-out {
  opacity: 0;
  transform: translateX(-50%) translateY(-10px);
  pointer-events: none;
}

@keyframes floatHint {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-6px); }
}

@media (max-width: 480px) {
  #game-hud {
    top: 6px;
    left: 6px;
    right: 6px;
    gap: 4px;
  }
  .hud-left, .hud-right {
    gap: 4px;
  }
  .hud-pill {
    padding: 4px 8px;
    font-size: 11px;
    gap: 4px;
  }
  .hud-pill .label {
    font-size: 9px;
  }
  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  .tutorial-hint {
    top: 75px;
    font-size: 11px;
    padding: 6px 12px;
  }
  .card {
    padding: 24px 18px;
  }
  .card-title {
    font-size: 24px;
  }
  .drop-btn {
    padding: 10px 24px;
    font-size: 14px;
  }
}
