/* ============================================================
   CardForge Deck Builder — cardforge-deck-builder.css
   Full deck composition experience at /cardforge/deck.html
   ============================================================ */

/* ── Layout ── */
.db-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: #0e0e1a;
  color: #e1e1ff;
  font-family: 'Inter', sans-serif;
}

/* Top bar */
.db-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: rgba(20, 20, 36, 0.95);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.db-bar-brand {
  font-size: 0.82rem;
  font-weight: 600;
  color: #a0a0c0;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.db-bar-brand:hover { color: #00d4ff; }

.db-bar-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #e1e1ff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.db-bar-title i { color: #7c3aed; }

.db-bar-actions {
  display: flex;
  gap: 0.5rem;
}

/* ── Shared button ── */
.db-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: #e1e1ff;
  font-size: 0.78rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 36px;
}

.db-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(124, 58, 237, 0.3);
  color: #c4b5fd;
}

.db-btn:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
}

.db-btn-primary {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border-color: rgba(124, 58, 237, 0.4);
  color: #fff;
}

.db-btn-primary:hover {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.3);
}

.db-btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.db-btn-accent {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border: none;
  color: #1a1a2e;
  font-weight: 600;
}

.db-btn-accent:hover {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
  color: #1a1a2e;
}

.db-btn-danger {
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.db-btn-danger:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.5);
  color: #f87171;
}

