:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #050816;
  --bg-elevated: #0f172a;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.1);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2933;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top, #1f2937 0, #020617 45%, #000 100%);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  min-height: 100vh;
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
}

.panel {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 1rem;
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.8);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.panel-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: var(--muted);
}

.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.6);
}

.app-title {
  font-size: 1.4rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f9fafb;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--muted);
}

.filters-section {
  margin-bottom: 0.9rem;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.4);
  padding-bottom: 0.7rem;
}
.filters-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.filters-section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

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

.pill {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.5);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  user-select: none;
  transition: all 0.15s ease;
}

.pill span.dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  display: inline-block;
  border: 1px solid rgba(15, 23, 42, 0.9);
}

.pill.selected {
  background: radial-gradient(circle at top left, #0ea5e9, #0369a1);
  border-color: rgba(15, 23, 42, 0.9);
  color: #f9fafb;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.6);
}

.pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.9);
}

.mtg-W { background: #f9fafb; }
.mtg-U { background: #0ea5e9; }
.mtg-B { background: #111827; }
.mtg-R { background: #ef4444; }
.mtg-G { background: #22c55e; }

.search-input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
.search-input::placeholder { color: rgba(148, 163, 184, 0.8); }
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.6);
}

.button-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
  gap: 0.4rem;
}

button { font: inherit; cursor: pointer; }

.btn {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  color: var(--muted);
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.15s ease;
}

.btn-primary {
  border-color: rgba(56, 189, 248, 0.8);
  background: linear-gradient(135deg, #0ea5e9, #0369a1);
  color: #f9fafb;
  box-shadow: 0 8px 18px rgba(56, 189, 248, 0.45);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.8);
}

.btn-primary:hover {
  box-shadow: 0 12px 20px rgba(56, 189, 248, 0.5);
}

.btn-ghost {
  border-style: dashed;
  opacity: 0.9;
}

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  max-height: calc(100vh - 7.5rem);
  overflow: auto;
  padding-right: 0.3rem;
}

.card {
  border-radius: 0.9rem;
  background: radial-gradient(circle at top, #1e293b, #020617);
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 0.6rem 0.65rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
}

/* Card image */
.card-image-wrap {
  width: 100%;
  border-radius: 0.7rem;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: radial-gradient(circle at top, #1e293b, #020617);
  margin-bottom: 0.4rem;
}

.card-image {
  display: block;
  width: 100%;
  height: auto;
}

.card-header {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  align-items: baseline;
}

.card-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #f9fafb;
}

.mana-cost {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  gap: 0.18rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* old circular style (kept for compatibility) */
.mana-symbol {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}

/* NEW: SVG mana icons */
.mana-symbol-img {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: middle;
}

/* Text fallback if SVG fails or unknown code:
   Looks like a mana pip with the number/letter inside */
.mana-symbol-fallback {
  min-width: 18px;
  height: 18px;
  padding: 0 3px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  background: #111827;
  color: #e5e7eb;
}

.card-type {
  font-size: 0.78rem;
  color: var(--muted);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.tag {
  font-size: 0.7rem;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.5);
  color: var(--muted);
}

.card-footer {
  margin-top: 0.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

.small-text { font-size: 0.7rem; color: var(--muted); }

.btn-xs {
  padding: 0.23rem 0.5rem;
  font-size: 0.75rem;
}

.counter-pill {
  font-size: 0.75rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.5);
  color: var(--muted);
}

.deck-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.deck-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
}

.deck-count { font-size: 0.8rem; color: var(--muted); }

.deck-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  margin: 0.6rem 0;
}

.stat-card {
  padding: 0.4rem 0.5rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), rgba(15, 23, 42, 0.9));
}

.stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 0.1rem;
}

.deck-list {
  flex: 1;
  overflow: auto;
  padding-right: 0.3rem;
  margin-top: 0.4rem;
  border-top: 1px dashed rgba(148, 163, 184, 0.5);
  padding-top: 0.6rem;
}

.deck-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.8rem;
  padding: 0.25rem 0.3rem;
  border-radius: 0.5rem;
}

.deck-row:nth-child(odd) {
  background: rgba(15, 23, 42, 0.7);
}

.deck-card-name {
  color: #f9fafb;
  font-weight: 500;
}

.deck-card-meta {
  font-size: 0.7rem;
  color: var(--muted);
}

.icon-btn {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.12s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.9);
}

.footer-note {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.6rem;
  text-align: left;
}

.muted-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.75rem;
  opacity: 0.85;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.view-toggle .btn {
  padding-inline: 0.6rem;
}

.btn-pill-active {
  background: radial-gradient(circle at top left, #0ea5e9, #0369a1);
  border-color: rgba(56, 189, 248, 0.9);
  color: #f9fafb;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.8);
}

/* ===== Card Modal Overlay ===== */

.card-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.card-modal {
  width: min(420px, 90vw);
  max-height: 90vh;
  overflow-y: auto;
  background: radial-gradient(circle at top, #1e293b, #020617);
  border-radius: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
  padding: 0.85rem 0.9rem 0.9rem;
}

.card-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.card-modal-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #f9fafb;
}

.card-modal-type {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.05rem;
}

.card-modal-mana {
  display: flex;
  flex-wrap: wrap;
  gap: 0.18rem;
  align-items: center;
  justify-content: flex-end;
}

.card-modal-close {
  border: 1px solid rgba(148, 163, 184, 0.6);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.95);
  color: var(--muted);
  width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  padding: 0;
  cursor: pointer;
}

.card-modal-close:hover {
  background: rgba(30, 64, 175, 0.6);
  color: #f9fafb;
}

.card-modal-image {
  width: 100%;
  border-radius: 0.7rem;
  border: 1px solid rgba(148, 163, 184, 0.5);
  margin-bottom: 0.6rem;
  display: block;
}

.card-modal-text {
  font-size: 0.8rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 0.6rem;
}

.card-modal-text p {
  margin: 0 0 0.35rem;
}

.card-modal-footer {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
}
