:root {
  --navy-900: #102544;
  --brand-50: #ebf2fc;
  --brand-200: #adc8ef;
  --brand-500: #2d6fd2;
  --brand-600: #1f5fbf;
  --brand-700: #184c99;
  --page: #eceff3;
  --surface: #fff;
  --ink: #0f172a;
  --white: #fff;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-900: #0f172a;
  --emerald-50: #ecfdf5;
  --emerald-300: #6ee7b7;
  --emerald-700: #047857;
  --rose-50: #fff1f2;
  --rose-300: #fda4af;
  --rose-700: #be123c;
  --sky-50: #f0f9ff;
  --sky-300: #7dd3fc;
  --sky-800: #075985;
  --violet-50: #f5f3ff;
  --violet-300: #c4b5fd;
  --violet-800: #5b21b6;
  --amber-50: #fffbeb;
  --amber-300: #fcd34d;
  --amber-800: #92400e;
  --radius: 0.25rem;
  color-scheme: light;
}

/*
 * Dark theme: <html class="dark">, set before paint by the head script in index.html. The palette
 * tokens are redefined, so the rules below render dark without per-rule overrides: the slate scale
 * is inverted, the light tints (50–300) become dark tints and the text shades (700–900) become
 * light. navy and --white (text on navy/brand) stay as they are; use --surface for card/input
 * backgrounds.
 */
html.dark {
  color-scheme: dark;
  --page: #0d131c;
  --surface: #161e2a;
  --ink: #dfe5ed;

  --slate-50: #1b2431;
  --slate-100: #212b3a;
  --slate-200: #2b3647;
  --slate-300: #3a4659;
  --slate-400: #76839a;
  --slate-500: #929eb1;
  --slate-600: #a9b4c4;
  --slate-700: #c3ccd8;
  --slate-900: #edf1f6;

  --brand-50: #16263d;
  --brand-200: #2a4670;
  --brand-500: #3f82e0;
  --brand-600: #3d80dd;
  --brand-700: #5b95e8;

  --rose-50: #2a1820;
  --rose-300: #6b2c40;
  --rose-700: #fb8fa5;

  --amber-50: #2a2112;
  --amber-300: #5e4719;
  --amber-800: #fcd37a;

  --emerald-50: #11261f;
  --emerald-300: #1f5a45;
  --emerald-700: #5fd3a4;

  --sky-50: #10233a;
  --sky-300: #245079;
  --sky-800: #9fd2f5;

  --violet-50: #211a3a;
  --violet-300: #4a3a80;
  --violet-800: #c9b8fb;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--ink);
  font-family: "Source Sans 3", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; background: var(--slate-100); padding: 0 0.25em; border-radius: 3px; }

.container {
  width: 100%;
  max-width: 80rem;
  margin: 0 auto;
  padding-left: 1rem;
  padding-right: 1rem;
}
@media (min-width: 640px) { .container { padding-left: 1.5rem; padding-right: 1.5rem; } }

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--navy-900);
  color: var(--white);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.site-header .container {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 3.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius);
  background: var(--brand-600);
}
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 0.25rem; }
.header-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 0.5rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--white);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}
.header-link:hover { background: rgba(255, 255, 255, 0.1); }
.header-link svg { width: 1.25rem; height: 1.25rem; }
@media (max-width: 767px) { .header-link .label-md { display: none; } }
/* both icons rendered, CSS picks one */
.theme-toggle .icon-sun { display: none; }
html.dark .theme-toggle .icon-moon { display: none; }
html.dark .theme-toggle .icon-sun { display: block; }

/* Main */
main.container { flex: 1; padding-top: 1.25rem; padding-bottom: 1.25rem; }

.page-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.75rem; margin-bottom: 0.75rem; }
.page-title { margin: 0; font-size: 1.5rem; line-height: 1.33; font-weight: 700; letter-spacing: -0.015em; }
.muted { color: var(--slate-500); font-size: 0.875rem; }

.panel {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--slate-300) 80%, transparent);
  border-radius: var(--radius);
}
.panel + .panel { margin-top: 0.75rem; }

.filters {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
}
@media (min-width: 640px) {
  .filters { flex-direction: row; align-items: flex-end; gap: 1rem; }
}
.filters .grow { flex: 1; }

.label { display: block; margin-bottom: 0.25rem; font-size: 0.75rem; font-weight: 600; color: var(--slate-700); }

.input {
  display: block;
  width: 100%;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--slate-300);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--slate-900);
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.43;
}
.input::placeholder { color: var(--slate-400); }
.input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand-500) 20%, transparent); }

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.125rem;
  font-size: 0.875rem;
  color: var(--slate-700);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.check input { width: 1rem; height: 1rem; margin: 0; accent-color: var(--brand-600); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { cursor: not-allowed; opacity: 0.5; }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }
.btn-primary { background: var(--brand-600); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--brand-700); }
.btn-secondary { background: var(--surface); border-color: var(--slate-300); color: var(--slate-700); }
.btn-secondary:hover:not(:disabled) { background: var(--slate-50); border-color: var(--slate-400); }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--slate-500);
  cursor: pointer;
}
.btn-icon:hover { background: color-mix(in srgb, var(--slate-200) 70%, transparent); color: var(--slate-900); }
.btn-icon svg { width: 1rem; height: 1rem; }

/* Loading bar */
.loading-bar { height: 2px; overflow: hidden; position: relative; }
.loading-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: -40%;
  width: 40%;
  height: 100%;
  background: var(--brand-500);
  animation: loading 1s ease-in-out infinite;
}
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
@keyframes loading { to { left: 100%; } }

