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

:root {
  --gold: #f59e0b;
  --gold-light: #fbbf24;
  --gold-dark: #d97706;
  --red: #ef4444;
  --green: #10b981;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-light: #818cf8;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ── */
.game-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.billionaire-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.billionaire-avatar {
  font-size: 2.5rem;
  line-height: 1;
}

.billionaire-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold-light);
}

.billionaire-title {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.balance-display {
  flex: 1;
  text-align: center;
}

.balance-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.balance-amount {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
  line-height: 1.1;
}

.balance-amount.positive {
  color: var(--gold-light);
}

.balance-amount.warning {
  color: #fb923c;
}

.balance-amount.critical {
  color: var(--red);
}

.balance-amount.broke {
  color: var(--red);
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.reset-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
}

.reset-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--primary-light);
}

/* ── Progress Bar ── */
.progress-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
}

.progress-bar-outer {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold-light));
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0%;
}

.progress-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  text-align: right;
}

/* ── Main Layout ── */
.game-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2rem;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 768px) {
  .game-main {
    grid-template-columns: 1fr;
  }
  .cart-panel {
    order: -1;
  }
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .balance-display {
    text-align: left;
  }
  .balance-amount {
    font-size: 1.5rem;
  }
}

/* ── Items Grid ── */
.items-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 1rem 0.875rem;
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
}

.item-card:hover {
  border-color: var(--primary-light);
  background: #2a3a52;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.15);
}

.item-card:active {
  transform: translateY(0);
}

.item-card.unaffordable {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.item-emoji {
  font-size: 2.5rem;
  line-height: 1;
}

.item-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.item-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.item-price {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold-light);
}

.item-count-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  opacity: 0;
  transform: scale(0);
  transition: all 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.item-count-badge.visible {
  opacity: 1;
  transform: scale(1);
}

/* ── Cart Panel ── */
.cart-panel {
  position: sticky;
  top: 90px;
}

.cart-panel h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cart-count {
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.cart-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 1rem;
  background: var(--surface);
  border-radius: 0.875rem;
  border: 1px dashed var(--border);
}

.cart-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 55vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.cart-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  padding: 0.625rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.cart-item-emoji {
  font-size: 1.4rem;
  flex-shrink: 0;
}

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

.cart-item-name {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item-subtotal {
  font-size: 0.72rem;
  color: var(--gold);
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.qty-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 22px;
  height: 22px;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}

.qty-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
}

.qty-num {
  font-size: 0.8rem;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
}

/* ── Cart Summary ── */
.cart-summary {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 1rem;
}

.cart-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.2rem 0;
}

.cart-summary-total {
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold-light);
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.625rem;
}

/* ── Broke Banner ── */
.broke-banner {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.broke-banner.active {
  display: flex;
}

.broke-card {
  background: var(--surface);
  border: 1px solid var(--red);
  border-radius: 1.25rem;
  padding: 2.5rem 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

.broke-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.broke-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--red);
  margin-bottom: 0.5rem;
}

.broke-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.broke-stats {
  background: rgba(239, 68, 68, 0.1);
  border-radius: 0.625rem;
  padding: 0.75rem;
  margin-bottom: 1.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.8;
}

.broke-stat-value {
  color: var(--text);
  font-weight: 700;
}

.broke-restart-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  color: white;
  padding: 0.75rem 2rem;
  border-radius: 0.625rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: all 0.2s;
  width: 100%;
}

.broke-restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

/* ── Congrats Banner ── */
.congrats-banner {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.congrats-banner.active {
  display: flex;
}

.congrats-card {
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: 1.25rem;
  padding: 2.5rem 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.congrats-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.congrats-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold-light);
  margin-bottom: 0.5rem;
}

.congrats-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.congrats-restart-btn {
  background: linear-gradient(135deg, var(--gold-dark), var(--gold-light));
  border: none;
  color: white;
  padding: 0.75rem 2rem;
  border-radius: 0.625rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: all 0.2s;
  width: 100%;
}

.congrats-restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.4);
}

/* ── Float Animation ── */
.float-label {
  position: fixed;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--red);
  pointer-events: none;
  z-index: 150;
  animation: floatUp 0.8s ease forwards;
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}

/* ── Back link ── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}
.back-link:hover { color: var(--text); }
