/*
 * Tienda web Keplerians — mobile first, legible en vertical y en horizontal.
 *
 * La regla de oro del layout: NADA depende de la altura de la ventana. En
 * horizontal un móvil deja ~350px de alto, así que todo scrollea y el panel de
 * compra es una hoja inferior que nunca ocupa más del 90% del viewport.
 */

:root {
  --bg: #0d0b14;
  --bg-soft: #17142180;
  --card: #1b1727;
  --card-hi: #241f33;
  --line: #322b46;
  --text: #f2effa;
  --muted: #a49dba;
  --accent: #7c4dff;
  --accent-hi: #9670ff;
  --danger: #ff6b6b;
  --radius: 14px;
  --pad: clamp(12px, 3vw, 20px);
}

* { box-sizing: border-box; }

/*
 * El atributo `hidden` del HTML lo pone el navegador como `display: none`, pero
 * con la especificidad más baja que existe: cualquier `display` que pongamos en
 * una clase lo gana. Sin esto, `.sheet { display: flex }` hacía que la hoja de
 * compra saliera nada más cargar y no se pudiera cerrar (hidden=true no hacía
 * nada). Regla global para que no vuelva a pasar con ningún componente.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Notch y barra de gestos: sin esto, en horizontal el contenido se come el borde */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: var(--pad);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }

.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* Avatar + marco equipados: caja de 40px, avatar cuadrado de 28px centrado y
   marco (arte cuadrado con transparencia) a 40px por encima ≈ 1,42x del avatar,
   la misma proporción que en la tarjeta de perfil y en el juego. */
.account-cosmetic { position: relative; width: 40px; height: 40px; flex: 0 0 40px; }
.account-avatar { position: absolute; left: 6px; top: 6px; width: 28px; height: 28px; object-fit: cover; background: var(--card-hi); border-radius: 4px; }
.account-frame { position: absolute; inset: 0; width: 40px; height: 40px; object-fit: contain; pointer-events: none; }
.account-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.account-text strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 32vw; }
.account-text small { font-size: 11px; color: var(--muted); }

/* ── Layout ─────────────────────────────────────────── */
main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: var(--pad); }
.view { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 4vw, 28px);
}
.card-login { max-width: 420px; margin: clamp(8px, 4vh, 40px) auto; }
.center { text-align: center; }

h1 { font-size: clamp(20px, 5vw, 26px); margin: 0 0 8px; }
h2 { font-size: clamp(17px, 4.5vw, 21px); margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }

/* ── Formulario ─────────────────────────────────────── */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }

input[type="text"] {
  width: 100%;
  padding: 14px;
  font-size: 20px;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent; }
button:disabled { opacity: .55; cursor: default; }

.btn-primary {
  width: 100%; padding: 14px; margin-top: 14px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hi); }

.btn-secondary {
  width: 100%; padding: 13px;
  background: var(--card-hi); color: var(--text); border-color: var(--line);
}

.btn-ghost { background: none; color: var(--muted); padding: 6px 10px; border-color: var(--line); font-size: 13px; }

.divider { display: flex; align-items: center; gap: 10px; margin: 20px 0 14px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.banner {
  background: #3a2c12; border: 1px solid #7a5a1e; color: #ffd68a;
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
}

/* ── Rejilla del catálogo ───────────────────────────── */
/*
 * auto-fill + minmax hace todo el trabajo responsive: 2 columnas en un móvil en
 * vertical, 4-5 en horizontal o tablet, sin una sola media query.
 */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: clamp(10px, 2.5vw, 16px);
}

.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  color: var(--text);
  transition: transform .12s ease, border-color .12s ease;
}
.item:hover { transform: translateY(-2px); border-color: var(--accent); }
.item:active { transform: none; }

.item-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: var(--bg-soft);
  border-radius: 10px;
}
.item-name { font-size: 14px; font-weight: 600; line-height: 1.25; }
.item-price { font-size: 13px; color: var(--accent-hi); font-weight: 700; margin-top: auto; }
.item-price.unknown { color: var(--muted); font-weight: 500; }

/* ── Hoja de compra ─────────────────────────────────── */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: #000000b8;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-panel {
  position: relative;
  width: min(440px, 100%);
  max-height: 90dvh;      /* clave en horizontal: nunca tapa toda la pantalla */
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(16px); } to { transform: none; } }

@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: var(--radius); }
}

.sheet-close {
  position: absolute; top: 10px; right: 10px;
  width: 34px; height: 34px; font-size: 22px; line-height: 1;
  background: var(--card-hi); color: var(--muted); border-color: var(--line);
}
.sheet-img { width: 120px; aspect-ratio: 1/1; object-fit: contain; display: block; margin: 0 auto 12px; }
.sheet-price { font-size: 22px; font-weight: 700; color: var(--accent-hi); margin: 12px 0 4px; }

.foot { padding: var(--pad); text-align: center; color: var(--muted); font-size: 12px; }

/* Google Identity Services inyecta su propio iframe/botón: sólo lo centramos. */
.google-btn { display: flex; justify-content: center; min-height: 44px; }

/* ── Monedas del jugador ────────────────────────────── */
/*
 * Va en la topbar, entre la marca y la cuenta. En móvil vertical el nombre de
 * la cuenta se encoge (max-width en .account-text strong) para dejarle sitio:
 * el saldo importa más que ver el nombre entero.
 */
.wallets { display: flex; align-items: center; gap: 10px; margin-left: auto; margin-right: 12px; }

.wallet {
  display: flex; align-items: center; gap: 5px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px 5px 6px;
  white-space: nowrap;
}
.wallet-icon { width: 20px; height: 20px; object-fit: contain; }
.wallet-amount { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-width: 420px) {
  .wallet { padding: 4px 8px 4px 5px; gap: 4px; }
  .wallet-icon { width: 17px; height: 17px; }
  .wallet-amount { font-size: 12px; }
  .account-text strong { max-width: 20vw; }
}

/*
 * Botón de Apple. Su JS inyecta un div propio; le damos el mismo ancho y alto
 * que el de Google para que los dos accesos se vean como iguales — el usuario de
 * iOS es el 36% de los pagadores y no debe parecer la opción de segunda.
 */
.apple-btn { display: flex; justify-content: center; margin-top: 8px; min-height: 44px; }
.apple-btn > div { width: 320px; max-width: 100%; height: 44px; cursor: pointer; }

/* ── Regalo a un amigo (selector de destinatario en la hoja) ─────── */
.item-badge {
  position: absolute; top: 8px; left: 8px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase;
  background: var(--accent); color: #fff; border-radius: 999px; padding: 3px 8px;
}
.item { position: relative; }
.gift-box { margin: 10px 0 14px; text-align: left; }
.gift-label { margin: 0 0 6px; font-weight: 600; font-size: 14px; }
.gift-search {
  width: 100%; box-sizing: border-box; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card-hi); color: var(--text); font: inherit;
}
.gift-friends { max-height: 220px; overflow-y: auto; margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.gift-friend {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 10px; border: 1px solid transparent;
  background: var(--card-hi); color: var(--text); font: inherit; cursor: pointer;
}
.gift-friend:hover { border-color: var(--line); }
.gift-friend[aria-selected="true"] { border-color: var(--accent-hi); background: #7c4dff2b; }
.gift-friend img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--line); flex: 0 0 auto; }
.gift-friend .gift-friend-name { font-weight: 600; font-size: 14px; }
.gift-friend .gift-friend-id { color: var(--muted); font-size: 11px; }

/* ── Carga inicial (entrada con código desde el juego) ─────── */
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 40dvh; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent-hi); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-top-color: var(--accent-hi); } }
