:root { --bg:#fff; --fg:#14213d; --muted:#667; --accent:#0b6e4f; --card:#ffffffee; --line:#d8dee9; }
@media (prefers-color-scheme: dark) { :root { --bg:#10151c; --fg:#e8edf4; --muted:#9aa6b6; --accent:#3ddc97; --card:#151c26ee; --line:#2a3544; } }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font: 15px/1.4 system-ui, sans-serif; background: var(--bg); color: var(--fg); }
#map { position: fixed; inset: 0; }
.bar { position: fixed; top: 10px; left: 10px; right: 10px; z-index: 1000; display: flex; gap: 8px; align-items: center;
  background: var(--card); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.bar h1 { font-size: 17px; margin: 0; margin-right: auto; }
.stats { color: var(--muted); font-size: 13px; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 8px; padding: 6px 10px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); width: 100%; padding: 10px; font-weight: 600; }
.hint { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 1000; background: var(--card); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; pointer-events: none; }
.panel { position: fixed; z-index: 1100; right: 12px; bottom: 12px; width: min(360px, calc(100vw - 24px)); max-height: calc(100vh - 90px); overflow: auto;
  background: var(--card); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.panel h2 { margin: 0 0 2px; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.owner { font-size: 17px; margin: 8px 0 2px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input { width: 100%; font: inherit; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); margin-bottom: 10px; }
.msg { min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.msg.err { color: #d62828; } .msg.ok { color: var(--accent); font-weight: 600; }
.close { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 2px 8px; }
.hidden { display: none !important; }
.modal { position: fixed; inset: 0; z-index: 2000; background: #0008; display: grid; place-items: center; padding: 16px; }
.modal-card { position: relative; background: var(--bg); border-radius: 14px; padding: 20px 24px; width: min(380px, 100%); }
.modal-card h2 { margin-top: 0; }
.leaflet-tooltip.owner-tip { background: transparent; border: 0; box-shadow: none; color: #fff; font-weight: 700; font-size: 11px; text-shadow: 0 1px 2px #000; padding: 0; }
.leaflet-tooltip.owner-tip::before { display: none; }

/* Casas en las parcelas compradas (emoji antiguo, ya no se usa) */
.house-marker {
  background: transparent !important;
  border: none !important;
}

.house-marker span {
  display: block;
  width: 32px;
  height: 32px;
  font-size: 27px;
  line-height: 32px;
  text-align: center;
  cursor: pointer;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
  user-select: none;
}

/* PayPal más pequeño: botones más estrechos y centrados */
#paypal-box, #paypal-box-2 { max-width: 220px; margin: 4px auto 0; }
#stripe-box, #stripe-box-2 { max-width: 220px; margin: 4px auto 0; }
#stripe-box button, #stripe-box-2 button { display: block; width: 100%; min-height: 38px; }
/* Google Pay bajo la tarjeta: abre el mismo pago de Stripe */
#stripe-box .gpay, #stripe-box-2 .gpay { margin-top: 8px; background: #000; color: #fff; border: 0; border-radius: 8px; font-weight: 600; }
#stripe-box .gpay b, #stripe-box-2 .gpay b { color: #4285f4; }
#stripe-box .gpay.official, #stripe-box-2 .gpay.official { background: transparent; padding: 0; min-height: 0; }
.gpay-img { display: block; height: 40px; max-width: 100%; margin: 0 auto; }

/* Botón "Tarjeta" bajo PayPal (móvil): lleva a la página de pago de PayPal */
.pp-card { display: block; width: 100%; height: 30px; margin-top: 8px; padding: 0; border: 0; border-radius: 4px; background: #2c2e2f; color: #fff;
  font: 600 14px/1 system-ui, sans-serif; cursor: pointer; }
.pp-card:disabled { opacity: 0.6; }

/* Fotos de las casas compradas */
.house-img { border-radius: 3px; }
.owner-label { background: transparent !important; border: 0 !important; }
/* Nombre del dueño centrado dentro de su casa; el tamaño sigue al de la parcela en pantalla (--ppx, ver syncLabels) */
.owner-pill { position: absolute; left: 0; top: calc(var(--ppx, 60) * .5px - 3px); transform: translate(-50%, -100%); white-space: nowrap; pointer-events: none;
  max-width: calc(var(--ppx, 60) * .92px); overflow: hidden; text-overflow: ellipsis; text-align: center;
  background: rgba(0,0,0,.7); color: #fff; font-family: system-ui, sans-serif; font-weight: 700; line-height: 1.2;
  font-size: clamp(5px, calc(var(--ppx, 60) * 1px / 13), 10px); padding: 1px 5px; border-radius: 999px; }
.labels-off .owner-pill { display: none; }
.p-photo { display: block; width: 100%; height: 120px; object-fit: cover; border-radius: 10px; margin: 6px 0 4px; }

/* ===== CABECERA ADAPTADA A MÓVILES ===== */

@media (max-width: 600px) {
  * {
    box-sizing: border-box;
  }

  .bar {
    width: calc(100% - 20px);
    max-width: 100%;
    margin: 10px auto;
    padding: 10px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) repeat(3, 48px);
    align-items: center;
    gap: 6px;
    overflow: hidden;
  }

  .bar h1 {
    font-size: 19px;
    line-height: 1.2;
    margin: 0;
    min-width: 0;
  }

  .bar .stats,
  #stats {
    display: none;
  }

  .bar button {
    width: 48px;
    min-width: 0;
    height: 48px;
    padding: 0;
    margin: 0;
    font-size: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    overflow: hidden;
  }

  #locate::before {
    content: "📍";
    font-size: 23px;
  }

  #rank-btn::before {
    content: "🏆";
    font-size: 23px;
  }

  #account-btn::before {
    content: "👤";
    font-size: 23px;
  }

  .hint {
    max-width: calc(100% - 40px);
    font-size: 14px;
    padding: 10px;
  }
}
#hint {
  display: none !important;
}

/* ===== PANEL DE TERRENO COMPACTO EN MÓVIL ===== */
@media (max-width: 600px) {
  .panel {
    left: 8px; right: 8px; bottom: 8px;
    width: auto;
    max-height: 48vh;
    padding: 10px 12px;
    overscroll-behavior: contain;
  }
  .panel h2 { font-size: 16px; padding-right: 28px; }
  .panel p { margin: 4px 0; }
  .panel .muted { font-size: 12px; margin: 0 0 4px; }
  .panel label { margin: 6px 0 2px; font-size: 12px; }
  .panel input, .panel select { padding: 7px 9px; margin-bottom: 6px; font-size: 14px; }
  #avatars { flex-wrap: nowrap !important; overflow-x: auto; gap: 4px !important; margin-bottom: 6px !important; padding-bottom: 2px; }
  #avatars button { flex: 0 0 auto; font-size: 20px !important; padding: 2px 6px; }
  #country { padding: 7px 9px !important; margin-bottom: 6px !important; }
  .p-photo { height: 80px; }
  #paypal-box { margin-top: 2px; }
  button.primary { padding: 8px; }
}

/* Anillo rojo parpadeante: zona donde puedes reclamar terrenos (500 m), sin relleno */
path.buy-range {
  stroke: #e63946; stroke-width: 3; fill: none; fill-opacity: 0;
  animation: buyblink 1.2s ease-in-out infinite;
}
@keyframes buyblink {
  0%, 100% { stroke-opacity: 1; }
  50%      { stroke-opacity: 0.2; }
}
@media (prefers-reduced-motion: reduce) { path.buy-range { animation: none; } }

/* Muñeco que pasea (da créditos al tocarlo) */
#walker {
  position: fixed; z-index: 900; width: 64px; height: 64px; padding: 0 !important;
  border: 0 !important; background: transparent !important; font-size: 46px; line-height: 1;
  cursor: pointer; filter: drop-shadow(0 3px 3px rgba(0,0,0,.45)); touch-action: manipulation;
}
#walker span { display: block; animation: walkerbob .45s ease-in-out infinite; }
@keyframes walkerbob { 0%,100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-7px) rotate(6deg); } }
.walker-float {
  position: fixed; z-index: 1001; pointer-events: none; font-weight: 800; font-size: 20px; color: #fff;
  text-shadow: 0 1px 3px #000, 0 0 8px #000; animation: walkerfloat 1.5s ease-out forwards;
}
@keyframes walkerfloat { 0% { opacity: 1; transform: translateY(0) scale(1.1); } 100% { opacity: 0; transform: translateY(-60px) scale(1); } }

