/* -------------------------------------------------- */
/*  Design tokens (matches dev branch)                 */
/* -------------------------------------------------- */
:root {
  --bg: #0a0c12;
  --surface: #12151e;
  --surface-up: #181c28;
  --border: #1f2436;
  --border-light: #2a3048;
  --text: #c8cee0;
  --text-muted: #8890a4;
  --text-dim: #6b7394;
  --text-faint: #3d4260;
  --blue: #5b8af5;
  --blue-dim: rgba(91, 138, 245, 0.15);
  --gold: #ffd700;
  --gold-dim: rgba(255, 215, 0, 0.15);
  --font-body: 'DM Sans', sans-serif;
  --font-display: 'Outfit', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* -------------------------------------------------- */
/*  Backdrop                                           */
/* -------------------------------------------------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.backdrop::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, #1a1f30 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.3;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.3;
  animation: orbFloat 20s ease-in-out infinite;
}

.orb-1 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--blue), transparent 70%);
  top: -10%; left: -5%;
}

.orb-2 {
  width: 350px; height: 350px;
  background: radial-gradient(circle, #a06ef5, transparent 70%);
  bottom: 10%; right: -5%;
  animation-delay: -10s;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(25px, -15px) scale(1.04); }
  66% { transform: translate(-15px, 10px) scale(0.96); }
}

/* -------------------------------------------------- */
/*  Header                                             */
/* -------------------------------------------------- */
header {
  position: relative;
  z-index: 2;
  background: linear-gradient(180deg, rgba(22, 26, 38, 0.95), rgba(18, 21, 30, 0.9));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.home-link {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: -0.3px;
  transition: color 0.15s;
  flex-shrink: 0;
}
.home-link:visited { color: var(--text-dim); }
.home-link:hover { color: var(--blue); }

h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.demo-tag {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #d4a017;
  border: 1px solid rgba(255, 215, 0, 0.25);
  background: rgba(255, 215, 0, 0.08);
  border-radius: 6px;
  padding: 3px 8px;
  vertical-align: middle;
}

.search-wrapper { flex: 1; max-width: 280px; margin: 0 auto; }
.search-wrapper input {
  width: 100%;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: #fff;
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-wrapper input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 10px rgba(91, 138, 245, 0.2);
}
.search-wrapper input::placeholder { color: var(--text-dim); }

/* -------------------------------------------------- */
/*  Toolbar / Filters                                  */
/* -------------------------------------------------- */
.toolbar {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
}

.filter-group.compact { display: flex; align-items: center; gap: 4px; }

.filter-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.pill {
  font-family: var(--font-display);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  line-height: 1.4;
}
.pill:hover { color: var(--text); border-color: var(--border-light); }
.pill.active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 10px rgba(91, 138, 245, 0.25);
}

/* Tag pills — subtler active */
.tag-pill.active {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: none;
}

/* Element icons in pills */
.el-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

/* Rarity labels */
.rarity-label { font-weight: 700; letter-spacing: 0.5px; }
.rarity-label.r { color: #8890a4; }
.rarity-label.sr { color: #5b9aff; }
.rarity-label.ssr { color: #ffd700; }
.rarity-label.ssr-plus { color: #ff8c42; }
.pill.active .rarity-label { color: #fff; }

/* -------------------------------------------------- */
/*  Collapsible sections                               */
/* -------------------------------------------------- */
.collapsible {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 4px;
}

.collapsible-toggle {
  font-family: var(--font-display);
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 6px 0;
  transition: color 0.15s;
}
.collapsible-toggle:hover { color: var(--text); }

.collapsible-toggle .chevron {
  width: 16px;
  height: 16px;
  margin-left: auto;
  transition: transform 0.2s;
  color: var(--text-faint);
}
.collapsible.open .chevron { transform: rotate(180deg); }

.toggle-count {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.toggle-count.has-active { color: var(--blue); }

.collapsible-body {
  padding: 6px 0 4px;
}

.hidden { display: none !important; }

/* -------------------------------------------------- */
/*  Main / Grid                                        */
/* -------------------------------------------------- */
main {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px;
}

.results-count {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.erodex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

/* -------------------------------------------------- */
/*  Character Card                                     */
/* -------------------------------------------------- */
.char-card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  aspect-ratio: 1;
}
.char-card:hover {
  border-color: var(--blue);
  transform: translateY(-3px);
  box-shadow: 0 6px 24px rgba(91, 138, 245, 0.2);
}

.char-card > img:first-child {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

/* Top-left meta (rarity + class) */
.card-top-meta {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: linear-gradient(to bottom, rgba(10, 12, 18, 0.75) 0%, transparent 100%);
  pointer-events: none;
}

.card-rarity {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
.card-rarity.r { color: #8890a4; }
.card-rarity.sr { color: #5b9aff; }
.card-rarity.ssr { color: #ffd700; }
.card-rarity.ssr-plus { color: #ff8c42; }

.card-class {
  font-size: 10px;
  color: var(--text-muted);
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* Element icon — top right */
.card-element-icon {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  pointer-events: none;
  filter: drop-shadow(0 1px 4px rgba(0,0,0,0.7));
}

/* Bottom name overlay — minimal gradient */
.card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28%;
  background: linear-gradient(to bottom, transparent 0%, rgba(10, 12, 18, 0.85) 60%, rgba(10, 12, 18, 0.95) 100%);
  display: flex;
  align-items: flex-end;
  padding: 6px 8px;
  pointer-events: none;
}

.card-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* -------------------------------------------------- */
/*  Empty state                                        */
/* -------------------------------------------------- */
.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 20px;
  font-size: 15px;
}

/* -------------------------------------------------- */
/*  Responsive                                         */
/* -------------------------------------------------- */
@media (max-width: 700px) {
  header { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  h1 { font-size: 16px; }
  .search-wrapper { max-width: none; order: 1; width: 100%; flex-basis: 100%; margin-left: 0; }
  .toolbar { padding: 10px 16px; }
  .toolbar-row { gap: 4px; }
  .filter-sep { display: none; }
  main { padding: 16px; }
  .erodex-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 8px;
  }
  .card-name { font-size: 12px; }
  .pill { padding: 4px 8px; font-size: 11px; }
  .orb-1 { width: 250px; height: 250px; }
  .orb-2 { width: 200px; height: 200px; }
}

@media (max-width: 400px) {
  .erodex-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
}

/* -------------------------------------------------- */
/*  Spine badge on cards                               */
/* -------------------------------------------------- */
.spine-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(91, 138, 245, 0.9), rgba(91, 138, 245, 0.4));
  border: 1.5px solid rgba(91, 138, 245, 0.6);
  pointer-events: none;
  z-index: 2;
  animation: spineBadgePulse 2.5s ease-in-out infinite;
}

@keyframes spineBadgePulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* -------------------------------------------------- */
/*  Detail overlay & panel                             */
/* -------------------------------------------------- */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.2s;
}

.detail-overlay.hidden {
  display: none !important;
}

.detail-panel {
  position: relative;
  width: 92%;
  max-width: 920px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: panelIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes panelIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 16px;
  z-index: 10;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: color 0.15s;
}
.detail-close:hover { color: #fff; }

.detail-content {
  padding: 28px 32px;
}

/* ---- Header ---- */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.detail-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: #fff;
}

.detail-element-icon {
  width: 28px;
  height: 28px;
}

.detail-meta {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--text-muted);
}

.detail-rarity {
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-right: 4px;
}

/* ---- Body (2-col) ---- */
.detail-body {
  display: flex;
  gap: 28px;
}

.detail-spine-col {
  flex: 1;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, #2a2d33 0%, #1c1e23 100%);
  border: 1px solid var(--border);
}

.detail-spine-col::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.75) 0 1px, transparent 1.5px),
    radial-gradient(circle at 72% 43%, rgba(255,255,255,0.55) 0 1px, transparent 1.5px),
    radial-gradient(circle at 40% 82%, rgba(255,255,255,0.7)  0 1.5px, transparent 2px),
    radial-gradient(circle at 87% 12%, rgba(255,255,255,0.5)  0 1px, transparent 1.5px),
    radial-gradient(circle at 22% 65%, rgba(255,255,255,0.6)  0 1px, transparent 1.5px),
    radial-gradient(circle at 55% 15%, rgba(255,255,255,0.65) 0 1px, transparent 1.5px),
    radial-gradient(circle at 92% 78%, rgba(255,255,255,0.5)  0 1.5px, transparent 2px),
    radial-gradient(circle at 5% 92%,  rgba(255,255,255,0.6)  0 1px, transparent 1.5px);
  background-size: 220px 220px;
  background-repeat: repeat;
  animation: spine-particles-slow 38s linear infinite;
}

.detail-spine-col::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,0.9)  0 1px, transparent 1.5px),
    radial-gradient(circle at 65% 70%, rgba(255,255,255,0.85) 0 1.5px, transparent 2px),
    radial-gradient(circle at 10% 85%, rgba(255,255,255,0.75) 0 1px, transparent 1.5px);
  background-size: 140px 140px;
  background-repeat: repeat;
  animation: spine-particles-fast 22s linear infinite;
  z-index: -1;
}

@keyframes spine-particles-slow {
  from { background-position: 0 0; }
  to   { background-position: 220px -220px; }
}
@keyframes spine-particles-fast {
  from { background-position: 0 0; }
  to   { background-position: -140px 140px; }
}

.detail-spine-col > div,
.detail-spine-col > img,
.detail-spine-col > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.detail-spine-col {
  transition: opacity 0.4s ease;
}
.detail-spine-col.spine-loading {
  opacity: 0;
}

.detail-spine-col .spine-player-widget {
  background: transparent !important;
}

.detail-portrait-fallback {
  max-width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.detail-info-col {
  flex: 1;
  min-width: 0;
}

/* ---- Stats grid ---- */
.detail-section-title {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}

.stat-cell {
  background: var(--surface-up);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}

.stat-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

/* ---- Skills ---- */
.detail-skills {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skill-card {
  background: var(--surface-up);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.skill-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.skill-slot {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--blue);
  background: var(--blue-dim);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.skill-slot.hidden-piece {
  color: var(--gold);
  background: var(--gold-dim);
}

.skill-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.skill-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.sd-val { color: #ff8c42; font-weight: 600; }
.sd-target { color: #60a5fa; }
.sd-buff { color: #4ade80; }
.sd-debuff { color: #f87171; }
.sd-cd { color: var(--text-dim); font-style: italic; }
.sd-keyword { color: #fff; }

.detail-spine-wrapper {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* ---- Spine Tuning Tool ---- */
.tune-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-up);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.tune-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}

.tune-slider {
  flex: 1;
  min-width: 80px;
  accent-color: var(--blue);
}

.tune-val {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  min-width: 36px;
}

.tune-btn {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--blue);
  background: var(--blue-dim);
  color: var(--blue);
  cursor: pointer;
  transition: all 0.15s;
}
.tune-btn:hover {
  background: var(--blue);
  color: #fff;
}

/* ---- Detail responsive ---- */
@media (max-width: 700px) {
  .detail-content { padding: 20px 18px; }
  .detail-body { flex-direction: column; gap: 20px; }
  .detail-spine-col { flex: none; height: 400px; }
  .detail-stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .detail-name { font-size: 20px; }
  .stat-value { font-size: 14px; }
}

@media (max-width: 400px) {
  .detail-content { padding: 16px 14px; }
  .detail-spine-col { flex: none; height: 320px; }
  .detail-stats { grid-template-columns: repeat(2, 1fr); }
  .detail-name { font-size: 18px; }
}
