/* ===== Battle Chest — styles ===== */

:root {
  --bg-deep: #140b26;
  --bg-mid: #1f1240;
  --bg-panel: #2a1a52;
  --bg-panel-light: #34205f;
  --gold: #ffce4a;
  --gold-deep: #e0a716;
  --text-main: #f4eeff;
  --text-dim: #b9a9e0;
  --comun: #9aa3ad;
  --comun-bg: #3a4048;
  --rara: #4fa8f0;
  --rara-bg: #163a5c;
  --epica: #c86bf0;
  --epica-bg: #3a1a55;
  --legendaria: #ffc93c;
  --legendaria-bg: #5a3c0a;
  --radius-lg: 18px;
  --radius-md: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background: var(--bg-deep);
  padding-bottom: calc(72px + var(--safe-bottom));
}

h1, h2, h3 {
  font-family: 'Cinzel', 'Nunito', serif;
  margin: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Catch-all: any element toggled via the .hidden class must actually hide,
   regardless of what display value its other classes set (e.g. .btn).
   Prevents the "hidden class present but no matching CSS rule" soft-lock bug. */
.hidden { display: none !important; }

/* ===== Top bar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg-deep);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 1.3rem; }
.brand h1 {
  font-size: 1.2rem;
  color: var(--gold);
  letter-spacing: 0.5px;
}

.currency-bar { display: flex; gap: 8px; }
.currency {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-panel);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.95rem;
  min-height: 32px;
}
.currency-icon { font-size: 1rem; }
.currency.bump { animation: currencyBump 0.4s ease; }
@keyframes currencyBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ===== Main / views ===== */
main { padding: 14px 16px 30px; max-width: 640px; margin: 0 auto; }
.view.hidden { display: none; }

/* ===== Free chest banner ===== */
.free-chest-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.free-chest-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.free-chest-icon { font-size: 1.8rem; flex-shrink: 0; }
.free-chest-title { margin: 0; font-weight: 800; font-size: 0.95rem; }
.free-chest-sub { margin: 2px 0 0; font-size: 0.8rem; color: var(--text-dim); }

.key-timer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 4px 0 16px;
}

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  font-size: 0.95rem;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.95); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-claim {
  background: var(--gold);
  color: #241304;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--gold);
  color: #241304;
  padding: 12px 28px;
  font-size: 1.05rem;
}

/* ===== Chest grid ===== */
.chest-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
@media (min-width: 480px) {
  .chest-grid { grid-template-columns: repeat(3, 1fr); }
}

.chest-card {
  background: var(--bg-panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  padding: 14px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-height: 44px;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}
.chest-card:active { transform: scale(0.96); }
.chest-card.locked { opacity: 0.55; }
.chest-card.tier-madera { border-color: rgba(201,134,47,0.45); }
.chest-card.tier-plata { border-color: rgba(200,210,220,0.4); }
.chest-card.tier-oro { border-color: rgba(255,206,74,0.5); }
.chest-card.tier-magico { border-color: rgba(200,107,240,0.5); }
.chest-card.tier-legendario { border-color: rgba(255,201,60,0.7); }

.chest-card-icon {
  font-size: 2.6rem;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4));
}
.chest-card-name { font-weight: 800; font-size: 0.88rem; line-height: 1.2; }
.chest-card-cost {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(0,0,0,0.25);
  border-radius: 999px;
  padding: 3px 10px;
  margin-top: 2px;
}

/* ===== How it works ===== */
.how-it-works {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  border: 1px solid rgba(255,255,255,0.08);
  margin-top: 4px;
}
.how-it-works h2 {
  color: var(--gold);
  font-size: 1.05rem;
  margin-bottom: 10px;
}
.how-it-works ol { margin: 0; padding-left: 20px; }
.how-it-works li { margin-bottom: 8px; font-size: 0.9rem; color: var(--text-dim); line-height: 1.4; }
.how-it-works strong { color: var(--text-main); }

/* ===== Collection view ===== */
#view-collection h2 { color: var(--gold); font-size: 1.3rem; margin-bottom: 12px; }

.filter-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 8px;
}
.filter-btn {
  flex: 0 0 auto;
  background: var(--bg-panel);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  min-height: 40px;
  cursor: pointer;
}
.filter-btn.active {
  background: var(--gold);
  color: #241304;
  border-color: var(--gold);
}

.collection-progress {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (min-width: 420px) {
  .collection-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 600px) {
  .collection-grid { grid-template-columns: repeat(5, 1fr); }
}

.coll-card {
  position: relative;
  border-radius: var(--radius-md);
  padding: 10px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  min-height: 44px;
  border: 1.5px solid transparent;
}
.coll-card-icon { font-size: 1.7rem; }
.coll-card-name { font-size: 0.68rem; font-weight: 700; line-height: 1.15; }
.coll-card-count {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.55);
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 6px;
}

.coll-card.rarity-comun { background: var(--comun-bg); border-color: rgba(154,163,173,0.4); }
.coll-card.rarity-rara { background: var(--rara-bg); border-color: rgba(79,168,240,0.5); }
.coll-card.rarity-epica { background: var(--epica-bg); border-color: rgba(200,107,240,0.5); }
.coll-card.rarity-legendaria {
  background: var(--legendaria-bg);
  border-color: rgba(255,201,60,0.7);
}

