/* The Forge — web Deck Builder. Mobile-first, dark-fantasy gold-on-black to
   match the Black Cat Card Forge desktop theme. No external fonts/assets: system
   font stack, everything inline-friendly. Designed down to ~360px width. */

:root {
  --bg: #0e0d0b;
  --panel: #17150f;
  --panel-line: #2a2418;
  --gold: #d4af37;
  --gold-soft: #e8cf7a;
  --ink: #ece7db;
  --muted: #9a917d;
  --error: #e5817a;
  --ok: #8fce8f;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, #1a1710 0%, var(--bg) 60%) fixed;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* Masthead */
/* Masthead + footer are hidden on every size: the builder IS the app, like the
   desktop dialog. The only intro line is the import panel's `.slogan`
   ("Let's get your deck ready for the forge"). The h1/subtitle/tagline styles
   below still apply if the masthead is ever shown again. */
.masthead {
  display: none;
  text-align: center;
  padding: 8px 0 20px;
}
.masthead h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 9vw, 3rem);
  letter-spacing: 0.04em;
  color: var(--gold);
  margin: 0;
  text-shadow: 0 2px 12px rgba(212, 175, 55, 0.25);
}
.subtitle {
  color: var(--gold-soft);
  font-style: italic;
  margin: 2px 0 10px;
  font-size: 0.95rem;
}
.tagline {
  color: var(--muted);
  margin: 0;
  font-size: 0.95rem;
}

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin: 16px 0;
}
.step {
  font-family: Georgia, serif;
  color: var(--gold);
  font-size: 1.15rem;
  margin: 0 0 14px;
  font-weight: 600;
}

/* Fields */
.field {
  display: block;
  margin: 0 0 14px;
}
.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}
input[type="text"],
input[type="url"],
textarea {
  width: 100%;
  background: #100e09;
  color: var(--ink);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  resize: vertical;
}
input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.18);
}
textarea {
  min-height: 120px;
  line-height: 1.6;
}

/* Buttons — large tap targets */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid var(--panel-line);
  background: #201c13;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn.primary {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #17140a;
  border-color: var(--gold);
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Import panel: slogan + green/red counts (mirrors the desktop deck builder's
   left panel). */
.slogan {
  color: var(--gold-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: 0.9rem;
  margin: 0 0 12px;
}
/* Invite-link banner: greets a named friend, or explains a link that's died.
   Sits under the slogan on step 1; hidden entirely without ?i= (web-0.13.1). */
.invite-banner {
  border: 1px solid var(--panel-line);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 12px;
  font-size: 0.92rem;
  color: var(--ink);
  background: rgba(212, 175, 55, 0.06);
}
/* A dead link is information, not an error the friend caused — warn in the
   muted error tone rather than shouting, since they can still send a deck. */
.invite-banner.dead {
  border-left-color: var(--error);
  background: rgba(229, 129, 122, 0.07);
  color: var(--muted);
}
/* Restored draft (web-0.24.0). Same shape as the invite banner but in the muted
   tone — it's a courtesy, not a greeting, and it shouldn't compete with the
   "Hi <name>" above it. Wraps on narrow screens so the button never squeezes
   the text to one word per line. */
.draft-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  border: 1px solid var(--panel-line);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 12px;
  font-size: 0.92rem;
  color: var(--ink);
}
.draft-banner span { flex: 1 1 12rem; }
.draft-discard {
  flex: none;
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  /* Comfortably tappable on a phone, which is where stepping away happens. */
  min-height: 40px;
}
.draft-discard:hover { color: var(--ink); border-color: var(--muted); }

/* Spent invite link: shown INSTEAD of the builder, so nobody builds a deck they
   can't send. Calm rather than alarming — they've done nothing wrong. */
.dead-link {
  border-left: 3px solid var(--error);
}
.dead-link-msg {
  color: var(--ink);
  margin: 0 0 8px;
}
.dead-link-hint {
  color: var(--muted);
  margin: 0;
  font-size: 0.92rem;
}
/* A one-off link fixes the name it was issued to (Gavin, 2026-07-21), so the
   field reads as locked rather than looking like an editable box that ignores you. */
