* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0d0d1a;
  --bg-secondary: #141428;
  --bg-panel: rgba(20, 20, 50, 0.85);
  --bg-card: rgba(30, 30, 65, 0.9);
  --border-color: rgba(0, 212, 255, 0.2);
  --accent-blue: #00d4ff;
  --accent-green: #39ff14;
  --accent-orange: #ff6b35;
  --accent-gold: #ffd700;
  --accent-pink: #ff4da6;
  --text-primary: #eef0ff;
  --text-secondary: #8888aa;
  --text-dim: #555577;
  --font-display: 'Fredoka', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

body {
  background: var(--bg-primary);
  background-image: 
    radial-gradient(ellipse at 20% 50%, rgba(0, 212, 255, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(57, 255, 20, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(255, 77, 166, 0.03) 0%, transparent 50%);
  color: var(--text-primary);
  font-family: var(--font-display);
  min-height: 100vh;
  overflow-x: hidden;
}

#game-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* HUD */
#hud {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
}

#level-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}

#level-text {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
  color: var(--accent-blue);
  text-shadow: 0 0 12px rgba(0, 212, 255, 0.5);
}

#xp-bar-container {
  width: 80px;
  height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 3px;
}

#xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
  border-radius: 3px;
  width: 0%;
  transition: width 0.5s ease;
}

#xp-text {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 1px;
}

#coins-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-gold);
}

#coins-display.pulse {
  animation: coinPulse 0.3s ease;
}

@keyframes coinPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.coin-icon { font-size: 22px; }

#prints-display {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-secondary);
}

.prints-label { font-size: 11px; }

#hud-buttons {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

#hud-buttons button {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#hud-buttons button:hover {
  border-color: var(--accent-blue);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
  transform: scale(1.05);
}

/* Main Content */
#main-content {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  flex: 1;
  min-height: 0;
}

/* Upgrades Panel */
#upgrades-panel {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 4px 0;
}

.upgrade-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
  position: relative;
}

.upgrade-card:hover {
  border-color: var(--accent-blue);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.15);
}

.upgrade-icon {
  font-size: 28px;
  width: 40px;
  text-align: center;
  flex-shrink: 0;
}

.upgrade-info {
  flex: 1;
  min-width: 0;
}

.upgrade-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

.upgrade-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.upgrade-stat {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-green);
  margin-top: 3px;
}

.upgrade-buy-btn {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.2), rgba(57, 255, 20, 0.2));
  border: 1px solid rgba(0, 212, 255, 0.4);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--accent-gold);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.upgrade-buy-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 16px rgba(0, 212, 255, 0.3);
}

.upgrade-buy-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.upgrade-buy-btn:active:not(:disabled) {
  transform: scale(0.95);
}

/* Canvas Area */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#canvas {
  width: 100%;
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  display: block;
  min-height: 300px;
}

#print-progress-container {
  position: relative;
  height: 28px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--border-color);
}

#print-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-green), var(--accent-gold));
  border-radius: 14px;
  width: 0%;
  transition: width 0.1s linear;
}

#print-progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* Style Selector */
#style-selector {
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

#style-selector::-webkit-scrollbar {
  height: 6px;
}

#style-selector::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.03);
  border-radius: 3px;
}

#style-selector::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.3);
  border-radius: 3px;
}

#style-scroll {
  display: flex;
  gap: 8px;
  padding: 4px 2px;
}

.style-card {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.style-card:hover:not(.locked) {
  border-color: var(--accent-blue);
  transform: translateY(-2px);
}

.style-card.selected {
  border-color: var(--accent-green);
  box-shadow: 0 0 20px rgba(57, 255, 20, 0.3);
}

.style-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.6);
}

.style-card .style-icon {
  font-size: 28px;
}

.style-card .style-name {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 4px;
}

.style-card .lock-overlay {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 14px;
}

.style-card .lock-text {
  position: absolute;
  bottom: 2px;
  font-size: 8px;
  font-family: var(--font-mono);
  color: var(--text-dim);
}

/* Stats Footer */
#stats-footer {
  margin-top: 10px;
  padding: 8px 0;
}

#stats-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 8px 16px;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