/* Jugadores en línea: botón flotante a la izquierda (encima de "mis terrenos" y del regalo diario) */
#online-btn { position: fixed; left: 12px; bottom: 156px; z-index: 1000; width: 56px; height: 56px; border-radius: 50%; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; line-height: 1;
  border: 1px solid var(--line); background: var(--card); color: var(--fg); box-shadow: 0 2px 8px rgba(0,0,0,.3); touch-action: manipulation; }
#online-btn b { font-size: 17px; font-weight: 800; }
#online-btn small { font-size: 9px; font-weight: 600; color: var(--muted); }
#online-btn i { position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: #2ecc71; border: 2px solid var(--bg); animation: onlinepulse 1.8s infinite; }
#online-btn.off i { background: #9aa6b6; animation: none; }
#online-tip { position: fixed; left: 76px; bottom: 172px; z-index: 1000; padding: 6px 12px; border-radius: 999px; white-space: nowrap;
  background: var(--card); color: var(--fg); border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.3); font-size: 13px; font-weight: 600;
  opacity: 0; transform: translateX(-6px); pointer-events: none; transition: opacity .2s, transform .2s; }
#online-tip.show { opacity: 1; transform: none; }
#online-tip:empty { display: none; }
@keyframes onlinepulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(46,204,113,.6); } 70% { box-shadow: 0 0 0 7px rgba(46,204,113,0); } }
@media (prefers-reduced-motion: reduce) { #online-btn i { animation: none; } #online-tip { transition: none; } }

/* Invita y gana: botón flotante a la izquierda (encima del de jugadores en línea) */
#invite-btn { position: fixed; left: 12px; bottom: 222px; z-index: 1000; width: 56px; height: 56px; border-radius: 50%; padding: 0; font-size: 28px; line-height: 1;
  display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: var(--card);
  box-shadow: 0 2px 8px rgba(0,0,0,.3); touch-action: manipulation; }
