:root {
  --bg: #0f1220;
  --bg-glow: #1c2140;
  --panel: #1a1e33;
  --panel-2: #232849;
  --text: #f2f2f7;
  --muted: #8a8fa8;
  --nav-border: rgba(255, 255, 255, 0.15);
  --row-tint: rgba(255, 255, 255, 0.05);

  --common: #9aa0b4;
  --uncommon: #4caf6a;
  --rare: #4a8ff0;
  --double-rare: #9a5cf0;
  --ultra-rare: #ff9d2f;
  --illustration-rare: #ff6fae;
  --special-illustration-rare: #ff3b5c;
  --hyper-rare: #f5c518;
}

:root[data-theme="light"] {
  --bg: #f3f4fa;
  --bg-glow: #e3e6f5;
  --panel: #ffffff;
  --panel-2: #eceef7;
  --text: #14161f;
  --muted: #5b6178;
  --nav-border: rgba(20, 22, 31, 0.15);
  --row-tint: rgba(20, 22, 31, 0.05);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, var(--bg-glow), var(--bg) 60%);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem 3rem;
  transition: background 0.3s ease, color 0.3s ease;
}

header {
  position: relative;
  text-align: center;
  margin-bottom: 1.5rem;
  width: 100%;
  max-width: 1000px;
}

header h1 {
  margin: 0 0 0.75rem;
  line-height: 0;
}

#logo {
  height: clamp(2.2rem, 8vw, 3.2rem);
  width: auto;
}

#theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--panel-2);
  border: 1px solid var(--nav-border);
  border-radius: 999px;
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: none;
  padding: 0;
}

#user-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

#view-nav {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.nav-btn {
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--nav-border);
  cursor: pointer;
  background: transparent;
  color: var(--muted);
}

.nav-btn.active {
  background: var(--panel-2);
  color: var(--text);
  border-color: transparent;
}

#pack-count {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

main {
  width: 100%;
  max-width: 1000px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.hidden {
  display: none !important;
}

/* ---------- Booster ---------- */

#view-pack {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

#pack-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#pack-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pack {
  width: clamp(220px, 60vw, 340px);
  height: auto;
  aspect-ratio: 466 / 700;
  object-fit: contain;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.5));
  transition: transform 0.4s ease, opacity 0.4s ease;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
  pointer-events: none;
}

#pack.opening {
  transform: scale(1.08);
  opacity: 0;
}

#open-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.25),
    0 0 26px 10px rgba(255, 204, 51, 0.75),
    0 0 55px 20px rgba(224, 57, 62, 0.5);
  animation: btn-glow 2s ease-in-out infinite alternate;
}

@keyframes btn-glow {
  from {
    box-shadow:
      0 0 0 4px rgba(255, 255, 255, 0.25),
      0 0 26px 10px rgba(255, 204, 51, 0.75),
      0 0 55px 20px rgba(224, 57, 62, 0.5);
  }
  to {
    box-shadow:
      0 0 0 4px rgba(255, 255, 255, 0.3),
      0 0 34px 14px rgba(255, 204, 51, 0.9),
      0 0 70px 26px rgba(224, 57, 62, 0.65);
  }
}

/* ---------- Stack (one card at a time) ---------- */

#stack-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

#stack-progress {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
  text-align: center;
}

#stack {
  position: relative;
  width: clamp(200px, 65vw, 300px);
  aspect-ratio: 63 / 88;
  margin-top: 16px;
}

