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

:root {
  --bg-dark: #1a1a2e;
  --bg-medium: #16213e;
  --bg-light: #1f3460;
  --accent-gold: #c9a55c;
  --accent-blue: #4a7db8;
  --accent-teal: #3d6b6b;
  --accent-sad: #6b8cae;
  --text-light: #e8e8e8;
  --text-dim: #8899aa;
  --border-color: #3d4f6f;
  --panel-bg: rgba(22, 33, 62, 0.95);
  --tear-color: #7ec8e3;
}

body {
  font-family: 'Press Start 2P', cursive;
  background: var(--bg-dark);
  color: var(--text-light);
  min-height: 100vh;
  image-rendering: pixelated;
  overflow-x: hidden;
}

.game-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: 
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0,0,0,0.1) 2px,
      rgba(0,0,0,0.1) 4px
    ),
    linear-gradient(180deg, #1a1a2e 0%, #0f1628 50%, #1a1a2e 100%);
  position: relative;
}

/* Rain effect */
.rain-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.raindrop {
  position: absolute;
  top: -20px;
  width: 2px;
  height: 15px;
  background: linear-gradient(transparent, var(--tear-color));
  opacity: 0.4;
  animation: fall linear infinite;
}

@keyframes fall {
  to {
    transform: translateY(100vh);
  }
}

/* Header */
.game-header {
  background: var(--bg-medium);
  border-bottom: 4px solid var(--border-color);
  padding: 12px 16px;
  text-align: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
  position: relative;
  z-index: 10;
}

.game-title {
  font-size: 16px;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
  margin-bottom: 8px;
  animation: titleBob 2s ease-in-out infinite;
}

.title-cry {
  display: inline-block;
  animation: cry 0.5s ease-in-out infinite alternate;
}

@keyframes cry {
  0% { transform: translateY(0); }
  100% { transform: translateY(-2px); }
}

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

.nut-display {
  margin-bottom: 4px;
}

.nut-count {
  font-size: 24px;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 #000;
}

.nut-label {
  font-size: 10px;
  color: var(--text-dim);
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.nps-display {
  font-size: 8px;
  color: var(--accent-teal);
}

.tears-display {
  font-size: 8px;
  color: var(--tear-color);
}

/* Mobile tabs */
.mobile-tabs {
  display: none;
  background: var(--bg-medium);
  border-bottom: 4px solid var(--border-color);
  position: relative;
  z-index: 10;
}

.mobile-tab {
  flex: 1;
  padding: 10px;
  font-family: inherit;
  font-size: 7px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.mobile-tab.active {
  background: var(--bg-light);
  color: var(--accent-gold);
}

/* Main layout */
.game-main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 260px;
  gap: 0;
  overflow: hidden;
  position: relative;
  z-index: 5;
}

.panel {
  background: var(--panel-bg);
  border-right: 4px solid var(--border-color);
  overflow-y: auto;
  padding: 12px;
}

.panel:last-child {
  border-right: none;
  border-left: 4px solid var(--border-color);
}

.panel-title {
  font-size: 10px;
  color: var(--accent-gold);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px dashed var(--border-color);
  text-align: center;
}

/* Creatures panel */
.creatures-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.creature-card {
  background: var(--bg-light);
  border: 3px solid var(--border-color);
  padding: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.creature-card:hover {
  border-color: var(--accent-gold);
  transform: translateX(2px);
}

.creature-card.locked {
  opacity: 0.5;
  cursor: default;
}

.creature-card-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.creature-sprite {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--border-color);
}

.creature-sprite img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.creature-sprite img.loading {
  opacity: 0;
}

.creature-sprite img.loaded {
  opacity: 1;
  animation: creatureIdle 2s ease-in-out infinite;
}

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

.sprite-placeholder {
  position: absolute;
  font-size: 24px;
}

.tear-drops {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
}

.tear {
  position: absolute;
  font-size: 8px;
  animation: tearFall 1.5s ease-in infinite;
  opacity: 0.8;
}

.tear-1 {
  left: 20%;
  animation-delay: 0s;
}

.tear-2 {
  right: 20%;
  animation-delay: 0.7s;
}

@keyframes tearFall {
  0% { top: 30%; opacity: 0.8; }
  100% { top: 100%; opacity: 0; }
}

.speech-bubble {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-dark);
  border: 2px solid var(--tear-color);
  padding: 6px 10px;
  font-size: 6px;
  color: var(--tear-color);
  white-space: nowrap;
  z-index: 20;
  animation: bubbleFade 4s ease-in-out;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--tear-color);
}

