.builder-page { overflow: hidden; }
.builder { display: grid; grid-template-columns: minmax(0, 1fr); height: calc(100vh - 56px); }
.builder.searching { grid-template-columns: minmax(0, 1fr) minmax(420px, 46%); }
/* Leader/base picker: the width it has with Stats open (about 20% smaller tiles than before), with or without Stats. */
.builder.searching.wide-scope { grid-template-columns: minmax(0, 1fr) minmax(480px, 48%); }
/* Stats sit in their own column on the left, so they can stay open next to card search. */
.builder.stats-open { grid-template-columns: 320px minmax(0, 1fr); }
.builder.stats-open.searching { grid-template-columns: 300px minmax(0, 1fr) minmax(400px, 40%); }
.builder.stats-open.searching.wide-scope { grid-template-columns: 300px minmax(0, 1fr) minmax(480px, 48%); }
.pane { overflow-y: auto; min-height: 0; min-width: 0; }
.deck-main { scrollbar-gutter: stable; }  /* room for the scrollbar always, so a short tab doesn't shift the page sideways */

/* ---------- deck template ---------- */
.deck-main { padding: 20px 24px 60px; }
.deck-main > * { max-width: 2240px; margin-left: auto; margin-right: auto; }  /* the card pages' cap */
.draft-banner {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: 14px; border-radius: 8px;
  background: var(--panel-2); border-left: 3px solid var(--accent); font-size: .9rem;
}
.draft-banner[hidden] { display: none; }
/* Above the Deck tabs, laid out like the deck page's hero: art on the left, the deck's details and stats beside it.
   Narrow panes (search or Stats open, phones) put the art in one row on top. */
.deck-main { container-type: inline-size; }
.edit-hero { --hero-leader-w: calc(300px * var(--card-scale, 1)); display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 32px; margin-bottom: 20px; }
.edit-info { min-width: 0; }
.edit-info .deck-top { display: contents; }
.edit-info > .hero-stats { margin-top: 0; }
.edit-hero .hero-sub { margin-top: 10px; }  /* room for the title box's outline */
.edit-actions { gap: 6px; padding-block: 26px; }  /* the same room as the deck page's buttons */
/* With card search open, or in any narrow pane: the deck's details on top, then the art, then the stats. */
@container (max-width: 1180px) {
  .edit-hero { display: flex; flex-direction: column; gap: 16px; }
  .edit-info { display: contents; }
  .edit-info .deck-top { display: block; order: 1; }
  .edit-hero .command-zone { order: 2; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, .8fr); align-items: start; width: 100%; max-width: 900px; }
  .edit-hero .command-zone .slot-base { grid-column: auto; width: 100%; }
  .edit-info > .hero-stats { order: 3; }
}
.builder.searching .edit-hero { display: flex; flex-direction: column; gap: 16px; }
.builder.searching .edit-info { display: contents; }
.builder.searching .edit-info .deck-top { display: block; order: 1; }
.builder.searching .edit-hero .command-zone { order: 2; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, .8fr); align-items: start; width: 100%; max-width: 900px; }
.builder.searching .edit-hero .command-zone .slot-base { grid-column: auto; width: 100%; }
.builder.searching .edit-info > .hero-stats { order: 3; }
@container (max-width: 760px) {
  .edit-hero .hero-sub { flex-direction: column; gap: 8px; }
  .edit-hero .deck-tags { flex-wrap: wrap; }
}
@container (max-width: 640px) {
  .edit-hero .glance-grid { grid-template-columns: minmax(0, 1fr); }
  .edit-hero .slot .change-slot { display: none; }  /* too big for phone-sized art: × clears a slot, then choose again */
  .deck-top #deck-name { font-size: 1.4rem; }
}
.deck-top #deck-name { font-size: 1.9rem; font-weight: 800; line-height: 1.25; background: transparent; border-color: transparent; padding-left: 0; }
.deck-top #deck-name:hover, .deck-top #deck-name:focus { border-color: var(--line); padding-left: 10px; background: var(--panel); }
.save-status { min-height: 1.2em; transition: color .2s; flex-basis: 100%; text-align: right; }  /* under Save */

/* Leaders side by side with the base under them, the deck page's sizes. */
.command-zone { display: grid; grid-template-columns: repeat(2, var(--hero-leader-w)); gap: 12px; justify-items: center; align-content: start; }
.command-zone .slot { width: 100%; }
.command-zone .slot-base { grid-column: 1 / -1; width: calc(225px * var(--card-scale, 1)); }
.slot { position: relative; aspect-ratio: 7 / 5; border-radius: 10px; overflow: hidden; }
.slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot .add-slot {
  width: 100%; height: 100%; border: 2px dashed var(--line); border-radius: 10px; background: transparent; cursor: pointer;
  color: var(--muted); font: inherit; font-weight: 600; display: grid; place-items: center;
}
.slot .add-slot:hover { border-color: var(--accent); color: var(--text); }
.slot.active .add-slot { border-color: var(--accent); color: var(--text); background: rgba(255, 154, 61, .06); }
.slot .x {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .75); color: #fff; font-size: 1rem; line-height: 1; opacity: 0; transition: opacity .1s;
}
.slot:hover .x, .slot .x:focus { opacity: 1; }
.slot .change-slot {
  position: absolute; right: 8px; bottom: 8px; padding: 3px 10px; border: 0; border-radius: 99px; cursor: pointer;
  background: rgba(0, 0, 0, .8); color: #fff; font: inherit; font-size: .8rem; font-weight: 600; opacity: 0; transition: opacity .1s;
}
.slot:hover .change-slot, .slot .change-slot:focus-visible { opacity: 1; }
@media (hover: none) { .slot .x, .slot .change-slot { opacity: 1; } }

.count.done b { color: var(--ok); }
.edit-hero .glance { align-items: center; }
.edit-hero .glance-legal { padding-top: 0; }
#issues:empty { display: none; }
#issues { margin: 0; }


.view-bar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.view-bar select { width: auto; padding: 5px 8px; }

/* Bigger text in the decklist block; the deck page matches. */
.deck-block .tabs .tab { font-size: 1.04rem; }
.deck-block .view-toggle a { font-size: .92rem; }
.deck-block .view-bar .row, .deck-block .view-bar select, .deck-block .btn.sm { font-size: .95rem; }
#deck-list .card-line { font-size: .98rem; padding-block: 3px; }
#deck-list .card-line .cost { width: 23px; height: 23px; font-size: .8rem; }
#deck-list .deck-section h3 { font-size: 1.08rem; }
#deck-list .add-btn { font-size: .84rem; }
#deck-list .count-toggle { font-size: .8rem; }
.section-empty { font-size: .94rem; }

/* List: laid out like Stacks. Sections sit side by side and wrap to the next row; a long section takes several columns
   under its one heading, so a group reads as one block. */