.invite-locked {
  opacity: 0.75;
  cursor: not-allowed;
}
.counts-row {
  display: flex;
  gap: 12px;
  margin: 10px 0 0;
}
.count-green {
  color: var(--ok);
  font-size: 0.85rem;
  font-weight: 700;
}
.count-red {
  color: #d0654f;
  font-size: 0.85rem;
  font-weight: 700;
}
.viewer-empty {
  display: none; /* desktop layout only, and only when the grid is empty */
  color: #6a6256;
  text-align: center;
  margin: 40px 0;
}

/* Status lines */
.status {
  margin: 12px 0 0;
  min-height: 1.2em;
  font-size: 0.92rem;
  color: var(--muted);
}
.status.error {
  color: var(--error);
}
.status.ok {
  color: var(--ok);
}

/* Review */
.summary {
  color: var(--gold-soft);
  font-weight: 600;
  margin: 0 0 12px;
}
.unresolved {
  background: rgba(229, 129, 122, 0.08);
  border: 1px solid rgba(229, 129, 122, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.unresolved-head {
  margin: 0 0 6px;
  color: var(--error);
  font-size: 0.9rem;
}
.unresolved ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 0.9rem;
}

/* Deck-section tabs (Commander / Main / Sideboard / Tokens) above the review grid.
   Hidden when the deck is a single section. Scrolls horizontally if it can't fit. */
.deck-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.deck-tabs::-webkit-scrollbar {
  display: none;
}
.deck-tab {
  flex: 1 0 auto;
  min-height: 40px;
  padding: 0 14px;
  white-space: nowrap;
  border: 1px solid var(--panel-line);
  background: #201c13;
  color: var(--muted);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.deck-tab.is-active {
  color: #17140a;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: var(--gold);
}

/* Filter bar — search the active tab + sort the grid (desktop #deckFilterBar). */
.deck-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
}
.deck-search {
  flex: 1;
  min-width: 0;
  background: #100e09;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 10px;
}
.deck-search:focus {
  outline: none;
  border-color: var(--gold);
}
.deck-sort-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.deck-sort-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.deck-sort {
  background: #100e09;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  color: var(--gold-soft);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 10px;
  cursor: pointer;
}
.deck-sort:hover {
  border-color: #3a3a35;
}
.deck-sort:focus {
  outline: none;
  border-color: var(--gold);
}

/* Show the empty note whenever the grid is empty (e.g. a search with no match). */
.card-grid:empty + .viewer-empty {
  display: block;
}

/* Card grid — auto-fill, phone-friendly */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin: 0 0 20px;
}
.card-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card-thumb {
  position: relative;
  aspect-ratio: 745 / 1040;
  border-radius: 8px;
  overflow: hidden;
  background: #100e09;
  border: 1px solid var(--panel-line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  /* It's a <button>: strip the native chrome, keep it tappable. */
  width: 100%;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.card-thumb:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-tile.missing .card-thumb {
  border-color: rgba(229, 129, 122, 0.5);
  color: var(--error);
}
/* Keyboard/click selection — the desktop's gold tile border. */
.card-tile.is-selected .card-thumb {
  outline: 2px solid #d98a1f;
  outline-offset: 2px;
}
/* Positioning context for the on-tile split switch overlay. */
.card-thumb-wrap {
  position: relative;
}
/* Not-found placeholder — "not found" over a smaller "tap to fix" hint. */
.card-nf {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
}
.card-nf-hint {
  font-size: 0.62rem;
  font-weight: 400;
  opacity: 0.8;
}
/* "Different art per copy" switch — bottom-left of the art (desktop's
   ToggleSwitch), clear of the qty badge in the bottom-right. */
.split-toggle {
  position: absolute;
  bottom: 5px;
  left: 5px;
  z-index: 3;
  width: 34px;
  height: 19px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(0, 0, 0, 0.72);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.split-toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--gold-soft);
  transition: transform 0.12s ease, background 0.12s ease;
}
.split-toggle.is-on {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: var(--gold);
}
.split-toggle.is-on .split-toggle-knob {
  transform: translateX(15px);
  background: #17140a;
}
.split-toggle:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* DFC flip badge — round control on the left edge, just above centre (desktop's
   FlipButton spot). Translucent dark disc + gold ring/glyph when showing the
   front; solid gold with a dark glyph when flipped to the back. */
.dfc-badge {
  position: absolute;
  left: 6px;
  top: 40%;
  transform: translateY(-50%);
  z-index: 3;
  width: 26px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(18, 16, 12, 0.84);
  border: 1px solid var(--gold);
  color: var(--gold);
  cursor: pointer;
}
.dfc-badge:hover {
  color: #f0a637;
  border-color: #f0a637;
}
.dfc-badge.is-flipped {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: var(--gold);
  color: #12100c;
}
.dfc-badge svg {
  display: block;
}
.dfc-badge:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.card-qty {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.78);
  color: var(--gold-soft);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.78rem;
  font-weight: 700;
}
/* One line, ellipsised — keeps every tile the same height so the grid stays
   even (full name in the tooltip / picker title). */
