:root {
  --bg: #12131a;
  --bg-elevated: #1b1d29;
  --bg-card: #21232f;
  --text: #e8e8f0;
  --text-dim: #9a9cae;
  --accent: #c9a24d;
  --accent-2: #7b5cff;
  --border: #2f3140;
  --white: #f5f2e6;
  --blue: #4fa8e0;
  --black: #8a8a94;
  --red: #e05656;
  --green: #4dbb6a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }

nav.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}

nav.topnav .brand {
  display: inline-flex;
  align-items: center;
  margin-right: 20px;
  padding: 0;
  line-height: 0;
}
nav.topnav .brand .brand-logo {
  height: 34px;
  width: auto;
  display: block;
}
nav.topnav .brand:hover { background: none; }

nav.topnav a {
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 0.9rem;
}

nav.topnav a:hover { background: var(--bg-card); color: var(--text); }
nav.topnav a.active { background: var(--accent); color: #1b1400; font-weight: 600; }

main { max-width: 1400px; margin: 0 auto; padding: 20px; }

.site-footer {
  max-width: 1400px;
  margin: 32px auto 0;
  padding: 18px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.site-footer a { color: var(--text-dim); }
.site-footer a:hover { color: var(--text); }
.site-footer .footer-gh { display: inline-flex; align-items: center; }
.site-footer .footer-gh:hover { color: var(--accent); }

.stats-bar {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 140px;
  flex: 1;
}

.stat-tile .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.stat-tile .stat-label { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  background: var(--bg-elevated);
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.controls input, .controls select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.9rem;
}

.controls input[type="text"] { flex: 2; min-width: 200px; }
.controls select { flex: 1; min-width: 130px; }

.nav-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.lang-toggle {
  cursor: pointer; font-family: inherit; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-dim);
  border-radius: 6px; padding: 6px 10px; min-width: 38px;
}
.lang-toggle:hover { border-color: var(--accent); color: var(--text); }
.sync-status { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; }
.sync-status.busy { color: var(--accent); }
.sync-spin { display: inline-block; animation: sync-rot 1s linear infinite; }
@keyframes sync-rot { to { transform: rotate(360deg); } }

.upload-btn, .reset-btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border-radius: 6px; padding: 7px 12px; font-size: 0.85rem; font-family: inherit;
  border: 1px solid var(--border); white-space: nowrap;
}
.upload-btn { background: var(--accent); color: #1b1400; font-weight: 600; border-color: var(--accent); }
.upload-btn:hover { filter: brightness(1.08); }
.reset-btn { background: var(--bg-card); color: var(--text-dim); }
.reset-btn:hover { border-color: var(--accent); color: var(--text); }

.result-count { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 10px; }

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

.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 70px 20px;
  color: var(--text-dim);
}
.empty-state .empty-logo {
  width: min(460px, 85%);
  height: auto;
  margin-bottom: 28px;
  filter: drop-shadow(0 8px 30px rgba(0,0,0,0.5));
}
.empty-state h2 { color: var(--text); font-size: 1.5rem; margin: 0 0 12px; }
.empty-state p { max-width: 500px; margin: 0 auto; line-height: 1.6; font-size: 0.95rem; }
.empty-state strong { color: var(--text); }

.card-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
}

.card-tile:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0,0,0,0.4); border-color: var(--accent); }

