:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8a92a3;
  --primary: #4f8cff;
  --primary-hover: #6b9fff;
  --danger: #e05555;
  --danger-hover: #ef6666;
  --success: #3fb27f;
  --warn: #e0a04a;
  --foil: #b58cff;
  --alt: #ffce6b;
  --over: #5ed0c0;
  --promo: #ff8fa3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* View toggle (Table | Gallery) */
.view-toggle {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.view-btn {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 6px 12px;
  font-size: 12px;
}
.view-btn:hover { background: rgba(255,255,255,0.04); }
.view-btn.active { background: var(--primary); color: white; }
.view-btn.active:hover { background: var(--primary-hover); }

/* Hamburger menu */
.menu-wrap { position: relative; }
.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  min-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 80;
}
.menu-section {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.menu-section:last-child { border-bottom: none; }
.menu-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 4px 10px 2px;
}
.sync-status {
  text-transform: none;
  letter-spacing: 0;
  font-size: 10px;
  margin-left: 6px;
  color: var(--muted);
  font-weight: normal;
}
.sync-status.sync-enabled { color: #4ec9b0; }
.menu-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 7px 10px;
  font: inherit;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
}
.menu-item:hover { background: var(--panel-2); }
.menu-item-check {
  display: inline-block;
  width: 14px;
  color: var(--success);
  font-weight: 700;
  text-align: center;
  margin-right: 4px;
}
.menu-item-danger { color: var(--danger); }
.menu-item-danger:hover { background: rgba(224,85,85,0.1); }

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.panel:last-child { border-right: none; }

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.panel-header h2 .muted {
  text-transform: none;
  letter-spacing: 0;
  margin-left: 6px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.filters > * { flex: 1 1 140px; min-width: 0; }
.filters > .gallery-controls { flex: 0 0 auto; }
.filters > input[type="search"] { flex: 2 1 220px; }

.sort-group {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  flex: 1 1 200px;
  min-width: 0;
}
.sort-group select { flex: 1; }
.sort-group .btn { padding: 6px 10px; flex: 0 0 auto; }

input[type="text"], input[type="search"], select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 4px;
  font: inherit;
  outline: none;
}

