:root {
  --bg:     #070d04;
  --panel:  #0f1a08;
  --border: rgba(120,180,60,0.25);
  --green:  #4ade80;
  --gold:   #fbbf24;
  --earth:  #d97706;
  --purple: #a78bfa;
  --blue:   #38bdf8;
  --red:    #ef4444;
  --text:   #e8f0d8;
  --muted:  rgba(180,210,130,0.5);
  --radius: 14px;
}
* { margin:0; padding:0; box-sizing:border-box; }

body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 90% 55% at 50% -5%, rgba(60,120,20,0.15) 0%, transparent 65%),
    radial-gradient(ellipse 40% 30% at 85% 85%, rgba(100,60,0,0.08) 0%, transparent 60%),
    repeating-linear-gradient(0deg,  transparent, transparent 48px, rgba(40,80,10,0.025) 48px, rgba(40,80,10,0.025) 49px),
    repeating-linear-gradient(90deg, transparent, transparent 48px, rgba(40,80,10,0.025) 48px, rgba(40,80,10,0.025) 49px);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar { width:6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: rgba(74,222,128,0.25); border-radius:3px; }

/* ── Header ──────────────────────────────────────────── */
header {
  width: 100%;
  background: linear-gradient(180deg, #1c100a 0%, #100b04 60%, rgba(10,8,2,0.98) 100%);
  border-bottom: 2px solid rgba(160,100,20,0.4);
  box-shadow:
    0 1px 0 rgba(255,200,80,0.08),
    0 2px 0 rgba(100,60,0,0.3),
    0 6px 30px rgba(0,0,0,0.7);
  padding: 10px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}
header::after {
  content: '';
  position: absolute;
  bottom: -3px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(74,222,128,0.15), transparent);
}
.logo {
  font-size: 1.35rem;
  font-weight: 900;
  color: #f0d080;
  text-shadow: 0 0 24px rgba(255,180,30,0.45), 0 2px 6px rgba(0,0,0,0.7);
  letter-spacing: 2.5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.logo::before { content: '🌾 '; }
.logo span { color: #4ade80; text-shadow: 0 0 18px rgba(74,222,128,0.6); }

.stats {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.chip {
  background: linear-gradient(160deg, rgba(30,18,4,0.9), rgba(18,10,2,0.95));
  border: 1px solid rgba(160,120,40,0.35);
  border-radius: 10px;
  padding: 5px 12px;
  font-size: .71rem;
  color: var(--muted);
  text-align: center;
  min-width: 64px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,200,60,0.06);
}
.chip b {
  color: var(--gold);
  font-size: .92rem;
  display: block;
  text-shadow: 0 0 10px rgba(251,191,36,0.45);
}

/* ── Badge usuario ───────────────────────────────────── */
#userBadge {
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(0,18,5,0.8);
  border: 1px solid rgba(74,222,128,0.28);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .78rem;
  color: var(--green);
  white-space: nowrap;
  box-shadow: 0 0 12px rgba(74,222,128,0.08);
}
#userBadge b { font-size: .82rem; }
#userBadge button {
  background: rgba(239,68,68,0.18);
  border: 1px solid rgba(239,68,68,0.4);
  color: var(--red);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: .68rem;
  cursor: pointer;
  font-family: inherit;
  margin-left: 4px;
  transition: background .2s;
}
#userBadge button:hover { background: rgba(239,68,68,0.32); }

/* ── Grid principal ──────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 22px;
  padding: 22px 20px 32px;
  max-width: 970px;
  width: 100%;
}

/* ── Game section ────────────────────────────────────── */
.game-section { display: flex; flex-direction: column; gap: 0; }
.game-section h2 {
  font-size: .68rem;
  color: var(--muted);
  letter-spacing: 3.5px;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.canvas-frame {
  background: linear-gradient(145deg, #3a1c05, #221004, #3a1c05);
  border-radius: 18px;
  padding: 14px;
  box-shadow:
    0 0 0 1px rgba(200,140,40,0.18),
    0 0 0 3px rgba(50,22,2,0.9),
    0 10px 50px rgba(0,0,0,0.8),
    inset 0 1px 0 rgba(255,200,80,0.1),
    inset 0 -1px 0 rgba(0,0,0,0.5);
  position: relative;
  overflow: visible;
  display: inline-block;
}
.canvas-frame::before,
.canvas-frame::after {
  content: '🌿';
  position: absolute;
  font-size: 1.2rem;
  opacity: 0.55;
  filter: drop-shadow(0 0 8px rgba(74,222,128,0.35));
}
.canvas-frame::before { top: 7px; left: 11px; }
.canvas-frame::after  { top: 7px; right: 11px; transform: scaleX(-1); }

#gameCanvas {
  display: block;
  border-radius: 10px;
  border: 1px solid rgba(50,30,6,0.7);
  background: #020902;
  cursor: pointer;
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.45),
    inset 0 0 0 1px rgba(255,255,255,0.02);
  max-width: 100%;
}

