:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --fg: #1c2030;
  --muted: #6b7385;
  --line: #e3e7f0;
  --head-bg: #f0f2f8;
  --zebra: #fafbfe;
  --chip-bg: #f6f8fc;
  --chip-line: #cdd5e4;
  --chip-hover: #e8eefc;
  --warn-bg: #fff6dd;
  --accent: #3b5bd9;
  --btn-bg: linear-gradient(135deg, #3b5bd9, #2b4a8b);
  --btn-fg: #ffffff;
  --shadow: 0 1px 3px rgba(20, 28, 55, .07), 0 8px 24px rgba(20, 28, 55, .06);
  --rd: #3f7fc4;   /* Rolling Dice brand-ish */
  --ks: #c94a4a;   /* Kindleshop brand-ish */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --panel: #171a23;
    --fg: #e8eaf2;
    --muted: #98a0b6;
    --line: #272c3b;
    --head-bg: #1d212e;
    --zebra: #1a1e29;
    --chip-bg: #1e2432;
    --chip-line: #39415a;
    --chip-hover: #2a3350;
    --warn-bg: #38311d;
    --accent: #8ab0ff;
    --btn-bg: linear-gradient(135deg, #4b6ce0, #34549c);
    --btn-fg: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
    --rd: #5f9bd9;
    --ks: #e07070;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  margin: 0; background: var(--bg); color: var(--fg); line-height: 1.5;
}
main, header, footer { max-width: 920px; margin: 0 auto; padding: 0 1rem; }
a { color: var(--accent); }

/* Header with WUBRG accent line */
header { padding-top: 1.6rem; }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand svg { flex: none; }
header h1 {
  font-family: "Space Grotesk", -apple-system, sans-serif;
  font-size: 1.65rem; margin: 0; letter-spacing: -.01em;
}
.tag { color: var(--muted); margin: .3rem 0 0; font-size: .92rem; }
.wubrg {
  height: 4px; border: 0; border-radius: 2px; margin: 1rem 0 1.4rem;
  background: linear-gradient(90deg, #e8dfa8, #4a90c9, #4a4453, #d3564a, #4e9b6b);
  opacity: .85;
}

/* Input panel */
.input-area {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 1rem; box-shadow: var(--shadow);
}
textarea {
  width: 100%; min-height: 11.5rem;
  font: .88rem/1.45 ui-monospace, "SF Mono", Menlo, monospace;
  padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--fg); resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea.dragover { outline: 2px dashed var(--accent); }
.controls { display: flex; align-items: center; gap: 1rem; margin-top: .7rem; flex-wrap: wrap; }
button#generate {
  background: var(--btn-bg); color: var(--btn-fg); border: 0; border-radius: 10px;
  padding: .6rem 1.6rem; font-size: .95rem; font-weight: 650; cursor: pointer;
  box-shadow: var(--shadow);
}
button#generate:hover { filter: brightness(1.08); }
button#generate:disabled { opacity: .55; cursor: wait; }
.rate { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: .35rem; }
.rate input {
  width: 5.4rem; padding: .35rem .45rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--fg); font-size: .85rem;
}
.linkish {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: .85rem; padding: 0; text-decoration: underline; text-underline-offset: 2px;
}
.hint { font-size: .78rem; color: var(--muted); margin: .55rem 0 0; }
.status { margin-top: .6rem; font-size: .85rem; color: var(--muted); }
.status.error { color: #d05045; }

/* Result */
#result { margin-top: 1.5rem; }
.summary-bar {
  display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; margin-bottom: .6rem;
}
.summary { font-size: .92rem; color: var(--muted); margin-right: auto; }
.summary b { color: var(--fg); }
.toolbtn {
  background: var(--chip-bg); color: var(--fg); border: 1px solid var(--chip-line);
  border-radius: 8px; padding: .35rem .8rem; font-size: .8rem; cursor: pointer;
}
.toolbtn:hover { background: var(--chip-hover); }

.table-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
}
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:nth-child(even) { background: var(--zebra); }
tbody tr:last-child td { border-bottom: none; }
th { background: var(--head-bg); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.missing { background: var(--warn-bg) !important; }
tfoot td { font-weight: 650; border-top: 2px solid var(--line); background: var(--head-bg); }

/* Card cell */
.cardcell { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.buy { width: 17px; height: 17px; flex: none; margin: 0; accent-color: var(--accent); cursor: pointer; }
tr.bought { opacity: .5; }
tr.bought .nm { text-decoration: line-through; text-decoration-thickness: 1.5px; }
.thumb {
  flex: none; width: 42px; height: 58px; border-radius: 4px; overflow: visible;
  position: relative; background: var(--head-bg);
}
.thumb img {
  width: 42px; height: 58px; object-fit: cover; border-radius: 4px; display: block;
  transition: transform .12s ease; transform-origin: left center;
}
@media (hover: hover) {
  .thumb:hover img { transform: scale(3.4); z-index: 40; position: relative;
    box-shadow: 0 6px 24px rgba(0,0,0,.45); border-radius: 6px; }
}
.cardmain { min-width: 0; }
.cardname { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.cardname a { color: var(--fg); text-decoration: none; font-weight: 600; }
.cardname a:hover { color: var(--accent); text-decoration: underline; }
.qty { color: var(--muted); font-weight: 650; }
.cardsub { font-size: .74rem; color: var(--muted); margin-top: .1rem; letter-spacing: .02em; }
small.nf { color: var(--muted); }

/* Color identity pips */
.pips { display: inline-flex; gap: 3px; }
.pip {
  width: 11px; height: 11px; border-radius: 50%; display: inline-block;
  border: 1px solid rgba(0,0,0,.25);
}
.pip.W { background: #f4eece; } .pip.U { background: #3179bd; }
.pip.B { background: #40353f; } .pip.R { background: #d3564a; }
.pip.G { background: #37835a; } .pip.C { background: #b9bec9; border-radius: 3px; }

/* Game Changer badge */
.gc {
  font-size: .62rem; font-weight: 700; letter-spacing: .04em; color: #fff;
  background: linear-gradient(135deg, #b0872f, #8a621c); border-radius: 4px;
  padding: .08rem .3rem; cursor: help;
}

/* Shop chips */
a.shop {
  display: inline-block; margin: .12rem .35rem .12rem 0; padding: .26rem .7rem;
  border: 1px solid var(--chip-line); border-radius: 999px; text-decoration: none;
  font-size: .8rem; color: var(--fg); background: var(--chip-bg); white-space: nowrap;
}
a.shop::before { content: "●"; font-size: .6rem; vertical-align: 1px; margin-right: .35rem; }
a.shop[data-shop="Rolling Dice"]::before { color: var(--rd); }
a.shop[data-shop="Kindleshop"]::before { color: var(--ks); }
a.shop:hover { background: var(--chip-hover); border-color: var(--accent); }

footer { margin-top: 2.2rem; padding-bottom: 2rem; }
footer .inner { border-top: 1px solid var(--line); padding-top: 1rem; }
footer p { font-size: .72rem; color: var(--muted); margin: .35rem 0; }

/* Phone layout */
@media (max-width: 640px) {
  header { padding-top: 1.1rem; }
  thead { display: none; }
  table, tbody, tfoot, tr, td { display: block; }
  tr { padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
  tbody tr:nth-child(even) { background: none; }
  td { border: none; padding: .12rem 0; }
  td.num { display: inline-block; margin-right: 1rem; }
  td.num::before { content: attr(data-label) " "; color: var(--muted); font-size: .72rem; }
  tfoot tr { border-bottom: none; border-top: 2px solid var(--line); background: var(--head-bg); }
  .thumb:active img { transform: scale(3.2); z-index: 40; position: relative; }
}
