* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #1a1e1b;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #fff;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #111412;
}

#gameCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

/* ================= HUD SUPERIOR ================= */
#hud-top {
  position: absolute;
  top: 16px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-card {
  background: rgba(30, 26, 21, 0.85);
  border: 2px solid #8e6840;
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6), inset 0 1px 1px rgba(255, 255, 255, 0.1);
  pointer-events: auto;
  backdrop-filter: blur(4px);
}

.time-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 195px;
}

.millennium-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 215, 0, 0.2);
  padding-bottom: 3px;
  margin-bottom: 1px;
}

.badge-millennium {
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  font-weight: 800;
  color: #ffd700;
  text-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
  letter-spacing: 0.5px;
}

.millennium-timer {
  font-family: monospace;
  font-size: 10px;
  color: #cbd5e1;
  background: rgba(0, 0, 0, 0.4);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.calendar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
}

.badge-year {
  font-size: 10px;
  font-weight: 800;
  color: #f5deb3;
  background: #3b2d1d;
  border: 1px solid #7c5c36;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: auto;
}

.day-text {
  font-size: 12px;
  font-weight: 800;
  color: #fef08a;
}

.badge {
  font-size: 11px;
  font-weight: 700;
  color: #f7a8b8;
  letter-spacing: 0.5px;
}

.date-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #f5deb3;
}

.world-day-row {
  display: flex;
  align-items: center;
  margin-top: 1px;
}

.badge-world-day {
  font-family: monospace;
  font-size: 10px;
  color: #a7f3d0;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 4px;
  padding: 2px 6px;
  width: 100%;
  text-align: center;
}

.digital-clock {
  font-family: 'Press Start 2P', monospace;
  font-size: 13px;
  color: #00ffcc;
  text-shadow: 0 0 8px rgba(0, 255, 204, 0.5);
  letter-spacing: 1px;
}

.stats-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 170px;
}

.stat-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
}

.bar-container {
  flex: 1;
  height: 10px;
  background: #111;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #443;
}

.bar-fill {
  height: 100%;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.stamina-fill {
  background: linear-gradient(90deg, #e74c3c, #ff7675);
}

.water-fill {
  background: linear-gradient(90deg, #0984e3, #74b9ff);
}

.val-text {
  font-family: monospace;
  font-size: 11px;
  color: #e2e8f0;
  min-width: 40px;
}

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

.location-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 170px;
}

.map-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  color: #a8e6cf;
}

.map-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-mini {
  font-family: monospace;
  font-size: 10px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
  color: #f1c40f;
}

.badge-protected {
  font-size: 10px;
  font-weight: 700;
  background: rgba(46, 204, 113, 0.2);
  color: #2ecc71;
  border: 1px solid rgba(46, 204, 113, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
}

.badge-wild {
  font-size: 10px;
  font-weight: 700;
  background: rgba(230, 126, 34, 0.2);
  color: #e67e22;
  border: 1px solid rgba(230, 126, 34, 0.4);
  padding: 2px 6px;
  border-radius: 4px;
}

.map-banner {
  position: absolute;
  top: 90px;
  background: rgba(22, 28, 24, 0.95);
  border: 2px solid #2ecc71;
  border-radius: 12px;
  padding: 14px 28px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8);
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 20;
  pointer-events: none;
}

.map-banner h3 {
  font-family: 'Press Start 2P', monospace;
  font-size: 13px;
  color: #2ecc71;
  margin-bottom: 4px;
}

.map-banner p {
  font-size: 11px;
  color: #bbb;
}

.gold-icon {
  font-size: 20px;
}

.gold-amount {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #f1c40f;
  text-shadow: 0 0 6px rgba(241, 196, 15, 0.4);
}

/* ================= HOTBAR INFERIOR ================= */
#hud-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
}

.hotbar {
  display: flex;
  gap: 8px;
  background: rgba(28, 24, 20, 0.92);
  border: 3px solid #8e6840;
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  pointer-events: auto;
}

