/* Juice Merger: Suika Fruit Physics */
*, *::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: #fef3c7;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #18181b;
}

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

#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(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

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

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

.level-pill .value {
  color: #0284c7;
}

.target-pill .value {
  color: #16a34a;
}

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

/* Next Fruit Preview */
.next-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 9999px;
  padding: 4px 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.next-label {
  font-size: 11px;
  font-weight: 800;
  color: #a16207;
}

.next-preview {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.next-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

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

.icon-btn:hover {
  background: #fff;
}

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

/* Overflow Warning Banner */
.overflow-warning {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: #fff;
  padding: 8px 24px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.8px;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.8);
  animation: pulseWarning 0.8s infinite alternate;
  pointer-events: none;
  z-index: 25;
}

.overflow-warning.hidden {
  display: none;
}

@keyframes pulseWarning {
  from { transform: translateX(-50%) scale(0.96); opacity: 0.9; }
  to { transform: translateX(-50%) scale(1.04); opacity: 1; }
}

/* --- Overlays & Modals --- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  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;
  color: #fff;
}

.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(234, 179, 8, 0.15);
}

.card-badge {
  display: inline-block;
  background: rgba(234, 179, 8, 0.15);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, 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, #facc15);
  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(234, 179, 8, 0.12);
  border: 1px solid rgba(234, 179, 8, 0.35);
  border-radius: 12px;
  padding: 10px 14px;
  margin: 18px 0;
  font-size: 13px;
  color: #fef08a;
}

.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(234, 179, 8, 0.4);
  background: rgba(234, 179, 8, 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: #facc15;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #facc15, #ea580c);
  border: none;
  outline: none;
  color: #0f172a;
  padding: 14px 20px;
  border-radius: 9999px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(234, 88, 12, 0.4);
  transition: transform 0.1s, box-shadow 0.15s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(234, 88, 12, 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(24, 24, 27, 0.88);
  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: #fef08a;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  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); }
}

/* Evolution Ladder */
.evolution-ladder {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 9999px;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #71717a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  pointer-events: none;
  z-index: 20;
  max-width: 95vw;
  overflow-x: auto;
}

.ladder-title {
  color: #b45309;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.ladder-items {
  display: flex;
  align-items: center;
  gap: 3px;
}

.ladder-step {
  font-size: 14px;
  line-height: 1;
  transition: transform 0.2s ease;
}

.ladder-step.target-step {
  transform: scale(1.35);
  filter: drop-shadow(0 0 4px #f59e0b);
}

.ladder-arrow {
  color: #a1a1aa;
  font-size: 11px;
  font-weight: 900;
}

@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;
  }
  .next-box {
    padding: 2px 8px;
    gap: 4px;
  }
  .next-label {
    font-size: 9px;
  }
  .next-preview {
    width: 28px;
    height: 28px;
  }
  .next-preview img {
    width: 28px;
    height: 28px;
  }
  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  .tutorial-hint {
    top: 75px;
    font-size: 11px;
    padding: 6px 12px;
  }
  .evolution-ladder {
    bottom: 4px;
    padding: 3px 8px;
    font-size: 9px;
  }
  .ladder-step {
    font-size: 12px;
  }
  .card {
    padding: 24px 18px;
  }
  .card-title {
    font-size: 24px;
  }
}
