/* ===== RESET & CUSTOM PROPERTIES ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; }

body {
  font-family: 'Outfit', sans-serif;
  color: var(--text-primary);
  transition: background 0.4s, color 0.4s;

  /* Light mode defaults */
  --bg-primary: #faf5e8;
  --bg-gradient: linear-gradient(160deg, #faf5e8 0%, #f0ead4 50%, #faf5e8 100%);
  --text-primary: #2a2210;
  --text-secondary: #7a6d50;
  --gold: #FFD700;
  --gold-dark: #DAA520;
  --gold-deeper: #B8860B;
  --panel-bg: rgba(180, 140, 60, 0.06);
  --panel-border: rgba(180, 140, 60, 0.18);
  --card-bg: rgba(180, 140, 60, 0.07);
  --card-border: rgba(180, 140, 60, 0.14);
  --card-hover-bg: rgba(180, 140, 60, 0.14);
  --card-affordable-border: rgba(255, 200, 0, 0.5);
  --card-affordable-glow: 0 0 12px rgba(255, 215, 0, 0.25);
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --toggle-track: #c8bfa8;
  --toggle-knob: #fff;
  --header-bg: rgba(250, 245, 232, 0.7);
  --rain-opacity: 0.35;
  --modal-overlay: rgba(0, 0, 0, 0.45);
  --modal-bg: rgba(250, 245, 232, 0.95);
  --btn-bg: linear-gradient(135deg, #FFD700, #DAA520);
  --btn-text: #2a2210;
  --reset-color: #a88;
}

body.dark-mode {
  --bg-primary: #08080f;
  --bg-gradient: linear-gradient(160deg, #08080f 0%, #140e24 50%, #08080f 100%);
  --text-primary: #f0e6d2;
  --text-secondary: #8a7e6a;
  --panel-bg: rgba(255, 215, 0, 0.025);
  --panel-border: rgba(255, 215, 0, 0.08);
  --card-bg: rgba(255, 215, 0, 0.04);
  --card-border: rgba(255, 215, 0, 0.08);
  --card-hover-bg: rgba(255, 215, 0, 0.09);
  --card-affordable-border: rgba(255, 215, 0, 0.35);
  --card-affordable-glow: 0 0 18px rgba(255, 215, 0, 0.12);
  --shadow: 0 4px 30px rgba(0,0,0,0.3);
  --toggle-track: #333;
  --toggle-knob: #FFD700;
  --header-bg: rgba(8, 8, 15, 0.7);
  --rain-opacity: 0.25;
  --modal-overlay: rgba(0, 0, 0, 0.7);
  --modal-bg: rgba(20, 14, 36, 0.96);
  --btn-bg: linear-gradient(135deg, #FFD700, #B8860B);
  --btn-text: #1a1000;
  --reset-color: #665;
}

body { background: var(--bg-gradient); }

/* ===== CANVAS BACKGROUND ===== */
#coinRain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ===== LAYOUT ===== */
.game-wrapper {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.game-title {
  font-size: 1.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, #FFD700 0%, #FFA500 50%, #FFD700 100%);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmerTitle 4s ease-in-out infinite;
}

@keyframes shimmerTitle {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.game-content {
  display: flex;
  flex: 1;
  gap: 0;
}

/* ===== PLAY AREA (LEFT) ===== */
.play-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  gap: 16px;
  min-height: calc(100vh - 60px);
}

.gold-display {
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
}

.gold-icon {
  font-size: 2.8rem;
  filter: drop-shadow(0 2px 6px rgba(255, 215, 0, 0.4));
}

.gold-amount {
  font-size: 3.2rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 2px 12px rgba(255, 215, 0, 0.25);
  transition: transform 0.1s;
  min-width: 120px;
}

.gold-amount.pulse {
  animation: goldPulse 0.15s ease-out;
}

@keyframes goldPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.gold-rates {
  display: flex;
  gap: 20px;
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.gold-rates span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rate-value {
  color: var(--gold-dark);
}

/* ===== COIN ===== */
.coin-outer {
  animation: coinFloat 3s ease-in-out infinite;
}

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

.coin-container {
  width: 220px;
  height: 220px;
  filter: drop-shadow(0 8px 25px rgba(255, 200, 0, 0.2));
  perspective: 1000px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.coin-container.clicked {
  animation: coinBounce 0.12s ease-out;
}

@keyframes coinBounce {
  0% { transform: scale(1); }
  40% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

.coin {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s ease-in-out;
}

.face {
  position: absolute;
  inset: 0;
}

.face.front { transform: translateZ(10px); }
.face.back { transform: translateZ(-10px) rotateY(180deg); }
.face.edge { filter: brightness(0.85); }

.click-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  opacity: 0.6;
  margin-top: -4px;
}

/* ===== STATS BAR ===== */
.stats-bar {
  display: flex;
  gap: 24px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

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

/* ===== FLOATING TEXT ===== */
.float-text {
  position: absolute;
  pointer-events: none;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 1px 6px rgba(255, 215, 0, 0.5);
  animation: floatUp 0.9s ease-out forwards;
  z-index: 20;
}

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

/* ===== SHOP PANEL (RIGHT) ===== */
.shop-panel {
  width: 340px;
  min-width: 340px;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
}

.shop-header {
  padding: 20px 20px 12px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--gold-dark);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--panel-border);
}

.shop-body {
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.shop-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 4px;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== UPGRADE CARDS ===== */
.upgrade-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.upgrade-card:hover {
  background: var(--card-hover-bg);
}

.upgrade-card.affordable {
  border-color: var(--card-affordable-border);
  box-shadow: var(--card-affordable-glow);
}

.upgrade-card.affordable:hover {
  transform: translateY(-1px);
  box-shadow: var(--card-affordable-glow), 0 4px 12px rgba(0,0,0,0.1);
}

.upgrade-card.affordable:active {
  transform: scale(0.97);
}

.upgrade-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.upgrade-icon {
  font-size: 1.6rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.upgrade-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.upgrade-level {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gold-dark);
  background: rgba(255, 215, 0, 0.1);
  padding: 1px 6px;
  border-radius: 6px;
}

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

.upgrade-cost {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== OFFLINE MODAL ===== */
.offline-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.offline-modal.show { display: flex; }

.offline-content {
  background: var(--modal-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 36px 44px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 360px;
  width: 90%;
}

.offline-content h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 8px;
}

.offline-content p {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.offline-gold-amount {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--gold);
  display: block;
  margin: 12px 0 20px;
  text-shadow: 0 2px 10px rgba(255, 215, 0, 0.3);
}

.offline-btn {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  padding: 12px 36px;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 800;
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 16px rgba(255, 215, 0, 0.3);
}

.offline-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(255, 215, 0, 0.4);
}

.offline-btn:active { transform: scale(0.96); }

/* ===== DARK MODE TOGGLE ===== */
.dark-toggle {
  background: var(--toggle-track);
  border: none;
  border-radius: 20px;
  width: 48px;
  height: 26px;
  cursor: pointer;
  position: relative;
  transition: background 0.3s;
  flex-shrink: 0;
}

.dark-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--toggle-knob);
  transition: transform 0.3s, background 0.3s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

body.dark-mode .dark-toggle::after {
  transform: translateX(22px);
}

/* ===== RESET BUTTON ===== */
.reset-btn {
  background: none;
  border: 1px solid var(--card-border);
  color: var(--reset-color);
  font-size: 0.75rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  align-self: center;
  margin-top: 8px;
}

.reset-btn:hover {
  border-color: #c44;
  color: #c44;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 800px) {
  .game-content {
    flex-direction: column;
  }

  .play-area {
    min-height: auto;
    padding: 24px 16px;
  }

  .gold-amount {
    font-size: 2.4rem;
  }

  .gold-icon {
    font-size: 2.2rem;
  }

  .coin-container {
    width: 170px;
    height: 170px;
  }

  .shop-panel {
    width: 100%;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--panel-border);
    max-height: none;
    position: static;
  }

  .stats-bar {
    gap: 16px;
    font-size: 0.78rem;
  }

  .game-title {
    font-size: 1.2rem;
  }
}

@media (max-width: 400px) {
  .gold-rates {
    flex-direction: column;
    gap: 4px;
    align-items: center;
  }

  .stats-bar {
    flex-direction: column;
    gap: 4px;
    align-items: center;
  }
}

/* ===== SCROLLBAR ===== */
.shop-panel::-webkit-scrollbar { width: 6px; }
.shop-panel::-webkit-scrollbar-track { background: transparent; }
.shop-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 215, 0, 0.15);
  border-radius: 3px;
}
.shop-panel::-webkit-scrollbar-thumb:hover { background: rgba(255, 215, 0, 0.25); }
