/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Force hidden attribute to always win over display:flex etc. */
[hidden] { display: none !important; }

/* ≥16px prevents iOS Safari from zooming the page on input focus */
input, textarea, select { font-size: max(16px, 1rem); }

/* ── Design tokens ──────────────────────────────────────────── */
:root {
  --bg:       #12101c;
  --surface:  #1b1828;
  --elevated: #252236;
  --border:   #3b3858;
  --accent:   #9b5de5;
  --accent2:  #c084fc;
  --text:     #ede9f9;
  --dim:      #9896b2;
  --muted:    #5a5878;
  --danger:   #f87171;
  --warn:     #fbbf24;
  --radius:   8px;

  /* Card dimensions — Scryfall 'normal' images are 488×680px.
     Display at 130px wide → height = 130 × (680/488) ≈ 181px.
     Stacked reveal = 48px: title bar (~20px) + art strip (~28px)
     so the quantity badge sits in the art strip, below the name. */
  --cw:  130px;
  --ch:  181px;
  --rev: 48px;
}

/* ── Base ───────────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  min-height: 100dvh;
  overflow-x: hidden;
}
a { color: var(--accent2); }
a:hover { text-decoration: underline; }

/* ── Top bar ────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}
.brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: .04em;
  background: linear-gradient(130deg, var(--accent) 0%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-tagline {
  font-size: .75rem;
  color: var(--muted);
}
@media (max-width: 480px) { .brand-tagline { display: none; } }

/* ── Mobile header: single-row, icon-only action buttons ────── */
@media (max-width: 480px) {
  .top-bar {
    flex-wrap: nowrap;
    gap: 4px;
    padding: 8px 10px;
  }
  /* Show icon buttons; hide text labels on small screens */
  .btn-ghost {
    padding: 0;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }
  .btn-ghost .btn-label { display: none; }
}

.deck-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .82rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.deck-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deck-count { color: var(--dim); white-space: nowrap; }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  padding: 5px 11px;
  border-radius: var(--radius);
  font-size: .78rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent2); }
.btn-ghost svg { flex-shrink: 0; }