/* Sections stretch to the height of their row, so the empty space under a short one still takes dropped cards. */
#deck-list.list { display: flex; flex-wrap: wrap; gap: 20px 24px; align-items: stretch; margin-inline: auto; }
#deck-list.list .deck-section { margin: 0; min-width: min(var(--list-col, 320px), 100%); max-width: 100%; }
/* A section of one column, or an empty one, stays that wide: its heading's buttons wrap instead of widening it. */
#deck-list.list .deck-section:not(:has(.list-col + .list-col)), #deck-list.list .deck-section.collapsed { width: var(--list-col, 320px); }
#deck-list.list .deck-section h3 { flex-wrap: wrap; }
#deck-list.list .section-body { display: flex; flex-wrap: wrap; gap: 0 24px; align-items: flex-start; }
#deck-list.list .list-col { flex: none; width: var(--list-col, 320px); max-width: 100%; }  /* card-size.js sets the width */
#deck-list.list .list-col .nm { white-space: normal; overflow: visible; }  /* the whole name, on two lines if it needs them */
@media (max-width: 700px) { #deck-list.list .deck-section, #deck-list.list .list-col { width: 100%; } }
#deck-list.list .section-empty { flex: 1; }
#deck-list.list .new-category, #deck-list.list .view-hint { flex-basis: 100%; margin-bottom: 0; }
.section-body { min-height: 8px; }
/* The builder's card grids fill every row with cards. --grid-template (card-size.js fitCardGrids) sets the column
   count: as many as fit on M; on L as many as fit, at least one fewer than M. */
#deck-list.images .section-body { display: grid; gap: 10px;
  grid-template-columns: var(--grid-template, repeat(auto-fill, minmax(min(var(--card-w), 100%), 1fr))); }
#deck-list.images .section-empty { grid-column: 1 / -1; }

/* Image view tiles */
.deck-tile-img { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 5 / 7; cursor: grab; }
.deck-tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.deck-tile-img.over { outline: 2px solid var(--bad); }
.deck-tile-img .tile-qty, .deck-tile-img .tile-pen {
  position: absolute; font-size: .8rem; font-weight: 800; padding: 2px 7px; border-radius: 99px; background: rgba(0, 0, 0, .8);
}
.deck-tile-img .tile-qty { top: 6px; left: 6px; }
.deck-tile-img .tile-pen { bottom: 6px; left: 6px; color: var(--warn); }
.deck-tile-img .line-actions { position: absolute; top: 6px; right: 6px; }
.deck-tile-img:hover .line-actions { display: inline-flex; }

/* Custom categories, drag and drop */
.deck-section .note { font-size: .8rem; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); }
.icon-btn {
  background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: .85rem; padding: 0 3px;
  opacity: 0; transition: opacity .1s;
}
.deck-section h3:hover .icon-btn, .icon-btn:focus { opacity: 1; }
.icon-btn:hover { color: var(--text); }
.new-category {
  display: block; width: 100%; margin: 0 0 18px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px;
  background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
}
.new-category:hover { border-color: var(--accent); color: var(--text); }
.deck-item[draggable] { cursor: grab; }
.deck-item.dragging { opacity: .4; }
#deck-list.drag-active [data-drop] { outline: 1px dashed var(--line); outline-offset: 4px; border-radius: 6px; }
#deck-list [data-drop].drop-over { outline: 2px solid var(--accent); background: rgba(255, 154, 61, .06); }

.move-menu {
  position: fixed; z-index: 200; min-width: 200px; max-height: 60vh; overflow-y: auto; padding: 6px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.move-menu .menu-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 8px; }
.move-menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); font: inherit; font-size: .9rem;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.move-menu button:hover { background: var(--panel); }
.move-menu button.on { color: var(--accent); font-weight: 700; }
.result.in-maybe { outline: 2px dashed var(--muted); }
.result[draggable] { cursor: grab; }
.result.dragging { opacity: .4; }

/* Counted / not counted switch on custom categories */
.count-toggle {
  font: inherit; font-size: .8rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; cursor: pointer;
  padding: 1px 8px; border-radius: 99px; border: 1px solid var(--line); background: none; color: var(--muted);
}
.count-toggle.on { color: var(--ok); border-color: rgba(76, 195, 138, .45); }
.count-toggle:hover { border-color: var(--accent); }
.count-toggle.fixed { cursor: default; }
.count-toggle.fixed:hover { border-color: var(--line); }
.count-toggle.fixed.on:hover { border-color: rgba(76, 195, 138, .45); }
/* The ⋯ at the end of a category's header: Rename, Move up/down, Move or remove all its cards, Delete. */
.cat-menu-btn {
  background: none; border: 1px solid transparent; border-radius: 6px; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 1rem; line-height: 1; padding: 1px 6px;
}
.cat-menu-btn:hover, .cat-menu-btn:focus-visible { color: var(--text); border-color: var(--line); }
.move-menu button.danger { color: var(--bad); }

/* Categories tab: one row per category, in order. */
.cat-manage-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cat-manage-bar p { margin: 0; flex: 1; }
#cat-manage { display: grid; gap: 6px; }
.cat-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px;
}
.cat-row.alt { border-style: dashed; }
.cat-row .grip { cursor: grab; color: var(--muted); }
.cat-row .cat-order { display: flex; }
.cat-row .cat-order .icon-btn { opacity: 1; font-size: 1rem; }
.cat-row .cat-order .icon-btn:disabled { opacity: .3; cursor: default; }
.cat-row .cat-name { display: grid; min-width: 120px; }
.cat-row .spacer { flex: 1; }
.cat-row .cat-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cat-row.dragging { opacity: .4; }
.cat-row.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.cat-row.drop-after { box-shadow: 0 3px 0 var(--accent); }

/* Drop bar: zero-height sticky holder so showing it never shifts the page under the cursor. */
.drop-bar-wrap { position: sticky; top: 0; height: 0; z-index: 30; }
.drop-bar {
  display: none; position: absolute; left: 0; right: 0; top: 0; padding: 10px; gap: 8px; flex-wrap: wrap; align-items: center;
  background: rgba(17, 20, 27, .96); border: 1px solid var(--accent); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.builder.is-dragging .drop-bar { display: flex; }
.drop-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-right: 4px; }
.drop-target {
  padding: 8px 14px; border-radius: 8px; border: 1px dashed var(--line); background: var(--panel); font-weight: 600; font-size: .88rem;
}
.drop-target.drop-over { border: 1px solid var(--accent); background: rgba(255, 154, 61, .15); color: var(--text); }
.deck-section { margin-bottom: 18px; }
.deck-section h3 {
  font-size: 1.02rem; color: var(--text); font-weight: 700;
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; margin: 0 0 6px; border-radius: 8px; background: var(--panel-2);
}
.deck-section h3 .n { color: var(--sun-1); }
.deck-section h3 .spacer { flex: 1; }
.deck-section.active h3 { color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.add-btn {
  background: none; border: 1px solid var(--line); color: var(--sun-1); border-radius: 6px; padding: 2px 9px;
  font: inherit; font-size: .8rem; font-weight: 700; cursor: pointer; text-transform: none; letter-spacing: 0;
}
.add-btn:hover { border-color: var(--accent); }
.section-empty {
  display: block; width: 100%; text-align: left; padding: 8px 4px; color: var(--muted); font: inherit; font-size: .88rem;
  background: none; border: 0; cursor: pointer;
}
.section-empty:hover { color: var(--text); }
.deck-section.alt { opacity: .85; }
.deck-main .card-line { position: relative; }
.card-line.over .nm { color: var(--bad); }
.card-line .rate { font-size: .8rem; color: var(--ok); font-weight: 700; }
.line-actions { display: none; gap: 2px; }
/* On hover the buttons float over the row's right end (over the aspect pips) instead of replacing them: they're a
   little taller than the pips, so swapping them grew the row, which reflowed the List view's columns and moved the
   row out from under the mouse, ending the hover. The row flickered between two columns. */
.card-line { position: relative; }
.card-line .line-actions { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); padding-left: 6px;
  background: var(--panel-2); }
