/* Biblioteca con portadas + ranking fijo (bp1). Se carga DESPUÉS de steam.css?v=m2 */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Tarjetas con portada ---------- */
.library { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.9rem; }

.game-card {
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  box-shadow: none;
}
.game-card:hover { transform: translateY(-3px); border-color: var(--machine, var(--accent)); }
.game-card.selected {
  border-color: var(--machine, var(--accent));
  box-shadow: 0 0 0 1px var(--machine, var(--accent)), 0 10px 30px rgba(0, 0, 0, 0.35), 0 0 22px color-mix(in srgb, var(--machine, #3ee0c5) 30%, transparent);
}
.card-main {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  flex: 1;
}
.game-screen {
  position: relative;
  display: block;
  width: 100%;
  min-height: 0;
  aspect-ratio: 16 / 9;
  padding: 0;
  border-radius: 0;
  overflow: hidden;
}
.cover-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block;
  transition: transform 0.35s ease;
}
.game-card:hover .cover-img, .game-card.selected .cover-img { transform: scale(1.04); }
.genre-tag {
  position: absolute; top: 0.5rem; left: 0.5rem; z-index: 1;
  padding: 0.15rem 0.5rem; border-radius: 999px;
  background: rgba(5, 8, 15, 0.72); backdrop-filter: blur(4px);
  color: #fff; font-size: 0.62rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
}
.game-card.selected .game-screen::after {
  content: "Seleccionado"; position: absolute; top: 0.5rem; right: 0.5rem;
  padding: 0.15rem 0.5rem; border-radius: 999px;
  background: var(--machine, var(--accent)); color: #061018;
  font-size: 0.62rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
}
.game-copy { padding: 0.7rem 0.8rem 0.4rem; }
.game-copy span { -webkit-line-clamp: 2; }
.card-foot { padding: 0.2rem 0.8rem 0.8rem; }

/* ---------- Detalle ---------- */
.hero-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero-banner-bg::before { z-index: 1; }
.detail .panel { margin-top: 0; }

/* ---------- Panel de ranking ---------- */
.rank-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(12, 16, 30, 0.96);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.rank-panel > .empty-state, .rank-empty { margin: 0; padding: 1rem; color: var(--text-muted); }
.rank-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--machine) 18%, transparent), transparent);
}
.rank-grip { display: flex; align-items: center; gap: 0.65rem; flex: 1; min-width: 0; text-align: left; cursor: default; }
.rank-thumb { position: relative; flex: 0 0 auto; width: 74px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 1px var(--machine); }
.rank-thumb-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.rank-title { min-width: 0; }
.rank-title small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--machine); font-size: 0.64rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.rank-title strong { display: block; font-family: var(--font-display); font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-chev { display: none; }
.rank-actions { display: flex; gap: 0.4rem; align-items: center; }
.rank-play { min-width: 0; padding: 0.25rem 0.8rem; }
.rank-refresh {
  width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--text-muted); font-size: 1.05rem; line-height: 1;
}
.rank-refresh:hover { color: var(--text); border-color: var(--accent); }
.rank-body { padding: 0.35rem 0.7rem 0.7rem; }
.rank-list { list-style: none; margin: 0; padding: 0; transition: opacity 0.2s; }
.rank-list.is-refreshing { opacity: 0.6; }
.rank-list li {
  display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto; gap: 0.5rem; align-items: center;
  padding: 0.5rem 0.35rem; border-bottom: 1px solid rgba(126, 182, 255, 0.1);
  animation: rank-in 0.25s ease both;
}
.rank-list li:last-child { border-bottom: none; }
.rank-list .rank {
  display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 999px;
  background: rgba(126, 182, 255, 0.1); color: var(--text-muted); font-size: 0.8rem;
}
.rank-list .medal-1 .rank { background: linear-gradient(180deg, #ffe58a, #f0b429); color: #2a1a00; }
.rank-list .medal-2 .rank { background: linear-gradient(180deg, #eef2f8, #9aa7bd); color: #121826; }
.rank-list .medal-3 .rank { background: linear-gradient(180deg, #f3b58a, #b8693a); color: #2a1206; }
.rank-list .medal-1 .score-val { color: #ffd862; }
.rank-list .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank-list .who em { color: var(--accent); font-style: normal; font-weight: 700; font-size: 0.8em; }
.rank-list .score-val { font-weight: 800; font-variant-numeric: tabular-nums; }
.rank-list li.is-me { background: rgba(62, 224, 197, 0.1); border-radius: 8px; }
.rank-list.is-skeleton li span { display: block; height: 0.9rem; border-radius: 6px; background: linear-gradient(90deg, #18203a, #26314f, #18203a); background-size: 200% 100%; animation: shimmer 1.1s linear infinite; }
.rank-list.is-skeleton li span:first-child { width: 1.7rem; height: 1.7rem; border-radius: 999px; }
.rank-list.is-skeleton li span:last-child { width: 3.5rem; }
.rank-error { margin: 0.4rem 0; padding: 0.5rem 0.6rem; border-radius: 8px; background: rgba(255, 90, 90, 0.12); color: #ffb3b3; font-size: 0.85rem; }
.rank-error button { color: #fff; text-decoration: underline; font-weight: 700; }
.rank-panel.is-preview .rank-head { border-bottom-style: dashed; }

@keyframes rank-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Escritorio / tablet horizontal: columna fija a la derecha */
@media (min-width: 900px) {
  .content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(290px, 28vw, 350px);
    gap: 1.1rem;
    align-items: start;
  }
  .library, .detail { grid-column: 1; }
  .detail { margin-top: 0.2rem; }
  .rank-panel {
    grid-column: 2; grid-row: 1 / span 2;
    position: sticky; top: 1rem;
    max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
    overflow-y: auto; overscroll-behavior: contain;
  }
}

/* Celular / tablet vertical: hoja inferior siempre visible */
@media (max-width: 899px) {
  body { padding-bottom: calc(15rem + env(safe-area-inset-bottom)); }
  .rank-panel {
    position: fixed; z-index: 50;
    left: max(0.5rem, env(safe-area-inset-left)); right: max(0.5rem, env(safe-area-inset-right));
    bottom: calc(0.5rem + env(safe-area-inset-bottom));
    max-width: 640px; margin: 0 auto;
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    backdrop-filter: blur(10px);
    background: rgba(10, 14, 26, 0.94);
    scroll-margin-bottom: 1rem;
  }
  .rank-head { padding: 0.5rem 0.6rem; }
  .rank-grip { cursor: pointer; min-height: 44px; }
  .rank-thumb { width: 58px; }
  .rank-chev { display: inline-block; margin-left: auto; color: var(--text-muted); font-size: 0.75rem; transition: transform 0.2s; }
  .rank-play, .rank-refresh { min-height: 40px; height: 40px; }
  .rank-refresh { width: 40px; }
  .rank-body { max-height: 9.6rem; overflow: hidden; padding-top: 0.2rem; padding-bottom: 0.4rem; transition: max-height 0.25s ease; }
  .rank-list li { padding: 0.32rem 0.3rem; }
  .rank-list li:nth-child(n + 4) { display: none; }
  .rank-panel.is-open .rank-body { max-height: min(60vh, 30rem); max-height: min(60dvh, 30rem); overflow-y: auto; overscroll-behavior: contain; }
  .rank-panel.is-open .rank-list li { display: grid; }
  .rank-panel.is-open .rank-chev { transform: rotate(180deg); }
  .rank-panel.is-open { box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6); }
}

@media (max-width: 640px) {
  .library { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .game-copy { padding: 0.55rem 0.6rem 0.3rem; }
  .game-copy strong { font-size: 0.95rem; }
  .game-copy span { font-size: 0.74rem; }
  .card-foot { padding: 0.2rem 0.6rem 0.6rem; flex-wrap: wrap; }
  .card-foot .badge { display: none; }
  .card-play { width: 100%; min-height: 40px; }
  .game-card.selected .game-screen::after { content: "✓"; }
}

@media (max-width: 360px) {
  .library { grid-template-columns: 1fr; }
}

/* Celular horizontal: poca altura → hoja más compacta y a la derecha */
@media (max-width: 899px) and (max-height: 500px) {
  body { padding-bottom: calc(5rem + env(safe-area-inset-bottom)); }
  .rank-panel { left: auto; width: min(360px, 48vw); }
  .rank-body { max-height: 0; padding: 0 0.6rem; }
  .rank-panel.is-open .rank-body { max-height: calc(100dvh - 6rem); padding: 0.3rem 0.6rem 0.5rem; }
  .library { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .game-card:hover, .game-card:hover .cover-img, .game-card.selected .cover-img { transform: none; }
  .rank-list li { animation: none; }
}
