/* === Tokens === */
:root {
  --bg: #0b1020;
  --bg-2: #0f1530;
  --surface: #131a36;
  --surface-2: #1a2147;
  --border: #283063;
  --text: #e7ecff;
  --text-dim: #9aa3c7;
  --muted: #6e76a0;
  --accent: #f59e0b;
  --accent-2: #f97316;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);

  /* Elements */
  --Fire: #ee8130; --Water: #6390f0; --Ice: #96d9d6;
  --Electricity: #f7d02c; --Leaf: #7ac74c; --Earth: #d2b48c;
  --Dragon: #6f35fc; --Dark: #4a3a3a; --Neutral: #a8a77a;

  /* Rarities */
  --rarity-Common: #9ca3af;
  --rarity-Uncommon: #22c55e;
  --rarity-Rare: #3b82f6;
  --rarity-Epic: #a855f7;
  --rarity-Legendary: #f59e0b;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-hover); text-decoration: none; }
a:hover { color: var(--accent); }

h1, h2, h3 {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

img { max-width: 100%; display: block; }

/* === Nav === */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 16, 32, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 17px;
}
.logo-icon { font-size: 22px; }
.logo-text strong { color: var(--accent); font-weight: 900; }
.nav-links {
  display: flex;
  list-style: none;
  margin: 0; padding: 0;
  gap: 6px;
}
.nav-links a {
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
}
.nav-links a:hover { background: var(--surface); color: var(--text); }
.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
}
@media (max-width: 768px) {
  .nav-links { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; padding: 16px; background: var(--bg-2); border-bottom: 1px solid var(--border); }
  .nav-links.open { display: flex; }
  .nav-toggle { display: block; }
}

/* === Hero === */
.hero {
  position: relative;
  padding: 90px 24px 60px;
  overflow: hidden;
  isolation: isolate;
}
.hero-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at top right, rgba(245, 158, 11, 0.18), transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(99, 102, 241, 0.18), transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  z-index: -1;
}
.hero-inner {
  max-width: 1100px; margin: 0 auto;
  text-align: center;
}
.hero-eyebrow {
  display: inline-block;
  padding: 6px 14px;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 24px;
}
.hero-title {
  font-size: clamp(36px, 6vw, 64px);
  margin: 0 0 16px;
}
.hero-title .accent { color: var(--accent); }
.hero-title .muted { color: var(--text-dim); font-weight: 600; }
.hero-sub {
  font-size: 18px;
  color: var(--text-dim);
  max-width: 640px; margin: 0 auto 36px;
}
.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  margin-bottom: 60px;
}
.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  max-width: 760px;
  margin: 0 auto;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat-num {
  font-size: 36px;
  font-weight: 900;
  color: var(--accent);
}
.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #1a0a00;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(245, 158, 11, 0.5); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--primary); }
.btn-small { padding: 8px 14px; font-size: 13px; }
.btn.disabled, .btn[aria-disabled="true"] {
  opacity: 0.4;
  pointer-events: none;
}

/* === Sections === */
.section {
  max-width: 1280px;
  margin: 0 auto;
  padding: 80px 24px;
}
.section-head {
  text-align: center;
  margin-bottom: 40px;
}
.section-head h2 {
  font-size: clamp(28px, 4vw, 40px);
  margin-bottom: 8px;
}
.section-head p {
  color: var(--text-dim);
  font-size: 17px;
  margin: 0;
}

/* === Toolbar === */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 30px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.search input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border 0.15s;
}
.search input:focus { border-color: var(--primary); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
}
.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.filter-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
  margin-right: 4px;
}
.chip {
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
.chip:hover { color: var(--text); border-color: var(--primary); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

#sortBy {
  padding: 7px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.paldeck-summary {
  color: var(--text-dim);
  margin-bottom: 18px;
  font-size: 14px;
}
.paldeck-summary strong { color: var(--accent); }

/* === Pal grid === */
.pal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
}
.pal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}
.pal-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.pal-card .pal-image {
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.1), transparent 60%), var(--bg);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.pal-card .pal-image img {
  width: 100%; height: 100%;
  object-fit: contain;
}
.pal-card .pal-meta {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.pal-card .pal-name {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}
.pal-card .pal-num {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.pal-card .pal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.pal-card .tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-dim);
  font-weight: 600;
}
.pal-card .tag-rarity {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  color: #1a0a00;
}