.card-name {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.3;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* − / + / ⋯ under each tile: remove a copy, add a copy, open the card menu. */
.card-actions {
  display: flex;
  gap: 4px;
}
.card-act {
  flex: 1;
  min-height: 30px;
  padding: 0;
  border-radius: 7px;
  border: 1px solid var(--panel-line);
  background: #201c13;
  color: var(--gold-soft);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.card-act:disabled {
  opacity: 0.35;
  cursor: default;
}
.card-act:active:not(:disabled) {
  transform: translateY(1px);
}

/* Success */
.success {
  border-color: rgba(143, 206, 143, 0.4);
}
.success .step {
  color: var(--ok);
}

.foot {
  display: none;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 24px;
}

/* A little more room on larger screens */
@media (min-width: 560px) and (max-width: 899px) {
  .wrap {
    padding: 32px 24px 64px;
  }
  .panel {
    padding: 22px 22px;
  }
}

/* ── Desktop layout (≥900px): mirror the desktop app's Deck Builder window ──
   Two flush panes filling the viewport — a fixed 300px import panel on the
   left (slogan, Text/URL tabs, Resolve, counts, status) and the viewer on the
   right (section-tab header bar, scrolling card grid, bottom action bar).
   Colours come straight from styles/forge.qss (#deckImport/#deckViewer/…). */
@media (min-width: 900px) {
  body {
    background: #171817;
    overflow: hidden;
  }
  .wrap {
    max-width: none;
    height: 100vh;
    padding: 0;
    display: flex;
    flex-direction: column;
  }
  .builder {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 300px 1fr;
  }

  /* Left: the import panel. */
  .pane-import {
    margin: 0;
    border: 0;
    border-right: 1px solid #2a2620;
    border-radius: 0;
    background: #141513;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 0;
    overflow-y: auto;
  }
  .pane-import .step {
    display: none; /* no step numbers — the desktop builder has none */
  }
  #pageText {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  #pageText .field {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  #pageText textarea {
    flex: 1;
    min-height: 160px;
    font-family: Menlo, Consolas, monospace;
    font-size: 0.8rem;
  }

  /* Right: the viewer pane. Shown even before a deck resolves (the desktop
     viewer always exists, with "Resolved cards appear here."); the author
     display below would beat [hidden] anyway, so it's deliberate. */
  .pane-viewer {
    margin: 0;
    border: 0;
    border-radius: 0;
    background: #171817;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .viewer-head {
    background: #161715;
    border-bottom: 1px solid #242421;
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 52px;
  }
  .viewer-head .step {
    display: none;
  }
  .viewer-head .summary {
    margin: 0 0 0 auto;
    color: #8a8276;
    font-size: 0.8rem;
    font-weight: 400;
  }
  /* Section tabs become the desktop's underline style in the header bar. */
  .viewer-head .deck-tabs {
    margin: 0;
    overflow: visible;
  }
  .viewer-head .deck-tab {
    flex: none;
    min-height: 0;
    padding: 4px 4px 6px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    color: #8a8276;
    letter-spacing: 0.5px;
  }
  .viewer-head .deck-tab:hover {
    color: #cbbf9f;
  }
  .viewer-head .deck-tab.is-active {
    background: transparent;
    color: #d98a1f;
    border-bottom-color: #d98a1f;
  }
  /* The filter bar becomes its own band under the header, like the desktop. */
  .deck-filter-bar {
    margin: 0;
    background: #131412;
    border-bottom: 1px solid #242421;
    padding: 8px 18px;
  }
  .viewer-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
  }
  .card-grid {
    margin: 0;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 14px 12px;
  }
  .card-grid:empty + .viewer-empty {
    display: block;
  }

  /* Bottom action bar: name + note + Send, like the desktop's Build bar. */
  .action-bar {
    background: #161715;
    border-top: 1px solid #242421;
    padding: 12px 18px;
    display: grid;
    grid-template-columns: 1fr 1.4fr auto;
    gap: 12px;
    align-items: end;
  }
  .action-bar .field {
    margin: 0;
  }
  .action-bar textarea {
    min-height: 0;
    height: 48px;
    resize: none;
  }
  .action-bar .btn {
    width: auto;
    padding: 12px 26px;
  }
  .action-bar .status {
    grid-column: 1 / -1;
    margin: 0;
    min-height: 0;
  }
  .action-bar .status:empty {
    display: none;
  }

  /* Sent ✓ becomes a centered overlay above the builder. */
  .success {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 60;
    min-width: 340px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  }
}

