/* ---------- inicio con perfiles (js/home.js) ---------- */
/* Usa las variables de style.css. Cada burbuja trae su color en --c y su sombra en --c-dark. */

.home {
  --bubble: clamp(140px, 19vw, 190px);
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: "head" "bubbles" "rank";
  align-content: start;
  justify-items: center;
  gap: 20px;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* Tablet en horizontal: burbujas a la izquierda, ranking a la derecha */
@media (orientation: landscape) and (min-width: 900px) {
  .home {
    --bubble: clamp(140px, min(14.5vw, 26vh), 190px);
    grid-template-columns: 1fr minmax(320px, 370px);
    grid-template-areas: "head head" "bubbles rank";
    align-items: start;
    column-gap: 28px;
  }
}

.home-loading { grid-area: bubbles; font-size: 26px; color: var(--muted); margin-top: 30vh; }

.home-head { grid-area: head; text-align: center; }
.home-title { font-size: clamp(40px, 7vw, 64px); }
.home-sub { margin: 4px 0 0; }

/* Burbujas: 4 por fila, la última fila centrada */
.bubbles {
  grid-area: bubbles;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 22px 18px;
  max-width: calc(var(--bubble) * 4 + 18px * 3);
  padding-top: 10px;
}

.bubble {
  width: var(--bubble);
  height: var(--bubble);
  flex: none;
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, rgba(255,255,255,.35) 0 14%, transparent 15%), var(--c);
  color: #fff;
  font-family: var(--ui);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 9px 0 var(--c-dark);
  animation: bob 2.4s ease-in-out infinite;
  position: relative;
}
.bubble-letter {
  font-family: var(--word);
  font-weight: 700;
  font-size: calc(var(--bubble) * 0.5);
  margin-top: calc(var(--bubble) * -0.04);
  text-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.bubble-name {
  font-weight: 700;
  font-size: calc(var(--bubble) * 0.14);
  margin-top: calc(var(--bubble) * 0.02);
  letter-spacing: .3px;
  max-width: 88%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bubble:active { transform: translateY(7px); box-shadow: 0 2px 0 var(--c-dark); animation: none; }

/* El último niño que jugó: anillo blanco y naranja y una estrella (pero hay que tocar igual) */
.bubble.last {
  box-shadow: 0 9px 0 var(--c-dark), 0 0 0 6px #fff, 0 0 0 11px var(--orange);
}
.bubble.last::after {
  content: '⭐';
  position: absolute;
  top: -6px; right: -4px;
  font-size: calc(var(--bubble) * 0.22);
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.12));
}

/* Al tocar: salta y las demás se apagan */
.bubbles:has(.chosen) .bubble:not(.chosen) { opacity: .35; transition: opacity .25s; }
.bubble.chosen { animation: chosen .35s ease-out forwards; }
@keyframes chosen { 50% { transform: scale(1.15); } 100% { transform: scale(1.08); } }

/* ---------- ranking (inicio y pantalla final) ---------- */
.home-rank { grid-area: rank; width: 100%; max-width: 640px; }

.ranking {
  background: var(--card);
  border-radius: 28px;
  box-shadow: 0 6px 0 var(--shadow);
  padding: 16px 18px 18px;
  text-align: left;
}
.ranking-title {
  margin: 0 0 10px;
  font-size: clamp(24px, 3.4vw, 32px);
  font-weight: 700;
  text-align: center;
}
.ranking-msg { margin: 6px 0; text-align: center; font-size: 22px; color: var(--muted); }

.ranking-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rank-row {
  display: grid;
  grid-template-columns: 34px 44px 118px 1fr 62px;
  grid-template-areas: "pos dot name bar count" "pos dot name bar today";
  align-items: center;
  column-gap: 10px;
  min-height: 52px;
  padding: 4px 10px 4px 4px;
  border-radius: 18px;
  background: var(--bg);
}
.rank-pos { grid-area: pos; text-align: center; font-size: 20px; font-weight: 700; color: var(--muted); }
.rank-pos.medal { font-size: 28px; }
.rank-dot {
  grid-area: dot;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--c);
  box-shadow: 0 3px 0 var(--c-dark);
  color: #fff;
  font-family: var(--word);
  font-weight: 700;
  font-size: 24px;
}
.rank-name { grid-area: name; font-size: 22px; font-weight: 600; white-space: nowrap; }
.rank-bar {
  grid-area: bar;
  height: 14px;
  border-radius: 999px;
  background: var(--bg-2);
  overflow: hidden;
  min-width: 40px;
}
.rank-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--c);
  transition: width .6s ease-out;
}
.rank-count {
  grid-area: count;
  font-size: 24px;
  font-weight: 700;
  min-width: 2ch;
  text-align: right;
  line-height: 1;
}
.rank-today { grid-area: today; font-size: 13px; color: var(--green); font-weight: 600; text-align: right; line-height: 1; }
.rank-today:empty { display: none; }
.rank-row:has(.rank-today:empty) { grid-template-areas: "pos dot name bar count" "pos dot name bar count"; }

@media (max-width: 480px) {
  .rank-name { font-size: 18px; }
  .rank-row { column-gap: 8px; grid-template-columns: 30px 44px 92px 1fr 62px; }
}