#toast { position: fixed; left: 50%; top: 70px; z-index: 3000; width: min(92vw, 380px); transform: translate(-50%, -12px); padding: 12px 16px; border-radius: 14px;
  background: rgba(11,61,46,.96); color: #fff; font-size: 15px; font-weight: 600; text-align: center; box-shadow: 0 4px 18px rgba(0,0,0,.45);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* Nivel del terreno: estrellas encima del nombre (mismo tamaño que el nombre, ver .owner-pill) */
.owner-stars { position: absolute; left: 0; top: calc(var(--ppx, 60) * .5px - 3px); transform: translate(-50%, -100%); white-space: nowrap; pointer-events: none;
  color: #ffd43b; line-height: 1; letter-spacing: .5px; text-shadow: 0 1px 2px #000;
  font-size: clamp(5px, calc(var(--ppx, 60) * 1px / 13), 10px); }
.labels-off .owner-stars { display: none; }

/* Chat por zona */
#chat-list { height: min(46vh, 340px); overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.chat-msg { margin: 0 0 9px; word-break: break-word; }
.chat-msg .who { font-weight: 700; font-size: 13px; border: 0; background: transparent; padding: 0; color: inherit; cursor: pointer; text-align: left; }
.chat-msg.mine .who { color: var(--accent); }
.chat-msg .when { color: var(--muted); font-size: 11px; margin-left: 6px; }
.chat-msg .del { float: right; padding: 0 6px; border: 0; background: transparent; }
.chat-msg .text { font-size: 15px; }
#chat-form { display: flex; gap: 6px; }
#chat-form input { margin: 0; flex: 1; min-width: 0; }
#chat-form button { width: auto; padding: 8px 14px; }
#chat-friends-btn { width: 100%; margin-top: 4px; }
#chat-friends { height: min(46vh, 340px); overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.chat-friend { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.chat-friend .who { flex: 1; font-weight: 700; font-size: 15px; }
.chat-friend button { padding: 4px 10px; }
#chat-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 0 0 8px; }
.chat-card-name { font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.chat-card-btns { display: flex; gap: 6px; }
.chat-card-btns button { width: auto; flex: 1; padding: 8px; }
.chat-msg .reacts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 3px; }
.chat-msg .reacts button { padding: 1px 8px; border-radius: 999px; font-size: 13px; }
.chat-msg .reacts button.on { border-color: var(--accent); background: #0b6e4f26; }
.chat-msg .reacts .plus { opacity: .55; }
.chat-msg .reacts .pick { display: inline-flex; gap: 3px; }
.chat-msg .reacts .pick button { font-size: 16px; padding: 0 6px; border: 0; background: transparent; }
/* Punto rojo: hay mensajes nuevos cerca */
#chat-btn, #menu-btn { position: relative; }
#chat-btn.has-dot::before, #menu-btn.has-dot::before { content: ''; position: absolute; top: 4px; right: 6px; width: 11px; height: 11px; border-radius: 50%; background: #e63946; border: 2px solid #fff; box-sizing: content-box; }

/* Ranking por ciudades */
.rank-link { cursor: pointer; }
.rank-link:hover, .rank-link:focus-visible { text-decoration: underline; }
#rank-back { background: none; border: 0; font: inherit; color: inherit; padding: 4px 0; cursor: pointer; font-weight: 600; }
#rank-cities-list { padding-left: 22px; }
.rank-city { width: 100%; text-align: left; background: none; border: 0; font: inherit; font-weight: 600; color: inherit; padding: 6px 0; cursor: pointer; }
.rank-owners { padding: 0 0 8px 4px; opacity: .8; }
.rank-owners.hidden { display: none; }

/* Primer minuto: guía para reclamar el primer terreno */
#coach { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 1050; width: min(92vw, 380px); padding: 12px 14px; border-radius: 16px;
  background: rgba(11,61,46,.96); color: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.45); animation: coachin .3s ease-out; }