/* Art-picker bottom sheet */
body.sheet-open {
  overflow: hidden; /* stop the page scrolling behind the sheet */
}
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center; /* centre the popup on screen */
  justify-content: center;
  padding: 16px;
}
/* The author `display: flex` above beats the UA `[hidden] { display: none }`
   rule, so `hidden` alone wouldn't hide the sheet — restore it explicitly. */
.sheet-overlay[hidden] {
  display: none;
}
.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.sheet-title {
  font-family: Georgia, serif;
  color: var(--gold);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The confirm/notice sheet is the one whose title is always an authored string
   ("Heads up", "A message from …") rather than a card name, so it can wrap
   instead of being ellipsised. Without this "A message from Black Cat Card
   Forge" truncates to "A message from Black Cat C…". */
#confirmTitle {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.sheet-close {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--panel-line);
  background: #201c13;
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}
.sheet-search {
  display: flex;
  gap: 8px;
}
.sheet-search input {
  flex: 1;
  min-width: 0;
}
.sheet-search-btn {
  width: auto;
  flex: none;
  padding: 12px 18px;
}
/* Source tabs (Scryfall / MPC) */
.picker-tabs {
  display: flex;
  gap: 6px;
  margin: 4px 0 10px;
}
.picker-tab {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--panel-line);
  background: #201c13;
  color: var(--muted);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.picker-tab.is-active {
  color: #17140a;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  border-color: var(--gold);
}
/* Options row: Tokens toggle + Min-DPI filter */
.picker-opts {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
/* "Fetch tokens" opt-in under the decklist box (desktop's Fetch-tokens check). */
.opt-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.opt-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
}

.picker-tokens {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.picker-tokens input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
}
.picker-dpi {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}
/* The author display above beats the UA [hidden] rule, so hide it explicitly
   when toggled off on the Scryfall tab (same fix as .sheet-overlay). */
