:root {
  --wood-dark: #3e2314;
  --wood-mid: #5d3620;
  --wood-light: #7c4a2d;
  --parchment: #fff9ec;
  --parchment-card: #ffffff;
  --gold: #ffca28;
  --gold-deep: #f57f17;
  --green-btn: #43a047;
  --green-btn-dark: #2e7d32;
  --sky-accent: #0288d1;
  --text-main: #2d1b10;
  --text-muted: #6d5344;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background: var(--wood-dark);
  color: var(--text-main);
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
}

/* --- Wooden Farm Header --- */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #6b3e26 0%, #4a2916 100%);
  border-bottom: 3px solid #2b160b;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  color: #fff8e1;
  z-index: 10;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 2px solid var(--gold);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  object-fit: cover;
}

.game-title {
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #ffe082;
  text-shadow: 0 2px 0 #2b160b;
  line-height: 1.1;
}

.game-tagline {
  font-size: 0.76rem;
  color: #ffcc80;
  font-weight: 700;
}

.score-plank {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(28, 14, 6, 0.65);
  border: 2px solid #8d5837;
  border-radius: 14px;
  padding: 5px 18px;
  min-width: 220px;
}

.main-counter {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 1.5rem;
  font-weight: 900;
  color: #fffde7;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.6);
}

.unit-label {
  font-size: 0.85rem;
  color: #ffe082;
  font-weight: 800;
}

.sub-rates {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

.rate-chip {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 1px 8px;
  border-radius: 99px;
  background: rgba(129, 199, 132, 0.22);
  color: #a5d6a7;
}

.rate-chip.click-chip {
  background: rgba(79, 195, 247, 0.22);
  color: #81d4fa;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cookie-badge {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 99px;
  background: rgba(255, 224, 130, 0.16);
  border: 1px solid rgba(255, 224, 130, 0.4);
  color: #ffe082;
  transition: transform 0.2s, background 0.25s;
}

.cookie-badge.saved-flash {
  background: rgba(102, 187, 106, 0.45);
  color: #ffffff;
  transform: scale(1.05);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 2px solid #8d5837;
  background: #5d3620;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

/* --- Meme Quote Ticker --- */
.meme-ticker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 16px;
  background: #2b170c;
  color: #ffe0b2;
  font-size: 0.8rem;
  font-weight: 700;
  border-bottom: 2px solid #4e2c18;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticker-badge {
  color: #ffca28;
  font-weight: 900;
  flex-shrink: 0;
}

/* --- Main Split Layout --- */
.game-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  min-height: 0;
  overflow: hidden;
}

/* --- Left: Interactive Farm Canvas --- */
.farm-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 290px;
  overflow: hidden;
  background: #29b6f6;
  border-right: 3px solid #2b160b;
}

#farm-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: none;
}

.storm-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #d84315, #ff8f00, #d84315);
  color: #fffde7;
  font-weight: 900;
  font-size: 0.9rem;
  padding: 6px 16px;
  border-radius: 99px;
  border: 2px solid #fff59d;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  z-index: 5;
  white-space: nowrap;
  animation: pulseStorm 0.7s infinite alternate;
  pointer-events: none;
}

@keyframes pulseStorm {
  from { transform: translateX(-50%) scale(1); }
  to { transform: translateX(-50%) scale(1.05); }
}

.farm-hint-bar {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: rgba(34, 19, 10, 0.76);
  color: #fff8e1;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.73rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid rgba(255, 224, 130, 0.35);
}

/* --- Right: Shop & Tabs Panel --- */
.shop-panel {
  display: flex;
  flex-direction: column;
  background: var(--parchment);
  min-height: 0;
  overflow: hidden;
}

.tabs-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: #4a2916;
  padding: 6px 6px 0;
  gap: 4px;
}

.tab-btn {
  padding: 9px 4px;
  border: none;
  border-radius: 10px 10px 0 0;
  background: #6d4025;
  color: #ffe0b2;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s;
}

.tab-btn:hover {
  background: #7e4b2c;
}

.tab-btn.active {
  background: var(--parchment);
  color: var(--wood-dark);
}

.tab-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tab-pane.active {
  display: flex;
}