.canvas-soil {
  background: linear-gradient(180deg, #1a0d03 0%, #0c0701 100%);
  border-radius: 0 0 14px 14px;
  height: 7px;
  margin: 0 5px;
  box-shadow: 0 5px 14px rgba(0,0,0,0.6);
}
.spawn-timer {
  margin-top: 10px;
  font-size: .70rem;
  color: var(--muted);
  text-align: center;
  padding: 7px 16px;
  background: linear-gradient(135deg, rgba(18,28,8,0.7), rgba(12,18,5,0.8));
  border: 1px solid rgba(80,120,30,0.22);
  border-radius: 22px;
  letter-spacing: .3px;
}

/* ── Paneles ─────────────────────────────────────────── */
.side-panel { display: flex; flex-direction: column; gap: 11px; }

.panel {
  background: linear-gradient(155deg, #101a07 0%, #0b1305 55%, #0e1808 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 4px 18px rgba(0,0,0,0.45),
    0 1px 0 rgba(255,255,255,0.02),
    inset 0 1px 0 rgba(120,180,60,0.07);
  transition: box-shadow .3s;
}
.panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--green), transparent);
  opacity: 0.5;
}
.panel.blue::before  { background: linear-gradient(90deg, transparent, var(--blue),  transparent); }
.panel.gold::before  { background: linear-gradient(90deg, transparent, var(--gold),  transparent); }
.panel.earth::before { background: linear-gradient(90deg, transparent, var(--earth), transparent); }
.panel.red::before   { background: linear-gradient(90deg, transparent, var(--red),   transparent); }

.panel-title {
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: 2.5px;
  color: var(--muted);
  margin-bottom: 11px;
  text-transform: uppercase;
}

/* ── Avatar del jugador ──────────────────────────────── */
.avatar-section {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
#avatarCanvas {
  border-radius: 12px;
  background: rgba(5,12,3,0.7);
  border: 1px solid rgba(74,222,128,0.2);
  box-shadow: 0 0 18px rgba(74,222,128,0.12), inset 0 0 8px rgba(0,0,0,0.4);
  flex-shrink: 0;
}
.avatar-info { flex: 1; }

/* ── Barra XP ────────────────────────────────────────── */
.level-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.level-badge {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3d1e04, #7a3c0c);
  border: 2px solid rgba(200,140,40,0.45);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: .8rem;
  color: var(--gold); flex-shrink: 0;
  box-shadow: 0 0 18px rgba(200,140,40,0.25), inset 0 1px 0 rgba(255,200,60,0.12);
}
.level-info  { flex: 1; }
.level-name  { font-size: .78rem; font-weight: 700; color: #86efac; margin-bottom: 4px; letter-spacing: .3px; }
.xp-bar-track {
  background: rgba(3,8,2,0.9);
  border: 1px solid rgba(60,120,20,0.25);
  border-radius: 5px; height: 9px; overflow: hidden; margin-bottom: 3px;
}
.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #14532d, #22c55e, #4ade80);
  border-radius: 5px; transition: width .6s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 0 8px rgba(74,222,128,0.45);
}
.xp-text { font-size: .67rem; color: rgba(120,200,100,0.55); }
.unlock-hint {
  font-size: .66rem; color: rgba(180,210,100,0.45);
  text-align: center; padding: 5px 10px;
  border: 1px solid rgba(80,120,30,0.18); border-radius: 8px;
  margin-top: 6px; background: rgba(8,16,3,0.5);
  line-height: 1.5;
}

