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

:root {
  --bg:        #1a1d23;
  --surface:   #22262f;
  --surface2:  #2b3040;
  --border:    #374057;
  --text:      #e2e6f0;
  --text-muted:#8893aa;
  --accent:    #5b9bd5;
  --accent2:   #3a7bbf;
  --green:     #3d9970;
  --yellow:    #c8a227;
  --red:       #c0392b;
  --radius:    6px;
  --shadow:    0 2px 8px rgba(0,0,0,.4);

  /* mana colours */
  --mw: #f9f6d0; --mu: #9ecde7; --mb: #b0a5a0;
  --mr: #e8967a; --mg: #82c49b; --mc: #ccc;
}

html { font-size: 15px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .5em 1.1em;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent2); }
.btn-primary:hover { background: var(--accent2); }
.btn-primary.loading { opacity: .6; cursor: default; }
.btn-ghost    { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface2); }
.btn-outline  { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-outline:hover { background: rgba(91,155,213,.15); }
.btn-danger-ghost { background: transparent; color: var(--red); border-color: var(--red); }
.btn-danger-ghost:hover { background: rgba(192,57,43,.12); }
.btn-sm { padding: .3em .8em; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: default; }

/* ── Alerts ── */
.alert { padding: .75em 1em; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: rgba(192,57,43,.2); border: 1px solid var(--red); color: #f5a69a; }

/* ══════════════════════════════════════════════════
   INDEX PAGE
══════════════════════════════════════════════════ */
.page-index { max-width: 700px; margin: 0 auto; padding: 2rem 1rem; }

.site-header { text-align: center; margin-bottom: 2rem; }
.site-header h1 { font-size: 2rem; color: var(--accent); }
.site-header .subtitle { color: var(--text-muted); margin-top: .3rem; }

.index-main { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }

.textarea-wrap textarea {
  width: 100%; height: 360px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem; font-family: 'Consolas', 'Courier New', monospace; font-size: .88rem;
  resize: vertical; outline: none;
  transition: border-color .15s;
}
.textarea-wrap textarea:focus { border-color: var(--accent); }

.index-actions { display: flex; gap: .75rem; margin-top: 1rem; flex-wrap: wrap; }

.format-hint {
  margin-top: 1rem; font-size: .8rem; color: var(--text-muted);
  background: var(--surface2); border-radius: var(--radius); padding: .75rem 1rem;
  line-height: 1.8;
}
.format-hint code {
  background: var(--bg); padding: .1em .4em;
  border-radius: 3px; color: var(--accent); font-size: .9em;
}

/* ══════════════════════════════════════════════════
   DECK PAGE
══════════════════════════════════════════════════ */
.page-deck { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Deck Header ── */
.deck-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  padding: .75rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.deck-header-left { display: flex; align-items: center; gap: 1rem; }
.deck-header-left h1 { font-size: 1.1rem; }
.back-link { color: var(--text-muted); font-size: .85rem; }
.back-link:hover { color: var(--text); }

.deck-header-right { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.counters { display: flex; gap: .5rem; flex-wrap: wrap; }
.counter-chip {
  background: var(--surface2); border: 1px solid var(--border);
  padding: .25em .75em; border-radius: 99px; font-size: .8rem; color: var(--text-muted);
}
.counter-chip.complete { border-color: var(--green); color: var(--green); }

/* ── Controls ── */
.deck-controls {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .6rem 1rem;
  background: var(--surface2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-input {
  flex: 1 1 180px; min-width: 140px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .35em .75em; font-size: .88rem; outline: none;
}
.search-input:focus { border-color: var(--accent); }

.filter-select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .35em .6em; font-size: .82rem; cursor: pointer; outline: none;
}
.filter-select:focus { border-color: var(--accent); }

.toggle-label {
  display: flex; align-items: center; gap: .4em;
  font-size: .82rem; color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
.toggle-label input { cursor: pointer; accent-color: var(--accent); }

/* ── Deck Body ── */
.deck-body {
  flex: 1; overflow-y: auto;
  padding: .6rem 1rem 2rem;
}

/* ══════════════════════════════════════════════════
   SECTION GROUPS (by type)
══════════════════════════════════════════════════ */
.section-group { margin-bottom: 1.2rem; }

.section-header {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .45rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: .78rem; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .07em;
}
.section-badge {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 99px; padding: .05em .5em;
  font-size: .7rem; color: var(--text-muted);
}

/* ── Not-found section header ── */
.not-found-section { margin-top: .5rem; }
.not-found-header .section-title { color: #c07060; }

/* ══════════════════════════════════════════════════
   CARDS GRID
══════════════════════════════════════════════════ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 5px;
}

/* ══════════════════════════════════════════════════
   CARD TILE
══════════════════════════════════════════════════ */
.card-tile {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: .45rem .55rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: filter .1s;
  min-width: 0;
}
.card-tile:hover { filter: brightness(1.12); }
.card-tile.tile-partial { border-top: 2px solid var(--yellow); }

/* ── MTG colour variants ── */
.tile-white     { background: #2a2820; border-left: 3px solid #c8b860; }
.tile-blue      { background: #1c2a36; border-left: 3px solid #4a90c0; }
.tile-black     { background: #1e1c26; border-left: 3px solid #6a5a80; }
.tile-red       { background: #281e1c; border-left: 3px solid #b05845; }
.tile-green     { background: #1c2a1c; border-left: 3px solid #4a8850; }
.tile-multi     { background: #28241a; border-left: 3px solid #b08825; }
.tile-colorless { background: #222630; border-left: 3px solid #607080; }
.tile-land      { background: #261e18; border-left: 3px solid #806050; }
.tile-unknown   { background: rgba(192,57,43,.1); border-left: 3px solid #a04535; }

/* ── Tile top row (qty + name + img button) ── */
.tile-top {
  display: flex; align-items: baseline; gap: .3em; min-width: 0;
}
.tile-qty {
  font-size: .72rem; color: var(--text-muted); font-weight: 700; flex-shrink: 0;
}
.tile-name {
  font-size: .82rem; font-weight: 600; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: .3em;
}
.tile-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tile-img-btn {
  flex-shrink: 0; background: none; border: none;
  cursor: pointer; color: var(--text-muted); font-size: .72rem;
  padding: 0 .1em; line-height: 1;
}
.tile-img-btn:hover { color: var(--accent); }

/* ── Tile bottom row (type + mana + selector) ── */
.tile-bot {
  display: flex; align-items: center; gap: .3em; flex-wrap: nowrap; min-width: 0;
}
.tile-type {
  font-size: .68rem; color: var(--text-muted);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-mana { display: flex; align-items: center; flex-shrink: 0; }

/* ── Selection indicator (single card) ── */
.tile-sel-indicator {
  flex-shrink: 0; width: 1.35rem; height: 1.35rem;
  border-radius: 50%; border: 1.5px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: var(--text-muted);
  background: rgba(0,0,0,.2);
}
.tile-sel-indicator.complete {
  background: var(--green); border-color: var(--green); color: #fff;
}
.tile-sel-indicator.partial {
  border-color: var(--yellow); color: var(--yellow);
}

/* ── Small counter (multi-copy card) ── */
.sel-counter-sm {
  display: flex; align-items: center; gap: .2rem; flex-shrink: 0;
}
.sel-btn-sm {
  width: 1.35rem; height: 1.35rem;
  border-radius: 50%; border: 1px solid var(--border);
  background: rgba(0,0,0,.25); color: var(--text); cursor: pointer; font-size: .72rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .1s; flex-shrink: 0;
}
.sel-btn-sm:hover { background: var(--surface2); border-color: var(--accent); }
.sel-btn-all-sm { color: var(--green); border-color: var(--green); font-size: .6rem; }
.sel-btn-all-sm:hover { background: rgba(61,153,112,.2); }
.sel-count-sm {
  font-size: .72rem; font-weight: 700;
  min-width: 2rem; text-align: center; flex-shrink: 0;
}

/* ── Unsleeve button (in sleeved section) ── */
.tile-unslv-btn {
  flex-shrink: 0; background: none;
  border: 1px solid var(--border); border-radius: 50%;
  width: 1.35rem; height: 1.35rem; cursor: pointer;
  color: var(--text-muted); font-size: .72rem;
  display: flex; align-items: center; justify-content: center;
}
.tile-unslv-btn:hover { border-color: var(--red); color: var(--red); }

/* ── Tile flash animation (click feedback) ── */
@keyframes tile-flash {
  0%   { filter: brightness(2) saturate(1.5); }
  100% { filter: brightness(1) saturate(1); }
}
.tile-flash { animation: tile-flash 0.35s ease-out; }

/* ══════════════════════════════════════════════════
   SLEEVED SECTION
══════════════════════════════════════════════════ */
.sleeved-section {
  background: rgba(61,153,112,.07);
  border: 1px solid rgba(61,153,112,.28);
  border-radius: var(--radius);
  margin-bottom: .8rem;
  overflow: hidden;
}
.sleeved-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .45rem .75rem; cursor: pointer;
  background: rgba(61,153,112,.12);
}
.sleeved-header:hover { background: rgba(61,153,112,.18); }
.sleeved-title-txt { font-size: .82rem; font-weight: 700; color: var(--green); }
.sleeved-body { padding: .5rem .6rem; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: .05em .4em; border-radius: 3px;
  font-size: .65rem; font-weight: 700; flex-shrink: 0;
}
.badge-not-found { background: rgba(192,57,43,.25); color: #f0a090; }
.badge-sb   { background: rgba(91,155,213,.2); color: var(--accent); }
.badge-cmd  { background: rgba(200,162,39,.2); color: var(--yellow); }
.badge-maybe{ background: rgba(130,130,130,.2); color: var(--text-muted); }

/* ── Mana cost ── */
.mana-sym {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.15em; height: 1.15em; border-radius: 50%;
  font-size: .65rem; font-weight: 700; color: #333;
  margin: 0 1px; flex-shrink: 0;
}
.ms-W { background: var(--mw); }
.ms-U { background: var(--mu); }
.ms-B { background: var(--mb); }
.ms-R { background: var(--mr); }
.ms-G { background: var(--mg); }
.ms-C { background: var(--mc); }
.ms-X, .ms-generic { background: #9aa; color: #fff; }

/* ── Empty state ── */
.empty-msg {
  color: var(--text-muted); font-size: .85rem;
  padding: 1.5rem 0; text-align: center;
}

/* ── Image modal ── */
.card-modal {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.75);
  align-items: center; justify-content: center;
  cursor: pointer;
}
.card-modal.active { display: flex; }
.card-modal-inner { text-align: center; pointer-events: none; }
.card-modal-inner img {
  max-width: min(90vw, 350px); border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.8);
}
.card-modal-inner p { margin-top: .5rem; color: #fff; font-size: .85rem; }

/* ── Responsive ── */
@media (max-width: 700px) {
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 4px; }
  .deck-controls { gap: .35rem; }
  .filter-select { font-size: .78rem; }
  .tile-name { font-size: .78rem; }
  .tile-type { font-size: .64rem; }
}
@media (max-width: 420px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