.tool-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 64px;
  background: #2b251e;
  border: 2px solid #574431;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-slot:hover {
  background: #3d352b;
  transform: translateY(-2px);
}

.tool-slot.active {
  background: #503d29;
  border-color: #f1c40f;
  box-shadow: 0 0 12px rgba(241, 196, 15, 0.6), inset 0 0 6px rgba(241, 196, 15, 0.3);
  transform: translateY(-4px);
}

.slot-num {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 9px;
  font-weight: 800;
  color: #aaa;
}

.tool-icon {
  font-size: 24px;
  margin-top: 4px;
}

.tool-name {
  font-size: 9px;
  font-weight: 700;
  color: #dfd5c6;
  margin-top: 2px;
}

/* ================= CHAT ================= */
#chat-container {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 320px;
  z-index: 10;
  pointer-events: auto;
}

#chat-messages {
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
  mask-image: linear-gradient(to bottom, transparent 0%, black 20%);
}

.chat-msg {
  background: rgba(0, 0, 0, 0.65);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
  animation: fadeIn 0.2s ease;
}

.chat-msg .sender {
  font-weight: 800;
  margin-right: 4px;
}

.chat-msg.system {
  color: #f1c40f;
  font-style: italic;
  font-size: 11px;
}

#chat-form {
  display: flex;
  gap: 6px;
}

#chat-input {
  flex: 1;
  background: rgba(20, 20, 20, 0.85);
  border: 1px solid #665;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: #fff;
  outline: none;
}

#chat-input:focus {
  border-color: #f1c40f;
  background: rgba(30, 30, 30, 0.95);
}

#chat-send {
  background: #8e6840;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
}

#chat-send:hover {
  background: #a97e4f;
}

/* ================= BANNER Y NOTIFICACIONES ================= */
.banner {
  position: absolute;
  top: 100px;
  background: rgba(20, 16, 12, 0.95);
  border: 3px solid #f1c40f;
  border-radius: 16px;
  padding: 24px 40px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.8);
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 20;
}

.banner h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: #f1c40f;
  margin-bottom: 8px;
}

.banner p {
  font-size: 14px;
  color: #ddd;
}

.report-box {
  margin-top: 12px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 13px;
  color: #2ecc71;
}

.toast {
  position: absolute;
  top: 80px;
  background: rgba(0, 0, 0, 0.85);
  border-left: 4px solid #f1c40f;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  z-index: 15;
  animation: fadeIn 0.2s ease;
}

.hidden {
  display: none !important;
}

.error-box {
  background: rgba(231, 76, 60, 0.2);
  border: 1px solid #e74c3c;
  color: #ff7675;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  animation: fadeIn 0.2s ease;
}

/* ================= MODAL INGRESO ================= */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-card {
  width: 90%;
  max-width: 440px;
  background: #231c15;
  border: 3px solid #8e6840;
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.9);
  text-align: center;
}

.logo-box {
  margin-bottom: 20px;
}

.logo-icon {
  font-size: 44px;
}

.logo-box h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  color: #f1c40f;
  margin-top: 8px;
  letter-spacing: 1px;
}

.logo-box h3 {
  font-size: 14px;
  color: #8ce8a2;
  margin-top: 4px;
}

.logo-box .subtitle {
  font-size: 11px;
  color: #a89f91;
  margin-top: 4px;
}

#join-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

#join-form label {
  font-size: 12px;
  font-weight: 700;
  color: #dfd5c6;
}

#farmer-name {
  background: #14100c;
  border: 2px solid #574431;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: #fff;
  outline: none;
}

#farmer-name:focus {
  border-color: #f1c40f;
}

.color-picker {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 6px 0;
}

.color-opt input {
  display: none;
}

.color-opt span {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.15s ease;
}

.color-opt input:checked + span {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
}

.controls-guide {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: #bbb;
}

