/* ====== RESET GLOBAL ====== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background-color: #0a0f25; /* azul muy oscuro */
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  overflow: hidden; /* mantiene 33%/67% sin scroll */
}

/* ====== CONTENEDOR SUPERIOR (33%) ====== */
#top-container {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  height: 33vh;           /* 33% pantalla */
  width: 100%;
  padding: 0 2vw;
}

/* ====== MITAD IZQUIERDA: TÍTULO ====== */
#title {
  width: 50%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9vw;         /* grande y llamativo */
  font-weight: 800;
  color: #5de26b;         /* verde armónico */
  text-shadow: 0 3px 16px rgba(0,0,0,0.6);
}

/* ====== MITAD DERECHA: RANKING ====== */
#ranking {
  width: 50%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: space-evenly;
  gap: 10px;
}
/* Fila interna creada por JS */
#ranking > div {
  height: 100%;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
}

/* ====== TARJETAS DEL RANKING ====== */
.rank-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(145deg, #1e2a4f, #0a0f25); /* gris azulado claro sobre fondo oscuro */
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  color: #fff;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  padding: 5px;
  will-change: transform;
}
/* Tamaño relativo por posición (1 más grande → 5 más chico) */
.rank-card:nth-child(1) { flex: 1.4; height: 100%; }
.rank-card:nth-child(2) { flex: 1.2; height: 90%; }
.rank-card:nth-child(3) { flex: 1.0; height: 80%; }
.rank-card:nth-child(4) { flex: 0.9; height: 70%; }
.rank-card:nth-child(5) { flex: 0.8; height: 60%; }

.rank-card:hover { transform: translateY(-5px); box-shadow: 0 10px 28px rgba(93, 226, 107, 0.3); }

/* ====== ESTRUCTURA INTERNA DE CADA CARD ====== */
.rank-number {
  flex: 5; /* 50% superior para el número */
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #5de26b;
}
.rank-name {
  flex: 3; /* 30% medio para nombre + bandera (en JS va en un solo texto) */
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-align: center;
  padding: 0 6px;
}

/* CONTADOR PRINCIPAL (abreviado) GRANDE */
.rank-score {
  flex: 2.4; /* algo más de espacio para el importe principal */
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #5de26b;
  text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

/* Escala del contador principal por posición */
.rank-card:nth-child(1) .rank-score { font-size: 2.4vw; }
.rank-card:nth-child(2) .rank-score { font-size: 2.2vw; }
.rank-card:nth-child(3) .rank-score { font-size: 2.0vw; }
.rank-card:nth-child(4) .rank-score { font-size: 1.8vw; }
.rank-card:nth-child(5) .rank-score { font-size: 1.6vw; }

/* CONTADOR SECUNDARIO (exacto con comas), muy pequeño abajo */
.rank-total {
  flex: 0.6; /* 20% inferior aproximado compartido con .rank-score */
  display: flex;
  align-items: flex-end;
  justify-content: center;
  color: rgba(255,255,255,0.86);
  font-weight: 700;
  letter-spacing: 0.2px;
  margin-bottom: 4px;
  font-size: clamp(10px, 0.8vw, 12px);
}

/* Tamaño del número de posición por card (proporcional) */
.rank-card:nth-child(1) .rank-number { font-size: 5vw; }
.rank-card:nth-child(2) .rank-number { font-size: 4.5vw; }
.rank-card:nth-child(3) .rank-number { font-size: 4vw; }
.rank-card:nth-child(4) .rank-number { font-size: 3.5vw; }
.rank-card:nth-child(5) .rank-number { font-size: 3vw; }

/* ====== ANIMACIONES (count-up y reordenamiento visual) ====== */
.rank-card.bump { animation: bump 650ms ease; box-shadow: 0 12px 28px rgba(93,226,107,0.35); }
@keyframes bump { 0%{transform:scale(1);} 30%{transform:scale(1.025);} 100%{transform:scale(1);} }

.rank-score.flash { animation: scoreFlash 1200ms ease; }
@keyframes scoreFlash {
  0%{ color:#b2ffbd; text-shadow:0 0 12px rgba(93,226,107,0.6);}
  60%{ color:#5de26b; text-shadow:0 0 6px rgba(93,226,107,0.3);}
  100%{ color:#5de26b; text-shadow:0 2px 10px rgba(0,0,0,0.35);}
}

/* ====== MAPA (66%) ====== */
#chartdiv {
  width: 100%;
  height: 67vh; /* 66-67% pantalla */
}

/* ====== POPUP DE PAGO ====== */
#payment-popup {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: none; /* controlado por .hidden */
  align-items: center; justify-content: center;
  z-index: 9999;
}
#payment-popup:not(.hidden) { display: flex; }

#popup-content {
  background: #1e2a4f;
  padding: 22px 30px;
  border-radius: 12px;
  position: relative;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#close-popup {
  position: absolute;
  top: 10px; right: 12px;
  cursor: pointer;
  font-weight: 700;
  color: #fff;
}

/* Controles Min/Max y campo con sufijo 'usd' */
.amount-controls {
  display: flex; gap: 10px;
  justify-content: center; margin-top: 6px;
}
.amount-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .2s ease, background .2s ease;
}
.amount-btn:hover {
  background: rgba(255,255,255,0.12);
  box-shadow: 0 0 14px rgba(93,226,107,0.25);
}
.amount-label { font-weight: 700; text-align: center; }
.amount-field { position: relative; display: flex; justify-content: center; }
#amount-input {
  padding: 10px 48px 10px 12px; /* espacio para sufijo */
  border-radius: 10px; border: none;
  width: 180px; text-align: left;
  font-weight: 700; font-size: 1rem; outline: none;
}
.currency-suffix {
  position: absolute;
  right: calc(50% - 90px + 12px); /* input 180px: mitad 90px + 12px padding */
  top: 50%; transform: translateY(-50%);
  color: #0a0f25; background: #5de26b;
  border-radius: 8px; padding: 4px 8px;
  font-weight: 800; text-transform: lowercase;
  pointer-events: none;
}