.card-line:hover .line-actions { display: inline-flex; }
.card-line:hover .pips { visibility: hidden; }
/* Deck list rows you can drag: hover outlines the row in orange (it can be moved, and its buttons act on it) and turns
   the name orange, like the deck page's list. Over-the-limit names stay red. */
#deck-list .card-line.deck-item[draggable] { transition: box-shadow .12s, opacity .15s, filter .15s, background-color .15s; }
#deck-list .deck-tile-img { transition: transform .12s, box-shadow .12s, opacity .15s, filter .15s, outline-color .15s; }
#deck-list .card-line.deck-item[draggable]:hover { box-shadow: inset 0 0 0 1px var(--accent); }
#deck-list .card-line.deck-item[draggable]:not(.over):hover .nm { color: var(--sun-1); }
.line-actions button {
  width: 22px; height: 22px; border-radius: 5px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  cursor: pointer; font-weight: 700; line-height: 1; padding: 0;
}
.line-actions button:hover { border-color: var(--accent); }
.sug { cursor: pointer; }

.tab-body h3 { font-size: .9rem; }

/* ---------- search drawer ---------- */
.drawer { background: #11141b; border-left: 1px solid var(--line); padding: 0 18px 40px; }
.drawer[hidden] { display: none; }
/* Side panels slide in from their edge with a fade, and back out when closed (builder.js waits for .closing). */
@keyframes panel-in-right { from { opacity: 0; transform: translateX(28px); } }
@keyframes panel-out-right { to { opacity: 0; transform: translateX(28px); } }
@keyframes panel-in-left { from { opacity: 0; transform: translateX(-28px); } }
@keyframes panel-out-left { to { opacity: 0; transform: translateX(-28px); } }
.drawer { animation: panel-in-right .18s ease-out; }
.drawer.closing { animation: panel-out-right .15s ease-in forwards; }
.stats-panel { animation-name: panel-in-left; }
.stats-panel.closing { animation-name: panel-out-left; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
dialog[open] { animation: dialog-in .16s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer.closing, dialog[open] { animation: none; }
}
.drawer-sticky {
  position: sticky; top: 0; z-index: 5; background: #11141b; margin: 0 -18px; padding: 0 18px 8px;
  border-bottom: 1px solid var(--line); margin-bottom: 12px;
}
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 14px 0 10px; }
.search-bar { position: relative; display: flex; gap: 8px; align-items: center; }
.name-suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40; display: grid; padding: 4px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.name-suggest[hidden] { display: none; }
.name-suggest button { display: flex; align-items: baseline; gap: 6px; padding: 6px 8px; border: 0; border-radius: 7px; background: none; color: var(--text); font: inherit; font-size: .9rem; text-align: left; cursor: pointer; }
.name-suggest button:hover, .name-suggest button.on { background: var(--panel); }
.name-suggest .spacer { flex: 1; }
.filters[hidden] { display: none; }
.drawer-head h2 { margin: 0; font-size: 1.1rem; }
.search-bar input { font-size: 1rem; padding: 10px 12px; }
.chips .chip b { font-weight: 700; }
.result-meta { margin-bottom: 10px; }

.results { display: grid; gap: 10px; grid-template-columns: var(--grid-template, repeat(auto-fill, minmax(min(var(--card-w), 100%), 1fr))); }
.result { position: relative; cursor: pointer; border-radius: 9px; overflow: hidden; aspect-ratio: 5 / 7; }
/* Leaders and bases are landscape; they never go below the M size so their text stays readable. */
.results.wide-cards { grid-template-columns: repeat(auto-fill, minmax(min(max(calc(var(--card-w) * 1.4), 224px), 100%), 1fr)); }
.result.wide { aspect-ratio: 7 / 5; }
.result img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Hover on card images (results, suggestions, deck list): a small lift and shadow, and an orange line drawn on the
   card itself, just inside its edge, so it follows the card's corners exactly. The frames are rounded like the card
   (5%, as in site.css) and have no background of their own (the images bring a loading placeholder, site.css), so no
   black shows at the corners and the in-deck outline hugs the card too. */
.result, .deck-tile-img { border-radius: 5%; isolation: isolate; }  /* isolation: the hover line stays under cards stacked on top */
.result, .deck-tile-img, .sug-tile img { transition: transform .12s, box-shadow .12s; }
.result:hover, #deck-list:not(.stacks) .deck-tile-img:hover, .sug-tile:hover img { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0, 0, 0, .5); }
/* The hover line is an overlay inside the frame (::before; ::after is the foil shine), so the frame's rounded clip
   can't shave it at the corners. A card already in the deck keeps its bold ring and only lifts. */
.result::before, .deck-tile-img::before {
  content: ""; position: absolute; inset: 0; z-index: 3; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 0 0 2px transparent; transition: box-shadow .12s;
}
.result:not(.in-deck):hover::before, .deck-tile-img:hover::before { box-shadow: inset 0 0 0 2px var(--accent); }
.sug-tile:hover img { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Stacks already slide the card out on hover (static/js/stacks.js): just the line there. */
/* Already in the deck: a bold orange ring around the card (with its check badge), clear at a glance next to hover's thin line. */
.result.in-deck { outline: 3px solid var(--accent); }
.result .have, .result .pen, .result .ban {
  position: absolute; font-size: .8rem; font-weight: 800; padding: 2px 7px; border-radius: 99px;
}
.result .have { top: 6px; right: 6px; background: var(--accent); color: #1a0f05;
  max-width: calc(100% - 40px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }  /* "✓ Removal" */
.result.in-maybe .have { background: #3a4150; color: var(--text); }
.result .pen { bottom: 6px; right: 6px; background: rgba(0, 0, 0, .8); color: var(--warn); }
.result .ban { top: 6px; left: 6px; background: var(--bad); color: #fff; }
.more { grid-column: 1 / -1; justify-content: center; }
.results-heading {
  grid-column: 1 / -1; margin: 10px 0 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  border-bottom: 1px solid var(--line); padding-bottom: 6px;
}
.results-heading:first-child { margin-top: 0; }
.results-heading span { color: var(--text); margin-left: 4px; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 20px;
  width: min(640px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }

@media (max-width: 900px) {
  .builder-page { overflow: auto; }
  .builder, .builder.searching, .builder.stats-open { grid-template-columns: 1fr; height: auto; }
  .pane { overflow: visible; }
  .deck-main { padding: 16px; }
  /* The drawer covers the screen on phones; "Done" returns to the deck. */
  .drawer { position: fixed; inset: 0; z-index: 60; overflow-y: auto; overscroll-behavior: contain; border-left: 0; padding: 0 16px 40px; }
  .drawer-sticky { margin: 0 -16px 12px; padding: 0 16px 8px; }
  /* While a panel covers the screen, the page under it holds still (and keeps its place for when it closes). */
  html:has(.drawer:not([hidden])), html:has(.drawer:not([hidden])) body { overflow: hidden; }
  /* Phones: two cards side by side, in search, Suggestions and the deck's image view. */
  .results { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  #deck-list.images .section-body, #tab-suggest .sug-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .results.wide-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- categories: primary vs secondary, remove ---------- */
.deck-item.secondary { opacity: .45; filter: grayscale(.85); cursor: pointer; }
.deck-item.secondary:hover { opacity: .7; }
.view-hint { margin-top: -6px; }

/* ---------- custom resource value, foil ---------- */
.card-line .cost.custom { background: var(--accent); color: #1a0f05; }
.deck-tile-img .tile-cost {
  position: absolute; bottom: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #1a0f05; font-weight: 800; font-size: .8rem;
}
.foil-mark { color: #9fd8ff; }

/* ---------- info button on search results ---------- */
.result-info {
  position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .75); color: #fff; font: italic 700 .85rem Georgia, serif; display: none;
}
.result:hover .result-info { display: block; }
.line-actions [data-act=info] { font: italic 700 .8rem Georgia, serif; }

/* ---------- card info panel ---------- */
.card-dialog { width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; overflow: hidden; }
.card-dialog .info { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); max-height: calc(100vh - 48px); }
.info-art { padding: 24px; display: grid; gap: 12px; align-content: start; justify-items: start; background: #0b0d12; border-right: 1px solid var(--line); }
.info-img { position: relative; border-radius: 12px; overflow: hidden; width: 100%; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
.info-img img { width: 100%; display: block; }
/* Each column scrolls on its own. The grid's max-height doesn't limit its row, so the columns need their own cap:
   without it a long printings list made the body taller than the dialog, which clipped it with no way to scroll. */
.info-art, .info-body { max-height: calc(100vh - 48px); overflow-y: auto; overscroll-behavior: contain; }
.info-body { padding: 0 28px 28px; }

.info-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; gap: 16px; justify-content: space-between;
  padding: 22px 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); margin-bottom: 14px;
}
.info-head h2 { margin: 0; font-size: 1.5rem; }
.info-sub { color: var(--muted); margin-top: 2px; }

.info-tags, .info-traits { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.info-tags .pip { width: 22px; height: 22px; }
.tag { font-size: .8rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); }
.trait { font-size: .8rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.trait + .trait::before { content: "·"; margin-right: 6px; }
.stats-row { display: flex; gap: 8px; margin: 4px 0 12px; }
.stat { display: grid; justify-items: center; min-width: 64px; padding: 6px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.stat b { font-size: 1.25rem; line-height: 1.1; }
.stat span { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ability { background: var(--panel-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; border-left: 3px solid var(--line); }
.ability-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.ability p { margin: 4px 0 0; white-space: pre-line; font-size: .93rem; }

.info-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.info-section h3 { margin: 0 0 12px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.section-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head-row h3 { margin: 0; }

.settings { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.setting-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 12px; align-content: start; }
.setting-title { font-weight: 700; font-size: .95rem; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.field select { width: 100%; }
.field .chips input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.setting-box p { margin: 0; }
.settings-foot { display: flex; justify-content: flex-end; margin-top: 12px; }

.view-toggle a.disabled { opacity: .35; pointer-events: none; }
.printings { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.printing {
  display: grid; gap: 2px; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.printing img { width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; }
.printing-name { font-weight: 700; font-size: .85rem; }
.printing-meta { font-size: .8rem; color: var(--muted); }
.printing:hover:not(:disabled) { border-color: #48505f; }
.printing.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.printing:disabled { cursor: default; }

.rulings { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rulings li { background: var(--panel-2); border-radius: 10px; padding: 10px 14px; }
.rulings p { margin: 2px 0 0; font-size: .92rem; }
.ruling-date { font-size: .8rem; color: var(--muted); font-weight: 600; }
.source-note { font-size: .8rem; color: var(--muted); margin: 10px 0 0; }
@media (max-width: 800px) {
  .card-dialog .info { grid-template-columns: 1fr; overflow-y: auto; }
  .info-art { border-right: 0; justify-items: center; padding: 16px; }
  .info-img { max-width: 260px; }
  .info-art, .info-body { max-height: none; overflow: visible; }
  .info-body { padding: 0 16px 20px; }
  .settings { grid-template-columns: 1fr; }
}

/* Search results: one "Add to" button on hover (clicking the card itself adds it) */
.result-actions { position: absolute; left: 8px; right: 8px; bottom: 8px; display: none; }
.result:hover .result-actions, .result:focus-within .result-actions { display: flex; }
.add-to {
  flex: 1; padding: 7px 8px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .12); cursor: pointer;
  font: inherit; font-size: .8rem; font-weight: 700; background: rgba(13, 15, 20, .92); color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}
.add-to:hover { border-color: var(--accent); color: var(--sun-1); }
.result:hover .pen { display: none; }

/* Search results as a list */
.results.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }  /* minmax: long names end in "…" instead of widening the list */
.result-row {
  aspect-ratio: auto; display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px;
  background: transparent; overflow: visible; font-size: .92rem;
}
.result-row:hover { background: var(--panel-2); }
.result-row.in-deck { outline: 0; background: rgba(255, 154, 61, .08); }
.result-row.in-maybe { outline: 0; background: rgba(154, 163, 178, .08); }
.result-row .cost {
  width: 22px; height: 22px; border-radius: 50%; background: #2c3340; display: grid; place-items: center;
  font-size: .8rem; font-weight: 700; flex: none;
}
.result-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-row .sub { color: var(--muted); }
.result-row .row-type { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.result-row .have, .result-row .ban { position: static; flex: none; }
.result-row .result-info { position: static; display: inline-block; flex: none; }
.result-row .add-to { flex: none; padding: 4px 9px; font-size: .8rem; background: var(--panel); box-shadow: none; }

/* ---------- search filters ---------- */
.drawer-head h2 { font-size: 1.15rem; }
.search-bar input { flex: 1; }
.filters {
  display: grid; gap: 10px; margin: 12px 0 0; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px;
}
.filter-row { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 10px; }
.filter-row[hidden] { display: none; }
.filter-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.filter-row select { width: 100%; max-width: 320px; }
.filters .chip { padding: 3px 10px; font-size: .82rem; }
.chip.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip.toggle:has(input:checked) { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.results-bar { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.results-bar .result-meta {
  margin: 0; font-size: .85rem; color: var(--muted); flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.results-bar .spacer { display: none; }
.results-bar .result-meta b { color: var(--text); }
.results-bar select { width: auto; padding: 5px 8px; }
.results-bar .view-toggle[hidden] { display: none; }
@media (max-width: 900px) {
  .results-bar .hint { display: none; }
  .filter-row { grid-template-columns: 52px minmax(0, 1fr); }
}

/* ---------- search syntax ---------- */
.query-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.query-summary[hidden], .search-help[hidden], .search-pins[hidden] { display: none; }
.query-hint { font-size: .8rem; color: var(--muted); align-self: center; }
/* Search terms kept with Enter, one bubble each. */
.search-pins { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.search-pin {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 99px; font-size: .8rem;
  font-weight: 600; background: var(--panel-2); border: 1px solid var(--accent); color: var(--text);
}
.search-pin button {
  width: 18px; height: 18px; border-radius: 50%; border: 0; padding: 0; background: transparent; color: var(--muted);
  font-size: 1rem; line-height: 1; cursor: pointer;
}
.search-pin button:hover { background: rgba(255, 255, 255, .1); color: var(--text); }
.search-pins .link-btn { border: 0; background: none; padding: 0 4px; color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer; }
.search-pins .link-btn:hover { color: var(--text); text-decoration: underline; }
.query-tag {
  font-size: .8rem; font-weight: 600; padding: 2px 9px; border-radius: 99px;
  background: rgba(255, 154, 61, .12); border: 1px solid rgba(255, 154, 61, .4); color: var(--sun-1);
}
.search-help {
  margin-top: 10px; padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: .85rem;
}
.search-help p { margin: 0 0 8px; color: var(--muted); }
.search-help table { width: 100%; border-collapse: collapse; }
.search-help td { padding: 4px 6px 4px 0; vertical-align: top; color: var(--muted); }
.search-help td:first-child { white-space: nowrap; font-family: ui-monospace, Consolas, monospace; font-size: .82rem; }
.search-help code { font-size: .8rem; color: var(--text); }

/* ---------- stats panel (opens on the right, like card search) ---------- */
.stats-panel .stats-body { display: grid; gap: 12px; }
.stat-block { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px;
  font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--muted);
}
.stat-head .muted, .stat-head .penalty { text-transform: none; letter-spacing: 0; font-weight: 600; }
details.stat-block summary { cursor: pointer; list-style: none; margin-bottom: 0; }
details.stat-block summary::-webkit-details-marker { display: none; }
details.stat-block[open] summary { margin-bottom: 8px; }
.curve.mini { height: 120px; gap: 6px; }
.curve.mini .bar b { font-size: .8rem; }
.type-line { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: .88rem; margin-bottom: 8px; }
#hero-highlights:empty { display: none; }
.highlight-chooser { display: grid; gap: 10px; }
.highlight-group { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 4px 10px; align-items: start; }
.highlight-group .filter-label { padding-top: 4px; }
.highlight-group .chip b { color: var(--text); font-weight: 800; }  /* number first, like the Highlights chips */
/* The stats panel's Highlights block: its chooser opens inside the block, labels above the chips to fit the panel.
   Each pick redraws the panel, so the chooser doesn't pop in again every time. */
.stats-highlights .highlight-chooser { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); animation: none; }
.stats-highlights .highlight-group { grid-template-columns: minmax(0, 1fr); }
.stats-highlights .highlight-group .filter-label { padding-top: 0; }
.stat-block .link-btn { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; font-size: .82rem; cursor: pointer; }
.stat-block .link-btn:hover { text-decoration: underline; }
.type-bar { grid-column: 1 / -1; height: 5px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.type-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--sun-1), var(--sun-2)); }
.icon-counts { display: flex; flex-wrap: wrap; gap: 12px; font-weight: 700; font-size: .95rem; }
.icon-counts > :is(span, button) { display: inline-flex; align-items: center; gap: 5px; }
.type-line.stat-click { width: 100%; }
.icon-counts .pip { width: 22px; height: 22px; }
.pen-line { font-size: .85rem; display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; }
#stats-toggle.on { border-color: var(--accent); color: var(--sun-1); }

/* ---------- deck details: description, visibility, primer ---------- */
.deck-top #deck-summary {
  background: transparent; border-color: transparent; padding-left: 0; color: #cfd5df;
}
.deck-top #deck-summary:hover, .deck-top #deck-summary:focus { border-color: var(--line); padding-left: 10px; background: var(--panel); }
#visibility[data-vis=unlisted] summary { color: #9fd8ff; }
#visibility summary { cursor: pointer; }
.primer-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.primer-bar code { font-size: .8rem; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
#deck-primer { min-height: 360px; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; line-height: 1.55; max-width: 960px; }
.primer-preview { max-width: 860px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 22px; }
.primer-preview[hidden] { display: none; }
.primer-columns { display: grid; grid-template-columns: minmax(0, 960px) minmax(240px, 380px); gap: 24px; align-items: start; }
.primer-guide { padding: 14px 16px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; font-size: .9rem; }
.primer-guide h3 { margin: 0 0 8px; font-size: 1rem; }
.primer-guide ul { margin: 0 0 12px; padding-left: 18px; display: grid; gap: 6px; }
.primer-guide b { color: var(--text); }
@container (max-width: 900px) { .primer-columns { grid-template-columns: minmax(0, 1fr); } }

/* ---------- blocks: the builder page in segments ---------- */
.deck-main { background: #0b0d12; }
.block {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; margin-bottom: 16px;
}
.save-status:empty { display: none; }
.block.deck-block .tabs { margin-top: -4px; }
.deck-top #deck-name:hover, .deck-top #deck-name:focus,
.deck-top #deck-summary:hover, .deck-top #deck-summary:focus { background: var(--panel-2); }
.stats-panel { order: -1; border-left: 0; border-right: 1px solid var(--line); }
.stats-panel .stat-block { background: var(--panel-2); }

/* ---------- suggestions ---------- */
#tab-suggest { max-width: none; }
.sug-note { margin: 0 0 12px; max-width: 760px; }
.sug-section { margin-bottom: 22px; }
.sug-section h3 { font-size: .9rem; margin: 0 0 10px; }
.sug-grid { display: grid; gap: 10px; grid-template-columns: var(--grid-template, repeat(auto-fill, minmax(min(var(--card-w), 100%), 1fr))); }
.sug-tile { position: relative; cursor: pointer; }
.sug-tile img { width: 100%; aspect-ratio: 5 / 7; object-fit: cover; border-radius: 9px; display: block; background: #000; }
.sug-caption { font-size: .8rem; color: var(--muted); margin-top: 5px; line-height: 1.3; }
.sug-caption b { color: var(--ok); }
.sug-add {
  position: absolute; top: 6px; right: 6px; display: none; padding: 4px 9px; border-radius: 7px; border: 0; cursor: pointer;
  font: inherit; font-size: .8rem; font-weight: 700; background: linear-gradient(135deg, var(--sun-1), var(--sun-2)); color: #1a0f05;
}
.sug-tile:hover .sug-add { display: block; }
@media (hover: none) { .sug-add { display: block; } }

/* ---------- import / export ---------- */
#export-formats input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
#export-formats .chip:has(input:checked) { background: var(--panel-2); color: var(--text); border-color: var(--accent); }

/* Info panel: leaders show both sides, labelled (no flip button) */
.info-art .side-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: -4px; }
.info-img.back { width: 72%; justify-self: center; }

.slot img[data-slot-card] { cursor: pointer; }

/* Epic Action tag in the card panel (same look as the leader and card pages) */
.ability.epic { border-left-color: var(--accent); background: rgba(255, 154, 61, .07); }
.epic-tag {
  display: inline-block; font-size: .8rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 9px; border-radius: 99px; background: linear-gradient(135deg, var(--sun-1), var(--sun-2)); color: #1a0f05;
}

/* Unsaved changes: a dot on the Save button (builder.js syncSaveState). */
#save-btn.unsaved::after {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #1a0f05; margin-left: 2px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}

/* Optional history note next to Save */
.undo-redo { display: inline-flex; gap: 4px; }
.undo-redo .btn { display: inline-flex; align-items: center; gap: 5px; padding-left: 9px; padding-right: 10px; }
.undo-redo svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#save-note { width: 200px; padding: 8px 10px; font-size: .9rem; }
/* Undo, Redo, the history note and Save stay together at the right end, also when the row wraps. */
.edit-save { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px; margin-left: auto; }
@media (max-width: 900px) { .edit-save { margin-left: 0; width: 100%; } #save-note { width: 100%; order: 10; } }

/* Empty deck: popular leader pairs to start from */
.starter-pairs { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.starter-pairs[hidden] { display: none; }
.builder.blank-deck :is(#hero-stats, #hero-highlights) { display: none; }
.block > .starter-pairs { margin-top: 0; padding-top: 0; border-top: 0; }
.starter-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
.starter-heading { font-size: 1.15rem; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.starter-heading .starter-close { opacity: 1; font-size: 1.4rem; line-height: 1; width: 36px; height: 36px; border-radius: 50%; }
.starter-heading .starter-close:hover { background: var(--panel-2); }
.starter-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.starter-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@container (max-width: 980px) { .starter-row { grid-template-columns: minmax(0, 1fr); gap: 14px; } }
.starter-pair {
  display: grid; gap: 4px; text-align: left; padding: 8px; border-radius: 10px; cursor: pointer; font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
}
.starter-pair:hover { border-color: var(--accent); }
.starter-name { font-weight: 700; font-size: .88rem; }

/* Spoiled cards (not released yet): red outline and an "Unreleased · date" tag; the tag itself is styled in site.css. */
.deck-tile-img.unreleased { outline: 3px solid var(--bad); outline-offset: -3px; }
.result .tile-new { position: absolute; left: 6px; bottom: 6px; font-size: .8rem; font-weight: 800; padding: 2px 7px;
  border-radius: 99px; background: rgba(0, 0, 0, .85); color: var(--bad); }
.deck-tile-img .tile-new { position: absolute; right: 6px; bottom: 6px; font-size: .8rem; font-weight: 800; padding: 2px 7px;
  border-radius: 99px; background: rgba(0, 0, 0, .85); color: var(--bad); }

/* "Paired with" chip: each leader/base tile's share of decks with the picked leader(s), and grouped plain bases. */
.result .share, .result .group-label { position: absolute; left: 6px; font-size: .8rem; font-weight: 700; padding: 2px 8px;
  border-radius: 99px; background: rgba(0, 0, 0, .85); pointer-events: none; }
.result .share { top: 6px; color: var(--sun-1); }
.result .share.none { color: var(--muted); font-weight: 600; }
.result .group-label { bottom: 6px; color: var(--text); }

/* Stacks (same idea as the deck page): sections side by side, each a column (or several) of overlapping cards
   showing their top strip; hovering a card drops the overlap on the next so the whole card shows. */
#deck-list.stacks { columns: auto; display: flex; flex-wrap: wrap; gap: 18px 22px; align-items: stretch; }
#deck-list.stacks .deck-section { margin: 0; min-width: calc(var(--card-w) + 10px); }
#deck-list.stacks .new-category, #deck-list.stacks .view-hint { flex-basis: 100%; }
#deck-list.stacks .section-body { display: flex; gap: 10px; align-items: flex-start; }
#deck-list.stacks .stack { width: var(--card-w); display: flex; flex-direction: column; padding-bottom: 4px; }
#deck-list.stacks .deck-tile-img { flex: none; box-shadow: 0 -2px 6px rgba(0, 0, 0, .55); }
#deck-list.stacks .deck-tile-img + .deck-tile-img { margin-top: -116%; }
#deck-list.stacks .deck-tile-img.peek + .deck-tile-img { margin-top: 0; }  /* .peek and the slide: static/js/stacks.js */
#deck-list.stacks .deck-tile-img .tile-qty { top: 4px; left: auto; right: 6px; }
#deck-list.stacks .deck-tile-img:hover .tile-qty { display: none; }  /* the card's buttons sit there on hover */

/* Several cards selected (Ctrl or Shift click): a blue edge, apart from the orange of hover and the stat filters. */
#deck-list .card-line.selected { background: rgba(60, 138, 216, .2); box-shadow: inset 0 0 0 1.5px var(--vigilance); }
#deck-list .deck-tile-img.selected { outline: 3px solid var(--vigilance); outline-offset: 1px; }
.select-bar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 150; display: flex; align-items: center; gap: 8px;
  max-width: calc(100vw - 24px); padding: 10px 14px; background: var(--panel-2); border: 1px solid var(--vigilance); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6); white-space: nowrap;
}
.select-bar[hidden] { display: none; }
.select-box { position: fixed; z-index: 140; pointer-events: none; background: rgba(60, 138, 216, .14); border: 1px solid var(--vigilance); border-radius: 3px; }
.deck-section.dragging { opacity: .4; }
/* An orange line where a dragged category will land, in the gap beside or above the section. */
.deck-section { position: relative; }
#deck-list { user-select: none; }  /* dragging here selects and moves cards, not text */
.deck-section[data-drop-line]::after { content: ""; position: absolute; z-index: 5; border-radius: 3px; background: var(--accent); pointer-events: none; }
.deck-section[data-drop-line=left]::after { top: 0; bottom: 0; left: -13px; width: 3px; }
.deck-section[data-drop-line=right]::after { top: 0; bottom: 0; right: -13px; width: 3px; }
.deck-section[data-drop-line=top]::after { left: 0; right: 0; top: -10px; height: 3px; }
.deck-section[data-drop-line=bottom]::after { left: 0; right: 0; bottom: -10px; height: 3px; }
.builder.is-dragging #deck-list .deck-item.selected { opacity: .4; }
.select-bar b { margin-right: 6px; }
.select-bar .danger { color: var(--bad); }

/* Deck tags in the details block: chips like the filters, up to 3 on. */
.deck-tags { gap: 8px; align-items: center; flex: none; flex-wrap: nowrap; }
.edit-meta { gap: 8px; }
.edit-meta #visibility summary { padding: 3px 10px; font-size: .82rem; }
.hero-sub-main .count-field { margin-top: 4px; }
/* The count sits inside the end of the box: shown on hover and while typing, and whenever the box is full. */
.count-field { position: relative; }
/* Name and description are one-line text boxes that wrap and grow (builder.js growFields), so a long name shows in full
   like on the deck page instead of being cut off. Room for the character count only while it shows. */
.count-field .grow-field { display: block; resize: none; overflow: hidden; min-height: 0; }
.count-field:is(:hover, :focus-within, :has(.char-count.full)) :is(input, textarea) { padding-right: 64px; }
/* In a box that wraps, the count sits by the first line rather than the middle. */
.count-field:has(.grow-field) .char-count { top: 12px; transform: none; }
.char-count {
  position: absolute; top: 50%; right: 10px; transform: translateY(-50%); pointer-events: none;
  font-size: .8rem; font-weight: 600; color: var(--muted); opacity: 0; transition: opacity .12s;
}
.count-field:hover .char-count, .count-field:focus-within .char-count, .char-count.full { opacity: 1; }
.char-count.full { color: var(--warn); }
.deck-tags .chips { flex-wrap: wrap; }
.deck-tags #deck-tags-on:empty { display: none; }
.deck-tags summary.chip { cursor: pointer; }
.tag-menu { min-width: 320px; padding: 10px; }
.tag-menu .chip { display: inline-block; width: auto; padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; }
.tag-menu .chip.on { border-color: var(--accent); }
.tag-menu-section { display: grid; gap: 4px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); justify-items: start; }
#retired-on[hidden] { display: none; }
.deck-tags .chip { font-size: .8rem; padding: 3px 10px; }

/* Stats panel: Tokens Needed, one button per token; the picked one highlights its cards in the deck (builder.js). */
.token-line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; width: 100%; margin: 4px 0;
  padding: 3px 8px; background: none; border: 1px solid transparent; border-left: 3px solid var(--muted); border-radius: 4px;
  color: inherit; font: inherit; font-size: .88rem; text-align: left; cursor: pointer; }
.token-line:hover { background: var(--panel-2); }
.token-line.unit { border-left-color: var(--sun-1); }
.token-line.upgrade { border-left-color: var(--vigilance); }
.token-line[aria-pressed="true"] { background: var(--panel-2); border-color: var(--sun-1); }
/* A token picked: its cards keep full colour with a highlight; the rest grey out but stay usable (as on the deck page). */
.token-filtered :is(.deck-item[data-id], [data-slot-card]):not(.token-match) { opacity: .35; filter: grayscale(1); }
[data-slot-card] { transition: opacity .15s, filter .15s; }
.token-filtered :is(.deck-item[data-id], [data-slot-card]):not(.token-match):hover { opacity: .7; }
.token-filtered .card-line.token-match { background: color-mix(in srgb, var(--sun-1) 14%, transparent); box-shadow: inset 3px 0 0 var(--sun-1); border-radius: 4px; }
.token-filtered :is(.deck-tile-img, [data-slot-card]).token-match { outline: 3px solid var(--sun-1); outline-offset: 1px; }
.block:has(> .starter-pairs[hidden]) { display: none; }

/* Highlighted stats: while the chooser is open, its toggle is the orange "Done choosing" that closes it. */
.stat-chip.add-stat.choosing { background: linear-gradient(135deg, var(--sun-1), var(--sun-2)) border-box; border: 1px solid transparent;
  color: #1a0f05; font-weight: 700; }
.stat-chip.add-stat.choosing:hover { color: #1a0f05; box-shadow: inset 0 0 0 1.5px #ffe2b0; }

/* Card search: "Adds to" picks where a click or tap on a card puts it. Orange edge when it isn't the main deck. */
.add-target { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.add-target[hidden] { display: none; }
.add-target select { flex: 1; width: auto; max-width: 320px; padding: 6px 8px; font-size: .92rem; color: var(--text); }
.add-target select:not(:has(option[value="auto"]:checked)) { border-color: var(--accent); }

/* ---------- touch screens ----------
   No hover, so no hover-only buttons, lines or lifts on cards: a tap acts on the card and a long press opens its menu
   (builder.js openCardSheet). The browser's own long-press menu (save image, select text) is turned off on cards.
   .touch-ui is set on <html> by base.html: on screens without hover, and from the first touch on any screen. */
.touch-ui .result .result-actions, .touch-ui .result:hover .result-actions, .touch-ui .result .result-info, .touch-ui .result:hover .result-info, .touch-ui .result-row .result-info, .touch-ui .result-row .add-to { display: none; }
.touch-ui .result:hover .pen { display: inline; }
.touch-ui .line-actions, .touch-ui .card-line:hover .line-actions, .touch-ui .deck-tile-img:hover .line-actions { display: none; }
.touch-ui .card-line:hover .pips { visibility: visible; }
.touch-ui #deck-list.stacks .deck-tile-img:hover .tile-qty { display: inline; }
.touch-ui .result:hover, .touch-ui #deck-list:not(.stacks) .deck-tile-img:hover, .touch-ui .sug-tile:hover img { transform: none; box-shadow: none; }
.touch-ui .result:not(.in-deck):hover::before, .touch-ui .deck-tile-img:hover::before { box-shadow: inset 0 0 0 2px transparent; }
.touch-ui .sug-tile:hover img { outline: 0; }
.touch-ui .result-row:not(.in-deck):not(.in-maybe):hover { background: transparent; }
.touch-ui .icon-btn { opacity: 1; }
.touch-tip { display: none; }
.touch-ui .touch-tip:not([hidden]) { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: rgba(255, 154, 61, .1); border: 1px solid rgba(255, 154, 61, .35); font-size: .88rem; line-height: 1.35; }
.touch-tip b { color: var(--sun-1); }
.touch-tip .btn { flex: none; margin-left: auto; }
.touch-ui .result, .touch-ui .deck-item, .touch-ui .result img, .touch-ui .deck-item img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
/* Holding a card sinks it a little, so the press reads as one before the menu opens. */
.touch-ui .result, .touch-ui .deck-item { transition: transform .35s ease .08s, opacity .15s, filter .15s, outline-color .15s; }
.touch-ui .result.pressing, .touch-ui .deck-item.pressing { transform: scale(.96); }

/* The long-press card menu: a sheet from the bottom of the screen, over a shade. */
.sheet-shade { position: fixed; inset: 0; z-index: 199; background: rgba(0, 0, 0, .55); animation: shade-in .15s ease-out; }
@keyframes shade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
.move-menu.card-sheet { left: 8px; right: 8px; bottom: 8px; max-width: 480px; margin-inline: auto; max-height: min(82vh, 680px);
  padding: 8px; border-radius: 16px; animation: sheet-in .18s ease-out; overscroll-behavior: contain; }
.card-sheet button { padding: 11px 12px; font-size: 1rem; border-radius: 9px; }
.card-sheet .menu-title { padding: 10px 12px 4px; }
.card-sheet hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 6px 8px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.sheet-head img { width: 46px; aspect-ratio: 5 / 7; object-fit: cover; border-radius: 4px; flex: none; }
.sheet-head b { display: block; font-size: 1.02rem; }
.sheet-head span { font-size: .85rem; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .sheet-shade, .move-menu.card-sheet { animation: none; } }

/* ---------- phones (390px wide and up) ----------
   The deck's name and details, then the leaders and base stacked big, then the deck's buttons, its numbers and Save. */
@media (max-width: 700px) {
  .deck-main { padding: 14px 16px 60px; }
  .edit-hero, .builder.searching .edit-hero { gap: 14px; }
  .edit-info .deck-top, .builder.searching .edit-info .deck-top { display: contents; }
  .deck-top > .count-field, .deck-top > .hero-sub { order: 1; }
  /* The description gets the full width; tags drop to their own row under it. */
  .edit-hero .hero-sub { flex-wrap: wrap; }
  .edit-hero .hero-sub > .deck-tags { flex-basis: 100%; }
  .edit-hero .hero-sub { margin-top: -6px; }
  .edit-hero .command-zone, .builder.searching .edit-hero .command-zone { order: 2; grid-template-columns: minmax(0, 1fr); gap: 10px; max-width: none; }
  /* Leader / Unit toggle on top; on Unit the leaders show their portrait unit side, large enough to read. */
  .slot-side-toggle { position: static; transform: none; justify-self: center; }
  .slot-side-toggle[hidden] { display: none; }
  .command-zone.show-unit .slot[data-slot^="leader"]:has(img) { aspect-ratio: 5 / 7; width: 82%; }
  .edit-hero .slot .change-slot { display: block; }
  /* Empty slots don't need a card's height. */
  .slot:has(> .add-slot) { aspect-ratio: auto; height: 64px; }
  .edit-actions { order: 3; padding-block: 0; flex-wrap: nowrap; }
  .edit-actions > .btn, .edit-actions > .menu { flex: 1 1 0; min-width: 0; }
  .edit-actions > .btn, .edit-actions > .menu > summary { width: 100%; justify-content: center; }
  .edit-info > .hero-stats, .builder.searching .edit-info > .hero-stats { order: 4; }
  /* Cost Curve, Deck Makeup and Highlights live only in the Stats panel on phones (it has a Highlights block). */
  #hero-stats, #hero-highlights { display: none; }
  .edit-hero .glance { gap: 10px 18px; }
  /* Undo and Redo as icons, Save filling the rest of the row, the note under them. */
  .edit-save { flex-wrap: wrap; gap: 8px; }
  .undo-redo .btn { font-size: 0; gap: 0; padding: 9px 12px; }
  .undo-redo svg { width: 18px; height: 18px; }
  #save-btn { flex: 1; justify-content: center; }
  .save-status { text-align: left; }

  /* The deck block: tabs share the width, the view controls sit in a tidy grid. */
  .block { padding: 12px 14px; border-radius: 12px; }
  .deck-block .tabs { gap: 0; }
  .deck-block .tabs .tab { flex: 1 1 auto; padding: 8px 4px; font-size: .9rem; white-space: nowrap; }
  .view-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .view-bar .view-toggle { grid-column: 1 / -1; display: flex; }
  .view-bar .view-toggle a { flex: 1; text-align: center; padding-block: 8px; }
  .view-bar label.row { display: grid; gap: 4px; font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .deck-block .view-bar select { width: 100%; padding: 8px; font-size: .95rem; letter-spacing: 0; text-transform: none; color: var(--text); }
  .view-bar .spacer { display: none; }
  .view-bar #search-cards-top { grid-column: 1 / -1; justify-content: center; padding-block: 10px; font-size: 1rem; }
  .view-bar #new-category-top, .view-bar #stats-toggle { justify-content: center; padding-block: 8px; }

  /* Card search: the head and the filters' controls get a touch more room. */
  .search-bar input { font-size: 16px; }  /* 16px keeps iOS from zooming in on the box */
  .results-bar { flex-wrap: wrap; }
  .results-bar .result-meta { flex-basis: 100%; }
  .results-bar .view-toggle { flex: 1; display: flex; }
  .results-bar .view-toggle a { flex: 1; text-align: center; }
  .results-bar select { flex: 1; }

  /* Stacks: one wider stack per row, so each card's name strip is big enough to read. */
  #deck-list.stacks { --card-w: min(240px, 68vw); }
  #deck-list.stacks .deck-section { width: 100%; }
  #deck-list.stacks .section-body { flex-direction: column; align-items: center; gap: 14px; }
}

/* Card details on phones: the panel scrolls as one column, so its × becomes a round button pinned to the bottom of the
   screen, within reach wherever you've scrolled to. The dialog only fades in there: a moving dialog would carry the
   pinned button with it while it animates. */
@media (max-width: 800px) {
  .card-dialog[open] { animation-name: shade-in; }
  .card-dialog .info-close {
    position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); translate: -50% 0; z-index: 5;
    width: 52px; height: 52px; font-size: 1.7rem; background: var(--panel-2); border-color: #48505f;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .6);
  }
  .card-dialog .info-body { padding-bottom: 84px; }  /* the last of the panel scrolls clear of the button */
}

/* Card details: a link to the card's own page (the leader's page for leaders), under its name. */
.info-page-link { display: inline-block; margin-top: 6px; font-size: .88rem; font-weight: 600; }

/* Section headers: sections outside the deck stats (Maybeboard, Sideboard, categories switched off) have a dashed
   edge and a quieter title, so counted and uncounted read apart at a glance. Custom categories switch it from their
   ⋯ menu (a long press on the header on touch screens, a right-click on desktop). */
.deck-section.alt > h3 { background: transparent; box-shadow: inset 0 0 0 1px var(--line); outline: 1px dashed #48505f; outline-offset: -1px; }
.deck-section.alt > h3 .title { color: var(--muted); }
.deck-section.alt.active > h3 { outline-color: var(--accent); }
.touch-ui .cat-menu-btn { display: none; }
.touch-ui .deck-section.custom > h3 { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.touch-ui .deck-section.custom > h3.pressing { transform: scale(.98); transition: transform .35s ease .08s; }
/* Menu items with a line of explanation, and the In deck stats switch at the top of a category's menu. */
.move-menu button small { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; margin-top: 1px; }
.move-menu button.stats-switch { position: relative; padding-right: 58px; font-weight: 700; }
.move-menu button.stats-switch::before, .move-menu button.stats-switch::after {
  content: ""; position: absolute; top: 50%; border-radius: 99px; transition: transform .22s cubic-bezier(.3, .7, .3, 1), background-color .22s, border-color .22s;
}
/* The switch: a track, and a knob that slides across it as the colours cross-fade. */
.move-menu button.stats-switch::before { right: 10px; width: 36px; height: 22px; translate: 0 -50%; background: var(--panel); border: 1px solid var(--line); box-sizing: border-box; }
.move-menu button.stats-switch::after { right: 28px; width: 14px; height: 14px; translate: 0 -50%; background: var(--muted); }
.move-menu button.stats-switch.on::before { background: var(--ok); border-color: var(--ok); }
.move-menu button.stats-switch.on::after { transform: translateX(14px); background: #fff; }
@media (prefers-reduced-motion: reduce) { .move-menu button.stats-switch::before, .move-menu button.stats-switch::after { transition: none; } }
.move-menu button.stats-switch.on { color: var(--text); }
/* Closing: the sheet sinks and fades, the shade fades (builder.js closeMenu waits for it). */
@keyframes sheet-out { to { transform: translateY(24px); opacity: 0; } }
@keyframes shade-out { to { opacity: 0; } }
.move-menu.card-sheet.closing { animation: sheet-out .16s ease-in forwards; pointer-events: none; }
.sheet-shade.closing { animation: shade-out .16s ease-in forwards; pointer-events: none; }
