/* ============================================================
   Neuroscape Deck Builder — deckbuilder.css
   Matches the existing site aesthetic (dark, cyan/purple accent)
   ============================================================ */

/* ── Reset / base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.db-page {
  --accent: #00eea3;
  --accent2: #a855f7;
  --bg: #0d0d0f;
  --bg2: #141418;
  --bg3: #1c1c22;
  --border: #2a2a35;
  --text: #e8e8f0;
  --text-muted: #6b6b80;
  --red: #ef4444;
  --yellow: #f59e0b;
  --green: #22c55e;
  --rarity-common: #6b7280;
  --rarity-uncommon: #22c55e;
  --rarity-rare: #3b82f6;
  --rarity-qr: #a855f7;
  --rarity-ar: #f59e0b;
  --rarity-basic: #9ca3af;

  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────── */
.db-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.db-logo { height: 32px; }
.db-logo-link { display: flex; align-items: center; }
.db-title { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.05em; color: var(--accent); flex: 1; }
.db-header-actions { display: flex; gap: 0.5rem; }

/* ── Buttons ─────────────────────────────────────────────── */
.db-btn {
  padding: 0.45rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, background 0.15s;
}
.db-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.db-btn-primary { background: var(--accent); color: #000; }
.db-btn-primary:hover:not(:disabled) { opacity: 0.85; }
.db-btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.db-btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.db-btn-danger { background: var(--red); color: #fff; }
.db-btn-danger:hover:not(:disabled) { opacity: 0.85; }

/* ── Main two-panel layout ───────────────────────────────── */
.db-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  flex: 1;
  overflow: hidden;
}

/* ── Catalog ─────────────────────────────────────────────── */
.db-catalog {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.db-catalog-controls {
  padding: 0.75rem 1rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.db-catalog-controls input[type="search"] {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.db-catalog-controls input[type="search"]:focus { outline: 2px solid var(--accent); border-color: transparent; }

.db-type-pills { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.db-pill {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg3);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.db-pill:hover { color: var(--text); border-color: var(--accent); }
.db-pill.active { background: var(--accent); color: #000; border-color: var(--accent); }

.db-filter-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.db-filter-row select {
  flex: 1;
  min-width: 110px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
}
.db-filter-row select:focus { outline: 2px solid var(--accent); }

.db-catalog-count { font-size: 0.78rem; color: var(--text-muted); }

/* Card grid */
.db-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.6rem;
  padding: 0.75rem;
  overflow-y: auto;
  flex: 1;
}
.db-card-tile {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  position: relative;
}
.db-card-tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.db-card-tile.db-tile-disabled { opacity: 0.45; cursor: default; }
.db-card-tile.db-tile-disabled:hover { border-color: var(--border); transform: none; }

.db-tile-img-wrap { position: relative; aspect-ratio: 3/4; background: var(--bg3); }
.db-tile-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.db-tile-img-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 2rem; }

.db-tile-qty-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent);
  color: #000;
  font-size: 0.7rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 1px 6px;
  line-height: 1.5;
}

/* ── Live copy counter (X/4) ─────────────────────────────── */
.db-copy-counter {
  position: absolute;
  bottom: 5px;
  right: 5px;
  font-size: 0.68rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 1px 6px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  pointer-events: none;
  transition: background 0.15s, color 0.15s;
}
.db-copy-counter--empty {
  background: rgba(0,0,0,0.55);
  color: var(--text-muted);
}
.db-copy-counter--active {
  background: var(--accent);
  color: #000;
}
.db-copy-counter--warn {
  background: var(--yellow);
  color: #000;
}
.db-copy-counter--full {
  background: var(--red);
  color: #fff;
}

.db-tile-info { padding: 0.4rem 0.5rem; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.db-tile-name { font-size: 0.72rem; font-weight: 700; line-height: 1.2; }
.db-tile-meta { font-size: 0.68rem; color: var(--text-muted); display: flex; justify-content: space-between; }
.db-tile-factions { font-size: 0.66rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.db-tile-add {
  width: 100%;
  background: var(--bg3);
  border: none;
  border-top: 1px solid var(--border);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0.3rem;
  transition: background 0.15s;
}
.db-tile-add:hover:not(:disabled) { background: var(--accent); color: #000; }
.db-tile-add:disabled { color: var(--text-muted); cursor: not-allowed; }

/* ── Workspace ───────────────────────────────────────────── */
.db-workspace {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg2);
}
.db-workspace-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}
.db-deck-name {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  padding: 0.2rem 0.4rem;
  letter-spacing: 0.02em;
}
.db-deck-name:focus { outline: none; border-bottom-color: var(--accent); }
.db-format-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  background: var(--bg3);
  color: var(--accent2);
  border: 1px solid var(--accent2);
  white-space: nowrap;
  letter-spacing: 0.05em;
}

/* Tabs */
.db-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.db-tab {
  flex: 1;
  padding: 0.55rem 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.db-tab:hover { color: var(--text); }
.db-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.db-tab-count {
  display: inline-block;
  background: var(--bg3);
  border-radius: 999px;
  padding: 1px 5px;
  font-size: 0.68rem;
  margin-left: 3px;
}
.db-tab.active .db-tab-count { background: var(--accent); color: #000; }

/* Progress */
.db-progress-area {
  padding: 0.45rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.db-progress-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
}
.db-progress-label { color: var(--text-muted); flex: 1; }
.db-progress-val { font-weight: 700; min-width: 60px; text-align: right; }
.db-progress-val.ok { color: var(--green); }
.db-progress-val.warn { color: var(--yellow); }
.db-progress-val.err { color: var(--red); }
.db-progress-bar { height: 3px; background: var(--bg3); border-radius: 2px; flex: 2; }
.db-progress-fill { height: 100%; border-radius: 2px; transition: width 0.2s; }
.db-progress-fill.ok { background: var(--green); }
.db-progress-fill.warn { background: var(--yellow); }
.db-progress-fill.err { background: var(--red); }

/* Deck list */
.db-deck-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}
.db-deck-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.db-deck-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  transition: background 0.1s;
}
.db-deck-row:hover { background: var(--bg3); }
.db-deck-row-qty {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--accent);
  min-width: 20px;
  text-align: center;
}
.db-deck-row-name {
  flex: 1;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.db-deck-row-name:hover { color: var(--accent); }
.db-deck-row-cost { font-size: 0.75rem; color: var(--text-muted); min-width: 24px; text-align: right; }
.db-deck-row-controls { display: flex; gap: 3px; }
.db-qbtn {
  width: 22px; height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: background 0.1s, border-color 0.1s;
}
.db-qbtn:hover:not(:disabled) { background: var(--accent); color: #000; border-color: var(--accent); }
.db-qbtn:disabled { opacity: 0.3; cursor: not-allowed; }
.db-qbtn.minus:hover:not(:disabled) { background: var(--red); border-color: var(--red); color: #fff; }

/* Workspace footer */
.db-workspace-footer {
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.db-stats { flex: 1; font-size: 0.78rem; color: var(--text-muted); line-height: 1.6; }
.db-footer-actions { display: flex; gap: 0.5rem; }

/* ── Rarity colors ───────────────────────────────────────── */
.rarity-common    { color: var(--rarity-common); }
.rarity-uncommon  { color: var(--rarity-uncommon); }
.rarity-rare      { color: var(--rarity-rare); }
.rarity-qr        { color: var(--rarity-qr); }
.rarity-ar        { color: var(--rarity-ar); }
.rarity-basic     { color: var(--rarity-basic); }

/* ── Modals ─────────────────────────────────────────────── */
.db-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.db-modal-overlay[hidden] { display: none; }
.db-modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.db-modal h2 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--accent); }
.db-modal-sub { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1rem; }
.db-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
}
.db-modal-close:hover { color: var(--text); }
.db-modal-footer { margin-top: 1rem; display: flex; justify-content: flex-end; gap: 0.5rem; }

/* Card detail modal */
.db-card-detail-modal { max-width: 640px; }
.db-detail-grid { display: grid; grid-template-columns: 200px 1fr; gap: 1.25rem; }
.db-detail-img { width: 100%; border-radius: 8px; }
.db-detail-name { font-size: 1.1rem; font-weight: 800; margin-bottom: 0.4rem; }
.db-detail-meta { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.75rem; line-height: 1.8; }
.db-detail-meta strong { color: var(--text); }
.db-detail-ability { background: var(--bg3); border-radius: 6px; padding: 0.5rem 0.75rem; margin-bottom: 0.5rem; font-size: 0.83rem; line-height: 1.5; }
.db-detail-ability-name { font-weight: 700; color: var(--accent); margin-bottom: 0.2rem; font-size: 0.78rem; }
.db-detail-ruling { font-size: 0.78rem; color: var(--text-muted); font-style: italic; border-left: 2px solid var(--border); padding-left: 0.5rem; margin-top: 0.4rem; }
.db-detail-add-btn { margin-top: 1rem; width: 100%; padding: 0.6rem; font-size: 0.9rem; }

/* Validation modal */
.db-val-pass { color: var(--green); font-size: 1rem; margin-bottom: 0.75rem; }
.db-val-fail { color: var(--red); font-size: 1rem; margin-bottom: 0.75rem; }
.db-val-list { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }
.db-val-list li {
  background: var(--bg3);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  border-left: 3px solid var(--red);
}
.db-val-list li.warn { border-left-color: var(--yellow); }

/* Export modal */
.db-export-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-top: 0.5rem; }
.db-export-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 1rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.15s, color 0.15s;
}
.db-export-btn:hover { border-color: var(--accent); color: var(--accent); }
.db-export-icon { font-size: 1.6rem; }

