:root {
  --bg-dark: #0f172a;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.4);
  --accent-gold: #fbbf24;
  --accent-red: #ef4444;
  --accent-green: #10b981;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --glass-bg: rgba(15, 23, 42, 0.75);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-family);
  color: var(--text-main);
}

#app-container {
  position: relative;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #1e1b4b 0%, #0f172a 100%);
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Base Screens & Overlays */
.screen, .overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: auto;
}

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

.active {
  opacity: 1;
  visibility: visible;
}

/* In-Game HUD */
#hud {
  justify-content: space-between;
  padding: 24px 20px;
  pointer-events: none;
  z-index: 5;
}

.hud-top {
  width: 100%;
  max-width: 500px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  padding: 8px 16px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.hud-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

.hud-value {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text-main);
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stage-badge {
  background: linear-gradient(135deg, var(--primary) 0%, #4338ca 100%);
  color: #fff;
  font-weight: 900;
  font-size: 1.1rem;
  padding: 8px 20px;
  border-radius: 30px;
  letter-spacing: 1px;
  box-shadow: 0 0 15px var(--primary-glow);
}

.boss-warning {
  margin-top: 6px;
  background: linear-gradient(135deg, #ef4444 0%, #991b1b 100%);
  color: #fff;
  font-weight: 900;
  font-size: 0.75rem;
  padding: 4px 12px;
  border-radius: 12px;
  animation: pulse-red 1s infinite alternate;
}

.coin-card {
  flex-direction: row;
  gap: 8px;
}

.coin-icon {
  font-size: 1.3rem;
}

.knife-counter-container {
  position: absolute;
  left: 20px;
  bottom: 40px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 6;
}

.knife-icon-hud {
  width: 14px;
  height: 32px;
  background: #ffffff;
  clip-path: polygon(50% 0%, 100% 30%, 80% 100%, 20% 100%, 0% 30%);
  transition: all 0.2s ease;
  box-shadow: 0 0 8px rgba(255,255,255,0.4);
}

.knife-icon-hud.used {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: none;
}

.pause-btn {
  position: absolute;
  top: 24px;
  right: 20px;
  pointer-events: auto;
}

/* Buttons */
.btn {
  font-family: var(--font-family);
  font-weight: 800;
  border: none;
  outline: none;
  border-radius: 16px;
  padding: 16px 32px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px var(--primary-glow);
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: white;
}

.btn-icon-text {
  padding: 12px 20px;
  font-size: 0.95rem;
  width: 100%;
}

.btn-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  color: white;
  font-size: 1.2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.2);
}

.pulse {
  animation: button-pulse 2s infinite;
}

@keyframes button-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 var(--primary-glow); }
  70% { transform: scale(1.03); box-shadow: 0 0 0 16px rgba(99, 102, 241, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

@keyframes pulse-red {
  0% { transform: scale(0.95); }
  100% { transform: scale(1.05); }
}

/* Main Menu */
#screen-main {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
}

.menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 90%;
  max-width: 400px;
}

.logo-container {
  text-align: center;
}

.logo-knife-icon {
  font-size: 4rem;
  filter: drop-shadow(0 10px 15px rgba(0,0,0,0.5));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.game-title {
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1;
  text-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

.accent-text {
  color: var(--primary);
}

.game-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  letter-spacing: 2px;
  margin-top: 6px;
  font-weight: 600;
}

.best-score-badge {
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.3);
  padding: 8px 24px;
  border-radius: 20px;
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--accent-gold);
  font-weight: 800;
  font-size: 0.95rem;
}

.menu-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Modals */
.modal-card {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  padding: 28px;
  width: 90%;
  max-width: 450px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--glass-shadow);
  animation: modal-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-pop {
  0% { opacity: 0; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 1px;
}

.coin-display {
  background: rgba(251, 191, 36, 0.15);
  padding: 6px 14px;
  border-radius: 16px;
  font-weight: 800;
  color: var(--accent-gold);
}

.modal-close {
  margin-top: 20px;
  width: 100%;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-top: 20px;
}

/* Shop Grids */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  overflow-y: auto;
  padding: 4px;
  max-height: 50vh;
}

.shop-grid::-webkit-scrollbar {
  width: 6px;
}

.shop-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.shop-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.shop-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.shop-item.selected {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.2);
  box-shadow: 0 0 15px var(--primary-glow);
}

.shop-item.locked {
  opacity: 0.6;
}

.shop-item-canvas {
  width: 64px;
  height: 64px;
}

.shop-item-name {
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
}

.shop-item-btn {
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 10px;
  width: 100%;
}

/* Achievements */
.achievements-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.achievement-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: center;
}

.achievement-card.unlocked {
  border-color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.08);
}

.achievement-icon {
  font-size: 2rem;
}

.achievement-info {
  display: flex;
  flex-direction: column;
}

.achievement-title {
  font-weight: 800;
  font-size: 0.95rem;
}

.achievement-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* How to Play */
.how-to-play-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.instruction-step {
  display: flex;
  gap: 14px;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
  border-radius: 14px;
}

.step-num {
  background: var(--primary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  flex-shrink: 0;
}

/* Game Over */
.gameover-card {
  align-items: center;
  text-align: center;
}

.gameover-title {
  font-size: 2.2rem;
  color: var(--accent-red);
  font-weight: 900;
}

#gameover-reason {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.stats-summary {
  width: 100%;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(0, 0, 0, 0.2);
  padding: 16px;
  border-radius: 16px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
}

.stat-row.highlight {
  color: var(--accent-gold);
}

.stat-val {
  color: var(--text-main);
  font-weight: 900;
}

@media (max-width: 480px) {
  .game-title {
    font-size: 2.8rem;
  }
  .modal-card {
    padding: 20px;
  }
}