@keyframes bubbleFade {
  0%, 100% { opacity: 0; transform: translateX(-50%) translateY(5px); }
  10%, 90% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.creature-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.creature-name {
  font-size: 8px;
  color: var(--text-light);
}

.creature-rarity {
  font-size: 6px;
}

.creature-stats {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.level-badge, .dupe-badge, .mood-badge {
  font-size: 6px;
  background: var(--bg-dark);
  padding: 2px 4px;
  border: 1px solid var(--border-color);
}

.mood-badge {
  border-color: var(--tear-color);
}

.creature-card-right {
  text-align: right;
}

.creature-nps {
  font-size: 7px;
  color: var(--accent-teal);
  margin-bottom: 4px;
}

.buy-button {
  font-family: inherit;
  font-size: 6px;
  padding: 6px 8px;
  border: 2px solid;
  cursor: pointer;
  transition: all 0.15s;
  max-width: 100px;
}

.buy-button.can-afford {
  background: var(--accent-teal);
  border-color: #5a9a9a;
  color: white;
}

.buy-button.can-afford:hover {
  transform: scale(1.05);
}

.buy-button.cannot-afford {
  background: var(--bg-dark);
  border-color: var(--border-color);
  color: var(--text-dim);
  cursor: not-allowed;
}

/* Click panel */
.click-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: none !important;
  background: transparent;
}

.forest-bg {
  position: absolute;
  inset: 0;
  background: 
    url('/api/retrodiffusion/image/512/512/simple?prompt=pixel+art+sad+rainy+forest+clearing+autumn+trees+fallen+leaves+melancholic+foggy&seed=1337') center/cover,
    linear-gradient(180deg, #1a2a3a 0%, #0f1a28 100%);
  opacity: 0.4;
  filter: blur(1px);
}

.nut-button-container {
  position: relative;
  z-index: 1;
}

.nut-button-container.lightning {
  animation: lightningFlash 0.2s ease-out;
}

@keyframes lightningFlash {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(2) contrast(1.2); }
}

.nut-button {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #8aa8c9 0%, #5a7a9a 50%, #3a5a7a 100%);
  border: 6px solid #2a4a6a;
  cursor: pointer;
  transition: transform 0.1s;
  box-shadow: 
    0 8px 0 #1a3a5a,
    0 12px 20px rgba(0,0,0,0.5),
    inset 0 -10px 20px rgba(0,0,0,0.3);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nut-button:hover {
  transform: scale(1.02);
}

.nut-button:active, .nut-button.wiggle {
  transform: scale(0.95);
  box-shadow: 
    0 4px 0 #1a3a5a,
    0 6px 10px rgba(0,0,0,0.5),
    inset 0 -10px 20px rgba(0,0,0,0.3);
}

.nut-image {
  width: 120px;
  height: 120px;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.floating-number {
  position: absolute;
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 #000;
  pointer-events: none;
  z-index: 10;
  transform: translateX(-50%);
}

.floating-number.cry-text {
  color: var(--tear-color);
  font-size: 12px;
}

.click-power-display {
  position: relative;
  z-index: 1;
  margin-top: 20px;
  font-size: 8px;
  color: var(--text-dim);
  background: rgba(0,0,0,0.6);
  padding: 6px 12px;
  border: 2px solid var(--border-color);
}

.why-button {
  position: absolute;
  bottom: 20px;
  right: 20px;
  font-family: inherit;
  font-size: 8px;
  padding: 8px 12px;
  background: var(--bg-dark);
  border: 2px solid var(--tear-color);
  color: var(--tear-color);
  cursor: pointer;
  transition: all 0.15s;
  z-index: 5;
}

.why-button:hover {
  background: var(--tear-color);
  color: var(--bg-dark);
}

.why-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-dark);
  border: 4px solid var(--tear-color);
  padding: 20px 30px;
  font-size: 10px;
  color: var(--tear-color);
  text-align: center;
  z-index: 100;
  max-width: 300px;
  animation: popupAppear 0.3s ease-out;
  box-shadow: 0 0 50px rgba(126, 200, 227, 0.3);
}

@keyframes popupAppear {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Stats & Upgrades panel */
.stats-box {
  background: var(--bg-dark);
  border: 2px solid var(--border-color);
  padding: 10px;
  margin-bottom: 16px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  font-size: 7px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border-color);
}

.stat-item:last-child {
  border-bottom: none;
}

.stat-item span:first-child {
  color: var(--text-dim);
}

.stat-item span:last-child {
  color: var(--accent-gold);
}

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

.upgrade-button {
  font-family: inherit;
  font-size: 7px;
  padding: 10px;
  border: 3px solid;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upgrade-button.can-afford {
  background: var(--bg-light);
  border-color: var(--accent-gold);
  color: var(--text-light);
}

.upgrade-button.can-afford:hover {
  background: var(--bg-medium);
}

.upgrade-button.cannot-afford {
  background: var(--bg-dark);
  border-color: var(--border-color);
  color: var(--text-dim);
  cursor: not-allowed;
}

.upgrade-button.purchased {
  background: var(--accent-teal);
  border-color: #5a9a9a;
  color: white;
  cursor: default;
}

.upgrade-name {
  color: var(--accent-gold);
}

.purchased .upgrade-name {
  color: white;
}

.upgrade-desc {
  font-size: 6px;
  color: var(--text-dim);
}

.purchased .upgrade-desc {
  color: rgba(255,255,255,0.8);
}

.upgrade-cost {
  font-size: 8px;
  color: var(--accent-gold);
}

.upgrade-owned {
  font-size: 8px;
  color: white;
}

/* Footer */
.game-footer {
  background: var(--bg-medium);
  border-top: 4px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 10;
}

.footer-btn {
  font-family: inherit;
  font-size: 7px;
  padding: 6px 12px;
  background: var(--bg-dark);
  border: 2px solid var(--border-color);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}

.footer-btn:hover {
  border-color: #e74c3c;
  color: #e74c3c;
}

.footer-link {
  font-size: 7px;
  color: var(--accent-gold);
  text-decoration: none;
}

.footer-link:hover {
  text-decoration: underline;
}

.footer-why {
  color: var(--tear-color);
  animation: cry 0.5s ease-in-out infinite alternate;
  display: inline-block;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-content {
  background: var(--bg-medium);
  border: 4px solid var(--accent-gold);
  padding: 20px;
  max-width: 320px;
  width: 100%;
  position: relative;
  box-shadow: 0 0 40px rgba(201, 165, 92, 0.3);
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: var(--bg-dark);
  border: 2px solid var(--border-color);
  color: var(--text-light);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  border-color: #e74c3c;
  color: #e74c3c;
}

.modal-header {
  text-align: center;
  margin-bottom: 16px;
}

.modal-sprite {
  display: inline-block;
  transition: filter 0.3s;
}

.modal-sprite.briefly-happy {
  filter: brightness(1.3) saturate(1.2);
}

.brief-joy {
  font-size: 8px;
  color: #90EE90;
  margin: 5px 0;
  animation: briefJoy 0.5s ease-out;
}

@keyframes briefJoy {
  0% { opacity: 0; transform: scale(0.5); }
  50% { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(1); }
}

.modal-header h2 {
  font-size: 12px;
  color: var(--accent-gold);
  margin: 10px 0 8px;
}

.creature-lore {
  font-size: 7px;
  color: var(--text-dim);
  line-height: 1.6;
}

.modal-stats {
  background: var(--bg-dark);
  border: 2px solid var(--border-color);
  padding: 10px;
  margin-bottom: 12px;
}

.modal-quote {
  font-size: 7px;
  color: var(--tear-color);
  text-align: center;
  padding: 10px;
  background: rgba(126, 200, 227, 0.1);
  border: 1px dashed var(--tear-color);
  margin-bottom: 16px;
  font-style: italic;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  padding: 4px 0;
}

.stat-row span:first-child {
  color: var(--text-dim);
}

.stat-row span:last-child {
  color: var(--text-light);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-button {
  font-family: inherit;
  font-size: 8px;
  padding: 12px;
  border: 3px solid;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  transition: all 0.15s;
}

.action-button.can-afford {
  background: var(--accent-teal);
  border-color: #5a9a9a;
  color: white;
}

.action-button.can-afford:hover {
  transform: scale(1.02);
}

.action-button.cannot-afford {
  background: var(--bg-dark);
  border-color: var(--border-color);
  color: var(--text-dim);
  cursor: not-allowed;
}

.action-cost {
  font-size: 10px;
  color: var(--accent-gold);
}

.cannot-afford .action-cost {
  color: var(--text-dim);
}

.action-benefit {
  font-size: 7px;
  color: #90ee90;
}

.cannot-afford .action-benefit {
  color: var(--text-dim);
}

/* Mobile responsive */
@media (max-width: 900px) {
  .mobile-tabs {
    display: flex;
  }
  
  .game-main {
    grid-template-columns: 1fr;
  }
  
  .panel {
    border: none !important;
    display: none;
  }
  
  .panel.mobile-visible {
    display: block;
  }
  
  .click-panel.mobile-visible {
    display: flex;
    min-height: 50vh;
  }
  
  .nut-button {
    width: 140px;
    height: 140px;
  }
  
  .nut-image {
    width: 100px;
    height: 100px;
  }
  
  .why-button {
    bottom: 10px;
    right: 10px;
  }
}

@media (max-width: 480px) {
  .game-title {
    font-size: 12px;
  }
  
  .nut-count {
    font-size: 20px;
  }
  
  .nut-button {
    width: 120px;
    height: 120px;
  }
  
  .nut-image {
    width: 80px;
    height: 80px;
  }
  
  .stats-row {
    flex-direction: column;
    gap: 4px;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border: 2px solid var(--bg-dark);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-gold);
}