/* Rarity colors on card */
.rarity-Common { background: var(--rarity-Common); }
.rarity-Uncommon { background: var(--rarity-Uncommon); }
.rarity-Rare { background: var(--rarity-Rare); color: white !important; }
.rarity-Epic { background: var(--rarity-Epic); color: white !important; }
.rarity-Legendary { background: var(--rarity-Legendary); }

/* Element tag colors */
.tag.elem-Fire { background: var(--Fire); color: white; }
.tag.elem-Water { background: var(--Water); color: white; }
.tag.elem-Ice { background: var(--Ice); color: #0a1a1a; }
.tag.elem-Electricity { background: var(--Electricity); color: #1a1500; }
.tag.elem-Leaf { background: var(--Leaf); color: #0a1a00; }
.tag.elem-Earth { background: var(--Earth); color: #1a1000; }
.tag.elem-Dragon { background: var(--Dragon); color: white; }
.tag.elem-Dark { background: var(--Dark); color: white; }
.tag.elem-Neutral { background: var(--Neutral); color: white; }

.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 32px;
}
.pagination button {
  min-width: 40px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.pagination button:hover { color: var(--text); border-color: var(--primary); }
.pagination button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.pagination button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* === TCG === */
.section-tcg {
  background: var(--bg-2);
  max-width: none;
  padding-left: 0; padding-right: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.section-tcg > .section-head, .section-tcg > .tcg-grid {
  max-width: 1280px;
  margin-left: auto; margin-right: auto;
  padding-left: 24px; padding-right: 24px;
}
.tcg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  padding-top: 30px;
}
.tcg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.15s, border-color 0.15s;
}
.tcg-card:hover { transform: translateY(-4px); border-color: var(--primary); }
.tcg-icon { font-size: 36px; }
.tcg-card h3 { font-size: 20px; }
.tcg-card p { color: var(--text-dim); margin: 0; font-size: 14px; flex-grow: 1; }
.tcg-card em { color: var(--accent); font-style: normal; font-weight: 600; }

/* === Files === */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.file-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.15s, border-color 0.15s;
  text-decoration: none;
  color: var(--text);
}
.file-card:hover { transform: translateY(-3px); border-color: var(--primary); }
.file-icon {
  font-size: 36px;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
  display: flex;
}
.file-info { flex-grow: 1; min-width: 0; }
.file-name { font-weight: 700; }
.file-meta { color: var(--text-dim); font-size: 12px; }

/* === Footer === */
.footer {
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  padding: 30px 24px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.footer-links { display: flex; gap: 16px; }
.footer-meta { color: var(--muted); }

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal[aria-hidden="false"] { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text); border-color: var(--primary); }
.modal-body { padding: 28px; }
.modal-image {
  background: var(--bg);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  display: flex; align-items: center; justify-content: center;
}
.modal-image img { max-height: 260px; }
.modal-title {
  font-size: 28px;
  margin-bottom: 8px;
}
.modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.modal-section {
  margin-bottom: 20px;
}
.modal-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 700;
}
.modal-works {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.work-tag {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-dim);
}
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* === Featured === */
.featured-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  max-width: 1000px;
  margin: 0 auto;
}
.featured-card {
  animation: glow 3s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 transparent; }
  50% { box-shadow: 0 0 20px rgba(245, 158, 11, 0.35); }
}
.featured .section-head p { color: var(--text-dim); }

/* === Loading spinner for lazy-loaded Pal images === */
.pal-image img { transition: opacity 0.2s; }
