:root {
  --bg: #12131a;
  --panel: #1c1e28;
  --line: #2e3140;
  --text: #e8e9f0;
  --muted: #8a8ea3;
  --accent: #6c8cff;
  --danger: #ff5c6c;
  --card-w: 170px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(ellipse at top, #1e2133, var(--bg) 60%) fixed;
  color: var(--text);
  font: 14px/1.4 system-ui, sans-serif;
  min-height: 100vh;
}

header {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: #0d0e14cc;
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}

nav { display: flex; gap: 6px; align-items: center; }
nav a, nav button { color: var(--text); text-decoration: none; }
nav .active { border-color: var(--accent); }

main { padding: 20px; }

button, select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
nav a { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; }

.muted { color: var(--muted); font-size: 12px; }
.error { color: var(--danger); }
.empty { text-align: center; margin-top: 80px; font-size: 18px; }
.empty a { color: var(--accent); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

.packs { display: flex; flex-wrap: wrap; gap: 24px; justify-content: center; }
.pack-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  width: 220px;
  padding: 14px;
  background: var(--panel);
  transition: transform .15s;
}
.pack-tile:hover { transform: translateY(-4px); }
.pack-art { width: 100%; aspect-ratio: 5 / 8; object-fit: cover; border-radius: 8px; display: block; }
.pack-art.blank {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #3b4bd8, #9a3bd8);
  font-weight: 700;
  font-size: 18px;
  padding: 10px;
  text-align: center;
}

.stage { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 20px; }
.pack-big {
  width: 260px;
  padding: 0;
  border: none;
  background: none;
  animation: float 2.4s ease-in-out infinite;
}
.pack-big:hover { filter: brightness(1.15); }
.pack-big.tearing { animation: tear .9s ease-in forwards; }

@keyframes float { 50% { transform: translateY(-10px); } }
@keyframes tear {
  0% { transform: rotate(0); }
  15% { transform: rotate(-4deg) scale(1.03); }
  30% { transform: rotate(4deg) scale(1.05); }
  45% { transform: rotate(-3deg) scale(1.07); }
  60% { transform: rotate(2deg) scale(1.1); filter: brightness(1.6); }
  100% { transform: scale(1.4); opacity: 0; filter: brightness(3); }
}

.reveal, .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--card-w));
  gap: 16px;
  justify-content: center;
}

.card {
  --rc: #888;
  position: relative;
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  border-radius: 10px;
  overflow: hidden;
  background: #222;
  box-shadow: 0 0 0 2px var(--rc), 0 4px 14px #0008;
  user-select: none;
}
.card .art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card .art.blank { background: linear-gradient(160deg, #333, #111); }
.card .frame { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.card .badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--rc);
  color: #111;
  font-weight: 800;
  font-size: 13px;
}
.card .badge.img { padding: 0; background: none; height: 26px; width: auto; }
.card .name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 8px 6px;
  background: linear-gradient(transparent, #000d);
  font-weight: 600;
  text-align: center;
}
.card .count {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #000b;
  border-radius: 4px;
  padding: 0 6px;
  font-weight: 700;
}
.card:not(.tier-0) { box-shadow: 0 0 0 2px var(--rc), 0 0 16px var(--rc); }
.card.top { box-shadow: 0 0 0 3px var(--rc), 0 0 28px var(--rc); }
.card.top::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, #fff6 45%, transparent 60%);
  background-size: 300% 100%;
  animation: shine 2.6s linear infinite;
  pointer-events: none;
}
@keyframes shine { from { background-position: 150% 0; } to { background-position: -150% 0; } }

.card.missing { box-shadow: 0 0 0 1px var(--line); }
.card.missing .art, .card.missing .frame { filter: brightness(0) opacity(.5); }
.card.missing::after { display: none; }
.grid .card:not(.missing) { cursor: pointer; }

.slot {
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  perspective: 900px;
  cursor: pointer;
  animation: deal .4s ease-out backwards;
}
@keyframes deal { from { transform: translateY(40px) scale(.8); opacity: 0; } }
.flipper {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform .55s cubic-bezier(.3, 1.4, .5, 1);
  transform-style: preserve-3d;
}
.slot.flipped .flipper { transform: rotateY(180deg); }
.slot.flipped { cursor: default; }
.face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 10px; overflow: hidden; }
.face.front { transform: rotateY(180deg); }
.face.back {
  background: repeating-linear-gradient(45deg, #2a2f55 0 10px, #232748 10px 20px);
  box-shadow: 0 0 0 2px #4a5090, 0 4px 14px #0008;
}
.face.back img { width: 100%; height: 100%; object-fit: cover; }
.slot:not(.flipped):hover .flipper { transform: translateY(-6px); }

.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle, var(--rc), transparent 70%);
  animation: flash .8s ease-out forwards;
  z-index: 20;
}
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }

.chip { --rc: var(--muted); border-color: var(--rc); }
.chip.active { background: var(--rc); color: #111; }

.modal {
  position: fixed;
  inset: 0;
  background: #000c;
  display: grid;
  place-items: center;
  z-index: 10;
}
.modal-body { display: flex; gap: 24px; align-items: flex-start; max-width: 720px; padding: 20px; }
.modal-body .card { --card-w: 280px; flex: none; }
.card-text { white-space: pre-wrap; }

.editor { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.editor section { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.editor h2 { margin: 0 0 12px; font-size: 16px; display: flex; gap: 10px; align-items: center; }
.editor table { border-collapse: collapse; width: 100%; }
.editor td, .editor th { padding: 4px 6px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.editor input[type=number] { width: 80px; }
.editor input[type=color] { padding: 0; width: 40px; height: 30px; }
.editor textarea { width: 100%; min-height: 34px; resize: vertical; }
.editor .id { font-family: monospace; color: var(--muted); font-size: 12px; }
.thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px dashed var(--line);
  background: #111;
  cursor: pointer;
  display: block;
}
.booster { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 10px; }
.row label { display: flex; gap: 6px; align-items: center; }
.members { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.members label { display: flex; gap: 4px; align-items: center; }
.issues { color: #ffb84d; margin: 0; padding-left: 18px; }
.savebar { display: flex; gap: 10px; align-items: center; }
.dirty { color: #ffb84d; }
.sim td:first-child { font-weight: 700; }

@media (max-width: 600px) {
  :root { --card-w: calc((100vw - 44px) / 2); }
  main { padding: 12px; }
  header { padding: 8px 12px; gap: 8px; }
  .reveal, .grid { gap: 12px; }
  .pack-tile { width: calc((100vw - 48px) / 2); padding: 8px; }
  .packs { gap: 12px; }
  .pack-big { width: 70vw; }
  .modal-body { flex-direction: column; align-items: center; }
  .modal-body .card { --card-w: 70vw; }
  .editor section { padding: 10px; overflow-x: auto; }
  #new-form { margin: 0 !important; }
}
