:root {
  --bg: #0b0d11;
  --surface: #14171d;
  --surface-2: #191d24;
  --border: #262b34;
  --border-soft: #1c2027;
  --text: #eceef1;
  --text-muted: #8b93a1;
  --text-faint: #5b6472;
  --primary: #3b82f6;
  --primary-hover: #2f6fdb;
  --primary-soft: rgba(59, 130, 246, 0.14);
  --danger: #f87171;
  --success: #34d399;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.28);
  --focus-ring: 0 0 0 3px var(--primary-soft);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

.pin-form {
  max-width: 340px;
  margin: 18vh auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.pin-form h1 { font-size: 1.15rem; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }

input, button, select, textarea {
  font-size: 0.925rem;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:hover, select:hover, textarea:hover { border-color: #333a46; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

textarea { width: 100%; resize: vertical; line-height: 1.5; }

button {
  background: var(--primary);
  border: 1px solid transparent;
  color: white;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: background-color 120ms ease, transform 80ms ease, opacity 120ms ease;
}

button:hover { background: var(--primary-hover); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.link-btn {
  background: none;
  border-color: transparent;
  color: var(--text-muted);
  font-weight: 500;
  padding: 6px 10px;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.link-btn:hover { background: var(--surface-2); color: var(--text); }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.05rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

.page-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 28px 0;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}

.page-tabs.sub-tabs { padding: 16px 28px 0; }

.page-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 4px;
  margin-right: 20px;
}

.page-tab:hover { color: var(--text); background: none; }
.page-tab.active { color: var(--text); border-bottom-color: var(--primary); }

.header-links { display: flex; align-items: center; gap: 6px; }

.admin-box {
  padding: 20px 28px;
  border-bottom: 1px solid var(--border-soft);
}

.admin-box h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  margin: 0 0 14px;
}

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.inline-form input, .inline-form select { flex: 1; min-width: 160px; }

#import-textarea {
  margin-bottom: 10px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.85rem;
}

.filter-bar {
  display: flex;
  gap: 10px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
  background: var(--surface);
}

.filter-bar input, .filter-bar select { flex: 1; min-width: 160px; background: var(--bg); }

.error {
  color: var(--danger);
  margin: 10px 0 0;
  font-size: 0.85rem;
  font-weight: 500;
}

.status { color: var(--text-muted); margin: 10px 0 0; font-size: 0.85rem; }
.muted { color: var(--text-muted); font-size: 0.85rem; display: block; }

main#card-table-container { padding: 20px 28px 40px; overflow-x: auto; }

.empty-state {
  color: var(--text-faint);
  padding: 48px 0;
  text-align: center;
  font-size: 0.9rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0;
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-soft);
}

th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.87rem;
  white-space: nowrap;
}

thead th {
  background: var(--surface-2);
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr { transition: background-color 100ms ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }

.count-input, .price-input {
  width: 80px;
  text-align: right;
  padding: 7px 10px;
  font-variant-numeric: tabular-nums;
}

.qty-stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-stepper .count-input {
  width: 44px;
  text-align: center;
  padding: 7px 4px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  flex: 0 0 auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
}

.qty-btn:hover { background: var(--border); }

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

.variant-actions select, .variant-actions button {
  padding: 7px 10px;
  font-size: 0.82rem;
}

.variant-actions .add-variant-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.variant-actions .add-variant-btn:hover { background: var(--border); }

.variant-actions .remove-variant-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--danger);
}
.variant-actions .remove-variant-btn:hover { background: rgba(248, 113, 113, 0.12); border-color: var(--danger); }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--bg);
}

.view-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 500;
  border-radius: 0;
  padding: 10px 18px;
}

.view-btn.active { background: var(--primary); color: white; }
.view-btn:hover:not(.active) { background: var(--surface-2); color: var(--text); }

#sort-dir-btn { flex: 0 0 auto; }

/* Small thumbnail used in the list view (public) and admin table */
.thumb-wrap, .admin-thumb-wrap {
  width: 46px;
  height: 62px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.thumb, .admin-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.thumb.missing, .admin-thumb.missing { visibility: hidden; }

.admin-thumb-wrap { display: flex; flex-direction: column; gap: 6px; height: auto; background: none; border: none; }
.admin-thumb-wrap .admin-thumb { height: 62px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); }

.image-upload-input {
  width: 100px;
  padding: 2px;
  font-size: 0.68rem;
  border: none;
  background: none;
  color: var(--text-faint);
}

/* Grid view */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 18px;
}

.grid-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.grid-card:hover {
  transform: translateY(-2px);
  border-color: var(--border);
  box-shadow: var(--shadow-md);
}

.grid-img-wrap {
  width: 100%;
  aspect-ratio: 5 / 7;
  background: var(--surface-2);
}

.grid-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.grid-img.missing { visibility: hidden; }

.grid-card-info {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-top: 1px solid var(--border-soft);
}

.grid-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: normal;
  letter-spacing: -0.01em;
}

.grid-card-meta {
  color: var(--text-muted);
  font-size: 0.76rem;
  white-space: normal;
}

.grid-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.grid-card-footer span:last-child { color: var(--success); }

/* Set cards (Sets tab) — same shape/treatment as card-grid, but a clickable
   button instead of a static div, and no image upload yet so a placeholder
   glyph stands in for real set art. */
.set-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--surface);
}

/* .grid-card already supplies the border/radius/hover-lift; these just cancel
   the generic <button> background/transform states so it reads as a card,
   not a button. */
.set-card:hover, .set-card:active { background: var(--surface); transform: translateY(-2px); }

.set-art-placeholder {
  width: 100%;
  aspect-ratio: 5 / 7;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  position: relative;
}

.set-art-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.set-art-img.missing { visibility: hidden; }

@media (max-width: 700px) {
  header { padding: 14px 16px; }
  .admin-box, .filter-bar { padding: 14px 16px; }
  main#card-table-container { padding: 14px 16px 32px; }
  .filter-bar, .inline-form { flex-direction: column; }
  .filter-bar input, .filter-bar select, .inline-form input, .inline-form select { width: 100%; }
  .view-toggle { width: 100%; }
  .view-btn { flex: 1; }
}
