/* ═══════════════════════════════════════════
   HARVEST HEROES — Playful Farm Battle Game
   ═══════════════════════════════════════════ */

:root {
  --sky: #87CEEB;
  --sky-top: #5BB5E8;
  --grass: #4CAF50;
  --grass-dark: #388E3C;
  --soil: #8B6914;
  --soil-dark: #6B4F12;
  --gold: #FFD700;
  --gold-dark: #E6AC00;
  --orange: #FF8C00;
  --red: #E53935;
  --pink: #FF6B9D;
  --blue: #2196F3;
  --blue-dark: #1565C0;
  --white: #FFFEF5;
  --brown: #5D4037;
  --shadow: rgba(0,0,0,0.15);
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Nunito', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: var(--font-body);
}

#game-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* ─── Screens ─── */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }
.screen.overlay {
  z-index: 100;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
}
.screen.overlay.hidden { display: none; }

/* ═══════════════════
   TITLE SCREEN
   ═══════════════════ */
.title-bg {
  flex: 1;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky) 40%, var(--grass) 70%, var(--grass-dark) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.cloud {
  position: absolute;
  font-size: 3rem;
  opacity: 0.7;
  animation: floatCloud 20s linear infinite;
}
.cloud-1 { top: 8%; left: -10%; animation-delay: 0s; }
.cloud-2 { top: 15%; left: -10%; animation-delay: -7s; font-size: 2.5rem; }
.cloud-3 { top: 5%; left: -10%; animation-delay: -13s; font-size: 3.5rem; }

@keyframes floatCloud {
  from { transform: translateX(-10vw); }
  to { transform: translateX(110vw); }
}

.sun {
  position: absolute;
  top: 5%;
  right: 10%;
  font-size: 4rem;
  animation: sunPulse 3s ease-in-out infinite;
}
@keyframes sunPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.game-title {
  font-family: var(--font-display);
  font-size: clamp(3rem, 12vw, 6rem);
  font-weight: 700;
  color: var(--white);
  text-align: center;
  text-shadow:
    4px 4px 0 var(--orange),
    6px 6px 0 var(--brown),
    0 0 30px rgba(255,215,0,0.4);
  line-height: 1.1;
  margin-bottom: 0.3em;
  animation: titleBounce 2s ease-in-out infinite;
}
@keyframes titleBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.title-emoji {
  font-size: clamp(1.8rem, 6vw, 3rem);
  letter-spacing: 0.3em;
  margin-bottom: 2rem;
  animation: titleBounce 2s ease-in-out infinite;
  animation-delay: 0.3s;
}

.player-select {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 1rem;
}

/* ─── Buttons ─── */
.btn {
  font-family: var(--font-display);
  font-size: clamp(1rem, 4vw, 1.4rem);
  font-weight: 700;
  border: none;
  border-radius: 1rem;
  padding: 0.8em 1.5em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5em;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.btn:active {
  transform: scale(0.93) !important;
}
.btn-icon {
  font-size: 1.4em;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: var(--white);
  box-shadow: 0 6px 0 #0D47A1, 0 8px 20px var(--shadow);
}
.btn-primary:active { box-shadow: 0 2px 0 #0D47A1; transform: translateY(4px) scale(0.93) !important; }

.btn-secondary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--brown);
  box-shadow: 0 6px 0 #B8860B, 0 8px 20px var(--shadow);
}
.btn-secondary:active { box-shadow: 0 2px 0 #B8860B; transform: translateY(4px) scale(0.93) !important; }

.btn-start {
  background: linear-gradient(135deg, var(--grass), var(--grass-dark));
  color: var(--white);
  box-shadow: 0 6px 0 #1B5E20, 0 8px 20px var(--shadow);
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  margin-top: 1.5rem;
}
.btn-start.disabled { opacity: 0.4; pointer-events: none; }
.btn-start:active { box-shadow: 0 2px 0 #1B5E20; transform: translateY(4px) scale(0.93) !important; }

.btn-close {
  background: var(--red);
  color: var(--white);
  box-shadow: 0 4px 0 #B71C1C;
  margin-top: 1rem;
}

.bounce {
  animation: btnBounce 1.5s ease-in-out infinite;
}
.bounce:nth-child(2) { animation-delay: 0.2s; }
@keyframes btnBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* ═══════════════════
   FARMER SELECT
   ═══════════════════ */
.farmer-select-bg {
  flex: 1;
  background: linear-gradient(180deg, #FFF9C4 0%, #FFE082 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.section-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  color: var(--brown);
  margin-bottom: 1.5rem;
  text-shadow: 2px 2px 0 rgba(255,255,255,0.5);
}

.farmer-carousel {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 400px;
}

.farmer-card {
  width: 80px;
  height: 100px;
  background: var(--white);
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 3px solid transparent;
  box-shadow: 0 4px 12px var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}
.farmer-card.selected {
  border-color: var(--blue);
  background: #E3F2FD;
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(33,150,243,0.3);
}
.farmer-avatar { font-size: 2.2rem; }
.farmer-name {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--brown);
  font-weight: 600;
}

/* ═══════════════════
   SEED SELECT
   ═══════════════════ */
.seeds-bg {
  flex: 1;
  background: linear-gradient(180deg, #C8E6C9 0%, #81C784 60%, var(--grass-dark) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.seed-count {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--white);
  background: var(--brown);
  border-radius: 2rem;
  padding: 0.3em 1em;
  margin-bottom: 1rem;
}

/* Swipeable seed container */
.swipe-hint {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
  margin-bottom: 0.5rem;
}

.seed-swipe-container {
  width: 100%;
  max-width: 360px;
  overflow: hidden;
  position: relative;
}

.seed-track {
  display: flex;
  transition: transform 0.3s ease;
}

.seed-page {
  min-width: 100%;
  flex-shrink: 0;
  padding: 0 0.5rem;
}

.seed-page-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--white);
  text-align: center;
  margin-bottom: 0.6rem;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.seed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.page-dots {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.8rem 0;
}
.page-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  cursor: pointer;
  transition: all 0.2s;
}
.page-dot.active {
  background: var(--white);
  transform: scale(1.3);
}

.seed-card {
  background: var(--white);
  border-radius: 1rem;
  padding: 0.8rem;
  text-align: center;
  border: 3px solid transparent;
  box-shadow: 0 4px 10px var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}
.seed-card.selected {
  border-color: var(--gold);
  background: #FFF8E1;
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(255,215,0,0.4);
}
.seed-card .seed-emoji { font-size: 2rem; }
.seed-card .seed-name {
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--brown);
  margin-top: 0.3rem;
  font-weight: 600;
}