.pane-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f5ebd6;
  border-bottom: 1px solid #e0cfa9;
}

.pane-heading {
  font-weight: 900;
  font-size: 0.92rem;
  color: var(--wood-mid);
}

.qty-selector {
  display: flex;
  gap: 4px;
}

.qty-btn {
  padding: 4px 10px;
  border-radius: 8px;
  border: 1.5px solid #c5a880;
  background: #fff;
  color: var(--wood-mid);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.76rem;
  cursor: pointer;
}

.qty-btn.active {
  background: var(--wood-mid);
  color: #ffe082;
  border-color: var(--wood-dark);
}

.cards-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* --- Shop Cards --- */
.shop-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--parchment-card);
  border: 2px solid #e2d3b5;
  box-shadow: 0 2px 5px rgba(62, 35, 20, 0.07);
  transition: transform 0.1s, border-color 0.15s, opacity 0.15s;
}

.shop-card.affordable {
  cursor: pointer;
  border-color: #66bb6a;
}

.shop-card.affordable:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(67, 160, 71, 0.18);
}

.shop-card.affordable:active {
  transform: scale(0.985);
}

.shop-card.unaffordable {
  opacity: 0.68;
  cursor: not-allowed;
}

.shop-card.locked-card {
  background: #efe6d5;
  border-style: dashed;
  opacity: 0.75;
}

.shop-card.maxed-card {
  background: #f1f8e9;
  border-color: #aed581;
}

.card-icon {
  position: relative;
  width: 62px;
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upg-emoji, .mystery-icon {
  font-size: 2rem;
  background: #fdf3de;
  border-radius: 12px;
  border: 1.5px solid #e6d2aa;
}

.owned-pill {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--wood-dark);
  color: #ffe082;
  font-size: 0.72rem;
  font-weight: 900;
  padding: 1px 7px;
  border-radius: 99px;
  border: 1.5px solid #ffe082;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card-title {
  font-weight: 900;
  font-size: 0.94rem;
  color: var(--wood-dark);
}

.card-subtitle {
  font-size: 0.74rem;
  font-weight: 800;
  color: #b26a00;
}

.card-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.28;
}

.card-stats {
  display: flex;
  gap: 10px;
  margin-top: 5px;
  font-size: 0.73rem;
  font-weight: 800;
  color: #2e7d32;
}

.plant-badge {
  padding: 2px 8px;
  font-size: 0.68rem;
  font-weight: 800;
  border-radius: 99px;
  border: 1px solid #a5d6a7;
  background: #f1f8e9;
  color: #2e7d32;
  cursor: pointer;
}

.plant-badge.active {
  background: #2e7d32;
  color: #ffffff;
}

.lvl-tag {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 6px;
  background: #f3e5ab;
  color: #5d4037;
}

.card-buy-col {
  text-align: right;
  flex-shrink: 0;
  background: #faf2e1;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid #e6d5b8;
  min-width: 96px;
}

.shop-card.affordable .card-buy-col {
  background: linear-gradient(180deg, #66bb6a 0%, #388e3c 100%);
  border-color: #1b5e20;
  color: #fff;
}

.buy-qty-label {
  font-size: 0.68rem;
  font-weight: 800;
  opacity: 0.88;
}

.buy-price {
  font-size: 0.86rem;
  font-weight: 900;
}

.maxed-label {
  color: #2e7d32;
}

/* --- Prestige Card --- */
.prestige-card {
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff8e1 0%, #ffe082 100%);
  border: 2px solid #ffb300;
}

.prestige-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.prestige-title {
  font-weight: 900;
  font-size: 0.92rem;
  color: #5d3620;
}

.prestige-desc {
  font-size: 0.76rem;
  color: #4e342e;
  margin-top: 3px;
}

.prestige-btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 2px solid #6a1b9a;
  background: linear-gradient(180deg, #ab47bc, #7b1fa2);
  color: #fff;
  font-family: inherit;
  font-weight: 900;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}

.prestige-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* --- Achievements --- */
.ach-summary-banner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  background: #f5ebd6;
  border-bottom: 1px solid #e0cfa9;
  font-size: 0.8rem;
}

.ach-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1.5px solid #e2d3b5;
}