/* Make native <select> visually match .multi-select-btn (custom chevron, same padding) */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 28px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a92a3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select:hover { border-color: #3a4050; }

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

textarea {
  width: 100%;
  resize: vertical;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover { background: #262b36; border-color: #3a4050; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }

.btn-small { padding: 4px 8px; font-size: 12px; }

.muted { color: var(--muted); font-weight: 400; }

/* Collection table */
.table-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
th:hover { color: var(--text); }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { text-align: right; }

tbody tr:hover { background: rgba(255,255,255,0.03); }
tbody tr.clickable { cursor: pointer; }

td.name-cell {
  font-weight: 500;
  max-width: 320px;
  overflow: hidden;
}
.name-with-thumb {
  display: flex;
  align-items: center;
  gap: 8px;
}
.name-with-thumb .rarity-badge { margin: 0 2px; }
.name-with-thumb > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Thumbnails + hover preview */
.thumb-wrap {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}
.thumb-wrap[data-action] { cursor: pointer; }
.thumb-wrap[data-action]:hover .card-thumb { border-color: var(--primary); }
.card-thumb {
  width: 32px;
  height: 44px;
  object-fit: cover;
  border-radius: 3px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: block;
  vertical-align: middle;
}
.thumb-placeholder {
  width: 32px;
  height: 44px;
  border-radius: 3px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  display: inline-block;
}
.thumb-large {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: 8px;
  width: 240px;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  z-index: 50;
  pointer-events: none;
  background: var(--panel);
}
.thumb-wrap:hover .thumb-large { display: block; }
/* Suppress the big hover preview while the user is actively dragging,
   unless they've opted in via the "Card preview during drag" menu toggle. */
body.is-dragging .thumb-large { display: none !important; }
body.is-dragging.drag-preview-enabled .thumb-large:hover,
body.is-dragging.drag-preview-enabled .thumb-wrap:hover .thumb-large { display: block !important; }
/* For rows near the right edge, flip the preview to the left of the thumb */
tr:has(.thumb-wrap:hover) .name-cell { position: relative; z-index: 51; }

td.avail-zero { color: var(--muted); }
td.avail-has { color: var(--success); font-weight: 600; }

.variant-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.variant-tag.foil { color: var(--foil); border-color: var(--foil); }
.variant-tag.alt { color: var(--alt); border-color: var(--alt); }
.variant-tag.over { color: var(--over); border-color: var(--over); }
.variant-tag.promo { color: var(--promo); border-color: var(--promo); }

/* Variant chips in the collection table */
.variants-cell { padding: 4px 6px; }
.vchip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.vchip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  line-height: 1.4;
  max-width: 100%;
  min-width: 0;
  flex-wrap: wrap;
}
.vchip-empty {
  color: #4a525e;
  border-color: #2a2f3a;
  background: transparent;
  opacity: 0.55;
  font-style: italic;
}
.vchip-owned { color: var(--text); border-color: #3a4050; background: rgba(255,255,255,0.04); }
.vchip-owned.foil { color: var(--foil); border-color: rgba(181,140,255,0.5); background: rgba(181,140,255,0.08); }
.vchip-owned.alt { color: var(--alt); border-color: rgba(255,206,107,0.5); background: rgba(255,206,107,0.08); }
.vchip-owned.over { color: var(--over); border-color: rgba(94,208,192,0.5); background: rgba(94,208,192,0.08); }
.vchip-owned.promo { color: var(--promo); border-color: rgba(255,143,163,0.5); background: rgba(255,143,163,0.08); }
/* Unowned chips (variant exists in catalog but user owns zero copies) — fade the variant color */
.vchip-owned.vchip-unowned {
  opacity: 0.45;
  filter: grayscale(0.6);
}
.vchip-owned.vchip-unowned:hover { opacity: 0.75; filter: grayscale(0.3); }
.vchip-name { font-weight: 500; word-break: break-word; min-width: 0; }
.vchip-code {
  font-size: 9px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: rgba(255,255,255,0.04);
  padding: 0 4px;
  border-radius: 2px;
  white-space: nowrap;
  flex-shrink: 0;
}
.vchip-owned.foil .vchip-code,
.vchip-owned.alt .vchip-code,
.vchip-owned.over .vchip-code,
.vchip-owned.promo .vchip-code { color: inherit; opacity: 0.7; }
.vchip-qty {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}
.vchip-owned.foil .vchip-qty,
.vchip-owned.alt .vchip-qty,
.vchip-owned.over .vchip-qty,
.vchip-owned.promo .vchip-qty { color: inherit; opacity: 0.85; }
.vchip-btn {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  font-weight: 600;
}
.vchip-btn:hover { background: #2a3040; }
.vchip-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.vchip-btn.plus { color: var(--success); }
.vchip-btn.minus { color: var(--warn); }
.vchip-deck-qty {
  color: var(--primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 14px;
  text-align: center;
  font-size: 11px;
}

.modal-variant-row .num { font-variant-numeric: tabular-nums; }

.row-actions {
  display: inline-flex;
  gap: 4px;
  justify-content: flex-end;
}

.qty-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
.qty-btn:hover { background: #2a3040; }
.qty-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.qty-btn.plus { color: var(--success); }
.qty-btn.minus { color: var(--warn); }
.qty-btn.info { color: var(--muted); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.drop-zone {
  max-width: 480px;
  margin: 20px auto;
  padding: 40px 24px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone p { margin: 6px 0; }
.drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(79,140,255,0.06);
}
.drop-zone .btn { margin: 0 2px; }

.deck-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.deck-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.12s;
}
.deck-item:hover { border-color: #3a4050; }
.deck-item.active {
  border-color: var(--primary);
  background: rgba(79,140,255,0.08);
}
.deck-item .deck-name { font-weight: 500; }
.deck-item .deck-count { color: var(--muted); font-size: 12px; }

.active-deck {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.active-deck-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 8px;
}
.active-deck-header h3 {
  margin: 0 0 2px 0;
  font-size: 14px;
}
.deck-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.section-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.section-tab {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.section-tab:hover { color: var(--text); }
.section-tab.active {
  background: rgba(79,140,255,0.12);
  border-color: var(--primary);
  color: var(--text);
}
.section-count {
  background: rgba(255,255,255,0.06);
  padding: 0 6px;
  border-radius: 8px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.section-tab.active .section-count {
  background: var(--primary);
  color: white;
}

.active-deck-cards {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 420px;
  overflow-y: auto;
}

.deck-card-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  background: var(--panel-2);
  border-radius: 3px;
  font-size: 12px;
}
.deck-card-row .dc-info {
  overflow: hidden;
  min-width: 0;
}
.deck-card-row .dc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.deck-card-row .dc-qty {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 26px;
  text-align: right;
  grid-column: 2;
  grid-row: 1;
}
.deck-card-row .dc-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 2px;
}

.qty-btn.move {
  width: auto;
  padding: 0 8px;
  font-size: 11px;
  color: var(--primary);
  border-color: var(--border);
}
.qty-btn.move:hover { background: rgba(79,140,255,0.12); border-color: var(--primary); }

.section-move {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 3px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  margin-left: auto;
}
.section-move:hover { color: var(--text); border-color: #3a4050; }

.hint { padding: 10px 14px; font-size: 12px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}
.modal-body {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-body-wide { max-width: 760px; }

/* Set completion list inside the set-completion modal */
#setCompletionList {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.set-row {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.set-row:hover {
  border-color: var(--primary);
  background: rgba(255,255,255,0.02);
}
.set-row-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 13px;
}
.set-row-name { font-weight: 600; }
.set-row-counts { font-variant-numeric: tabular-nums; color: var(--muted); }
.set-bar-track {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}
.set-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.25s ease;
}
.set-bar-complete { background: #4ec9b0; }
.modal-card-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
  align-items: start;
}
.modal-card-image img {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}
.modal-image-caption {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.modal-image-strip {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 6px;
}
.modal-image-thumb {
  background: none;
  border: 2px solid transparent;
  border-radius: 4px;
  padding: 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: inherit;
  color: var(--muted);
  transition: border-color 0.12s;
}
.modal-image-thumb:hover { border-color: var(--border); color: var(--text); }
.modal-image-thumb.active {
  border-color: var(--primary);
  color: var(--text);
}
.modal-image-thumb.foil.active { border-color: var(--foil); }
.modal-image-thumb.alt.active { border-color: var(--alt); }
.modal-image-thumb.over.active { border-color: var(--over); }
.modal-image-thumb.promo.active { border-color: var(--promo); }
.modal-image-thumb img {
  width: 100%;
  border-radius: 3px;
  display: block;
}
.modal-image-thumb-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.modal-no-image {
  width: 100%;
  aspect-ratio: 744 / 1039;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
}
.modal-card-info { min-width: 0; }
@media (max-width: 700px) {
  .modal-card-layout { grid-template-columns: 1fr; }
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body h2 { margin: 0 0 4px; }
.modal-body h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.modal-stats { display: flex; gap: 16px; margin-top: 12px; }
.stat {
  background: var(--panel-2);
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }

.modal-deck-entry {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 4px;
  margin-bottom: 4px;
}
.modal-deck-entry .md-qty { color: var(--primary); font-weight: 600; }
.modal-no-decks { color: var(--muted); font-style: italic; padding: 8px 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  z-index: 200;
  animation: toastIn 0.2s ease;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }
@keyframes toastIn {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

@media (max-width: 900px) {
  .app-main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); }
  .filters { grid-template-columns: 1fr 1fr; }
}

/* Multi-select filter dropdowns */
.multi-select { position: relative; }
.multi-select-btn {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.multi-select-btn::after {
  content: "▾";
  color: var(--muted);
  margin-left: 6px;
  font-size: 10px;
}
.multi-select-btn:hover { border-color: #3a4050; }
.multi-select-btn.has-selection { border-color: var(--primary); color: var(--text); }
.multi-select-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 200px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 30;
}
.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
}
.multi-select-option:hover { background: var(--panel-2); }
.multi-select-option input { margin: 0; }
.multi-select-actions {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  gap: 6px;
}
.multi-select-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  padding: 2px 6px;
}
.multi-select-link:hover { text-decoration: underline; }

/* Gallery view */
.gallery-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.gallery-size-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.gallery-size-label input { width: 100px; }

.gallery-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-size, 180px), 1fr));
  gap: 14px;
  align-content: start;
}
.gallery-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s;
}
.gallery-card:hover { border-color: #3a4050; }
.gallery-card.dragging { opacity: 0.5; }

/* Unowned cards (catalog rows the user doesn't own — shown when "Show unowned" is on) */
#collectionTable tbody tr.unowned {
  opacity: 0.45;
  filter: grayscale(0.55);
}
#collectionTable tbody tr.unowned:hover { opacity: 0.75; }
#collectionTable tbody tr.unowned .card-thumb,
#collectionTable tbody tr.unowned .thumb-placeholder { cursor: pointer; }

.gallery-card.unowned {
  opacity: 0.45;
  filter: grayscale(0.55);
  transition: opacity 0.15s, filter 0.15s, border-color 0.12s, transform 0.12s;
}
.gallery-card.unowned:hover { opacity: 0.85; filter: grayscale(0.2); }

/* Show-unowned filter checkbox */
.show-unowned-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.show-unowned-toggle input[type="checkbox"] { cursor: pointer; margin: 0; }
.show-unowned-toggle:hover { color: var(--text); }
.gallery-card-image {
  width: 100%;
  aspect-ratio: 744 / 1039;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.gallery-card-image.no-image { color: var(--muted); font-size: 11px; padding: 8px; text-align: center; }
.gallery-card-name {
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-card-meta {
  font-size: 10px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 4px;
}
.gallery-card-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.gallery-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

/* Drag-and-drop */
.deck-item.drop-target,
.loc-item.drop-target {
  border-color: var(--primary);
  background: rgba(79,140,255,0.16);
  transform: scale(1.02);
}
.deck-item.dragging,
.loc-item.dragging { opacity: 0.5; }
[draggable="true"] { cursor: grab; }
[draggable="true"]:active { cursor: grabbing; }

/* Rarity badges (shapes indicating game rarity: common / uncommon / rare / epic / showcase) */
.rarity-badge {
  display: inline-block;
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  vertical-align: middle;
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.rarity-badge.rarity-lg { width: 18px; height: 18px; }
.rarity-common {
  background: radial-gradient(circle at 35% 35%, #e8e8e8, #888);
  border-radius: 50%;
  border: 1px solid #333;
}
.rarity-uncommon {
  background: linear-gradient(180deg, #6dd5d8, #2a7073);
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  box-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.rarity-rare {
  background: linear-gradient(135deg, #c9a5ff, #7a4fd1);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  box-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.rarity-epic {
  background: linear-gradient(180deg, #ffe08a, #c88a2a);
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
  box-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}
.rarity-showcase {
  background: linear-gradient(180deg, #fff176, #f9a825);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  box-shadow: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

/* Gallery card: overlay the rarity badge at bottom-center of the image */
.gallery-card-image { position: relative; }
.gallery-card-image .rarity-badge {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
}

/* Sidebar (Decks / Locations / Borrowers accordion) */
.sidebar-panel {
  background: var(--panel);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.sidebar-zone {
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-zone:last-child { border-bottom: none; }
.zone-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  cursor: pointer;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
}
.zone-header:hover { color: var(--text); }
.sidebar-zone.collapsed .zone-header { border-bottom: none; }
.zone-title { flex: 1; }
.zone-count {
  background: var(--panel-2);
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 10px;
  text-transform: none;
  font-weight: 600;
  color: var(--text);
}
.zone-toggle {
  display: inline-block;
  transition: transform 0.18s ease;
  color: var(--muted);
  font-size: 10px;
}
.sidebar-zone.collapsed .zone-toggle { transform: rotate(-90deg); }
.sidebar-zone.collapsed .zone-body { display: none; }
.zone-body { padding: 10px 12px 12px; }
.zone-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.zone-controls input { flex: 1; }
.borrower-controls { flex-wrap: wrap; }
.borrower-controls input { min-width: 0; }
.zone-overdue-badge {
  background: var(--danger);
  color: white;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 10px;
  text-transform: none;
  font-weight: 600;
}

/* Borrowers */
.borrower-list { display: flex; flex-direction: column; gap: 6px; }
.borrower-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.borrower-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 8px 10px;
  gap: 6px;
}
.borrower-info { min-width: 0; flex: 1; }
.borrower-name {
  font-weight: 500;
  font-size: 13px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.borrower-overdue {
  background: rgba(224,85,85,0.14);
  color: var(--danger);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}
.borrower-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.borrower-loans {
  border-top: 1px dashed var(--border);
  padding: 4px 0;
}
.borrower-loan-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 10px;
  gap: 6px;
}
.borrower-loan-row.overdue { background: rgba(224,85,85,0.06); }
.borrower-loan-info { min-width: 0; flex: 1; }
.borrower-loan-name { font-size: 12px; }
.borrower-loan-actions { display: flex; gap: 2px; }

/* Loan pills in the card modal */
.modal-variant-lending {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.loan-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 2px 2px 8px;
  border-radius: 4px;
  background: rgba(79,140,255,0.08);
  border: 1px solid rgba(79,140,255,0.4);
  font-size: 11px;
  color: var(--primary);
}
.loan-pill.overdue {
  background: rgba(224,85,85,0.08);
  border-color: rgba(224,85,85,0.5);
  color: var(--danger);
}
.loan-pill-name { font-weight: 500; }
.loan-pill-count { font-size: 10px; opacity: 0.85; font-variant-numeric: tabular-nums; }
.loan-pill-days { font-size: 9px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.lend-select {
  background: var(--panel);
  border: 1px solid rgba(79,140,255,0.4);
  color: var(--primary);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 11px;
  font: inherit;
  cursor: pointer;
  max-width: 160px;
}
.lend-select:hover { border-color: var(--primary); }
.loc-list {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.loc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  transition: border-color 0.12s, background 0.12s;
  gap: 6px;
}
.loc-item:hover { border-color: #3a4050; }
.loc-info { min-width: 0; }
.loc-name { font-weight: 500; font-size: 13px; }
.loc-count { color: var(--muted); font-size: 11px; }
.loc-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}
.loc-item:hover .loc-actions { opacity: 1; }
.btn-icon {
  width: 22px;
  height: 22px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 3px;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}
.btn-icon:hover { background: var(--panel); color: var(--text); }

.modal-variant-row {
  display: block;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 12px;
}
.modal-variant-header {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 10px;
  align-items: center;
}
.modal-variant-header .num { font-variant-numeric: tabular-nums; }
.modal-variant-locations {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.loc-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 2px 2px 8px;
  border-radius: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 11px;
}
.loc-pill-name { font-weight: 500; }
.loc-pill-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}
.loc-pill-btn {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  font-weight: 600;
}
.loc-pill-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.loc-pill-unlocated {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(224,160,74,0.08);
  border: 1px solid rgba(224,160,74,0.4);
  color: var(--warn);
  font-size: 11px;
  font-style: italic;
}
.loc-add-select {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 3px;
  font-size: 11px;
  font: inherit;
  cursor: pointer;
  max-width: 160px;
}