/* Library modal */
.db-storage-note { color: var(--yellow) !important; }
.db-library-actions { margin-bottom: 0.75rem; }
.db-library-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 0.4rem;
  background: var(--bg3);
}
.db-library-item-name { flex: 1; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.db-library-item-name:hover { color: var(--accent); }
.db-library-item-meta { font-size: 0.74rem; color: var(--text-muted); }
.db-library-item-actions { display: flex; gap: 0.3rem; }

/* Import modal */
#importJson {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.78rem;
  font-family: monospace;
  resize: vertical;
}
.db-file-import { margin-top: 0.5rem; }

/* ── Responsive: mobile ──────────────────────────────────── */
@media (max-width: 768px) {
  .db-main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .db-catalog {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 55vh;
  }
  .db-workspace { max-height: 45vh; }
  .db-detail-grid { grid-template-columns: 1fr; }
  .db-detail-img { max-width: 200px; }
  .db-export-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .db-card-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .db-header { padding: 0.5rem 0.75rem; }
  .db-title { font-size: 0.95rem; }
}

/* ── Deck row slide-in animation ─────────────────────────── */
@keyframes db-row-in {
  from { opacity: 0; transform: translateX(-10px); background: color-mix(in srgb, var(--accent) 15%, transparent); }
  60%  { opacity: 1; transform: translateX(0); }
  to   { background: transparent; }
}
.db-deck-row--new {
  animation: db-row-in 0.35s ease-out forwards;
}

/* ── Tab badge flash ─────────────────────────────────────── */
@keyframes db-badge-flash {
  0%   { background: var(--accent); color: #000; transform: scale(1.3); }
  60%  { background: var(--accent); color: #000; transform: scale(1.15); }
  100% { transform: scale(1); }
}
.db-tab-count--flash {
  animation: db-badge-flash 0.5s ease-out forwards;
}