.ach-card.unlocked {
  border-color: #ffb300;
  background: #fffdf5;
}

.ach-card.locked {
  opacity: 0.55;
}

.ach-icon {
  font-size: 1.65rem;
  width: 42px;
  text-align: center;
}

.ach-name {
  font-weight: 900;
  font-size: 0.88rem;
}

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

/* --- Leaderboard --- */
.leader-toolbar {
  gap: 8px;
  flex-wrap: wrap;
}

.leader-toolbar label {
  font-weight: 800;
  font-size: 0.82rem;
}

.leader-toolbar input {
  flex: 1;
  min-width: 150px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1.5px solid #c5a880;
  font-family: inherit;
  font-weight: 800;
}

.leader-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1.5px solid #e2d3b5;
}

.leader-row.player-row {
  background: #fff8e1;
  border: 2px solid #ffa000;
  box-shadow: 0 2px 8px rgba(255, 160, 0, 0.2);
}

.leader-rank {
  width: 34px;
  font-weight: 900;
  font-size: 1.05rem;
  text-align: center;
}

.leader-main {
  flex: 1;
}

.leader-name {
  font-weight: 900;
  font-size: 0.9rem;
}

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

.leader-score {
  font-weight: 900;
  font-size: 0.88rem;
  color: var(--wood-mid);
}

.you-pill {
  background: #ef6c00;
  color: #fff;
  font-size: 0.66rem;
  padding: 1px 6px;
  border-radius: 99px;
  margin-left: 4px;
}

/* --- Settings & Cookie Tab --- */
.settings-box {
  background: #fff;
  border: 1.5px solid #e2d3b5;
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-box h3 {
  font-size: 0.94rem;
  color: var(--wood-dark);
}

.settings-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.cookie-stats-card {
  background: #faf3e3;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.76rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#save-code-box {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1.5px solid #c5a880;
  font-family: monospace;
  font-size: 0.75rem;
  resize: none;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.action-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: var(--green-btn);
  color: #fff;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.8rem;
  cursor: pointer;
}

.action-btn.secondary {
  background: #0288d1;
}

.action-btn.danger {
  background: #d32f2f;
}

/* --- Toasts & Modals --- */
.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.game-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(45, 25, 13, 0.95);
  color: #fff8e1;
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 10px 14px;
  max-width: 320px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  transition: opacity 0.4s, transform 0.4s;
}

.game-toast.fade-out {
  opacity: 0;
  transform: translateY(10px);
}

.toast-icon {
  font-size: 1.6rem;
}

.toast-title {
  font-weight: 900;
  font-size: 0.86rem;
  color: #ffe082;
}

.toast-body {
  font-size: 0.75rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-card {
  background: var(--parchment);
  border: 3px solid var(--gold);
  border-radius: 20px;
  padding: 24px;
  max-width: 390px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.modal-icon {
  font-size: 2.6rem;
  margin-bottom: 6px;
}

.modal-card p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 10px 0 14px;
  line-height: 1.4;
}

.offline-reward-pill {
  font-size: 1.35rem;
  font-weight: 900;
  color: #2e7d32;
  background: #e8f5e9;
  border: 2px solid #81c784;
  border-radius: 12px;
  padding: 8px 14px;
  margin-bottom: 16px;
}

.big-collect-btn {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
}

.hidden {
  display: none !important;
}

/* --- Mobile Portrait Responsiveness --- */
@media (max-width: 860px) {
  .top-header {
    padding: 6px 10px;
    flex-wrap: wrap;
  }
  .game-tagline, .cookie-badge {
    display: none;
  }
  .game-title {
    font-size: 1.02rem;
  }
  .brand-logo {
    width: 36px;
    height: 36px;
  }
  .score-plank {
    min-width: auto;
    padding: 3px 12px;
    flex: 1;
  }
  .main-counter {
    font-size: 1.2rem;
  }
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 44vh 1fr;
  }
  .farm-stage {
    border-right: none;
    border-bottom: 3px solid #2b160b;
  }
  .farm-hint-bar {
    font-size: 0.65rem;
    padding: 3px 9px;
  }
  .tab-btn {
    font-size: 0.72rem;
    padding: 8px 2px;
  }
}