.picker-dpi[hidden] {
  display: none;
}
.picker-dpi select {
  background: #100e09;
  color: var(--ink);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 0.9rem;
}
.picker-note {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 6px 0 2px;
  min-height: 1em;
}
.picker-grid {
  display: grid;
  /* Fixed cell size (like the desktop picker's CELL_SIZE) so the row height is
     deterministic and never depends on when/whether an image loads — that image
     dependence is what let the cards overlap. auto-fill packs as many columns
     as fit; justify-content centres the leftover gutter. */
  grid-template-columns: repeat(auto-fill, 104px);
  grid-auto-rows: 145px; /* 104 × 1040/745 ≈ 145, the card aspect */
  justify-content: center;
  align-content: start;
  gap: 10px;
  margin-top: 8px;
  flex: 1 1 auto; /* take the remaining sheet height … */
  min-height: 0; /* … and allow shrinking so overflow-y actually scrolls */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.picker-cell {
  position: relative;
  height: 100%; /* fill the fixed 145px row track */
  border-radius: 8px;
  overflow: hidden;
  background: #100e09;
  border: 1px solid var(--panel-line);
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.picker-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Inset, not offset: an outline drawn outside the cell gets clipped by the
   grid's own overflow-y scroller, so the gold box lost its top and bottom edges
   (Gavin, 2026-07-21). Drawing it inside can't be clipped by anything. */
.picker-cell:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}
.picker-cell:active {
  transform: translateY(1px);
}
.picker-cell-dpi {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 1px 5px;
  background: rgba(0, 0, 0, 0.72);
  color: var(--gold-soft);
  border-radius: 5px;
  font-size: 0.62rem;
  font-weight: 700;
}

/* Help button (viewer header) + the help sheet (desktop `#deckHelpBtn` look).
   Header button is desktop-only; mobile uses the floating `.help-fab` below. */
.help-btn {
  display: none;
  background: transparent;
  border: 1px solid #3a3630;
  border-radius: 6px;
  color: #a89c86;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 12px;
  cursor: pointer;
  margin-left: auto;
}

/* Floating Help — phones only. Fixed to the bottom-right so it's reachable from
   any screen (including before a deck is resolved). Hidden on desktop, which
   keeps the header button. iOS safe-area padding keeps it off the home bar. */
.help-fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: inline-flex;
  align-items: center;
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #17140a;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}
.help-fab:active {
  transform: translateY(1px);
}
/* Desktop keeps Help in the review header and drops the floating FAB. Placed
   after the base rules above so it wins the cascade at >=900px. */
@media (min-width: 900px) {
  .viewer-head .help-btn {
    display: inline-flex;
  }
  .help-fab {
    display: none;
  }
}
.help-btn:hover {
  color: #d98a1f;
  border-color: #d98a1f;
}
.viewer-head .help-btn {
  flex: none;
}
.viewer-head .summary {
  margin-left: 0;
}
.sheet--help {
  max-width: 560px;
}
.help-body {
  overflow-y: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.help-section {
  color: #cbbf9f;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 16px 0 8px;
}
.help-section:first-child {
  margin-top: 0;
}
.help-list {
  margin: 0;
}
.help-list dt {
  color: #f2b24c;
  font-size: 0.88rem;
  font-weight: 700;
  margin: 8px 0 2px;
}
.help-list dd {
  color: #a89c86;
  font-size: 0.88rem;
  margin: 0;
}

/* Card-actions sheet: a small centered menu (Move to / per-copy art / Delete),
   sharing the picker's overlay styling. */
.sheet--menu {
  max-width: 360px;
}
.menu-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
/* Where the chosen art came from (web-0.21.0). Information, not an action —
   styled deliberately unlike .menu-btn so it isn't tapped at. */
.menu-info {
  margin: 0 0 2px;
  padding: 2px 4px 8px;
  border-bottom: 1px solid var(--panel-line);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}
.menu-btn {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-line);
  background: #201c13;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.menu-btn:active {
  transform: translateY(1px);
}
/* Armed destructive state ("Really delete …?") + the delete row itself. */
.menu-btn-delete {
  color: var(--error);
}
.menu-btn.danger {
  border-color: rgba(229, 129, 122, 0.6);
  background: rgba(229, 129, 122, 0.12);
  color: var(--error);
}

/* Merge confirm sheet — warning text over a Cancel / Merge row. */
.confirm-message {
  margin: 0 0 4px;
  color: var(--ink);
  line-height: 1.45;
  /* The text is set with textContent, so line breaks in a message would
     otherwise collapse to spaces — the send warning uses one to separate what
     happens from what it costs. */
  white-space: pre-line;
}
.confirm-actions {
  display: flex;
  gap: 8px;
}
.confirm-actions .menu-btn {
  flex: 1;
  text-align: center;
}

/* Tap targets: kill the iOS double-tap-zoom delay/absorption so a quick tap
   always registers as a click (fixes "tapping does nothing" on iPhone — e.g.
   opening the ⋯ menu then tapping Move to / a section tab in quick succession).
   Every interactive control here is a <button>, so one rule covers them all. */
button {
  touch-action: manipulation;
}

/* Hover-to-enlarge preview: a floating card-sized image, positioned in JS.
   pointer-events:none so it never eats the mouse; above the sheet (z 50). */
.hover-preview {
  position: fixed;
  z-index: 100;
  width: 230px;
  pointer-events: none;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--gold);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
  background: #100e09;
}
.hover-preview[hidden] {
  display: none; /* author display would otherwise beat the UA [hidden] rule */
}
.hover-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 745 / 1040;
  object-fit: cover;
}