#stats-toggle:hover {
  border-color: var(--accent-blue);
}

#stats-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 16px;
  margin-top: 8px;
}

#stats-content.hidden {
  display: none;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-row span:last-child {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.stat-actions {
  margin-top: 10px;
  text-align: right;
}

.danger-btn {
  background: rgba(255, 50, 50, 0.2);
  border: 1px solid rgba(255, 50, 50, 0.4);
  border-radius: 8px;
  padding: 6px 14px;
  color: #ff5555;
  font-family: var(--font-display);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.danger-btn:hover {
  background: rgba(255, 50, 50, 0.3);
  transform: scale(1.03);
}

#footer-link {
  text-align: center;
  margin-top: 12px;
  padding-bottom: 12px;
}

#footer-link a {
  color: var(--text-dim);
  font-size: 12px;
  text-decoration: none;
  transition: color 0.2s;
}

#footer-link a:hover {
  color: var(--accent-blue);
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(0, 212, 255, 0.1);
}

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

.modal-header h2 {
  font-size: 22px;
  color: var(--accent-gold);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
}

#store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.store-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
  transition: all 0.2s;
}

.store-item:hover {
  border-color: var(--accent-blue);
}

.store-item .si-icon {
  font-size: 36px;
  display: block;
  margin-bottom: 6px;
}

.store-item .si-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--text-primary);
}

.store-item .si-price {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-gold);
  margin-top: 4px;
}

.store-item .si-req {
  font-size: 10px;
  color: var(--accent-orange);
  margin-top: 2px;
}

.store-item.owned {
  border-color: rgba(57, 255, 20, 0.3);
}

.store-item .si-status {
  margin-top: 6px;
  font-size: 12px;
}

.store-item .si-status.owned-text {
  color: var(--accent-green);
}

.store-item .si-buy-btn {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-green));
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  color: var(--bg-primary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 6px;
}

.store-item .si-buy-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.4);
}

.store-item .si-buy-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.store-item.level-locked {
  opacity: 0.4;
}

/* Welcome modal */
.welcome-content {
  text-align: center;
}

.welcome-content h2 {
  color: var(--accent-gold);
  font-size: 24px;
  margin-bottom: 12px;
}

.welcome-content p {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-green));
  border: none;
  border-radius: 10px;
  padding: 10px 28px;
  color: var(--bg-primary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.4);
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  animation: toastIn 0.4s ease;
}

.toast.hidden {
  display: none;
}

.toast-content {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.9), rgba(57, 255, 20, 0.9));
  padding: 14px 28px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 18px;
  color: var(--bg-primary);
  box-shadow: 0 4px 30px rgba(0, 212, 255, 0.4);
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast-icon {
  font-size: 24px;
}

@keyframes toastIn {
  0% { opacity: 0; transform: translateX(-50%) translateY(-20px) scale(0.8); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

/* Mobile */
@media (max-width: 768px) {
  #main-content {
    flex-direction: column;
  }

  #upgrades-panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .panel-title {
    width: 100%;
  }

  .upgrade-card {
    flex: 1;
    min-width: 160px;
    padding: 10px;
  }

  .upgrade-icon {
    font-size: 22px;
    width: 30px;
  }

  .upgrade-name { font-size: 12px; }
  .upgrade-desc { font-size: 10px; }

  #canvas {
    min-height: 250px;
  }

  .modal-content {
    width: 95%;
    max-height: 85vh;
    padding: 16px;
  }

  #hud {
    gap: 10px;
    padding: 8px 12px;
  }

  #coins-display {
    font-size: 16px;
  }

  .style-card {
    width: 70px;
    height: 70px;
  }
}

@media (max-width: 480px) {
  .upgrade-card {
    min-width: 100%;
  }

  #store-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Sparkle animation overlay */
.sparkle {
  position: absolute;
  pointer-events: none;
  animation: sparkleAnim 0.8s ease-out forwards;
}

@keyframes sparkleAnim {
  0% { opacity: 1; transform: scale(0) rotate(0deg); }
  50% { opacity: 1; transform: scale(1) rotate(180deg); }
  100% { opacity: 0; transform: scale(0.5) rotate(360deg); }
}