/* Tables */
.table-wrap { overflow-x: auto; }
@media (min-width: 640px) { .table-wrap.allow-overflow { overflow: visible; } }

.tbl { width: 100%; border-collapse: collapse; font-size: 0.875rem; line-height: 1.43; }
.tbl th, .tbl td { padding: 0.375rem 0.75rem; border-bottom: 1px solid var(--slate-200); text-align: left; vertical-align: middle; }
.tbl th {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  background: var(--slate-100);
  border-bottom-color: var(--slate-300);
  color: var(--slate-600);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.tbl tbody tr:nth-child(2n) td { background: color-mix(in srgb, var(--slate-50) 70%, transparent); }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--brand-50) 60%, transparent); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tfoot td { background: var(--slate-50); font-weight: 700; border-bottom: 0; border-top: 1px solid var(--slate-300); }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .thumb-cell { width: 1%; padding-top: 0.25rem; padding-bottom: 0.25rem; padding-right: 0; }

.link { color: var(--brand-600); font-weight: 600; }
.link:hover { color: var(--brand-700); text-decoration: underline; }

.shop-name { white-space: nowrap; color: var(--slate-700); }
.shop-sub { display: none; margin-top: 0.125rem; font-size: 0.75rem; color: var(--slate-500); }
.price { font-weight: 700; }

@media (max-width: 639px) {
  .tbl th, .tbl td { padding-left: 0.5rem; padding-right: 0.5rem; }
  .hide-sm { display: none; }
  .shop-sub { display: block; }
}

tr.out-of-stock .price, tr.out-of-stock .shop-name { color: var(--slate-500); }
tr.out-of-stock .thumb img { opacity: 0.6; }

/* Card thumbnail with hover preview */
.thumb {
  position: relative;
  display: block;
  width: 1.75rem;
  aspect-ratio: 500 / 698;
  border-radius: 4% / 3%;
  background: var(--slate-200);
}
.thumb > img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.thumb-preview {
  display: none;
  position: absolute;
  left: calc(100% + 0.5rem);
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  width: 220px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--slate-300);
  border-radius: var(--radius);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.18);
  pointer-events: none;
}
.thumb-preview img { width: 100%; height: auto; border-radius: 3px; }
@media (hover: hover) and (min-width: 640px) {
  .thumb:hover .thumb-preview { display: block; }
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.375rem;
  padding: 0 0.375rem;
  border: 1px solid var(--slate-300);
  border-radius: 2px;
  background: var(--slate-100);
  color: var(--slate-600);
  font-size: 11px;
  font-weight: 600;
  line-height: 1rem;
  white-space: nowrap;
  vertical-align: 1px;
}
.badge-FOIL { border-color: var(--sky-300); background: var(--sky-50); color: var(--sky-800); }
.badge-FULL_ART { border-color: var(--violet-300); background: var(--violet-50); color: var(--violet-800); }
.badge-GOLDEN { border-color: var(--amber-300); background: var(--amber-50); color: var(--amber-800); }
.badge-ALTERNATE_ART { border-color: var(--emerald-300); background: var(--emerald-50); color: var(--emerald-700); }

/* Stock */
.stock { display: inline-flex; align-items: center; gap: 0.25rem; white-space: nowrap; font-size: 0.8125rem; font-weight: 600; }
.stock::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: currentColor; }
.stock-in { color: var(--emerald-700); }
.stock-out { color: var(--slate-400); }
.stock-cell { white-space: nowrap; }
.stock-cell .btn-icon { margin-left: 0.25rem; vertical-align: middle; color: var(--amber-800); }
.subscribe-form { margin-top: 0.25rem; }
.subscribe-email-form { display: flex; gap: 0.375rem; }
.subscribe-email-form .input { width: 11rem; padding-top: 0.25rem; padding-bottom: 0.25rem; }
.msg-ok { color: var(--emerald-700); font-weight: 600; }
.msg-err { color: var(--rose-700); font-weight: 600; }

.empty { padding: 1.5rem 1rem; text-align: center; color: var(--slate-500); }

/* Footer */
.site-footer { padding: 1rem 0 1.5rem; color: var(--slate-500); font-size: 0.75rem; }
.site-footer p { margin: 0.125rem 0; }

/* Cart modal */
.cart-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.5);
  justify-content: center;
  align-items: center;
}
.cart-modal-overlay.active { display: flex; }
html.dark .cart-modal-overlay { background: rgba(0, 0, 0, 0.6); }
.cart-modal {
  width: 100%;
  max-width: 1400px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--slate-200);
  background: var(--slate-50);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--slate-900);
}
.panel-head h2 { margin: 0; display: flex; align-items: center; gap: 0.5rem; font-size: 1rem; font-weight: 700; }
.panel-head h2 svg { width: 1.125rem; height: 1.125rem; }
.cart-panels { display: flex; gap: 1rem; padding: 1rem; }
.cart-left { flex: 0 0 300px; display: flex; flex-direction: column; gap: 0.75rem; }
.cart-right { flex: 1; min-width: 0; overflow-x: auto; }
.cart-left textarea { min-height: 220px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.75rem; }
.cart-notes { font-size: 0.8125rem; color: var(--slate-500); }
.cart-notes ul { margin: 0; padding-left: 1.1rem; }
.cart-notes li + li { margin-top: 0.25rem; }
.cart-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.cart-unavailable { color: var(--rose-700); font-weight: 600; }
.cart-table .thumb { width: 1.5rem; }
@media (max-width: 767px) {
  .cart-panels { flex-direction: column; }
  .cart-left { flex: none; }
}