.coll-card.undiscovered {
  filter: grayscale(1) brightness(0.5);
  background: #241a3a;
  border-color: rgba(255,255,255,0.08);
}
.coll-card.undiscovered .coll-card-name { color: #6a5f8a; }
.coll-card.undiscovered .coll-card-icon { opacity: 0.5; }

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  background: var(--bg-deep);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 6px calc(10px + var(--safe-left)) calc(6px + var(--safe-bottom)) calc(10px + var(--safe-right));
}
.bottom-nav .nav-btn { max-width: 320px; }
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  min-height: 44px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--radius-md);
}
.nav-btn.active { color: var(--gold); background: rgba(255,206,74,0.08); }
.nav-icon { font-size: 1.3rem; }

/* ===== Overlay: opening flow ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(circle at 50% 30%, #2a1a52 0%, #0c0718 75%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
}
.overlay.hidden { display: none; }

.overlay-close {
  position: absolute;
  top: calc(16px + var(--safe-top));
  right: 16px;
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text-main);
  width: 40px; height: 40px;
  min-width: 44px; min-height: 44px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}
.overlay-close.hidden { display: none; }

.open-stage, .reveal-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 360px;
}
.reveal-stage.hidden { display: none; }

.chest-charge-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chest-visual {
  font-size: 7rem;
  filter: drop-shadow(0 0 0 rgba(255,206,74,0));
  transition: filter 0.2s ease;
  user-select: none;
  cursor: pointer;
  z-index: 2;
}
.chest-visual.charging {
  animation: chestShake 0.35s infinite;
  filter: drop-shadow(0 0 30px rgba(255,206,74,0.85));
}
.chest-visual.bursting {
  animation: chestBurst 0.55s ease forwards;
}

@keyframes chestShake {
  0% { transform: rotate(0deg) translateX(0); }
  20% { transform: rotate(-6deg) translateX(-4px); }
  40% { transform: rotate(5deg) translateX(3px); }
  60% { transform: rotate(-4deg) translateX(-3px); }
  80% { transform: rotate(6deg) translateX(4px); }
  100% { transform: rotate(0deg) translateX(0); }
}
@keyframes chestBurst {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.4); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

.charge-hint {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
  margin: 0;
}

.charge-bar-track {
  width: 100%;
  height: 12px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}
.charge-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--gold);
  border-radius: 999px;
  transition: width 0.08s linear;
}

/* Particles / confetti */
.particles {
  position: absolute;
  inset: -40px;
  pointer-events: none;
  z-index: 1;
}
.particle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  opacity: 0;
}
.particle.fly {
  animation: particleFly 0.9s ease-out forwards;
}
@keyframes particleFly {
  0% { opacity: 1; transform: translate(-50%, -50%) rotate(0deg) translateY(0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot, 180deg)) translateY(var(--dist, -140px)) scale(0.4); }
}

/* Card reveal */
.card-flip-zone {
  perspective: 1000px;
  width: 190px;
  height: 260px;
}
.reveal-card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(.2,.9,.3,1.2);
  cursor: pointer;
}
.reveal-card.flipped { transform: rotateY(180deg); }
.reveal-card.pop { animation: cardPop 0.45s ease; }
@keyframes cardPop {
  0% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}

.reveal-card-back, .reveal-card-front {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
}
.reveal-card-back {
  background: linear-gradient(160deg, var(--bg-panel-light), var(--bg-panel));
  border: 2px solid rgba(255,206,74,0.4);
}
.reveal-card-front {
  transform: rotateY(180deg);
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  text-align: center;
  border: 2px solid transparent;
}
.reveal-card-front .rc-icon { font-size: 3.2rem; }
.reveal-card-front .rc-name { font-family: 'Cinzel', serif; font-weight: 800; font-size: 1rem; }
.reveal-card-front .rc-rarity { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; opacity: 0.85; }
.reveal-card-front .rc-dup { font-size: 0.72rem; margin-top: 4px; color: var(--gold); font-weight: 700; }

.reveal-card-front.rarity-comun { background: var(--comun-bg); border-color: var(--comun); color: var(--text-main); }
.reveal-card-front.rarity-rara { background: var(--rara-bg); border-color: var(--rara); box-shadow: 0 0 24px rgba(79,168,240,0.35); }
.reveal-card-front.rarity-epica { background: var(--epica-bg); border-color: var(--epica); box-shadow: 0 0 30px rgba(200,107,240,0.45); }
.reveal-card-front.rarity-legendaria {
  background: linear-gradient(160deg, var(--legendaria-bg), #7a4e0a);
  border-color: var(--legendaria);
  box-shadow: 0 0 44px rgba(255,201,60,0.6);
  animation: legendaryGlow 1.2s ease-in-out infinite alternate;
}
@keyframes legendaryGlow {
  from { box-shadow: 0 0 30px rgba(255,201,60,0.5); }
  to { box-shadow: 0 0 60px rgba(255,201,60,0.85); }
}

.reveal-caption { color: var(--text-dim); font-size: 0.9rem; margin: 0; min-height: 1.2em; text-align: center; }
.reveal-progress { color: var(--text-dim); font-size: 0.8rem; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel-light);
  border: 1px solid rgba(255,206,74,0.4);
  color: var(--text-main);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 18px 20px 10px;
  color: var(--text-dim);
  font-size: 0.72rem;
  max-width: 640px;
  margin: 0 auto;
}