/* ── Metadata bar ── */
.db-meta {
  padding: 1rem 1.5rem;
  background: rgba(20, 20, 36, 0.6);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.db-meta-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(124, 58, 237, 0.12);
  border: 1px solid rgba(124, 58, 237, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7c3aed;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.db-meta-icon:hover {
  background: rgba(124, 58, 237, 0.2);
  border-color: rgba(124, 58, 237, 0.4);
}

.db-meta-name {
  font-size: 1.1rem;
  font-weight: 700;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #e1e1ff;
  padding: 0.3rem 0.5rem;
  font-family: inherit;
  min-width: 160px;
  max-width: 300px;
  transition: border-color 0.15s ease;
}

.db-meta-name:hover { border-color: rgba(255,255,255,0.1); }
.db-meta-name:focus {
  outline: none;
  border-color: rgba(124, 58, 237, 0.4);
  background: rgba(255,255,255,0.04);
}

.db-meta-desc {
  font-size: 0.8rem;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #a0a0c0;
  padding: 0.3rem 0.5rem;
  font-family: inherit;
  flex: 1;
  min-width: 120px;
}

.db-meta-desc:hover { border-color: rgba(255,255,255,0.08); }
.db-meta-desc:focus {
  outline: none;
  border-color: rgba(124, 58, 237, 0.3);
  background: rgba(255,255,255,0.03);
  color: #e1e1ff;
}

.db-meta-capacity {
  font-size: 0.75rem;
  font-weight: 600;
  color: #a0a0c0;
  padding: 0.25rem 0.6rem;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
}

.db-meta-capacity.full { color: #f59e0b; border-color: rgba(245, 158, 11, 0.3); }
.db-meta-capacity.over { color: #ef4444; border-color: rgba(239, 68, 68, 0.3); }

/* ── Main content split ── */
.db-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Collection panel (left) */
.db-collection {
  flex: 1 1 45%;
  min-width: 280px;
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  background: rgba(15, 15, 28, 0.6);
}

.db-collection-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.db-collection-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #a0a0c0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.db-collection-title .count {
  background: rgba(124, 58, 237, 0.15);
  color: #c4b5fd;
  padding: 0.1rem 0.45rem;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 600;
}

.db-collection-search {
  position: relative;
}

.db-collection-search input {
  width: 100%;
  padding: 0.4rem 0.6rem 0.4rem 2rem;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: #e1e1ff;
  font-size: 0.78rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.db-collection-search input:focus {
  outline: none;
  border-color: rgba(124, 58, 237, 0.4);
}

.db-collection-search i {
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: #6a6a8a;
  font-size: 0.72rem;
  pointer-events: none;
}

.db-collection-filters {
  display: flex;
  gap: 0.35rem;
}

.db-collection-filters select {
  flex: 1;
  padding: 0.3rem 0.4rem;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: #a0a0c0;
  font-size: 0.72rem;
  font-family: inherit;
  cursor: pointer;
}

.db-collection-filters select:focus {
  outline: none;
  border-color: rgba(124, 58, 237, 0.3);
}

/* Collection card grid */
.db-collection-grid {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.6rem;
  align-content: start;
}

.db-collection-grid::-webkit-scrollbar { width: 4px; }
.db-collection-grid::-webkit-scrollbar-track { background: transparent; }
.db-collection-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.db-coll-card {
  background: #1a1a2e;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.db-coll-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  border-color: rgba(124, 58, 237, 0.3);
}

.db-coll-card.in-deck {
  opacity: 0.45;
  pointer-events: none;
}

.db-coll-card.in-deck::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 255, 136, 0.9);
  color: #000;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

/* ── Mini-card rendered preview ── */
.db-mini-card-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  overflow: hidden;
  background: #12121e;
}

.db-mini-card-wrap .mini-card-scaler {
  --db-scale: 0.35;
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-width, 400px);
  transform: scale(var(--db-scale));
  transform-origin: top left;
  pointer-events: none;
}

.db-mini-card-wrap .mini-card-scaler > .card-front,
.db-mini-card-wrap .mini-card-scaler > [class*="card-front"] {
  height: var(--card-height, 560px) !important;
  overflow: hidden !important;
}

/* ── Card info section below card visual ── */
.db-coll-card-info {
  padding: 0.4rem 0.5rem 0.45rem;
  background: rgba(15, 15, 28, 0.9);
  border-top: 1px solid rgba(255,255,255,0.04);
}
.db-coll-card-name {
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.2rem;
}
.db-coll-card-meta {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}
.db-coll-card-class {
  font-size: 0.58rem;
  color: #8888aa;
  font-weight: 500;
}
.db-coll-card-info .db-rarity-badge {
  font-size: 0.52rem;
  padding: 0.1rem 0.35rem;
}
.db-coll-card-info .db-stat-pills {
  gap: 0.2rem;
}
.db-coll-card-info .db-stat-pill {
  font-size: 0.5rem;
  padding: 0.1rem 0.3rem;
}

/* ── Fallback styled card (when renderedFront not available) ── */
.db-fallback-card {
  width: 100%;
  aspect-ratio: 5 / 7;
  display: flex;
  flex-direction: column;
  background: #12121e;
  border: 1.5px solid #3a3a5a;
  border-radius: 6px;
  overflow: hidden;
}
.db-fallback-card-header {
  padding: 0.35rem 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.db-fallback-card-title {
  font-size: 0.6rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #e1e1ff;
}
.db-fallback-card-art {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a16;
}
.db-fallback-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.db-fallback-card-placeholder {
  color: #3a3a5a;
  font-size: 1.4rem;
}
.db-fallback-card-footer {
  padding: 0.3rem 0.45rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 15, 28, 0.9);
  border-top: 1px solid rgba(255,255,255,0.04);
}
.db-fallback-card-class {
  font-size: 0.55rem;
  color: #8888aa;
  font-weight: 500;
}
.db-fallback-card-rarity {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.db-collection-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: #6a6a8a;
  grid-column: 1 / -1;
}

.db-collection-empty i {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  display: block;
}

/* ── Deck composition panel (right) ── */
.db-deck {
  flex: 1 1 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.db-deck-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.db-deck-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #a0a0c0;
}

.db-deck-stats {
  display: flex;
  gap: 0.75rem;
  font-size: 0.7rem;
  color: #6a6a8a;
}

.db-deck-stat {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.db-deck-stat i { color: #7c3aed; font-size: 0.65rem; }

/* Deck cards list */
.db-deck-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.db-deck-list::-webkit-scrollbar { width: 4px; }
.db-deck-list::-webkit-scrollbar-track { background: transparent; }
.db-deck-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.db-deck-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.65rem;
  background: rgba(26, 26, 46, 0.8);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  transition: background 0.12s ease, border-color 0.12s ease;
  cursor: grab;
}

.db-deck-item:active { cursor: grabbing; }

.db-deck-item:hover {
  background: rgba(26, 26, 46, 1);
  border-color: rgba(124, 58, 237, 0.2);
}

.db-deck-item.drag-over {
  border-color: rgba(124, 58, 237, 0.5);
  background: rgba(124, 58, 237, 0.08);
}

.db-deck-item-num {
  font-size: 0.65rem;
  color: #6a6a8a;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

.db-deck-item-thumb {
  width: 36px;
  height: 50px;
  border-radius: 4px;
  object-fit: cover;
  background: #12121e;
  flex-shrink: 0;
}

.db-deck-item-thumb-placeholder {
  width: 36px;
  height: 50px;
  border-radius: 4px;
  background: #12121e;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3a3a5a;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.db-deck-item-info {
  flex: 1;
  min-width: 0;
}

.db-deck-item-name {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-deck-item-meta {
  font-size: 0.65rem;
  color: #6a6a8a;
  margin-top: 0.1rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* ── Rarity badge (deck list) ── */
.db-rarity-badge {
  font-size: 0.55rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--rarity-color, #9ca3af);
  background: color-mix(in srgb, var(--rarity-color, #9ca3af) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--rarity-color, #9ca3af) 25%, transparent);
  padding: 0.08rem 0.35rem;
  border-radius: 4px;
  white-space: nowrap;
}

/* ── Stat pills (deck list) ── */
.db-stat-pills {
  display: flex;
  gap: 0.2rem;
  margin-top: 0.2rem;
  flex-wrap: wrap;
}

.db-stat-pill {
  font-size: 0.55rem;
  font-weight: 500;
  color: #a0a0c0;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  padding: 0.06rem 0.3rem;
  border-radius: 3px;
  white-space: nowrap;
}

.db-deck-item-remove {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #6a6a8a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  transition: all 0.12s ease;
  flex-shrink: 0;
}

.db-deck-item-remove:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.db-deck-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #6a6a8a;
}

.db-deck-empty i {
  font-size: 2rem;
  margin-bottom: 0.75rem;
  display: block;
  color: #3a3a5a;
}

.db-deck-empty p { margin-bottom: 0.35rem; }
.db-deck-empty small { font-size: 0.72rem; }

/* ── View mode (shared deck) ── */
.db-view-container {
  width: 100%;
  max-width: 900px;
  padding: 2rem 1.5rem 4rem;
  margin: 0 auto;
}

.db-view-header {
  text-align: center;
  margin-bottom: 2rem;
}

.db-view-icon {
  font-size: 2rem;
  color: #7c3aed;
  margin-bottom: 0.5rem;
}

.db-view-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.db-view-desc {
  color: #a0a0c0;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.db-view-tags {
  display: flex;
  gap: 0.35rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.db-view-tag {
  padding: 0.15rem 0.55rem;
  border-radius: 9px;
  background: rgba(124, 58, 237, 0.08);
  border: 1px solid rgba(124, 58, 237, 0.15);
  color: #c4b5fd;
  font-size: 0.68rem;
  font-weight: 500;
}

.db-view-meta {
  font-size: 0.75rem;
  color: #6a6a8a;
}

.db-view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

/* ── Icon picker dropdown ── */
.db-icon-picker {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.35rem;
  background: #1a1a2e;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.25rem;
  z-index: 120;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  display: none;
}

.db-icon-picker.open { display: grid; }

.db-icon-picker button {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #a0a0c0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.1s ease;
}

.db-icon-picker button:hover {
  background: rgba(124, 58, 237, 0.15);
  color: #c4b5fd;
}

.db-icon-picker button.selected {
  background: rgba(124, 58, 237, 0.2);
  color: #7c3aed;
}

/* ── Toast ── */
.db-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: #1e1e32;
  border: 1px solid rgba(124, 58, 237, 0.25);
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  color: #c4b5fd;
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
}

.db-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Loading / Error states ── */
.db-loading,
.db-error {
  text-align: center;
  padding: 4rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.db-loading i,
.db-error i {
  font-size: 2rem;
  margin-bottom: 1rem;
  display: block;
}

.db-loading i { color: #7c3aed; }
.db-error i { color: #ef4444; }
.db-error p { color: #a0a0c0; margin-bottom: 1rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .db-main {
    flex-direction: column;
  }

  .db-collection {
    width: 100%;
    max-width: none;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    max-height: 45vh;
  }

  .db-collection-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .db-meta {
    padding: 0.75rem 1rem;
  }

  .db-meta-name {
    min-width: 120px;
  }

  .db-bar-title { display: none; }
}

@media (max-width: 480px) {
  .db-collection-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }

  .db-collection {
    max-height: 40vh;
  }

  .db-meta {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .db-meta-name {
    max-width: none;
    width: 100%;
  }

  .db-view-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .db-view-title { font-size: 1.2rem; }
}

/* ── Tutorial Tips ── */
.db-tip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(124, 58, 237, 0.08);
  border: 1px solid rgba(124, 58, 237, 0.15);
  border-radius: 6px;
  font-size: 0.72rem;
  color: #c4b5fd;
  line-height: 1.4;
  max-height: 100px;
  overflow: hidden;
  transition: opacity 0.2s ease, max-height 0.2s ease, padding 0.2s ease, margin 0.2s ease;
}

.db-tip-accent {
  background: rgba(245, 158, 11, 0.06);
  border-color: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.db-tip-accent .db-tip-icon { color: #f59e0b; }

.db-tip-icon {
  color: #7c3aed;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.db-tip span { flex: 1; }
.db-tip span i { font-size: 0.65rem; opacity: 0.7; }
.db-tip span strong { color: #e1e1ff; font-weight: 600; }

.db-tip-close {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  opacity: 0.5;
  flex-shrink: 0;
  transition: opacity 0.12s ease;
}

.db-tip-close:hover { opacity: 1; }

/* Tips inside deck panel insert after header */
.db-deck > .db-tip { margin: 0 0.75rem; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .db-coll-card,
  .db-deck-item,
  .db-toast,
  .db-btn {
    transition: none;
  }
}
