:root {
  --ground: #231E2B;
  --panel: #2E2838;
  --raised: #3A3346;
  --line: #4D4559;
  --text: #F1EBDF;
  --muted: #BDB3C2;
  --accent: #C9C5BC;
  --band: linear-gradient(90deg, #C9C5BC 0 100%);
  --good: #A6DDB4;
  --warn: #F5C98A;
  --serif: "Alegreya", Georgia, serif;
  --sans: "Alegreya Sans", "Trebuchet MS", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--ground); color: var(--text);
  font: 400 1.0625rem/1.5 var(--sans);
}
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); }
h2 { font-size: 1.5rem; margin-bottom: .6rem; }
h3 { font-size: 1.2rem; margin: 1.5rem 0 .5rem; }
h4 { font-size: 1.05rem; }
p { margin: .4rem 0; }
a { color: var(--accent); }
img { display: block; max-width: 100%; height: auto; }
small { display: block; font-weight: 400; font-size: .85em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.band { height: 8px; background: var(--band); transition: background .4s; }
.top {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem 2rem;
  max-width: 1320px; margin: 0 auto; padding: 1rem 16px .4rem;
}
.brand { font: 700 1.5rem var(--serif); color: var(--text); text-decoration: none; }
#nav { display: flex; flex-wrap: wrap; gap: .2rem 1.1rem; min-width: 0; }
#nav button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  font: 500 1rem var(--sans); padding: .2rem 0; cursor: pointer;
  max-width: 16rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#nav button:hover { color: var(--text); }
#nav button[aria-current] { color: var(--text); border-color: var(--accent); }

main { max-width: 1320px; margin: 0 auto; padding: 0 16px 3rem; }
.lede { max-width: 42rem; margin: 2.2rem 0 1.8rem; }
.lede p { font-size: 1.2rem; color: var(--muted); }
.foot { max-width: 1320px; margin: 0 auto; padding: 1.2rem 16px 2.4rem; color: var(--muted); font-size: .9rem; }
.foot p { max-width: 62rem; }

.panel { background: var(--panel); border-radius: 10px; padding: 1.2rem 1.3rem; margin-bottom: 1.2rem; }
.panel > h3:first-of-type { margin-top: 1.1rem; }
.summary { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: center; justify-content: space-between; }
.summary strong { font: 700 1.5rem var(--serif); }
.scan { width: 100%; }
.scan label { display: block; font-size: .95rem; color: var(--muted); }
progress { width: 100%; height: 8px; accent-color: var(--accent); }
.import { max-width: 46rem; }
.steps { padding-left: 1.3rem; margin: .4rem 0 1rem; }
.import label[for="paste"] { display: block; margin-top: 1rem; }

input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; background: var(--ground); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: .55rem .7rem; font: 400 1rem var(--sans);
}
textarea { resize: vertical; margin: .3rem 0 .8rem; font-size: .95rem; }
::placeholder { color: #A79DAD; }
input[type=file] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.filebtn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.btn {
  display: inline-block; background: var(--raised); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: .5rem .95rem; font: 500 1rem var(--sans); cursor: pointer; text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #231E2B; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { background: none; color: var(--muted); }
.btn.small { padding: .3rem .65rem; font-size: .95rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link {
  background: none; border: 0; padding: 0; color: var(--accent); font: inherit;
  text-decoration: underline; cursor: pointer; text-align: left;
}
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.stack { display: grid; gap: .5rem; margin-top: .8rem; }
.meta { color: var(--muted); font-size: .92rem; }
.error { color: var(--warn); }
.empty { color: var(--muted); padding: 1.6rem 0; max-width: 34rem; }
.notice { background: var(--raised); border-left: 3px solid var(--warn); padding: .5rem .8rem; border-radius: 0 6px 6px 0; }

.tag {
  display: inline-block; padding: .05rem .45rem; border-radius: 4px; font-size: .85rem;
  background: var(--raised); color: var(--muted); white-space: nowrap;
}
.tag.own { color: var(--good); background: #2F4238; }
.pip {
  display: inline-grid; place-items: center; width: 1.25em; height: 1.25em; border-radius: 50%;
  background: var(--pip); color: #231E2B; font: 700 .72rem var(--sans);
}

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .9rem; margin-top: .9rem; }
.choice {
  position: relative; padding: 0; background: none; border: 0; color: var(--text); cursor: pointer; text-align: left;
  font: 500 1rem var(--sans);
}
.choice img { border-radius: 4.5% / 3.2%; margin-bottom: .3rem; }
.choice:hover img { outline: 2px solid var(--accent); outline-offset: 1px; }
.choice-name { display: block; }
.choice-pips { display: flex; gap: 2px; }

.decklist { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.decklist li { display: flex; flex-wrap: wrap; gap: .1rem .8rem; align-items: baseline; }
.precons { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .4rem; }
.precons button {
  width: 100%; height: 100%; text-align: left; background: var(--raised); color: var(--text); border: 1px solid transparent;
  border-radius: 6px; padding: .45rem .7rem; cursor: pointer; font: 400 .95rem/1.3 var(--sans);
}
.precons button:hover { border-color: var(--accent); }
.precons strong { display: block; font: 700 1.05rem var(--serif); }
.precons span { color: var(--muted); }

.bench { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 1.2rem; align-items: start; margin-top: 1rem; }
.deck { margin: 0; }
.commander-art { display: flex; gap: .5rem; margin-bottom: .7rem; }
.commander-art button { flex: 1; min-width: 0; background: none; border: 0; padding: 0; cursor: pointer; }
.commander-art img { border-radius: 4.5% / 3.2%; }
.stub { display: grid; place-items: center; aspect-ratio: 488 / 680; background: var(--raised); color: var(--muted); padding: .5rem; border-radius: 8px; font: 500 .9rem var(--sans); text-align: center; }
input.deckname { font: 700 1.3rem var(--serif); background: transparent; border-color: transparent; padding: .1rem .2rem; margin-left: -.2rem; }
input.deckname:hover { border-color: var(--line); }
.count { margin: .2rem 0; }
.count strong { font: 700 1.2rem var(--serif); }
.count.off strong { color: var(--warn); }
.check { display: flex; gap: .4rem; align-items: center; font-size: .98rem; }
.draft { width: 100%; margin-top: .7rem; }
.inline { margin-top: .7rem; }
.inline label { font-size: .95rem; color: var(--muted); }
.inline .row { margin-top: .15rem; flex-wrap: nowrap; }
.deck h3 { font-size: 1.05rem; margin: 1.1rem 0 .15rem; }
.cards { list-style: none; margin: 0; padding: 0; }
.cards li { display: flex; align-items: baseline; }
.cardname {
  flex: 1; min-width: 0; background: none; border: 0; padding: .1rem 0; color: var(--text); text-align: left;
  font: 400 1rem/1.3 var(--sans); cursor: pointer;
}
.cardname:hover { color: var(--accent); }
.cardname.unowned { color: var(--muted); font-style: italic; }
.x { background: none; border: 0; color: var(--muted); font-size: 1.15rem; line-height: 1; padding: .1rem .35rem; cursor: pointer; }
.x:hover { color: var(--warn); }
.deck-foot { margin-top: 1rem; }

.work { min-width: 0; }
.tabs { display: flex; gap: 1.3rem; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button {
  background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); white-space: nowrap;
  font: 700 1.15rem var(--serif); padding: .35rem 0 .45rem; cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected=true] { color: var(--text); border-color: var(--accent); }
.tabbody { padding-top: 1rem; }
.flavor { font: italic 400 1.1rem/1.5 var(--serif); color: var(--muted); max-width: 44rem; margin-top: 0; }
.sources { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; margin-top: 1.6rem; font-size: .95rem; }

.swaphead { display: flex; flex-wrap: wrap; gap: .7rem 1.4rem; align-items: end; margin-bottom: .6rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { background: none; border: 0; color: var(--muted); font: 500 1rem var(--sans); padding: .42rem .8rem; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--raised); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: .6rem 1rem; }
.controls label { display: grid; gap: .1rem; font-size: .92rem; color: var(--muted); min-width: 170px; }
.summaryline { display: flex; flex-wrap: wrap; gap: .1rem 1rem; }

/* The swap row is the centre of the tool: the old card gives way to the new one. */
.swaps { list-style: none; margin: .8rem 0 0; padding: 0; display: grid; gap: .9rem; }
.swap {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: .6rem 1.2rem; align-items: center;
  background: var(--panel); border-radius: 10px; padding: .8rem 1rem;
}
.swap-side { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: .9rem; align-items: center; transition: transform .24s ease, opacity .24s ease; }
.swap-side h4 { overflow-wrap: anywhere; }
.swap-card { padding: 0; background: none; border: 0; cursor: pointer; }
.swap-card img, .swap-card .stub { border-radius: 4.5% / 3.2%; transform: rotate(-1.5deg); }
.swap .in .swap-card img, .swap .in .swap-card .stub { transform: rotate(1.5deg); box-shadow: 0 0 0 2px var(--accent); }
.swap .out .swap-card img { filter: saturate(.55) brightness(.85); }
.swap.applied .out { transform: translateX(-16px); opacity: 0; }
.swap.applied .in { transform: translateX(-24px); }
.swap .link { font-size: .92rem; display: block; margin-top: .2rem; }
.history { padding-left: 1.1rem; margin: .3rem 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 1rem .9rem; }
.tile { display: flex; flex-direction: column; min-width: 0; }
.tile-img { padding: 0; background: none; border: 0; cursor: pointer; margin-bottom: .3rem; }
.tile-img img { border-radius: 4.5% / 3.2%; }
.tile h4 { font: 500 1rem/1.25 var(--sans); overflow-wrap: anywhere; }
.tile .meta { font-size: .85rem; line-height: 1.25; margin: .1rem 0 .3rem; }
.tile-foot { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; justify-content: space-between; margin-top: auto; }

.curve { margin: 0 0 1.2rem; max-width: 34rem; }
.curve figcaption { font-size: .95rem; color: var(--muted); margin-bottom: .4rem; }
.bars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; height: 150px; }
.bar { display: flex; flex-direction: column; min-width: 0; }
.bar .col { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar i { display: block; width: min(70%, 34px); background: var(--accent); border-radius: 4px 4px 0 0; }
.bar .v { font-size: .85rem; color: var(--muted); line-height: 1.3; }
.bar .k { text-align: center; font-size: .88rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: .15rem; }
.checks { list-style: none; margin: 1rem 0; padding: 0; display: grid; gap: .3rem; max-width: 46rem; }
.checks li { padding: .55rem 0; border-top: 1px solid var(--line); }
.check-head { display: flex; flex-wrap: wrap; gap: .1rem 1rem; align-items: baseline; }
.check-head h4 { min-width: 7rem; }
.check-num strong { font: 700 1.15rem var(--serif); }
.fix { margin: .2rem 0 0; }
.combos { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; max-width: 50rem; }
.combos p { margin: 0; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.3rem; max-width: min(640px, calc(100vw - 32px)); width: 100%;
}
dialog::backdrop { background: rgba(20, 16, 26, .72); }
.carddetail { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 1.2rem; }
.carddetail img { border-radius: 4.5% / 3.2%; }
.copybox { font-size: .9rem; }

#preview { position: fixed; z-index: 20; width: 280px; border-radius: 14px; pointer-events: none; box-shadow: 0 10px 34px rgba(0, 0, 0, .55); }
#preview[hidden] { display: none; }
#toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translate(-50%, 1rem); z-index: 30;
  max-width: calc(100vw - 32px); background: var(--text); color: #231E2B; border-radius: 6px; padding: .5rem 1rem;
  font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 960px) {
  .bench { grid-template-columns: minmax(0, 1fr); }
  .deck { order: 2; }
  .work { order: 1; }
  .commander-art { max-width: 180px; }
}
@media (max-width: 640px) {
  .swap { grid-template-columns: minmax(0, 1fr); }
  .swap-side { grid-template-columns: 88px minmax(0, 1fr); }
  .swap-go .btn { width: 100%; }
  .swap-go { order: 3; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .carddetail { grid-template-columns: minmax(0, 1fr); }
  .carddetail img { max-width: 220px; }
  .panel { padding: 1rem; }
  .controls label { min-width: 0; flex: 1 1 140px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