/* ── Wallet ──────────────────────────────────────────── */
.wallet-addr {
  background: rgba(0,8,0,0.6);
  border: 1px solid rgba(60,120,20,0.25);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: 'Courier New', monospace;
  font-size: .73rem;
  margin-bottom: 8px;
  color: rgba(180,220,120,0.65);
  word-break: break-all;
}
.badge-row { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .63rem;
  font-weight: 700;
  border: 1px solid;
  letter-spacing: .5px;
}
.badge.green  { color: #4ade80; border-color: rgba(74,222,128,0.5);   background: rgba(0,50,18,0.5); }
.badge.blue   { color: #38bdf8; border-color: rgba(56,189,248,0.5);   background: rgba(0,18,50,0.5); }
.badge.purple { color: #c084fc; border-color: rgba(192,132,252,0.5);  background: rgba(38,0,70,0.5); }

/* ── Inventario ──────────────────────────────────────── */
.inv-row { display: flex; gap: 8px; margin-bottom: 8px; }
.inv-item {
  flex: 1;
  background: linear-gradient(155deg, rgba(10,18,5,0.8), rgba(6,12,3,0.9));
  border: 1px solid rgba(80,120,30,0.28);
  border-radius: 11px; padding: 8px 10px;
  display: flex; align-items: center; gap: 8px;
  transition: border-color .2s;
}
.inv-item:hover { border-color: rgba(80,120,30,0.5); }
.inv-emoji { font-size: 1.35rem; flex-shrink: 0; filter: drop-shadow(0 0 5px rgba(74,222,128,0.3)); }
.inv-info  { flex: 1; }
.inv-label { font-size: .58rem; color: var(--muted); letter-spacing: .6px; text-transform: uppercase; }
.inv-value { font-size: .92rem; font-weight: 900; color: white; }
.inv-hint  { font-size: .54rem; color: rgba(120,160,80,0.4); text-align: right; align-self: flex-end; }
.inv-guide {
  font-size: .63rem; color: rgba(140,190,100,0.48);
  text-align: center; line-height: 1.65;
  border: 1px solid rgba(60,100,20,0.18); border-radius: 9px;
  padding: 6px 10px; background: rgba(4,10,2,0.6);
}

/* ── ZEN Points ──────────────────────────────────────── */
.zen-points-display {
  text-align: center; font-size: 2rem; font-weight: 900;
  color: var(--gold); margin-bottom: 8px;
  text-shadow: 0 0 24px rgba(251,191,36,0.45); letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}
.zen-bar-track {
  background: rgba(5,3,0,0.9);
  border: 1px solid rgba(100,80,20,0.35);
  border-radius: 5px; height: 15px; overflow: hidden; margin-bottom: 6px;
  position: relative;
}
.zen-bar-track::after {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent, transparent 18px, rgba(255,255,255,0.025) 18px, rgba(255,255,255,0.025) 19px);
  pointer-events: none;
}
.zen-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #78350f, #d97706, #f59e0b, #fbbf24);
  border-radius: 5px; transition: width .7s cubic-bezier(.34,1.4,.64,1);
  box-shadow: 0 0 12px rgba(251,191,36,0.35);
}
.merge-hint { font-size: .68rem; color: var(--muted); text-align: center; }

/* ── Cadena de Evolución ─────────────────────────────── */
.chain {
  display: flex; align-items: center;
  justify-content: space-between;
  gap: 2px; overflow-x: auto; padding: 4px 2px;
  scrollbar-width: none;
}
.chain::-webkit-scrollbar { display: none; }
.chain-node { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 28px; }
.chain-node .emoji {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; border: 1.5px solid rgba(80,120,30,0.45);
  background: rgba(4,12,3,0.9); transition: all .4s;
}
.chain-node:not(.locked) .emoji { box-shadow: 0 0 10px rgba(74,222,128,0.22); }
.chain-node.zen .emoji { border-color: var(--gold); background: rgba(50,28,0,0.95); box-shadow: 0 0 14px rgba(251,191,36,0.35); }
.chain-node span  { font-size: .5rem; color: var(--muted); text-align: center; }
.chain-node small { font-size: .45rem; color: rgba(120,160,80,0.32); }
.chain-arrow { color: rgba(80,120,40,0.3); font-size: .62rem; flex-shrink: 0; }
.chain-node.locked .emoji { filter: grayscale(100%) brightness(0.28); border-color: rgba(55,55,38,0.3); }
.chain-node.locked span,
.chain-node.locked small { color: rgba(75,75,55,0.38); }

/* ── Leaderboard ─────────────────────────────────────── */
.lb-row { display: flex; align-items: center; padding: 5px 7px; border-radius: 8px; gap: 8px; border: 1px solid transparent; margin-bottom: 3px; transition: background .2s; }
.lb-row.you { background: rgba(74,222,128,0.07); border-color: rgba(74,222,128,0.25); }
.lb-medal { width: 20px; text-align: center; font-size: .85rem; }
.lb-name  { flex: 1; font-size: .71rem; color: var(--muted); }
.lb-pts   { font-size: .76rem; font-weight: 700; color: var(--gold); }

/* ── Botones de acción ───────────────────────────────── */
.action-bar { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1;
  padding: 11px 8px;
  border-radius: 11px;
  border: 1.5px solid;
  color: white;
  font-weight: 800;
  font-size: .76rem;
  cursor: pointer;
  transition: all .2s cubic-bezier(.34,1.56,.64,1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 56px;
  text-align: center;
  background: transparent;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}
.btn::before {
  content: '';
  position: absolute; inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity .2s;
}
.btn:hover:not(:disabled)::before { opacity: .08; }
.btn.purple { border-color: #a78bfa; color: #a78bfa; background: rgba(80,40,180,0.15); }
.btn.blue   { border-color: #38bdf8; color: #38bdf8; background: rgba(10,55,110,0.22); }
.btn.gold   { border-color: #fbbf24; color: #fbbf24; background: rgba(75,45,0,0.28); }
.btn.red    { border-color: #ef4444; color: #ef4444; background: rgba(90,8,8,0.2); }
.btn:hover:not(:disabled)  { transform: translateY(-3px); filter: brightness(1.18); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }
.btn:active:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .3; filter: grayscale(70%); }

/* ── Save / Toast ────────────────────────────────────── */
#saveIndicator {
  position: fixed; top: 66px; right: 16px;
  font-size: .63rem; color: rgba(74,222,128,0.7);
  opacity: 0; transition: opacity .4s; z-index: 200;
  pointer-events: none; background: rgba(8,18,4,0.92);
  padding: 4px 12px; border-radius: 8px;
  border: 1px solid rgba(74,222,128,0.22);
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
#saveIndicator.show { opacity: 1; }

#toast {
  position: fixed; bottom: 26px; right: 26px;
  background: rgba(6,12,3,0.97);
  border: 1.5px solid var(--green); border-radius: 14px;
  padding: 12px 20px; font-size: .82rem;
  opacity: 0; transform: translateY(12px);
  transition: all .3s cubic-bezier(.34,1.56,.64,1); z-index: 999;
  max-width: 310px; pointer-events: none;
  box-shadow: 0 10px 36px rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}
#toast.show { opacity: 1; transform: translateY(0); }

/* ── LEVEL-UP flash ──────────────────────────────────── */
@keyframes levelUpFlash {
  0%   { box-shadow: 0 0 0 0   rgba(251,191,36,0); }
  40%  { box-shadow: 0 0 0 12px rgba(251,191,36,0.3); }
  100% { box-shadow: 0 0 0 24px rgba(251,191,36,0); }
}
.levelup-flash { animation: levelUpFlash .8s ease-out; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 820px) {
  .main { grid-template-columns: 1fr; max-width: 100%; padding: 14px 10px 24px; }
  header { padding: 9px 14px; }
  .logo  { font-size: 1.05rem; letter-spacing: 1.5px; }
  .stats { gap: 4px; }
  .chip  { min-width: 52px; padding: 4px 8px; font-size: .63rem; }
  .action-bar { flex-wrap: wrap; }
  .btn { min-width: 105px; min-height: 50px; font-size: .7rem; }
  .side-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .side-panel .panel:first-child,
  .side-panel .panel:last-child { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .side-panel { grid-template-columns: 1fr; }
  .side-panel .panel:first-child,
  .side-panel .panel:last-child { grid-column: auto; }
}