:root {
  --ink: #17181c;
  --panel: #1f2025;
  --panel-raised: #26272d;
  --border: #34353c;
  --text: #eceae2;
  --text-dim: #9b9a97;
  --accent: #c9a35a;
  --accent-tint: #2d2717;

  /* mana colors, used functionally as filter identity, not decoration */
  --mana-w: #f8f4e3;
  --mana-u: #2179b8;
  --mana-b: #8b7ab3;
  --mana-r: #d9483a;
  --mana-g: #3f7d4e;
  --mana-c: #9a9a9a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
}

h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; margin: 0; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark { color: var(--accent); font-size: 20px; }
.brand h1 { font-size: 20px; font-weight: 600; letter-spacing: 0.2px; }

.search-wrap { flex: 1; max-width: 480px; }
#searchInput {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--ink);
  color: var(--text);
  font-size: 14px;
}
#searchInput:focus { outline: none; border-color: var(--accent); }

.topbar-meta { margin-left: auto; color: var(--text-dim); font-size: 13px; flex-shrink: 0; display: flex; align-items: center; gap: 6px; }

.cart-btn {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  margin-left: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cart-btn:hover { border-color: var(--accent); }
.cart-count {
  background: var(--accent);
  color: #1b1706;
  font-weight: 700;
  font-size: 11px;
  border-radius: 20px;
  padding: 1px 7px;
}

.cart-panel { max-width: 480px; }
.cart-items { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; max-height: 320px; overflow-y: auto; }
.cart-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.cart-item-name { font-size: 13.5px; font-weight: 600; }
.cart-item-meta { font-size: 11.5px; color: var(--text-dim); }
.cart-item-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.cart-item-price { font-family: 'Fraunces', serif; color: var(--accent); font-size: 14px; min-width: 56px; text-align: right; }

.cart-total-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: 'Fraunces', serif; font-size: 20px;
  border-top: 1px solid var(--border); padding-top: 12px; margin-top: 4px;
}

.cart-buyer-form { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.cart-buyer-form .text-input { margin-bottom: 6px; }
.cart-buyer-form textarea.text-input { font-family: inherit; resize: vertical; }
.field-label { font-size: 12px; color: var(--text-dim); font-weight: 600; margin-top: 4px; }
.select-input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%), linear-gradient(135deg, var(--text-dim) 50%, transparent 50%); background-position: calc(100% - 16px) center, calc(100% - 11px) center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; gap: 0; min-height: calc(100vh - 65px); }

.filters {
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.filter-group h2 {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0.3px;
  color: var(--text-dim);
  margin-bottom: 10px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
}
.filter-hint { font-weight: 400; text-transform: none; letter-spacing: 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.12s ease;
}
.chip:hover { border-color: var(--accent); }
.chip.active { border-color: var(--accent); background: var(--accent-tint); }

.chip-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); cursor: pointer; }

.clear-btn {
  margin-top: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.clear-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* ---------- results ---------- */
.results { padding: 20px 28px 40px; }

.results-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  color: var(--text-dim);
  font-size: 13px;
}

.sort-row { display: flex; align-items: center; gap: 8px; }
#sortSelect {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
}

.card-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  display: flex;
  flex-direction: column;
}
.card-tile:hover { transform: translateY(-3px); border-color: var(--accent); }

.card-art { width: 100%; aspect-ratio: 5/7; background: var(--panel-raised); position: relative; overflow: hidden; }
.card-art img { width: 100%; height: 100%; object-fit: cover; display: block; }

.qty-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.72);
  color: var(--text);
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
}
.qty-badge.zero { color: #d9483a; }

.card-info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.card-name { font-size: 13.5px; font-weight: 600; line-height: 1.25; }
.card-type { font-size: 11.5px; color: var(--text-dim); }
.card-printing { font-size: 11px; color: var(--accent); }

.card-price-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.card-price { font-family: 'Fraunces', serif; font-size: 17px; color: var(--accent); }
.card-market { font-size: 11px; color: var(--text-dim); text-decoration: line-through; }

.empty-state { padding: 60px 0; text-align: center; color: var(--text-dim); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 28px; color: var(--text-dim); font-size: 13px; }
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 560px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--text-dim);
  font-size: 24px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body { display: flex; gap: 20px; }
.modal-body img { width: 200px; border-radius: 10px; flex-shrink: 0; }
.modal-details h2 { font-size: 20px; margin-bottom: 6px; }
.modal-details .mana { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }
.modal-details .oracle { font-size: 13px; line-height: 1.55; color: var(--text-dim); margin-bottom: 14px; white-space: pre-line; }
.modal-details .price-block { display: flex; gap: 20px; }
.modal-details .price-block div { }
.modal-details .price-block .label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.4px; }
.modal-details .price-block .value { font-family: 'Fraunces', serif; font-size: 22px; }