/* ═══════════════════
   GAME VIEWPORT
   ═══════════════════ */
#screen-game {
  flex-direction: column;
  background: #000;
}

.game-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.game-viewport.hidden { display: none; }

.game-viewport canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* ─── HUD ─── */
.hud {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  right: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}
.hud-player {
  background: rgba(0,0,0,0.5);
  border-radius: 2rem;
  padding: 0.2em 0.7em;
  color: var(--white);
  font-family: var(--font-display);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.3em;
}
.hud-weight {
  background: rgba(0,0,0,0.5);
  border-radius: 2rem;
  padding: 0.2em 0.7em;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}
.hud-tool {
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

/* ─── Action Button ─── */
.action-btn {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--orange));
  border: 4px solid var(--white);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  animation: actionPulse 1.2s ease-in-out infinite;
}
.action-btn.hidden { display: none; }
.action-icon { font-size: 1.8rem; }

@keyframes actionPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
  50% { transform: scale(1.1); box-shadow: 0 4px 24px rgba(255,165,0,0.5); }
}

/* ─── HUD held items ─── */
.hud-held {
  background: rgba(0,0,0,0.5);
  border-radius: 2rem;
  padding: 0.2em 0.5em;
  font-size: 1.1rem;
  min-width: 2rem;
  text-align: center;
}

/* ═══════════════════
   SHED SCREEN
   ═══════════════════ */
.shed-panel {
  background: linear-gradient(180deg, #EFEBE9 0%, #D7CCC8 100%);
  border-radius: 1.5rem;
  padding: 2rem;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.shed-items {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.8rem;
  width: 100%;
}

.shed-item {
  background: var(--white);
  border-radius: 1rem;
  padding: 1rem;
  text-align: center;
  border: 3px solid transparent;
  box-shadow: 0 4px 10px var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}
.shed-item:active {
  transform: scale(0.93);
  border-color: var(--blue);
}
.shed-item.upgrade {
  grid-column: span 2;
  background: linear-gradient(135deg, #FFF8E1, #FFE082);
  border-color: var(--gold);
}
.shed-icon { font-size: 2rem; }
.shed-label {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--brown);
  margin-top: 0.3rem;
}

/* ═══════════════════
   RESULT SCREEN
   ═══════════════════ */
.result-bg {
  flex: 1;
  background: linear-gradient(180deg, #FFF9C4 0%, #FFD54F 40%, #FFB300 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  position: relative;
  overflow: hidden;
}
.result-bg::before {
  content: '🪙🪙🪙🪙🪙💰💰💵💵💴';
  position: absolute;
  font-size: 2.5rem;
  word-spacing: 0.5rem;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0.4;
  animation: coinFloat 3s ease-in-out infinite;
}
@keyframes coinFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-10px); }
}

.result-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 3rem);
  color: var(--brown);
  text-shadow: 2px 2px 0 rgba(255,255,255,0.5);
  margin-bottom: 1.5rem;
}

.result-players {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.result-card {
  background: var(--white);
  border-radius: 1.2rem;
  padding: 1.2rem 1.5rem;
  text-align: center;
  box-shadow: 0 6px 20px var(--shadow);
  min-width: 120px;
}
.result-card.winner {
  border: 4px solid var(--gold);
  box-shadow: 0 6px 24px rgba(255,215,0,0.5);
}
.result-card .rc-avatar { font-size: 2.5rem; }
.result-card .rc-name {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--brown);
}
.result-card .rc-weight {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--grass-dark);
}
.result-card .rc-days {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--brown);
  margin-top: 0.2rem;
}

.result-winner {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  color: var(--red);
  text-shadow: 1px 1px 0 var(--white);
  margin-bottom: 1.5rem;
}

.result-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