.stack-card {
  position: absolute;
  inset: 0;
  perspective: 900px;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.stack-card .card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stack-card.flipped .card-inner {
  transform: rotateY(180deg);
}

.stack-card.consumed {
  transform: translateY(-120%) rotate(-8deg) scale(0.9);
  opacity: 0;
  pointer-events: none;
}

.stack-card:not(.active) {
  pointer-events: none;
}

.card-price {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.3s ease 0.15s;
}

.stack-card.flipped .card-price {
  opacity: 1;
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back {
  background: linear-gradient(135deg, #3b6fd6, #1a1a2e);
  border: 3px solid #0f1220;
}

.card-back::after {
  content: "?";
  font-size: 3rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.6);
}

.card-front {
  transform: rotateY(180deg);
  background: var(--panel);
  border: 3px solid var(--common);
  flex-direction: column;
}

.card-front img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.card-front.rarity-common { border-color: var(--common); }
.card-front.rarity-uncommon { border-color: var(--uncommon); box-shadow: 0 0 12px var(--uncommon); }
.card-front.rarity-rare { border-color: var(--rare); box-shadow: 0 0 14px var(--rare); }
.card-front.rarity-double-rare { border-color: var(--double-rare); box-shadow: 0 0 16px var(--double-rare); }
.card-front.rarity-ultra-rare { border-color: var(--ultra-rare); box-shadow: 0 0 18px var(--ultra-rare); }
.card-front.rarity-illustration-rare { border-color: var(--illustration-rare); box-shadow: 0 0 20px var(--illustration-rare); }
.card-front.rarity-special-illustration-rare { border-color: var(--special-illustration-rare); box-shadow: 0 0 24px var(--special-illustration-rare); }
.card-front.rarity-hyper-rare {
  border-color: var(--hyper-rare);
  box-shadow: 0 0 28px var(--hyper-rare);
  animation: shimmer 1.6s ease-in-out infinite alternate;
}

@keyframes shimmer {
  from { box-shadow: 0 0 16px var(--hyper-rare); }
  to { box-shadow: 0 0 34px var(--hyper-rare); }
}

.rarity-badge {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 0.65rem;
  text-align: center;
  padding: 0.2rem 0.3rem;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-name {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  font-size: 0.65rem;
  text-align: center;
  padding: 0.2rem 0.3rem;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}

/* ---------- Buttons ---------- */

button {
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #ffcc33, #e0393e);
  color: #1a1a2e;
  box-shadow: 0 6px 18px rgba(224, 57, 62, 0.35);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

button:hover {
  transform: translateY(-2px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--nav-border);
  font-size: 0.85rem;
  padding: 0.6rem 1.1rem;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
  box-shadow: 0 6px 18px rgba(192, 57, 43, 0.35);
  font-size: 0.85rem;
  padding: 0.6rem 1.1rem;
}

#collection-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

/* ---------- Collection ---------- */

#view-collection {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

#collection-summary {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.stat-tile {
  background: var(--panel);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 120px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
}

.stat-label {
  color: var(--muted);
  font-size: 0.8rem;
}

#rarity-breakdown {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.rarity-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  border-left: 4px solid var(--common);
  font-size: 0.85rem;
}

.rarity-row .rarity-name {
  color: var(--text);
}

.rarity-row .rarity-count {
  font-weight: 700;
  color: var(--muted);
}

.rarity-row.rarity-common { border-color: var(--common); }
.rarity-row.rarity-uncommon { border-color: var(--uncommon); }
.rarity-row.rarity-rare { border-color: var(--rare); }
.rarity-row.rarity-double-rare { border-color: var(--double-rare); }
.rarity-row.rarity-ultra-rare { border-color: var(--ultra-rare); }
.rarity-row.rarity-illustration-rare { border-color: var(--illustration-rare); }
.rarity-row.rarity-special-illustration-rare { border-color: var(--special-illustration-rare); }
.rarity-row.rarity-hyper-rare { border-color: var(--hyper-rare); }

#collection-empty {
  color: var(--muted);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.85rem;
  width: 100%;
}

.collection-card {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 3px solid var(--common);
  aspect-ratio: 63 / 88;
}

.collection-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.collection-card .count-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}

.collection-card .price-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}

.collection-card.rarity-common { border-color: var(--common); }
.collection-card.rarity-uncommon { border-color: var(--uncommon); }
.collection-card.rarity-rare { border-color: var(--rare); }
.collection-card.rarity-double-rare { border-color: var(--double-rare); }
.collection-card.rarity-ultra-rare { border-color: var(--ultra-rare); }
.collection-card.rarity-illustration-rare { border-color: var(--illustration-rare); }
.collection-card.rarity-special-illustration-rare { border-color: var(--special-illustration-rare); }
.collection-card.rarity-hyper-rare { border-color: var(--hyper-rare); }

@media (max-width: 480px) {
  .cards-grid {
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  }
}

/* ---------- Connexion ---------- */

#view-login {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-top: 2rem;
}

#login-form {
  background: var(--panel);
  border-radius: 12px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 320px;
}

#login-form label {
  font-size: 0.9rem;
  color: var(--muted);
}

#login-form input {
  font: inherit;
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--nav-border);
  background: var(--panel-2);
  color: var(--text);
}

#login-error {
  color: var(--special-illustration-rare);
  font-size: 0.85rem;
  margin: 0;
}

/* ---------- Limite de packs ---------- */

#pack-limit {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  max-width: 320px;
  margin: 0.75rem auto 0;
}

#unlock-btn {
  display: block;
  margin: 0.75rem auto 0;
  background: none;
  box-shadow: none;
  border: none;
  font-size: 0.85rem;
  padding: 0.3rem;
  opacity: 0.25;
  transition: opacity 0.2s ease;
}

#unlock-btn:hover {
  opacity: 0.8;
  transform: none;
}

/* ---------- Classement ---------- */

#view-leaderboard {
  width: 100%;
}

#leaderboard-table {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
}

#leaderboard-table th,
#leaderboard-table td {
  padding: 0.6rem 0.9rem;
  text-align: left;
  font-size: 0.9rem;
}

#leaderboard-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--nav-border);
}

#leaderboard-table tbody tr:nth-child(even) {
  background: var(--row-tint);
}

#leaderboard-table tr.me {
  outline: 2px solid var(--hyper-rare);
  outline-offset: -2px;
}

footer {
  margin-top: 2.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  max-width: 480px;
}

footer p {
  margin: 0 0 0.5rem;
}

footer .legal {
  font-size: 0.7rem;
  opacity: 0.7;
  line-height: 1.5;
}

footer a {
  color: var(--muted);
  text-decoration: underline;
}
