/* Display Case theme — colorful sprites on a deep Poké Ball-case background */
:root {
  --bg: #14161f;
  --surface: #1f2230;
  --surface-2: #2a2e40;
  --line: #343a52;
  --ink: #f0f2f8;
  --muted: #9aa0b4;
  --red: #ee1515;
  --gold: #ffcb05;
  --blue: #3b4cca;
  --radius: 12px;
  --display: "Fredoka", system-ui, sans-serif;
  --body: "Inter", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 var(--body);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 50% -8%, #1d2233 0%, rgba(29, 34, 51, 0) 60%),
    var(--bg);
  background-attachment: fixed;
}

/* Header */
header {
  padding: 14px 22px;
  background: rgba(31, 34, 48, .92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
header h1 {
  margin: 0 0 10px;
  font: 700 22px/1 var(--display);
  letter-spacing: .01em;
}
header h1::before {
  content: "";
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 9px;
  vertical-align: -2px;
  border-radius: 50%;
  background: linear-gradient(var(--red) 0 50%, #fff 50% 100%);
  box-shadow: inset 0 0 0 1.5px #0b0c10, 0 0 0 2px rgba(255, 255, 255, .06);
}
.actions { display: flex; gap: 8px; align-items: center; }
.status { margin: 8px 0 0; min-height: 1.7em; color: var(--muted); }
.status:not(:empty) {
  display: inline-block;
  padding: 4px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
}
.error { color: #ff8a8a; margin: 8px 0 0; }
.hidden { display: none !important; }

/* Buttons */
button, .add-toggle {
  font: 600 13px var(--body);
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease,
              background .12s ease, border-color .12s ease;
}
button:hover, .add-toggle:hover { transform: translateY(-1px); border-color: #4b5276; }
#pull-btn, .add-toggle, .editor-actions button:first-child {
  background: var(--red); border-color: var(--red); color: #fff;
}
#pull-btn:hover, .add-toggle:hover, .editor-actions button:first-child:hover {
  background: #ff2a1f; border-color: #ff2a1f;
}
#generate-btn { background: transparent; border-color: var(--blue); color: #b7c0ff; }
#generate-btn:hover { background: rgba(59, 76, 202, .18); }
#pdf-link {
  color: var(--gold); font-weight: 600; text-decoration: none;
  padding: 7px 10px; border-radius: 8px;
}
#pdf-link:hover { background: rgba(255, 203, 5, .12); }
.cancel-toggle { background: transparent; border-color: transparent; color: var(--muted); }
.cancel-toggle:hover { background: var(--surface-2); }
.row-buttons .danger { background: transparent; border-color: transparent; color: #ff6b6b; }
.row-buttons .danger:hover { background: rgba(255, 107, 107, .14); }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Groups → card grids */
main { display: flex; flex-direction: column; gap: 18px; padding: 18px; }
.group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.group h2 {
  margin: 0;
  font: 600 13px var(--display);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.add-bar { margin-bottom: 14px; }
.grid { display: grid; gap: 14px;
        grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; padding: 14px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.card:hover {
  transform: translateY(-3px);
  border-color: #4b5276;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .4);
}
.thumb { width: 200px; height: 200px; object-fit: contain;
         filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .45)); }
.name { font: 600 18px var(--display); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip {
  font: 600 11px var(--body); padding: 2px 9px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.chip.shiny {
  background: rgba(255, 203, 5, .14); border-color: var(--gold); color: var(--gold);
}
.chip.warn {
  background: rgba(245, 158, 11, .16); border-color: #f59e0b; color: #fbbf24;
  cursor: help;
}
.row-buttons { display: flex; gap: 6px; align-items: center; margin-top: auto; }
.row-buttons form { margin: 0; }

/* Modal editor */
dialog.editor-dialog {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  max-width: 920px;
  width: 92vw;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
}
dialog.editor-dialog::backdrop { background: rgba(8, 9, 14, .62); backdrop-filter: blur(3px); }
/* Shift the modal left so the costume drawer doesn't cover the species grid. */
dialog.editor-dialog.with-drawer { margin-right: 408px; transition: margin .18s ease; }
.editor { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.editor-preview {
  grid-column: 1 / -1; justify-self: center;
  width: 180px; height: 180px; object-fit: contain;
  filter: drop-shadow(0 8px 22px rgba(0, 0, 0, .55));
}
.editor-preview:not([src]) { display: none; }
.editor label {
  display: flex; flex-direction: column; gap: 4px;
  font: 600 11px var(--body); letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted);
}
.editor .shiny-field {
  flex-direction: row; align-items: center; gap: 6px;
  text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--ink);
}
.editor input, .editor select {
  font: 13px var(--body); color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px;
}
.editor-actions { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 4px; }

/* Selection grids (species + costume) */
.species-grid {
  grid-column: 1 / -1; display: grid; gap: 8px; padding: 8px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  max-height: 440px; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.grid-cell, .costume-cell {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.grid-cell span, .costume-cell span { font: 600 12px var(--display); color: var(--ink); }
.grid-cell img, .costume-cell img { width: 150px; height: 150px; object-fit: contain; }
.grid-cell:hover, .costume-cell:hover {
  transform: translateY(-2px); border-color: #4b5276;
  box-shadow: 0 8px 18px rgba(0, 0, 0, .4);
}
.grid-cell.selected, .costume-cell.selected {
  border-color: var(--red); box-shadow: 0 0 0 2px var(--red);
}
.grid-cell.selected::after, .costume-cell.selected::after {
  content: "\2713"; position: absolute; top: 5px; right: 6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--red); color: #fff; font-size: 12px;
  display: grid; place-items: center;
}
.grid-cell.dim { filter: grayscale(1); opacity: .4; }

/* Skeleton shimmer until a sprite loads */
.grid-cell:not(.loaded), .costume-cell:not(.loaded) {
  background: linear-gradient(100deg,
    var(--surface-2) 30%, #343a52 50%, var(--surface-2) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -220% 0; } }

/* Costume side drawer */
.costume-popout {
  position: fixed; top: 0; right: 0; height: 100vh; width: 384px;
  padding: 16px; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -16px 0 50px rgba(0, 0, 0, .55); z-index: 20;
}
.costume-popout h3 { margin: 0 0 14px; font: 700 16px var(--display); color: var(--gold); }
.costume-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { transition: none !important; animation: none !important; }
}

.bg-field { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.bg-current { color: var(--muted); font-size: 12px; }
.bg-change { white-space: nowrap; }
.background-drawer {
  position: fixed; top: 0; left: 0; height: 100vh; width: 384px;
  padding: 16px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  box-shadow: 16px 0 50px rgba(0, 0, 0, .55); z-index: 20;
}
.background-drawer h3 { margin: 0 0 14px; font: 700 16px var(--display); color: var(--gold); }
.background-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.bg-cell {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 4px; font-size: 10px; cursor: pointer;
  background: var(--surface-2); border: 1px solid transparent; border-radius: 6px;
}
.bg-cell img { width: 150px; height: 84px; object-fit: cover; border-radius: 4px; }
.bg-cell span { color: var(--ink); }
.bg-cell.selected { border-color: var(--red); box-shadow: 0 0 0 2px var(--red); }
.bg-cell.eligible { border-color: #22c55e; }
.bg-cell.ineligible { opacity: .5; }
.bg-cell.bg-hidden { display: none; }
.bg-showall {
  display: flex; align-items: center; gap: 7px; margin: 0 0 10px;
  font: 12px var(--body); color: var(--muted); cursor: pointer;
}
.bg-showall input { accent-color: var(--gold); }
.bg-cell .bg-badge {
  position: absolute; top: 6px; right: 6px; width: 18px; height: 18px;
  display: grid; place-items: center; border-radius: 50%;
  font-size: 11px; font-weight: 700; color: #0b0e16;
}
.bg-cell.eligible .bg-badge { background: #22c55e; }
.bg-cell.ineligible .bg-badge { background: #f59e0b; }
.bg-cell:not(.loaded) {
  background: linear-gradient(100deg, var(--surface-2) 30%, #343a52 50%, var(--surface-2) 70%);
  background-size: 220% 100%; animation: shimmer 1.2s linear infinite;
}
dialog.editor-dialog.with-bg-drawer { margin-left: 408px; transition: margin .18s ease; }

/* Add-group bar */
.add-group-bar {
  padding: 0 18px 4px;
}
.add-group-form {
  display: flex; gap: 8px; align-items: center;
}
.add-group-input {
  font: 13px var(--body); color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px;
  flex: 0 1 260px;
}
.add-group-input::placeholder { color: var(--muted); }
.add-group-btn {
  background: var(--blue); border-color: var(--blue); color: #fff;
  white-space: nowrap;
}
.add-group-btn:hover { background: #5467e8; border-color: #5467e8; }

/* Group header row: name + delete button side by side */
.group-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.group-header h2 { margin: 0; }
.group-delete-btn {
  margin-left: auto;
  font-size: 11px; padding: 4px 10px;
  background: transparent; border-color: transparent; color: #ff6b6b;
}
.group-delete-btn:hover { background: rgba(255, 107, 107, .14); }

/* Drag-to-reorder */
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: .4; cursor: grabbing; outline: 2px dashed var(--gold); }

/* Selector filter bar + multi-select */
.filter-bar {
  grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 14px; align-items: end;
}
.filter-bar label { flex: 0 0 auto; }
.grid-cell.filtered { display: none; }
.add-selected-btn:disabled { opacity: .5; cursor: not-allowed; }
.add-selected-btn:disabled:hover { transform: none; background: var(--red); }
.species-grid .grid-cell.selected { box-shadow: 0 0 0 2px var(--red); }

/* Dynamax / Gigantamax / Purified */
.chip.gmax { background: rgba(150,40,130,.20); border-color: #9c2882; color: #e483cf; }
.chip.dmax { background: rgba(236,72,153,.16); border-color: #ec4899; color: #f7a8d3; }
.chip.purified { background: rgba(56,189,248,.16); border-color: #38bdf8; color: #7dd3fc; }
.max-field { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.max-label { font: 600 11px var(--body); letter-spacing: .05em;
             text-transform: uppercase; color: var(--muted); }
