:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --gold: #c9a227;
  --gold-dim: #8a7020;
  --accent: #58a6ff;
  --w: #f8f6d8;
  --u: #0e68ab;
  --b: #150b00;
  --r: #d3202a;
  --g: #00733e;
  --radius: 10px;
  --font-display: 'Cinzel', serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(201, 162, 39, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(88, 166, 255, 0.08), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.95);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-icon { font-size: 1.75rem; color: var(--gold); }
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.04em;
}
.brand p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.8rem; }

.deck-summary { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); }
#deck-count { color: var(--gold); font-weight: 600; font-size: 1.1rem; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr 240px;
  gap: 1rem;
  padding: 1rem;
  max-width: 1800px;
  margin: 0 auto;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .deck { order: 3; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.filters h2, .deck h2 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--gold);
}

.filters section { margin-bottom: 1.25rem; }
.filters h3 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

label { display: block; margin-bottom: 0.5rem; font-size: 0.85rem; }
select, input[type="search"], input[type="number"] {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.cmc-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

.color-row { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.color-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid transparent;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}
.color-btn[data-color="W"] { background: var(--w); color: #333; }
.color-btn[data-color="U"] { background: var(--u); color: #fff; }
.color-btn[data-color="B"] { background: #444; color: #fff; border-color: #666; }
.color-btn[data-color="R"] { background: var(--r); color: #fff; }
.color-btn[data-color="G"] { background: var(--g); color: #fff; }
.color-btn.active { box-shadow: 0 0 0 2px var(--gold); transform: scale(1.08); }

.tag-grid { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.tag {
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.tag:hover { border-color: var(--gold-dim); color: var(--text); }
.tag.active { background: rgba(201, 162, 39, 0.2); border-color: var(--gold); color: var(--gold); }

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: #21262d; }
.btn.primary { background: var(--gold-dim); border-color: var(--gold); color: #fff; }
.btn.primary:hover { background: var(--gold); color: #111; }
.btn.ghost { background: transparent; }
.btn.small { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn.full { width: 100%; margin-top: 0.5rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.suggestions {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  max-height: 160px;
  overflow-y: auto;
}
.suggestions li {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.suggestions li.empty-hit {
  color: var(--muted);
  cursor: default;
  font-style: italic;
}
.suggestions li.empty-hit:hover { background: transparent; }
.hidden { display: none !important; }

.commander-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.4rem;
  border-radius: 6px;
  background: rgba(201, 162, 39, 0.1);
  border: 1px solid var(--gold-dim);
  font-size: 0.85rem;
}
.commander-chip img { width: 36px; border-radius: 4px; }
.commander-chip button { margin-left: auto; }

.meta { color: var(--muted); font-size: 0.8rem; margin: 0.75rem 0 0; }
.hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--gold-dim); font-size: 0.65rem; }

.catalog-banner {
  text-align: center;
  padding: 0.75rem;
  background: rgba(201, 162, 39, 0.15);
  color: var(--gold);
  font-size: 0.85rem;
}

select[multiple] {
  width: 100%;
  min-height: 6rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.8rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.card img {
  width: 100%;
  aspect-ratio: 488 / 680;
  object-fit: cover;
  background: #111;
}
.card-body { padding: 0.6rem; flex: 1; display: flex; flex-direction: column; }
.card h4 { margin: 0 0 0.25rem; font-size: 0.85rem; line-height: 1.2; }
.card .type { margin: 0; color: var(--muted); font-size: 0.7rem; }
.card .text {
  margin: 0.35rem 0;
  font-size: 0.68rem;
  color: var(--muted);
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card.in-deck { outline: 2px solid var(--gold); }

.loading, .empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

#deck-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}
#deck-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
#deck-list button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
#deck-list button:hover { color: var(--r); }

.mode-tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0 1.5rem 0.75rem;
  max-width: 1800px;
  margin: 0 auto;
}
.mode-tab {
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}
.mode-tab.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201, 162, 39, 0.12);
}

.build-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1fr;
  gap: 1rem;
  padding: 0 1rem 1rem;
  max-width: 1800px;
  margin: 0 auto;
}
.build-commander { grid-column: 1 / -1; }
.build-presets { grid-column: 1; grid-row: 2; }
.build-ai { grid-column: 1; grid-row: 3; }
.build-recs { grid-column: 1; grid-row: 4; }
.build-deck-tray { grid-row: 2 / 5; grid-column: 2; }
@media (max-width: 1100px) {
  .build-layout { grid-template-columns: 1fr; }
  .build-deck-tray { grid-row: auto; grid-column: 1; }
  .build-presets, .build-ai, .build-recs { grid-row: auto; grid-column: 1; }
}

.saved-deck-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.saved-deck-card {
  text-align: left;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.saved-deck-card:hover {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.08);
}

.saved-deck-card strong {
  display: block;
  font-family: var(--font-display);
  color: var(--gold);
  margin-bottom: 0.25rem;
}

.saved-deck-theme {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.saved-deck-card p {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--muted);
}

.build-commander {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.build-commander img { width: 80px; border-radius: 8px; }
.build-commander h2 { margin: 0; font-family: var(--font-display); color: var(--gold); }

.btn-row { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
textarea {
  width: 100%;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.ai-plan {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: rgba(201, 162, 39, 0.08);
  border: 1px solid var(--gold-dim);
  font-size: 0.85rem;
}
.ai-plan ul { margin: 0.5rem 0 0; padding-left: 1.2rem; }

.rec-bucket { margin-bottom: 1rem; }
.rec-bucket h4 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
}
.rec-cards { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.rec-card {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: calc(50% - 0.25rem);
  font-size: 0.75rem;
}
.rec-card img { width: 40px; border-radius: 4px; }
.rec-score { color: var(--muted); font-size: 0.65rem; display: block; }

.deck-count-badge {
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: 600;
}

.mana-curve {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 48px;
  margin: 0.5rem 0;
}
.mana-curve .bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.mana-curve .bar {
  width: 100%;
  background: var(--gold-dim);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}
.mana-curve .lbl { font-size: 0.55rem; color: var(--muted); margin-top: 2px; }

.deck-cats {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.deck-categorized li {
  font-size: 0.78rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}