/* ── Import panel ───────────────────────────────────────────── */
.import-panel {
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.import-panel.import-hidden { display: none; }

.import-inner {
  max-width: 580px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.import-label {
  font-size: .8rem;
  color: var(--dim);
  font-weight: 500;
}
.deck-input {
  width: 100%;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'SF Mono', ui-monospace, 'Cascadia Code', 'Consolas', monospace;
  font-size: 16px;   /* ≥16px prevents iOS Safari zoom */
  line-height: 1.55;
  padding: 8px 12px;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.deck-input:focus { border-color: var(--accent); }
.deck-input::placeholder { color: var(--muted); }

.import-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent2); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.import-hint { font-size: .72rem; color: var(--muted); }

/* ── Status bars ────────────────────────────────────────────── */
.status-bar {
  padding: 8px 20px;
  font-size: .82rem;
  border-bottom: 1px solid transparent;
}
.status-bar.error {
  background: rgba(248,113,113,.1);
  border-color: rgba(248,113,113,.3);
  color: var(--danger);
}
.status-bar.loading {
  background: rgba(155,93,229,.1);
  border-color: rgba(155,93,229,.3);
  color: var(--accent2);
  text-align: center;
}
.status-bar.warning {
  background: rgba(251,191,36,.1);
  border-color: rgba(251,191,36,.3);
  color: var(--warn);
}

/* ── Deck layout ────────────────────────────────────────────── */
.deck-layout {
  display: flex;
  flex: 1;
  align-items: flex-start;
  min-height: 420px;
}

/* ── Columns scroll area ────────────────────────────────────── */
.columns-scroll-area {
  flex: 1;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 20px 16px 48px;
  min-width: 0;
  /* thin scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.columns-scroll-area::-webkit-scrollbar { height: 5px; }
.columns-scroll-area::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 3px;
}

/* ── Mana column ────────────────────────────────────────────── */
.mana-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: calc(var(--cw) + 8px);
}
.col-header {
  font-size: .68rem;
  font-weight: 700;
  color: var(--dim);
  letter-spacing: .07em;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.col-count {
  font-size: .62rem;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── Card stack ─────────────────────────────────────────────── */
.card-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: var(--cw);
}

/* Non-last entries: clip to reveal height only */
.card-stack .card-entry:not(:last-child) {
  height: var(--rev);
  overflow: hidden;
}

.card-entry {
  position: relative;
  width: var(--cw);
  flex-shrink: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.card-img {
  width: var(--cw);
  height: var(--ch);
  object-fit: cover;
  object-position: top;
  border-radius: 7px;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
  background: var(--elevated);
}

/* Error state: placeholder */
.card-entry.img-error .card-img {
  object-fit: none;
  background: var(--elevated);
  border: 1px solid var(--border);
}
.card-entry.img-error .card-name-label { display: flex; }

.card-name-label {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  align-items: center;
  justify-content: center;
  padding: 6px;
  font-size: .62rem;
  color: var(--dim);
  text-align: center;
  word-break: break-word;
  line-height: 1.3;
  pointer-events: none;
}

/* Quantity badge — Arena-style: fully inside the art strip below
   the title bar, inset ~9% from the right so it never overflows.
   Font scales with card width so it stays readable at all sizes. */
.qty-badge {
  position: absolute;
  /* Art window starts ≈11.5% from card top, right edge ≈7.5% from card right.
     Percentages are of the containing block (card-entry): top% of height,
     right% of width — scales with every card size without pixels. */
  top: calc(11.5% + 4px);
  right: calc(7.5% + 4px);
  left: auto;
  transform: none;
  background: none;
  color: #fff;
  font-size: calc(var(--cw, 130px) * 0.095);
  font-weight: 800;
  padding: 0;
  border-radius: 0;
  border: none;
  pointer-events: none;
  line-height: 1;
  letter-spacing: .02em;
  z-index: 1;
  /* dark outline so text reads on light or dark art */
  text-shadow:
     1px  1px 0 rgba(0,0,0,.9),
    -1px -1px 0 rgba(0,0,0,.9),
     1px -1px 0 rgba(0,0,0,.9),
    -1px  1px 0 rgba(0,0,0,.9),
     0    2px 4px rgba(0,0,0,.7);
}

/* ── Preview overlay ────────────────────────────────────────── */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  -webkit-tap-highlight-color: transparent;
  cursor: zoom-out;
  overflow-y: auto;
  padding: 16px;
}
.preview-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: min(90vw, 400px);
  cursor: default;
}
.preview-img {
  width: 100%;
  max-height: 70dvh;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0,0,0,.7);
  pointer-events: none;
  -webkit-user-drag: none;
  display: block;
}

/* ── P3: Card detail panel (oracle text, type, mana cost) ────── */
.preview-details {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .78rem;
  line-height: 1.5;
}
.pd-mana  { color: var(--accent2); font-weight: 600; letter-spacing: .04em; }
.pd-type  { color: var(--dim); font-weight: 500;
            border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.pd-oracle { color: var(--text); white-space: pre-line; }
.pd-flavor {
  color: var(--muted); font-style: italic;
  border-top: 1px solid var(--border); padding-top: 6px; font-size: .72rem;
}
.pd-stat  { color: var(--dim); font-weight: 700; text-align: right; }

/* ── P3: Text list view ──────────────────────────────────────── */
.columns-scroll-area.layout-list {
  flex-direction: column;
  overflow-x: hidden;
  gap: 0;
  padding: 16px;
  align-items: stretch;
}
.list-column { margin-bottom: 20px; }
.list-col-header {
  font-size: .68rem;
  font-weight: 700;
  color: var(--dim);
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 4px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.list-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  -webkit-tap-highlight-color: transparent;
}
.list-card-row.clickable { cursor: pointer; }
.list-qty  { font-size: .72rem; font-weight: 700; color: var(--accent2);
             min-width: 18px; text-align: right; flex-shrink: 0; }
.list-name { font-size: .82rem; color: var(--text); }
.list-card-row.clickable:hover .list-name { color: var(--accent2); }

/* ── P3: .p3-feature hidden below P3 ────────────────────────── */
.p3-feature { display: none !important; }
html.phase-3 .p3-feature { display: revert !important; }

/* ── P4: .p4-feature hidden below P4 ────────────────────────── */
.p4-feature { display: none !important; }
html.phase-4 .p4-feature { display: revert !important; }

/* ── P4: Collection badge on card ────────────────────────────── */
/* Hidden unless collect mode is active — avoids covering card text */
.collect-badge {
  position: absolute;
  top: 20px;      /* art area, below title bar — not over oracle text */
  right: 4px;     /* right side, below mana cost zone */
  bottom: unset;
  left: unset;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.72);
  color: var(--muted);
  font-size: .64rem;
  font-weight: 800;
  display: none;        /* hidden until collect-mode active */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  padding: 0;
  line-height: 1;
  transition: background .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
/* Only show collection markers when tracking is in use */
html.collect-mode .collect-badge { display: flex; }
.collect-badge.owned {
  background: rgba(74,222,128,.88);
  color: #000;
  border-color: transparent;
}
.collect-badge:not(.owned):hover {
  background: rgba(155,93,229,.6);
  color: #fff;
  border-color: transparent;
}

/* ── P3: Print stylesheet ────────────────────────────────────── */
@media print {
  .top-bar, .import-panel, .status-bar, .stats-strip,
  .sideboard-aside, .site-footer, .preview-overlay,
  .settings-wrapper, .btn-ghost, .settings-panel { display: none !important; }
  body { background: #fff; color: #000; }
  .deck-layout { display: block; }
  .columns-scroll-area {
    display: flex !important;
    flex-wrap: wrap;
    overflow: visible !important;
    gap: 8px;
    padding: 8px;
  }
  .mana-column { break-inside: avoid; }
  .card-img { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Sideboard aside ────────────────────────────────────────── */
.sideboard-aside {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  align-self: stretch;
  transition: width .2s ease;
  overflow: hidden;
}
.sideboard-aside.collapsed  { width: 42px; }
.sideboard-aside:not(.collapsed) { width: 185px; }

.sideboard-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: .78rem;
  font-weight: 600;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  min-height: 44px;
}
.sb-label, #sideboardCountLabel {
  transition: opacity .15s;
  overflow: hidden;
}
.sideboard-aside.collapsed .sb-label,
.sideboard-aside.collapsed #sideboardCountLabel {
  opacity: 0;
  width: 0;
}
#sideboardCountLabel {
  color: var(--dim);
  font-weight: 400;
  font-size: .72rem;
}
.toggle-arrow {
  margin-left: auto;
  color: var(--dim);
  font-size: .72rem;
  transition: transform .2s;
  flex-shrink: 0;
}
.sideboard-aside:not(.collapsed) .toggle-arrow { transform: rotate(180deg); }

.sideboard-cards {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.sideboard-aside.collapsed .sideboard-cards { display: none; }

/* Sideboard card entry */
.sb-card-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.sb-card-img {
  width: 44px;
  height: 61px;   /* 44 × (680/488) ≈ 61 */
  border-radius: 3px;
  object-fit: cover;
  object-position: top;
  flex-shrink: 0;
  background: var(--elevated);
}
.sb-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.sb-card-name {
  font-size: .68rem;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sb-qty {
  font-size: .65rem;
  color: var(--accent2);
  font-weight: 700;
  margin-top: 2px;
}

/* ── Footer ─────────────────────────────────────────────────── */
.site-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.6;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.site-footer a { color: var(--dim); }

/* ── Settings button & panel ────────────────────────────────── */
.settings-wrapper {
  position: relative;
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--dim);
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent2); }
.btn-icon.active { border-color: var(--accent); color: var(--accent2); }

.settings-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 150px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.settings-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.settings-label {
  font-size: .72rem;
  color: var(--dim);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.settings-options {
  display: flex;
  gap: 6px;
}
.settings-opt {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--dim);
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 36px;
  transition: border-color .15s, color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.settings-opt:hover { border-color: var(--accent); color: var(--accent2); }
.settings-opt.active {
  border-color: var(--accent);
  color: var(--accent2);
  background: rgba(155,93,229,.12);
}

/* ── Buy Me a Coffee footer link ────────────────────────────── */
.bmc-footer-link { color: var(--dim); text-decoration: none; }
.bmc-footer-link:hover { color: var(--accent2); text-decoration: underline; }

/* ── Buy Me a Coffee dialog ─────────────────────────────────── */
dialog.bmc-dialog {
  width: min(420px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px
                   - env(safe-area-inset-top, 0px)
                   - env(safe-area-inset-bottom, 0px));
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
dialog.bmc-dialog::backdrop {
  background: rgba(0, 0, 0, .6);
}
dialog.bmc-dialog[open] {
  display: flex;
  flex-direction: column;
}
.bmc-head {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
  font-weight: 600;
}
.bmc-close {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.bmc-close:hover { border-color: var(--accent); color: var(--accent2); }
dialog.bmc-dialog iframe {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 600px;
  border: 0;
  background: #fff;
}
.bmc-alt {
  flex: none;
  padding: 8px 16px 12px;
  font-size: .72rem;
  color: var(--muted);
  text-align: center;
}
.bmc-alt a { color: var(--dim); }

/* ── P1: Stats strip ─────────────────────────────────────────── */
.stats-strip {
  display: flex;
  align-items: flex-end;
  gap: 24px;
  padding: 10px 20px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.stats-strip::-webkit-scrollbar { display: none; }
/* On narrow screens, wrap stats into two rows — nothing gets clipped */
@media (max-width: 480px) {
  .stats-strip {
    flex-wrap: wrap;
    overflow-x: visible;
    gap: 10px 20px;
    align-items: flex-start;
    padding: 8px 16px;
  }
}

.stats-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex-shrink: 0;
}
.stats-label {
  font-size: .62rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .07em;
  text-transform: uppercase;
}

/* Curve chart */
.curve-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 44px;
}
.curve-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 22px;
  height: 44px;
  gap: 2px;
  cursor: default;
}
.curve-bar-fill {
  width: 100%;
  min-height: 2px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  opacity: .85;
  transition: height .3s ease;
}
.curve-bar:hover .curve-bar-fill { opacity: 1; }
.curve-bar-label {
  font-size: .58rem;
  color: var(--muted);
  letter-spacing: .02em;
  line-height: 1;
  flex-shrink: 0;
}

/* Color pips */
.color-pips {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
  min-height: 24px;
}
.color-pip {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: default;
  flex-shrink: 0;
}
/* SVG image inside pip fills the circle */
.color-pip .mana-sym-img-sm {
  width: 22px;
  height: 22px;
}

/* ── P1: Avg CMC stat ────────────────────────────────────────── */
.stats-avg-cmc {
  font-size: .88rem;
  font-weight: 700;
  color: var(--accent2);
  letter-spacing: .02em;
  line-height: 1;
  padding-top: 4px;
}

/* ── P2: Price block ─────────────────────────────────────────── */
.stats-price {
  font-size: .88rem;
  font-weight: 700;
  color: #4ade80;   /* green-400 */
  letter-spacing: .02em;
  line-height: 1;
  padding-top: 4px;
}
.stats-price.partial { color: var(--dim); }

/* ── P2: Legality badges ─────────────────────────────────────── */
.legality-badges {
  display: flex;
  gap: 4px;
  padding-top: 4px;
  flex-wrap: wrap;
}
.legality-badge {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid;
  line-height: 1.4;
  cursor: default;
}
.legality-badge.legal {
  color: #4ade80;
  border-color: rgba(74,222,128,.35);
  background: rgba(74,222,128,.08);
}
.legality-badge.not-legal {
  color: var(--muted);
  border-color: rgba(90,88,120,.4);
  background: transparent;
}
.legality-badge.banned {
  color: var(--danger);
  border-color: rgba(248,113,113,.35);
  background: rgba(248,113,113,.08);
}

/* ── P2: Recent decks ────────────────────────────────────────── */
.recent-decks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.recent-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.recent-deck-btn {
  background: none;
  border: none;
  color: var(--dim);
  font-size: .78rem;
  text-align: left;
  padding: 3px 0;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.recent-deck-btn:hover { color: var(--accent2); }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .deck-layout {
    flex-direction: column;
    align-items: stretch;  /* children fill full width, not content width */
  }
  .sideboard-aside {
    border-left: none;
    border-top: 1px solid var(--border);
    align-self: auto;
    width: 100% !important;
    transition: none;
  }
  .sideboard-aside.collapsed {
    height: 44px;
    overflow: hidden;
  }
  .sideboard-aside:not(.collapsed) .sideboard-cards {
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 50vh;
    overflow-y: auto;
  }
  .toggle-arrow { transform: none !important; }
  .sideboard-aside:not(.collapsed) .toggle-arrow {
    transform: rotate(90deg) !important;
  }
  .sideboard-aside.collapsed .sb-label,
  .sideboard-aside.collapsed #sideboardCountLabel {
    opacity: 1;
    width: auto;
  }

  /* ── Grid layout: 2-column wrap, mana order, lands last ─── */
  .columns-scroll-area.layout-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow-x: hidden;
    gap: 8px;
    padding: 12px 12px 48px;
    align-items: start;
    align-content: start;
  }
  .columns-scroll-area.layout-grid .mana-column {
    width: 100%;
  }
  .columns-scroll-area.layout-grid .card-stack {
    width: 100%;
  }
  .columns-scroll-area.layout-grid .card-entry {
    width: 100%;
  }
  .columns-scroll-area.layout-grid .card-img {
    width: 100%;
    height: auto;
    aspect-ratio: 488 / 680;
  }
}