.card-tile .thumb {
  aspect-ratio: 63/88;
  background: #0d0e14;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.card-tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-tile .thumb .foil-badge {
  position: absolute; top: 6px; right: 6px;
  background: linear-gradient(135deg, #ffd76a, #b57bff);
  color: #1b1400; font-size: 0.65rem; font-weight: 700;
  padding: 2px 6px; border-radius: 4px;
}
.card-tile .thumb .qty-badge {
  position: absolute; bottom: 6px; right: 6px;
  background: rgba(0,0,0,0.7);
  color: var(--text); font-size: 0.7rem; font-weight: 600;
  padding: 2px 6px; border-radius: 4px;
}
.card-tile .thumb .lang-flags {
  position: absolute; bottom: 6px; left: 6px;
  display: flex; gap: 2px; flex-wrap: wrap; max-width: 70%;
}
.card-tile .thumb .lang-flag {
  background: rgba(0,0,0,0.7); border-radius: 4px; padding: 1px 4px;
  font-size: 0.72rem; line-height: 1.3;
}
.card-tile .no-image {
  color: var(--text-dim); font-size: 0.75rem; text-align: center; padding: 10px;
}

.card-tile .info { padding: 8px 10px; }
.card-tile .info .name { font-size: 0.82rem; font-weight: 600; line-height: 1.2; }
.card-tile .info .meta { font-size: 0.72rem; color: var(--text-dim); margin-top: 3px; display: flex; justify-content: space-between; }

.loading-overlay {
  position: fixed; inset: 0; background: rgba(10,10,14,0.92);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  flex-direction: column; gap: 14px;
}
.loading-text { color: var(--text-dim); font-size: 0.95rem; }
.loading-bar { width: 320px; height: 8px; background: var(--bg-card); border-radius: 4px; overflow: hidden; }
.loading-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.2s ease; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: none; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-body {
  background: var(--bg-elevated); border-radius: var(--radius); border: 1px solid var(--border);
  max-width: 700px; width: 100%; max-height: 90vh; overflow-y: auto; position: relative;
}
.modal-close {
  position: absolute; top: 10px; right: 14px; cursor: pointer; font-size: 1.4rem; color: var(--text-dim);
}
.modal-close:hover { color: var(--text); }
.modal-card { display: flex; gap: 20px; padding: 24px; flex-wrap: wrap; }
.modal-image { flex: 0 0 260px; }
.modal-image img { width: 100%; border-radius: 12px; }
.modal-image .no-image { width: 260px; aspect-ratio: 63/88; background: #0d0e14; display: flex; align-items: center; justify-content: center; color: var(--text-dim); border-radius: 12px; }
.modal-details { flex: 1; min-width: 220px; }
.modal-details h2 { margin: 0 0 4px; }
.modal-type { color: var(--text-dim); margin: 0 0 14px; font-style: italic; }
.modal-details dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 10px; margin: 0; }
.modal-details dt { color: var(--text-dim); font-size: 0.85rem; }
.modal-details dd { margin: 0; font-size: 0.9rem; }

/* Per-language detail table in card modal */
.lang-table-title { font-size: 0.9rem; color: var(--text-dim); margin: 18px 0 8px; }
.lang-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.lang-table th, .lang-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.lang-table th { color: var(--text-dim); font-weight: 600; font-size: 0.8rem; }
.lang-table th.num, .lang-table td.num { text-align: right; }
.lang-foil {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: #1b1400; background: linear-gradient(135deg, #ffd76a, #b57bff);
  padding: 1px 5px; border-radius: 4px; margin-left: 4px;
}

/* Single-card detail overlay (opened from the edition overlay) */
.eo-card-overlay { z-index: 260; }
.eo-detail-missing { color: var(--red); font-size: 0.9rem; margin: 16px 0 0; }

/* Binder view */
.binder-page {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  background: #0d0e14;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 520px;
}
.binder-slot { display: flex; align-items: center; justify-content: center; }
.binder-slot .card-tile { width: 100%; }
.binder-slot.empty { border: 1px dashed var(--border); border-radius: var(--radius); aspect-ratio: 63/88; }
.binder-controls { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 16px; }
.binder-controls button {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 8px 18px; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.binder-controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.binder-controls button:not(:disabled):hover { border-color: var(--accent); }
.binder-page-label { color: var(--text-dim); font-size: 0.9rem; min-width: 100px; text-align: center; }

/* Carousel view */
.carousel-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.carousel-card { display: flex; gap: 30px; align-items: center; }
.carousel-image { width: 320px; aspect-ratio: 63/88; border-radius: 14px; overflow: hidden; background: #0d0e14; box-shadow: 0 12px 40px rgba(0,0,0,0.5); }
.carousel-image img { width: 100%; height: 100%; object-fit: cover; }
.carousel-info { min-width: 260px; }
.carousel-info h2 { margin-top: 0; }
.carousel-controls { display: flex; gap: 16px; align-items: center; }
.carousel-controls button {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 10px 20px; border-radius: 6px; cursor: pointer; font-size: 1rem;
}
.carousel-controls button:hover { border-color: var(--accent); }
.carousel-index { color: var(--text-dim); }

/* Dashboard */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.chart-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.chart-card h3 { margin: 0 0 12px; font-size: 1rem; color: var(--text-dim); }
.chart-card canvas { max-height: 320px; }

/* Deck checker */
.deck-checker-layout { display: grid; grid-template-columns: 1fr 1.4fr; gap: 20px; }
.deck-checker-layout textarea {
  width: 100%; height: 400px; background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius); padding: 12px; font-family: monospace; font-size: 0.85rem; resize: vertical;
}
.deck-checker-layout button {
  margin-top: 10px; background: var(--accent); color: #1b1400; border: none;
  padding: 10px 18px; border-radius: 6px; font-weight: 600; cursor: pointer;
}
table.deck-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.deck-table th, table.deck-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.deck-table th { color: var(--text-dim); font-weight: 600; }
.status-owned { color: var(--green); font-weight: 600; }
.status-partial { color: var(--accent); font-weight: 600; }
.status-missing { color: var(--red); font-weight: 600; }
.deck-summary { display: flex; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }

/* Editions overview */
.section-hint {
  color: var(--text-dim); font-size: 0.85rem; line-height: 1.5; margin: 0 0 16px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 12px 16px; max-width: 900px;
}
.section-hint strong { color: var(--text); }

.edition-table {
  width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.92rem;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.edition-table th, .edition-table td { padding: 13px 16px; text-align: left; vertical-align: middle; }
.edition-table thead th {
  color: var(--text-dim); font-weight: 600; font-size: 0.78rem; letter-spacing: 0.03em; text-transform: uppercase;
  background: var(--bg-card); border-bottom: 1px solid var(--border); position: sticky; top: 56px; z-index: 10;
}
.edition-table th.num, .edition-table td.num { text-align: right; }
.edition-table .dim { color: var(--text-dim); font-weight: 400; }
.edition-table td.money { font-weight: 600; color: var(--accent); white-space: nowrap; }

.edition-row { cursor: pointer; transition: background 0.12s ease; }
.edition-row td { border-bottom: 1px solid var(--border); }
.edition-row:nth-of-type(4n+1) td { background: rgba(255,255,255,0.015); }
.edition-row:hover td { background: var(--bg-card); }
.edition-row--empty .edition-title { color: var(--text-dim); font-weight: 500; }
.edition-row--empty .edition-icon { opacity: 0.5; }

.edition-name { display: flex; align-items: center; gap: 10px; }
.edition-icon { font-size: 1rem; opacity: 0.85; }
/* Scryfall set symbols are monochrome (black) SVGs; force them to a light tone
   so they read on the dark background. */
.set-icon {
  width: 20px; height: 20px; object-fit: contain; flex-shrink: 0;
  filter: brightness(0) invert(0.85);
}
.edition-row--empty .set-icon { opacity: 0.45; }
.set-icon-lg { width: 26px; height: 26px; vertical-align: -5px; margin-right: 4px; }
.edition-title { font-weight: 600; font-size: 0.98rem; }
.edition-code {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-dim); background: var(--bg); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 4px; white-space: nowrap;
}

.progress-cell { min-width: 170px; }
.progress-head { font-size: 0.9rem; white-space: nowrap; margin-bottom: 6px; }
.progress-head strong { font-size: 1.05rem; }
.progress-pct { color: var(--accent); font-weight: 700; margin-left: 6px; }
.progress-sub { font-size: 0.78rem; }
.progress-track { height: 7px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 4px; }

/* Edition overlay (all cards with images) */
.edition-overlay { align-items: stretch; justify-content: center; padding: 24px; }
.eo-panel {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 1200px; margin: auto; display: flex; flex-direction: column;
  max-height: calc(100vh - 48px); overflow: hidden;
}
.eo-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.eo-header h2 { margin: 0 0 6px; font-size: 1.3rem; display: flex; align-items: center; gap: 10px; }
.eo-sub { color: var(--text-dim); font-size: 0.9rem; }
.eo-sub strong { color: var(--text); }
.eo-sub-missing { color: var(--red); }
.eo-close { position: static; font-size: 1.6rem; line-height: 1; flex-shrink: 0; }
.eo-toolbar { display: flex; gap: 8px; padding: 12px 22px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.eo-radio {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 12px; font-size: 0.85rem; color: var(--text-dim);
}
.eo-radio:has(input:checked) { border-color: var(--accent); color: var(--text); }
.eo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px;
  padding: 20px 22px; overflow-y: auto;
}
.eo-loading, .eo-empty { grid-column: 1 / -1; text-align: center; color: var(--text-dim); padding: 40px 0; }

.eo-card { display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.eo-thumb {
  position: relative; aspect-ratio: 63/88; border-radius: 8px; overflow: hidden;
  background: #0d0e14; border: 1px solid var(--border);
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.eo-card:hover .eo-thumb { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.45); border-color: var(--accent); }
.eo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.eo-thumb .no-image { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-dim); font-size: 0.72rem; }
.eo-cardname { font-size: 0.74rem; line-height: 1.25; color: var(--text-dim); }
.eo-num { color: var(--text); font-weight: 600; }

.eo-card.missing .eo-thumb img { filter: grayscale(1) brightness(0.4); }
.eo-card.missing .eo-thumb { opacity: 0.85; }
.eo-card.missing .eo-cardname { opacity: 0.6; }

.eo-qty {
  position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,0.75);
  color: var(--text); font-size: 0.72rem; font-weight: 600; padding: 2px 6px; border-radius: 4px;
}
.eo-check {
  position: absolute; top: 6px; left: 6px; background: var(--green); color: #0b1a0e;
  width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700;
}
.eo-missing-tag {
  position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,0.7); color: var(--text-dim);
  font-size: 0.68rem; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.04em;
}

@media (max-width: 800px) {
  .deck-checker-layout { grid-template-columns: 1fr; }
  .edition-table { font-size: 0.82rem; }
  .edition-table th, .edition-table td { padding: 9px 8px; }
  .edition-table thead th { top: 0; position: static; }
  .progress-cell { min-width: 110px; }
  .edition-overlay { padding: 0; }
  .eo-panel { max-height: 100vh; border-radius: 0; }
  .eo-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; padding: 14px; }
}