.btn-start {
  background: linear-gradient(180deg, #27ae60, #219150);
  border: 2px solid #2ecc71;
  border-radius: 10px;
  padding: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(39, 174, 96, 0.4);
  transition: transform 0.15s ease, background 0.15s ease;
  margin-top: 6px;
}

.btn-start:hover {
  transform: translateY(-2px);
  background: linear-gradient(180deg, #2ecc71, #27ae60);
}

/* ================= CONTROLES TACTILES ================= */
#touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
}

@media (max-width: 900px), (pointer: coarse) {
  #touch-controls {
    display: block;
  }
  #chat-container {
    width: 200px;
    bottom: 90px;
  }
}

#dpad {
  position: absolute;
  left: 20px;
  bottom: 24px;
  width: 120px;
  height: 120px;
  pointer-events: auto;
}

.dbtn {
  position: absolute;
  width: 40px;
  height: 40px;
  background: rgba(40, 35, 30, 0.85);
  border: 2px solid #8e6840;
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.dbtn.up { top: 0; left: 40px; }
.dbtn.down { bottom: 0; left: 40px; }
.dbtn.left { top: 40px; left: 0; }
.dbtn.right { top: 40px; right: 0; }

#action-buttons {
  position: absolute;
  right: 20px;
  bottom: 24px;
  pointer-events: auto;
}

.abtn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(180deg, #e67e22, #d35400);
  border: 3px solid #f39c12;
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* ================= BOTÓN SHORTCUT MAPA ================= */
.btn-map-shortcut {
  background: #34495e;
  border: 1px solid #5dade2;
  border-radius: 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: 6px;
}

.btn-map-shortcut:hover {
  background: #2980b9;
  transform: scale(1.05);
}


/* ================= MARCADOR GLOBAL TOP 10 DINERO ================= */
#leaderboard-hud {
  position: absolute;
  top: 84px;
  right: 20px;
  width: 242px;
  z-index: 10;
  padding: 10px 12px;
  transition: all 0.2s ease;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 215, 0, 0.22);
  padding-bottom: 6px;
}

#leaderboard-hud.collapsed .leaderboard-header {
  border-bottom: none;
  padding-bottom: 0;
}

#leaderboard-hud.collapsed .leaderboard-list {
  display: none;
}

.leaderboard-title {
  font-size: 12px;
  font-weight: 800;
  color: #ffd700;
  text-shadow: 0 0 6px rgba(255, 215, 0, 0.35);
  letter-spacing: 0.3px;
}

.btn-leaderboard-toggle {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 215, 0, 0.35);
  border-radius: 5px;
  color: #ffd700;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-leaderboard-toggle:hover {
  background: rgba(255, 215, 0, 0.22);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 7px;
  max-height: 278px;
  overflow-y: auto;
}

.leaderboard-empty {
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
  padding: 6px 0;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 11px;
}

.leaderboard-row.rank-1 {
  background: rgba(241, 196, 15, 0.16);
  border-color: rgba(241, 196, 15, 0.45);
}

.leaderboard-row.rank-2 {
  background: rgba(203, 213, 225, 0.11);
  border-color: rgba(203, 213, 225, 0.32);
}

.leaderboard-row.rank-3 {
  background: rgba(217, 119, 6, 0.14);
  border-color: rgba(217, 119, 6, 0.38);
}

.leaderboard-row.is-self {
  border-color: #2ecc71;
  box-shadow: inset 0 0 8px rgba(46, 204, 113, 0.22);
}

.lb-left {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex: 1;
}

.lb-rank {
  font-weight: 800;
  min-width: 22px;
  text-align: center;
  color: #cbd5e1;
  font-size: 11px;
}

.lb-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #64748b;
}

.lb-status-dot.online {
  background: #2ecc71;
  box-shadow: 0 0 6px #2ecc71;
}

.lb-name {
  font-weight: 700;
  color: #f8fafc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-gold {
  font-family: monospace;
  font-weight: 800;
  color: #f1c40f;
  font-size: 11px;
  white-space: nowrap;
}

@media (max-width: 900px) {
  #leaderboard-hud {
    width: 196px;
    top: 82px;
    right: 12px;
    padding: 8px 10px;
  }
}