/* ── P5: Skip navigation ─────────────────────────────────────── */
.skip-nav {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 9999;
  background: var(--accent);
  color: #fff;
  padding: 8px 18px;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: .88rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.skip-nav:focus-visible { left: 50%; transform: translateX(-50%); }

/* ── P5: Global focus-visible rings ──────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
  border-radius: 2px;
}
/* Buttons already use border for highlight; keep outline subtle */
button:focus-visible { outline-offset: 3px; }

/* ── P5: .p5-feature gating ──────────────────────────────────── */
.p5-feature { display: none !important; }
html.phase-5 .p5-feature { display: revert !important; }

/* ── P5: Mana symbols (inline in oracle text / mana cost) ────── */
.mana-sym {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25em;
  height: 1.25em;
  border-radius: 50%;
  font-size: .68em;
  font-weight: 800;
  vertical-align: middle;
  margin: 0 1px;
  line-height: 1;
  letter-spacing: 0;
  border: 1px solid rgba(255,255,255,.12);
  background: #64748b;   /* default: colorless gray */
  color: #fff;
  flex-shrink: 0;
  cursor: default;
}

/* ── P5: Stats mana base advisor ─────────────────────────────── */
.stats-mana-base {
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .01em;
  padding-top: 4px;
  line-height: 1;
}
.stats-mana-base.ok   { color: #4ade80; }
.stats-mana-base.warn { color: var(--warn); }

/* ── P5: Search modal ────────────────────────────────────────── */
.search-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 998;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 56px 16px 16px;
  -webkit-tap-highlight-color: transparent;
}
.search-modal-inner {
  width: 100%;
  max-width: 480px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,.72);
}
.search-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--border);
}
#searchInput {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: var(--text);
  /* font-size governed by the global ≥16px rule above */
  outline: none;
  font-family: inherit;
}
#searchInput::placeholder { color: var(--muted); }
.search-results {
  max-height: 60dvh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.search-result-item {
  padding: 10px 16px;
  font-size: .84rem;
  cursor: pointer;
  color: var(--text);
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}
.search-result-item:hover { background: var(--surface); }
.search-result-item:focus { background: var(--surface); outline: none; }
.search-result-item.search-status {
  color: var(--muted); font-style: italic; cursor: default;
}

/* ── P6 feature gate ───────────────────────────────────────────────────────── */
.p6-feature { display: none !important; }
html.phase-6 .p6-feature { display: revert !important; }

/* ── P6: cloud deck list (extends .recent-decks) ──────────────────────────── */
.cloud-deck-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.cloud-deck-row .recent-deck-btn { flex: 1; min-width: 0; }
.cloud-deck-del {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color .15s;
}
.cloud-deck-del:hover { color: var(--text); }


/* ── P7: Card browser panel ─────────────────────────────────────── */
.browser-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.browser-search-row {
  display: flex;
  gap: 6px;
  align-items: flex-start; /* buttons pin to top of multi-line textarea */
}
.browser-query-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
}
#browserQuery {
  display: block;
  width: 100%;
  min-width: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 32px 7px 10px; /* right padding for clear btn */
  outline: none;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;   /* shows scrollbar at max-height; JS auto-grows below that */
  box-sizing: border-box;
  overflow-wrap: anywhere;
  -webkit-appearance: none;
  appearance: none;
  background-clip: padding-box; /* Safari default border hack */
  min-height: 36px;
  max-height: min(calc(1.4em * 5 + 14px), 40svh);
  -webkit-overflow-scrolling: touch;
}
#browserQuery:focus { border-color: var(--accent); }
/* Clear button inside the textarea wrapper */
.browser-query-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  line-height: 1;
  touch-action: manipulation;
}
.browser-query-clear.visible { display: flex; }
.browser-query-clear:hover { color: var(--text); }
.browser-search-row input[type="search"] {
  flex: 1;
  min-width: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  outline: none;
  /* font-size handled by global reset (≥16px) */
}
.browser-search-row input[type="search"]:focus { border-color: var(--accent); }
.browser-search-btn,
.browser-filter-toggle {
  flex-shrink: 0;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--dim);
  padding: 7px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 36px;
  min-height: 36px;
  touch-action: manipulation;
}
.browser-search-btn:hover,
.browser-filter-toggle:hover,
.browser-filter-toggle.active { color: var(--text); border-color: var(--accent); }