#coach .coach-step { font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #ffb703; }
#coach .coach-text { font-size: 15px; font-weight: 600; margin: 4px 0 10px; }
#coach .coach-btns { display: flex; gap: 8px; }
#coach .coach-go { flex: 1; padding: 9px 12px; border: 0; border-radius: 999px; background: #ffb703; color: #222; font-weight: 800; animation: coachpulse 1.6s ease-in-out infinite; }
#coach .coach-x { padding: 9px 14px; border-radius: 999px; background: transparent; color: #fff; border: 1px solid #fff8; }
@keyframes coachin { from { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes coachpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,183,3,.6); } 70% { box-shadow: 0 0 0 9px rgba(255,183,3,0); } }
@media (prefers-reduced-motion: reduce) { #coach, #coach .coach-go { animation: none; } }

/* Pregunta de avisos al móvil (push.js) */
#push-ask { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1050; width: min(92vw, 380px); padding: 12px 14px; border-radius: 16px;
  background: rgba(11,61,46,.96); color: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.45); }
#push-ask .pa-text { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
#push-ask .pa-btns { display: flex; gap: 8px; }
#push-ask .pa-yes { flex: 1; padding: 9px 12px; border: 0; border-radius: 999px; background: #ffb703; color: #222; font-weight: 800; }
#push-ask .pa-no { padding: 9px 14px; border-radius: 999px; background: transparent; color: #fff; border: 1px solid #fff8; }

/* Aviso al presidente de un pueblo (verdoso) */
#ayto-banner { position: fixed; left: 50%; top: 76px; z-index: 2500; width: min(94vw, 420px); transform: translateX(-50%); display: flex; gap: 10px; align-items: center;
  padding: 12px 12px 12px 14px; border-radius: 16px; background: linear-gradient(135deg, #2a9d8f, #1f7a5c); color: #fff; border: 2px solid #8ce0b4;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); cursor: pointer; animation: aytobanner .5s ease-out; }
@keyframes aytobanner { from { opacity: 0; transform: translate(-50%, -14px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { #ayto-banner { animation: none; } }

/* Aviso "Estás en…" al ir a mi ubicación (se cierra al tocarlo) */
#where-banner { position: fixed; left: 50%; top: 76px; z-index: 2400; width: min(94vw, 420px); transform: translateX(-50%); display: flex; gap: 10px; align-items: center;
  padding: 11px 14px; border-radius: 16px; background: linear-gradient(135deg, #1d6fd6, #164f9c); color: #fff; border: 2px solid #9cc7ff;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); cursor: pointer; font-size: 15px; animation: aytobanner .4s ease-out; }
@media (prefers-reduced-motion: reduce) { #where-banner { animation: none; } }