.add-to-cart-row { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-raised);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13.5px;
  z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- admin page ---------- */
.admin-link { color: var(--accent); text-decoration: none; font-size: 13px; margin-left: 14px; }
.admin-link:hover { text-decoration: underline; }

.admin-main { max-width: 760px; margin: 0 auto; padding: 32px 24px 60px; display: flex; flex-direction: column; gap: 28px; }
.admin-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px 24px; }
.admin-panel h2 { font-size: 17px; margin-bottom: 8px; }
.admin-help { color: var(--text-dim); font-size: 13px; line-height: 1.5; }

.dropzone {
  margin-top: 16px;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 40px 20px;
  text-align: center;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.dropzone.dragover { border-color: var(--accent); background: var(--accent-tint); }
.dropzone p { margin: 4px 0; }

.file-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  background: var(--panel-raised);
}
.file-btn:hover { border-color: var(--accent); }

.table-wrap { max-height: 360px; overflow-y: auto; margin-top: 14px; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; position: sticky; top: 0; background: var(--panel-raised); }
td.note-flag { color: var(--mana-r); }

.admin-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.text-input {
  padding: 9px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--ink);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}
.text-input:focus { outline: none; border-color: var(--accent); }
.text-input.small { width: 100px; }

.add-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.add-form #addName { flex: 1; min-width: 180px; }

.qty-input { width: 56px; padding: 5px 7px; border-radius: 5px; border: 1px solid var(--border); background: var(--ink); color: var(--text); font-size: 13px; text-align: center; }
.qty-stepper { display: flex; align-items: center; gap: 6px; }
.qty-stepper button { width: 22px; height: 22px; border-radius: 5px; border: 1px solid var(--border); background: var(--panel-raised); color: var(--text); cursor: pointer; font-size: 14px; line-height: 1; }
.qty-stepper button:hover { border-color: var(--accent); }

.row-remove { background: none; border: 1px solid var(--border); color: var(--mana-r); border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.row-remove:hover { border-color: var(--mana-r); }
.row-dirty { background: var(--accent-tint); }
.primary-btn {
  background: var(--accent);
  color: #1b1706;
  border: none;
  padding: 10px 16px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.primary-btn.secondary { background: var(--panel-raised); color: var(--text); border: 1px solid var(--border); }
.primary-btn:hover { opacity: 0.9; }

.filters-toggle {
  display: none;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.filters-toggle.active { border-color: var(--accent); }

@media (max-width: 780px) {
  /* ---- topbar: stack into rows instead of cramming everything in one ---- */
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }
  .brand h1 { font-size: 17px; }
  .search-wrap { order: 3; max-width: none; flex-basis: 100%; }
  .topbar-meta { margin-left: auto; gap: 8px; }
  .topbar-meta #statusText { display: none; } /* saves space; not essential on mobile */
  .cart-btn { margin-left: 0; padding: 6px 10px; }

  /* ---- layout: single column, filters become a collapsible drawer ---- */
  .layout { grid-template-columns: 1fr; }

  .filters-toggle { display: inline-block; }

  .filters {
    display: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
    gap: 18px;
  }
  .filters.open { display: flex; }
  .clear-btn { margin-top: 4px; }

  /* ---- results ---- */
  .results { padding: 14px 14px 32px; }
  .results-bar { flex-wrap: wrap; gap: 10px; }
  #resultsCount { order: 1; }
  .filters-toggle { order: 0; }
  .sort-row { order: 2; flex-basis: 100%; justify-content: space-between; }
  #sortSelect { flex: 1; max-width: 220px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card-name { font-size: 12.5px; }
  .card-price { font-size: 15px; }

  /* ---- card modal ---- */
  .modal-panel { padding: 16px; width: 94%; max-height: 90vh; }
  .modal-body { flex-direction: column; gap: 14px; }
  .modal-body img { width: 100%; max-width: 240px; margin: 0 auto; }
  .modal-details .price-block { flex-wrap: wrap; gap: 14px; }
  .add-to-cart-row { flex-wrap: wrap; }
  .add-to-cart-row .qty-input { width: 100%; }
  .add-to-cart-row #addToCartBtn { width: 100%; }

  /* ---- cart panel ---- */
  .cart-panel { width: 94%; }
  .cart-item { flex-wrap: wrap; gap: 8px; }
  .cart-item-controls { width: 100%; justify-content: space-between; }

  /* ---- admin page ---- */
  .admin-main { padding: 16px 12px 40px; gap: 18px; }
  .admin-panel { padding: 16px; }
  .add-form { flex-direction: column; align-items: stretch; }
  .add-form .text-input.small { width: 100%; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 480px; }
}
