:root {
  --bg: #1b1410;
  --panel: #2a2019;
  --panel-2: #382b21;
  --border: #6b4f33;
  --gold: #e8c27a;
  --text: #f1e6d3;
  --muted: #a8977f;
  --common: #f1e6d3;
  --rare: #4a90e2;
  --epic: #b26bd6;
  --legendary: #f39c12;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at top, #3a2a1c, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

button, select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
}

button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--gold); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: #8a5a1f; border-color: var(--gold); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 10px 20px;
  background: rgba(27, 20, 16, .95);
  border-bottom: 2px solid var(--border);
}

.topbar h1 { margin: 0; font-size: 1.3rem; color: var(--gold); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.filters #search { min-width: 220px; flex: 1; }

.mana { display: flex; gap: 4px; }
.mana button {
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%;
  background: #1f5fa8;
  font-weight: 700;
}
.mana button.active { border-color: var(--gold); box-shadow: 0 0 8px var(--gold); }

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  padding: 16px 20px 40px;
  align-items: start;
}

.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin-bottom: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}

.card {
  position: relative;
  aspect-ratio: 3 / 4;
  cursor: pointer;
  user-select: none;
  transition: transform .12s;
}

.card:hover { transform: scale(1.04); z-index: 1; }
.card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card.unavailable { filter: grayscale(1) brightness(.55); cursor: not-allowed; }
.card.unavailable:hover { transform: none; }

.badge {
  position: absolute;
  bottom: 4px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, .8);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 1px 12px;
  border-radius: 12px;
  font-weight: 700;
}

.empty { text-align: center; color: var(--muted); padding: 40px; }

.deck {
  position: sticky;
  top: 70px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.deck h2 { font-size: 1rem; color: var(--gold); margin: 16px 0 6px; }
.deck-head { display: flex; flex-direction: column; gap: 8px; }
.deck-count { text-align: right; margin: 8px 0 4px; font-weight: 700; color: var(--gold); }

.deck-list { list-style: none; margin: 0; padding: 0; }
.deck-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 4px 8px;
  margin-bottom: 2px;
  background: var(--panel-2);
  border-left: 4px solid var(--common);
  border-radius: 4px;
  cursor: pointer;
}
.deck-list li:hover { background: #4a392c; }
.deck-list li.RARE { border-left-color: var(--rare); }
.deck-list li.EPIC { border-left-color: var(--epic); }
.deck-list li.LEGENDARY { border-left-color: var(--legendary); }
.deck-list .cost {
  background: #1f5fa8; border-radius: 50%;
  width: 24px; height: 24px; display: grid; place-items: center; font-size: .85rem; font-weight: 700;
}
.deck-list .qty { color: var(--gold); font-weight: 700; }
.deck-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.curve { display: flex; align-items: flex-end; gap: 4px; height: 70px; margin-top: 12px; }
.curve div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; font-size: .7rem; color: var(--muted); }
.curve span { display: block; width: 100%; background: #1f5fa8; border-radius: 3px 3px 0 0; min-height: 0; }

.warning { margin-top: 8px; color: #ffb4a8; font-size: .85rem; }

.deck-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.saved { list-style: none; margin: 0; padding: 0; }
.saved li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; margin-bottom: 4px;
  background: var(--panel-2); border-radius: 4px;
}
.saved li.current { outline: 1px solid var(--gold); }
.saved .info { flex: 1; cursor: pointer; overflow: hidden; }
.saved .info small { display: block; color: var(--muted); }
.saved .del { padding: 2px 8px; }

.preview {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  width: 320px;
}
.preview img { width: 100%; filter: drop-shadow(0 0 12px #000); }

dialog { background: var(--panel); border: 2px solid var(--border); border-radius: 10px; color: var(--text); width: min(520px, 90vw); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog textarea { width: 100%; font-family: Consolas, monospace; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 12px 0 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .deck { position: static; max-height: none; }
}