#pay-button {
  padding: 10px 18px;
  border-radius: 8px; border: none;
  background: #5de26b; color: #0a0f25;
  font-weight: 700; cursor: pointer;
}

/* ====== TERMS & CONDITIONS POPUP (siempre visible al cargar) ====== */
#terms-popup {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center; justify-content: center;
  z-index: 10000; /* por encima de todo */
}
#terms-popup.hidden { display: none !important; }

#terms-popup-content {
  background: #1e2a4f;
  width: 92%; max-width: 640px; max-height: 82vh;
  border-radius: 14px;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
#terms-popup-content h2 {
  margin: 0; padding: 18px 24px 12px;
  text-align: center; font-size: 1.6rem;
  color: #5de26b;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0));
}
.terms-body {
  padding: 0 24px 16px 24px;
  overflow-y: auto; overscroll-behavior: contain;
  max-height: calc(82vh - 56px - 76px); /* total - header - footer */
  line-height: 1.45; font-size: 0.98rem;
}
.terms-body::-webkit-scrollbar { width: 8px; }
.terms-body::-webkit-scrollbar-track { background: rgba(255,255,255,0.06); border-radius: 8px; }
.terms-body::-webkit-scrollbar-thumb { background: rgba(93,226,107,0.45); border-radius: 8px; }
.terms-body p { margin: 10px 0; }
.terms-body strong { color: #a7f0b1; font-weight: 800; }
.terms-actions {
  padding: 14px 24px 18px;
  display: flex; justify-content: center;
  background: linear-gradient(0deg, rgba(0,0,0,0.22), rgba(0,0,0,0));
  border-top: 1px solid rgba(255,255,255,0.08);
}
#accept-terms-btn {
  padding: 12px 24px; border-radius: 10px; border: none;
  background: #5de26b; color: #0a0f25;
  font-weight: 800; font-size: 1rem; cursor: pointer;
  box-shadow: 0 0 12px rgba(93,226,107,0.35);
  transition: transform .08s ease, box-shadow .2s ease;
}
#accept-terms-btn:hover { box-shadow: 0 0 18px rgba(93,226,107,0.55); }
#accept-terms-btn:active { transform: scale(0.98); }

/* ====== UTILIDAD ====== */
.hidden { display: none !important; }

/* ====== RESPONSIVE ====== */
@media (max-width: 720px) {
  html, body { overflow: auto; } /* permite scroll en móviles si es necesario */
  #top-container { flex-direction: column; height: auto; padding: 10px; }
  #title { width: 100%; font-size: 14vw; height: auto; }
  #ranking { width: 100%; flex-wrap: wrap; justify-content: center; height: auto; }
  #ranking > div { height: auto; align-items: stretch; }

  /* Ajustes responsive de tamaños */
  .rank-card:nth-child(1) .rank-number { font-size: 12vw; }
  .rank-card:nth-child(2) .rank-number { font-size: 10vw; }
  .rank-card:nth-child(3) .rank-number { font-size: 9vw; }
  .rank-card:nth-child(4) .rank-number { font-size: 8vw; }
  .rank-card:nth-child(5) .rank-number { font-size: 7vw; }

  .rank-card:nth-child(1) .rank-score { font-size: 6.4vw; }
  .rank-card:nth-child(2) .rank-score { font-size: 5.8vw; }
  .rank-card:nth-child(3) .rank-score { font-size: 5.2vw; }
  .rank-card:nth-child(4) .rank-score { font-size: 4.6vw; }
  .rank-card:nth-child(5) .rank-score { font-size: 4.2vw; }

  .rank-total { font-size: clamp(10px, 2.8vw, 12px); }
}

/* ====== POSITION NUMBER SNAP (up/down) ====== */
.rank-number.num-up {
  animation: numUp 550ms ease;
}
@keyframes numUp {
  0%   { transform: translateY(40%);  opacity: .7; }
  60%  { transform: translateY(-8%);  opacity: 1;  }
  100% { transform: translateY(0%);   opacity: 1;  }
}

.rank-number.num-down {
  animation: numDown 550ms ease;
}
@keyframes numDown {
  0%   { transform: translateY(-40%); opacity: .7; }
  60%  { transform: translateY(8%);   opacity: 1;  }
  100% { transform: translateY(0%);   opacity: 1;  }
}