/* Color filter row — 8 symbols, single row via grid */
.browser-color-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: center;
  gap: 3px;
}
.color-filter-btn {
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  font-size: .8rem;
  font-weight: 800;
  cursor: pointer;
  color: rgba(0,0,0,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: transform .1s, border-color .1s;
}
.color-filter-btn.active { border-color: var(--text); transform: scale(1.12); }
.color-w { background: #f5f0de; }
.color-u { background: #3b82f6; color: #fff; }
.color-b { background: #4a3f5c; color: #c8b8d0; }
.color-r { background: #ef4444; color: #fff; }
.color-g { background: #22c55e; }
.color-filter-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 2px;
}
#formatSelect {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  cursor: pointer;
  min-height: 32px;
  /* font-size: global reset ensures ≥16px */
}
#formatSelect:focus { border-color: var(--accent); outline: none; }

/* Advanced filters */
.browser-advanced {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.adv-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.adv-label {
  font-size: .8rem;
  color: var(--dim);
  flex-shrink: 0;
}
.adv-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  width: 72px;
  min-height: 32px;
  outline: none;
  /* font-size: global reset */
}
.adv-input:focus { border-color: var(--accent); }
.adv-input-wide { width: 120px; }
.adv-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 8px;
  min-height: 32px;
  outline: none;
  /* font-size: global reset */
}
.adv-select:focus { border-color: var(--accent); }
.adv-query-preview {
  font-size: .75rem;
  color: var(--muted);
  font-family: monospace;
  word-break: break-all;
}

/* Browser results */
.browser-results-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.browser-status {
  font-size: .82rem;
  color: var(--dim);
  padding: 4px 0;
}
.browser-status-msg {
  font-size: .82rem;
  color: var(--dim);
  padding: 4px;
}

/* ── Query display: "Searching: <query>" line ──────────────── */
.browser-query-display {
  font-size: .75rem;
  color: var(--text-muted, var(--dim));
  padding: 4px 2px 2px;
  line-height: 1.4;
  overflow-wrap: break-word;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.browser-query-display:hover { opacity: .75; }
.browser-query-display[hidden] { display: none; }
.bqd-label { opacity: .6; }
.bqd-query  { font-family: monospace; font-size: .72rem; word-break: break-all; }

/* ── Zero-results panel ──────────────────────────────────────── */
.browser-no-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 4px;
}
.browser-no-results-msg {
  font-size: .84rem;
  color: var(--dim);
}
.browser-no-results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.browser-no-results-btn {
  font-size: .82rem;
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}
.browser-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  padding-bottom: 6px;
  min-height: 80px;
}
@media (max-width: 399px) {
  .browser-results {
    grid-template-columns: repeat(2, 1fr);
  }
}
.browser-more-btn {
  align-self: flex-start;
  font-size: .82rem;
}

/* Individual browser card */
.browser-card-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  position: relative;
}
.browser-card-img {
  width: 100%;
  border-radius: 5px;
  display: block;
  transition: transform .12s;
  -webkit-user-drag: none;
}
.browser-card-slot:active .browser-card-img { transform: scale(.95); }
.browser-card-slot.hold-active .browser-card-img {
  outline: 2px solid var(--accent, #f97316);
  outline-offset: 1px;
}
.browser-card-slot.illegal-card .browser-card-img {
  box-shadow: 0 0 0 2px #ef4444, 0 0 8px 1px rgba(239,68,68,.5);
}
.browser-card-name {
  font-size: .72rem;
  color: var(--dim);
  text-align: center;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Count badge on browser search results */
.browser-card-count {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent, #f97316);
  color: #fff;
  font-size: .65rem;
  font-weight: 800;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  pointer-events: none;
  display: none;
}
.browser-card-count.visible { display: block; }
/* Hint bar above results */
.browser-results-hint {
  font-size: .75rem;
  color: var(--muted);
  padding: 4px 0;
  text-align: center;
}

/* Diamond indicators */
.card-diamonds {
  display: flex;
  gap: 3px;
  justify-content: center;
  height: 10px;
}
.diamond {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  background: transparent;
  flex-shrink: 0;
}
.diamond.filled {
  background: var(--accent);
  border-color: var(--accent);
}

/* ── P7: Illegal card highlighting ──────────────────────────────── */
.card-entry.illegal-card,
.sb-card-entry.illegal-card {
  box-shadow: 0 0 0 2px #ef4444, 0 0 10px 2px rgba(239,68,68,.4);
  position: relative;
}
.card-entry.illegal-card::after,
.sb-card-entry.illegal-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(239, 68, 68, .12);
  border-radius: var(--radius);
  pointer-events: none;
}
/* Illegal warning in deck info */
.illegal-warning {
  font-size: .75rem;
  color: var(--danger);
  font-weight: 600;
  background: rgba(248, 113, 113, .12);
  border-radius: 4px;
  padding: 2px 6px;
}

/* ── P7: Deck card inline controls overlay ──────────────────────── */
.deck-ctrl-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(18, 16, 28, .72);
  border-radius: var(--radius);
  z-index: 2;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.deck-ctrl-btn {
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.deck-ctrl-btn:active { background: var(--border); }
.deck-ctrl-minus { color: var(--danger); }
.deck-ctrl-plus  { color: #4ade80; }
.deck-ctrl-eye   { color: var(--dim); }

/* ── P7: Stats modal ────────────────────────────────────────────── */
.stats-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.stats-modal-inner {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 600px;
  /* Anchored to bottom: take as much content height as needed up to 92dvh.
     Subtract safe-area-top + 8px so it never overlaps a notch/status bar. */
  max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 8px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 0;
}
.stats-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.stats-modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stats-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stats-section-title {
  font-size: .8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}

/* Format — compact select */
.stats-fmt-section {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.stats-fmt-select {
  flex: 1;
  max-width: 200px;
  min-width: 140px;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  appearance: auto;
}

/* Counts row — 2×2 grid on mobile, single row on wider screens */
.stats-counts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (min-width: 480px) {
  .stats-counts-row { grid-template-columns: repeat(4, 1fr); }
}
.stats-count-block {
  min-width: 0;
  background: var(--elevated);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.stats-count-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
}
.count-creature  { color: #f97316; }
.count-noncreature { color: #3b82f6; }
.count-land      { color: #22c55e; }
.stats-count-lbl {
  font-size: .68rem;
  color: var(--muted);
  text-align: center;
}

/* Mana curve in stats modal */
.stats-curve-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
/* Legend row */
.stats-curve-legend {
  display: flex;
  gap: 12px;
  font-size: .68rem;
  color: var(--muted);
}
.stats-curve-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.legend-swatch.creature    { background: #f97316; }
.legend-swatch.noncreature { background: #3b82f6; }
/* Plot area: fixed height with overflow:hidden so tallest bar never clips header */
.stats-curve-plot {
  position: relative;
  height: 120px;
  overflow: hidden;
}
.stats-curve-bars {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 100%;
}
.stats-curve-col {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  /* reserve 18px at bottom for label, 16px at top for count */
  padding-bottom: 18px;
  padding-top: 16px;
  box-sizing: border-box;
  justify-content: flex-end;
}
.stats-curve-bar {
  width: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: stretch;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
  flex-shrink: 0;
  /* height is set via inline style in JS */
}
.stats-curve-bar.empty-bucket {
  background: var(--border);
  opacity: 0.5;
}
.bar-fill {
  width: 100%;
  min-height: 2px;
}
.bar-creature    { background: #f97316; }
.bar-noncreature { background: #3b82f6; }
.stats-curve-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: .65rem;
  color: var(--muted);
  height: 18px;
  line-height: 18px;
}
.stats-curve-count {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: .65rem;
  color: var(--dim);
  height: 16px;
  line-height: 16px;
}

/* Color chips in stats modal */
.stats-color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.stats-color-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--elevated);
  border-radius: 20px;
  padding: 5px 10px;
}
.color-sym {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--pip-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .68rem;
  font-weight: 800;
  color: rgba(0,0,0,.8);
  flex-shrink: 0;
}
.color-cnt {
  font-size: .88rem;
  font-weight: 700;
  color: var(--text);
}
.color-pct {
  font-size: .75rem;
  color: var(--muted);
}

/* Type breakdown */
.stats-type-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stats-type-row {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 6px;
  border-radius: 4px;
  overflow: hidden;
}
.stats-type-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: rgba(249,115,22,.14);
  border-radius: 4px;
  pointer-events: none;
  transition: width .3s;
}
.stats-type-name {
  position: relative;
  font-size: .88rem;
  color: var(--text);
  font-weight: 600;
  z-index: 1;
}
.stats-type-cnt {
  position: relative;
  font-size: .88rem;
  color: var(--dim);
  z-index: 1;
}
.stats-subtype-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 6px 2px 20px;
}
.stats-subtype-name { font-size: .78rem; color: var(--dim); }
.stats-subtype-toggle {
  font-size: .75rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px 2px 20px;
  text-align: left;
  touch-action: manipulation;
}

/* Price + legality side-by-side blocks */
.stats-price-legal-row {
  flex-direction: row;
  gap: 12px;
  flex-wrap: wrap;
}
.stats-info-block {
  flex: 1;
  min-width: 100px;
  background: var(--elevated);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stats-info-val {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.stats-info-lbl {
  font-size: .72rem;
  color: var(--muted);
}

/* Legality in stats modal */
.leg-ok {
  font-size: .85rem;
  color: #4ade80;
  padding: 6px 0;
}
.leg-illegal-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
  gap: 8px;
}
.leg-name  { font-size: .82rem; color: var(--dim); }
.leg-status {
  font-size: .75rem;
  color: var(--danger);
  font-weight: 600;
  flex-shrink: 0;
}

/* ── P8: Account modal ────────────────────────────────────────────── */
.account-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.account-modal[hidden] { display: none; }
.account-modal-inner {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 340px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.account-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: .95rem;
  color: var(--text);
}
.account-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.account-label {
  font-size: .78rem;
  color: var(--muted);
  font-weight: 500;
}
.account-optional {
  font-weight: 400;
  color: var(--dim);
  font-size: .75rem;
}
.username-availability {
  display: block;
  font-size: .78rem;
  margin-top: 3px;
  min-height: 1.2em;
}
.username-availability.checking { color: var(--dim, #888); }
.username-availability.available { color: var(--success, #4a9e5c); }
.username-availability.taken     { color: var(--danger, #e06060); }
.account-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 16px; /* 16px minimum — prevents iOS Safari autozoom */
  padding: 9px 11px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color .15s;
}
.account-input:focus {
  border-color: var(--accent);
}
.account-btn {
  width: 100%;
  padding: 10px 14px;
  font-size: .88rem;
  min-height: 44px; /* 44px tap target */
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all .15s;
  font-weight: 500;
}
.account-passkey-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-primary.account-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary.account-btn:hover {
  filter: brightness(1.1);
}
.btn-ghost.account-btn {
  background: none;
  color: var(--text);
}
.btn-ghost.account-btn:hover {
  border-color: var(--accent);
  color: var(--accent2);
}
.account-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--dim);
  font-size: .75rem;
}
.account-divider::before,
.account-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.account-hint {
  font-size: .78rem;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}
.account-no-email-note {
  color: var(--dim);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.account-link {
  background: none;
  border: none;
  color: var(--accent2);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.account-link:hover { color: var(--accent); }
.account-msg {
  font-size: .78rem;
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
}
.account-msg.ok { color: #4ade80; }
.account-welcome {
  font-size: .88rem;
  color: var(--dim);
  margin: 0;
}
.account-welcome strong { color: var(--text); }
.account-passkeys-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.account-no-passkeys {
  color: var(--text-muted, #888);
  font-size: .82rem;
  margin: 0;
}
.passkey-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.passkey-item:last-child { border-bottom: none; }
.passkey-label {
  flex: 1;
  font-size: .82rem;
  color: var(--text);
  word-break: break-word;
}
.passkey-remove-btn {
  font-size: .78rem;
  padding: 4px 10px;
  border-radius: 6px;
  min-height: 32px;
  flex-shrink: 0;
  color: var(--danger, #e06060);
  border-color: var(--danger, #e06060);
}
.passkey-remove-btn:hover { background: var(--danger, #e06060); color: #fff; }
/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .84rem;
  padding: 9px 18px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  z-index: 2000;
  pointer-events: none;
  opacity: 1;
  transition: opacity .3s, transform .3s;
  white-space: nowrap;
}
.toast.hiding {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
}

/* P9: AI search button in browser panel */
.browser-ai-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  padding: 6px 10px;
  border-radius: 6px;
  min-height: 36px;
  min-width: 44px; /* 44px tap target */
  white-space: nowrap;
}

/* P9: AI search modal */
.ai-search-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 998;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 56px 16px 16px;
  -webkit-tap-highlight-color: transparent;
}
.ai-search-modal[hidden] { display: none; }
.ai-search-inner {
  width: 100%;
  max-width: 480px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0,0,0,.72);
}
.ai-search-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .9rem;
}
.ai-search-header .bmc-close {
  margin-left: auto;
}
.ai-search-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-search-label {
  font-size: .84rem;
  color: var(--text-muted);
}
.ai-search-textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 16px; /* >= 16px: prevents iOS Safari autozoom */
  font-family: inherit;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}
.ai-search-textarea:focus {
  border-color: var(--accent);
}
.ai-search-actions {
  display: flex;
  justify-content: flex-end;
}
.ai-search-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px; /* >= 16px: prevents iOS Safari autozoom */
  padding: 10px 20px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: opacity .15s;
}
.ai-search-btn:disabled {
  opacity: .5;
  cursor: default;
}
.ai-search-status {
  font-size: .84rem;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  line-height: 1.5;
}
.ai-search-status.error {
  border-color: var(--red, #e55);
  color: var(--red, #e55);
}
.ai-usage-bar {
  font-size: .78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── P3: Image preview modal (Get Image) ──────────────────────── */
/* ID selector (specificity 1,1,0) beats html.phase-3 .p3-feature (0,2,1).
   Without this, `display: revert !important` from the phase gate would
   re-show the modal overlay even with hidden="". */
#imgPreviewModal[hidden] { display: none !important; pointer-events: none !important; }
.img-preview-modal[hidden] { display: none !important; }
.img-preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 16px;
}
.img-preview-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.img-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-size: .88rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.img-preview-body {
  overflow-y: auto;
  padding: 14px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 100px;
}
.img-preview-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dim);
  font-size: .88rem;
  padding: 32px 0;
}
.img-preview-img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: 6px;
  display: block;
  /* checkered bg to show transparency */
  background-image:
    linear-gradient(45deg,#444 25%,transparent 25%),
    linear-gradient(-45deg,#444 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#444 75%),
    linear-gradient(-45deg,transparent 75%,#444 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #2a2a2a;
}
.img-preview-error {
  color: var(--red, #e55);
  font-size: .88rem;
  text-align: center;
  padding: 12px 0;
}
.img-preview-actions {
  display: flex;
  gap: 10px;
  padding: 10px 16px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}
.img-action-btn {
  flex: 1;
  min-height: 44px;
  font-size: .88rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Body scroll lock (applied when any modal is open) ─────────────── */
body.modal-open {
  overflow: hidden;
}

/* ── Mana symbol images (Scryfall SVGs in assets/mana/) ──────────────── */
.mana-sym-img {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.mana-sym-img-sm {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.mana-sym-img-lg {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: block;
}

/* ── Arena-style card selection (P7 tap controls) ────────────────────── */
/* Suppress iOS long-press callout on deck cards */
.card-entry, .sb-card-entry {
  -webkit-touch-callout: none;
  user-select: none;
}
/* Glow when selected */
.card-entry.card-selected {
  outline: 2px solid var(--accent, #f97316);
  outline-offset: 1px;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.35), 0 0 14px 5px rgba(249, 115, 22, 0.25);
  z-index: 2;
}
/* Inline +/− overlay row — sits in the art strip */
.deck-ctrl-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--rev, 48px) * 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 0 4px;
  pointer-events: none; /* children handle their own events */
  z-index: 3;
}
.deck-ctrl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  pointer-events: auto;
}
.deck-ctrl-btn {
  width: 28px;
  height: 28px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 6px;
  border: none;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background .1s;
}
.deck-ctrl-btn:active { background: rgba(249,115,22,.85); }
.deck-ctrl-qty {
  min-width: 28px;
  text-align: center;
  font-size: .9rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
  pointer-events: none;
}
.deck-ctrl-move {
  pointer-events: auto;
  background: rgba(0,0,0,.62);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 600;
  padding: 3px 7px;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  min-height: 28px;
  line-height: 1;
}
.deck-ctrl-move:active { background: rgba(249,115,22,.75); }

/* ── 8-option color filter strip ────────────────────────────────────── */
.browser-color-row {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 0;
  position: relative;
  flex-wrap: nowrap;
}
/* Each color-strip-btn takes equal space; land open button is auto-width */
.browser-color-row .color-strip-btn {
  flex: 1;
}
.browser-color-row .color-strip-land-open {
  flex-shrink: 0;
}
.color-strip {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  flex: 1;
}
.color-strip-btn {
  -webkit-appearance: none;
  appearance: none;
  width: auto;
  height: auto;
  min-height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--elevated);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: opacity .15s, border-color .15s, box-shadow .15s;
  touch-action: manipulation;
  padding: 4px;
}
.color-strip-btn img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: block;
}
.color-strip-btn[aria-pressed="true"] {
  opacity: 1;
  border-color: var(--accent, #f97316);
  box-shadow: 0 0 0 2px rgba(249,115,22,.35);
}
.color-strip-btn:hover { opacity: 0.85; }

/* Color popover — appears below the strip */
.color-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.color-popover-btn {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--elevated);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  opacity: 0.5;
  transition: opacity .15s, border-color .15s, box-shadow .15s;
  touch-action: manipulation;
  padding: 6px;
}
.color-popover-btn img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: block;
}
.color-popover-btn span {
  font-size: .6rem;
  color: var(--muted);
  line-height: 1;
}
.color-popover-btn[aria-pressed="true"] {
  opacity: 1;
  border-color: var(--accent, #f97316);
  box-shadow: 0 0 0 2px rgba(249,115,22,.35);
}
.color-popover-btn:hover { opacity: 0.75; }

.color-filter-sep { flex: 1; }
.color-filter-sep-narrow { width: 0; }

/* Format selector row that sits below the color strip */
.browser-format-row {
  padding: 2px 0 0;
}
.browser-format-row select {
  -webkit-appearance: auto;
  appearance: auto;
  font-size: 16px;
  padding: 5px 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  cursor: pointer;
}

/* ── Advanced filter accordion (Arena-style) ─────────────────────────── */
.adv-top {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0 4px;
}
.adv-color-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}
.adv-mv-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.adv-chip {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--dim);
  font-size: .8rem;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 36px;
  transition: background .12s, border-color .12s, color .12s;
}
.adv-chip[aria-pressed="true"] {
  /* #7c3aed is WCAG AA compliant (5.7:1) with white — #9b5de5 falls short at 4.1:1 */
  background: #7c3aed;
  border-color: #7c3aed;
  color: #fff;
}
.adv-mv-chip {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  padding: 0;
  font-weight: 700;
}
.adv-color-chip {
  -webkit-appearance: none;
  appearance: none;
  width: auto;
  height: auto;
  min-height: 44px;
  border-radius: 50%;
  padding: 4px;
}
.adv-color-chip img { width: 100%; height: 100%; border-radius: 50%; display: block; }
.adv-accordion { display: flex; flex-direction: column; }
.adv-section {
  border-top: 1px solid var(--border);
}
.adv-section-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--text);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 44px;
}
.adv-section-header svg {
  transition: transform .2s;
  flex-shrink: 0;
}
.adv-section-header[aria-expanded="true"] svg { transform: rotate(180deg); }
.adv-section-body {
  padding: 4px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.adv-chip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.adv-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.adv-type-row {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  padding: 0 10px;
  min-height: 44px;
  height: 44px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  cursor: pointer;
  gap: 8px;
  touch-action: manipulation;
  text-align: left;
}
.adv-type-row:hover { background: var(--surface); }
.adv-type-row[aria-pressed="true"] {
  background: var(--accent, #f97316);
  border-color: var(--accent, #f97316);
  color: #fff;
}
.adv-type-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  opacity: 0.75;
}
.adv-type-row[aria-pressed="true"] .adv-type-icon { opacity: 1; }
.adv-type-label {
  flex: 1;
  font-size: .84rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.adv-subtype-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.adv-subtype-label {
  font-size: .78rem;
  color: var(--muted);
  flex-shrink: 0;
}
.adv-subtype-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 16px;
  padding: 7px 10px;
  min-height: 36px;
}
.adv-footer {
  display: flex;
  gap: 8px;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  margin-top: 4px;
  flex-shrink: 0;
}
.adv-reset {
  flex: 1;
  min-height: 44px;
}
.adv-apply {
  flex: 2;
  min-height: 44px;
}
/* Active filter count badge on filter toggle button */
.filter-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--accent, #f97316);
  color: #fff;
  font-size: .58rem;
  font-weight: 800;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1;
}
.browser-filter-toggle {
  position: relative;
}

/* Hide browser results wrapper when empty */
.browser-results-wrap:not(.has-results) {
  display: none;
}

/* Header deck count — allow wrapping on very small screens */
@media (max-width: 420px) {
  .top-bar {
    flex-wrap: wrap;
  }
  .brand {
    order: 0;
    flex: 1;
  }
  .deck-info {
    order: 2;
    width: 100%;
    padding: 2px 4px;
    display: flex;
    gap: 6px;
    align-items: baseline;
  }
  /* Keep icon buttons on same row as brand */
  .btn-ghost, .btn-icon, .settings-wrapper {
    order: 1;
  }
}

/* Stats color chip — with mana symbol image */
.stats-color-chip .mana-sym-img {
  width: 22px;
  height: 22px;
}

/* Land strip button — open-popover affordance (not a toggle) */
.color-strip-land-open {
  display: flex;
  align-items: center;
  gap: 2px;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--elevated);
  color: var(--muted);
  cursor: pointer;
  opacity: 0.65;
  transition: opacity .15s, border-color .15s;
  touch-action: manipulation;
  padding: 4px 5px;
}
.color-strip-land-open img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: block;
}
.color-strip-land-open:hover { opacity: 0.9; }
.color-strip-land-open.popover-open {
  border-color: var(--accent, #f97316);
  opacity: 1;
}

/* ── Typeahead (shared for Subtype + Set) ──────────────────────────── */
.typeahead-wrap {
  position: relative;
}
/* chips + input */
.typeahead-field {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
  min-height: 36px;
  cursor: text;
}
.typeahead-field:focus-within {
  border-color: var(--accent);
}
.typeahead-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--accent, #f97316);
  color: #fff;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.typeahead-chip-remove {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 2px;
  width: 14px;
  height: 14px;
  touch-action: manipulation;
}
.typeahead-chip-remove:hover { color: #fff; }
.typeahead-input {
  flex: 1;
  min-width: 60px;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  padding: 0;
  line-height: 1.4;
  min-height: 26px;
}
/* Dropdown */
.typeahead-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,.45);
  overflow: hidden;
  overflow-y: auto;
  max-height: min(280px, 40svh);
  -webkit-overflow-scrolling: touch;
}
/* Position above when at bottom of page */
.typeahead-dropdown.drop-up {
  bottom: calc(100% + 4px);
  top: auto;
}
.typeahead-dropdown.drop-down {
  top: calc(100% + 4px);
  bottom: auto;
}
.typeahead-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
  font-size: .82rem;
  color: var(--text);
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}
.typeahead-option:hover,
.typeahead-option.active {
  background: var(--elevated);
}
.typeahead-option-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.typeahead-option-icon img,
.typeahead-option-icon svg {
  width: 20px;
  height: 20px;
}
.typeahead-option-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.typeahead-option-group {
  font-size: .68rem;
  color: var(--muted);
  flex-shrink: 0;
}
.typeahead-no-results {
  padding: 10px 12px;
  font-size: .82rem;
  color: var(--muted);
}

/* ── Meta panel ─────────────────────────────────────────────────────────────── */

.meta-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.meta-overlay[hidden] { display: none; }

.meta-sheet {
  width: 100%;
  max-width: 700px;
  max-height: min(92dvh, 700px);
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.meta-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.meta-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
.meta-subtitle {
  font-size: .78rem;
  color: var(--muted);
  flex: 1;
}
.meta-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background .15s;
}
.meta-close:hover { background: var(--elevated); }

.meta-loading {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
}

.meta-grid {
  overflow-y: auto;
  padding: 12px 12px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
@media (max-width: 480px) {
  .meta-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
}

.meta-deck-card {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.meta-deck-card:hover,
.meta-deck-card:focus-visible {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--elevated) 85%, var(--accent));
  outline: none;
}
.meta-deck-card:active {
  opacity: .85;
}

.meta-deck-num {
  font-size: .68rem;
  color: var(--muted);
}
.meta-deck-cards {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.meta-deck-card-name {
  font-size: .78rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta-deck-action {
  font-size: .72rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: 4px;
  text-align: right;
}

/* Meta button active state */
#metaBtn.active {
  color: var(--accent);
}

/* ── New deck modal ─────────────────────────────────────────────────── */
.new-deck-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.new-deck-inner {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.new-deck-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.new-deck-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.new-deck-save-warning {
  font-size: .85rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--elevated) 90%, var(--accent));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0;
}
.new-deck-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.new-deck-label {
  font-size: .8rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.new-deck-input,
.new-deck-select {
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  box-sizing: border-box;
}
.new-deck-input:focus,
.new-deck-select:focus {
  border-color: var(--accent);
}
.new-deck-footer {
  display: flex;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.new-deck-btn {
  flex: 1;
  min-height: 44px;
  font-size: 1rem;
}

/* Tappable deck name in top bar */
.deck-name-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  margin: 0;
  cursor: pointer;
  color: var(--text);
  font-size: inherit;
  font-family: inherit;
  font-weight: inherit;
  border-radius: 4px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
}
.deck-name-btn:hover {
  background: var(--elevated);
}
.deck-name-btn:focus-visible {
  outline: 2px solid var(--accent);
}
