:root {
  --bg: #f4f1ea; --panel: #fffdf8; --panel-2: #efeadf; --ink: #1d1b17; --muted: #6b655a; --line: #ddd5c4;
  --accent: #9b7420; --accent-ink: #fff; --ok: #2f7a4b; --warn: #b4651b; --bad: #b23a3a;
  --W: #f3ecd2; --U: #9cc7e8; --B: #a59c98; --R: #ef9a7f; --G: #9fcf9b; --C: #cfcac2;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418; --panel: #1a1d23; --panel-2: #22262e; --ink: #ece7dc; --muted: #9a9486; --line: #2f343d;
    --accent: #d2ab55; --accent-ink: #15130e; --ok: #6cc28d; --warn: #e3a35d; --bad: #e57373;
    --W: #e9e1c4; --U: #6fa9d6; --B: #8a817c; --R: #e07b5f; --G: #77b874; --C: #a9a39a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121418; --panel: #1a1d23; --panel-2: #22262e; --ink: #ece7dc; --muted: #9a9486; --line: #2f343d;
  --accent: #d2ab55; --accent-ink: #15130e; --ok: #6cc28d; --warn: #e3a35d; --bad: #e57373; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: var(--panel); padding: 6px 10px; z-index: 50; }
h1, h2, h3 { font-family: ui-serif, Georgia, "Iowan Old Style", serif; font-weight: 600; letter-spacing: -.01em; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }

/* header */
.top { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font: 600 1.15rem ui-serif, Georgia, serif; color: var(--ink); text-decoration: none; }
.brand-mark { width: 14px; height: 20px; border-radius: 3px; background: var(--accent); box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--accent) 60%, #000); }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--panel-2); }
.owner-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--panel); margin-left: auto; }
.owner-switch button { border: 0; background: none; padding: 4px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.owner-switch button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.pill { font-size: .78rem; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); }

main { max-width: 1400px; margin: 0 auto; padding: 18px 16px 40px; outline: none; }
.foot { max-width: 1400px; margin: 0 auto; padding: 0 16px 30px; color: var(--muted); font-size: .8rem; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* controls */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; }
.toolbar input[type=search], .toolbar select, .field { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.toolbar input[type=search] { flex: 1 1 220px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--ink); display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.sm { padding: 3px 8px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.chips { display: inline-flex; gap: 4px; }
.chip { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; font-weight: 700; font-size: .75rem; color: #222; }
.chip[aria-pressed="true"] { border-color: var(--ink); }
.chip[data-c=W] { background: var(--W); } .chip[data-c=U] { background: var(--U); } .chip[data-c=B] { background: var(--B); }
.chip[data-c=R] { background: var(--R); } .chip[data-c=G] { background: var(--G); } .chip[data-c=C] { background: var(--C); } .chip[data-c=M] { background: linear-gradient(135deg, var(--W), var(--U), var(--B), var(--R), var(--G)); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 0 0 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font: 600 1.35rem ui-serif, Georgia, serif; }
.stat span { color: var(--muted); font-size: .8rem; }

/* card grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.grid.dense { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.tile { position: relative; display: block; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.art { aspect-ratio: 488 / 680; border-radius: 4.75% / 3.5%; overflow: hidden; background: var(--panel-2); box-shadow: var(--shadow); transition: transform .12s; }
.tile:hover .art, .tile:focus-visible .art { transform: translateY(-3px); }
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.textcard { height: 100%; padding: 9px; display: flex; flex-direction: column; gap: 6px; border: 6px solid #222; border-radius: inherit; background: var(--panel); font-size: .78rem; }
.textcard .tc-name { font-weight: 700; font-size: .82rem; display: flex; justify-content: space-between; gap: 4px; }
.textcard .tc-type { color: var(--muted); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 2px 0; }
.textcard .tc-text { overflow: hidden; flex: 1; }
.textcard.token { border-color: #6d5d3a; }
.qty { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.78); color: #fff; font-weight: 700; font-size: .78rem; padding: 2px 7px; border-radius: 999px; }
.flag { position: absolute; top: 6px; left: 6px; display: flex; gap: 3px; }
.flag span { font-size: .68rem; background: rgba(0,0,0,.72); color: #fff; padding: 2px 6px; border-radius: 999px; }
.flag .foil { background: linear-gradient(120deg, #c46bd8, #5bb6e9, #8fe08a, #f1d05c); color: #111; }
.cap { padding: 6px 2px 0; font-size: .82rem; line-height: 1.25; }
.cap b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cap small { color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }
.ev-checked { background: var(--ok); } .ev-decklist { background: #5b8fd6; } .ev-photo { background: var(--warn); } .ev-unverified { background: var(--bad); }

/* mana symbols */
.ms { display: inline-grid; place-items: center; width: 1.15em; height: 1.15em; border-radius: 50%; font: 700 .7em/1 ui-sans-serif, system-ui; color: #1a1a1a; background: var(--C); margin: 0 1px; vertical-align: -.12em; box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.ms-W { background: var(--W); } .ms-U { background: var(--U); } .ms-B { background: var(--B); } .ms-R { background: var(--R); } .ms-G { background: var(--G); }
.ms-hy { background: linear-gradient(135deg, var(--h1) 50%, var(--h2) 50%); }

/* drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--panel); border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(0,0,0,.2); transform: translateX(105%); transition: transform .2s ease; z-index: 40; overflow-y: auto; padding: 18px; }
.drawer.open { transform: none; }
.drawer-close { position: sticky; top: 0; float: right; border: 0; background: var(--panel-2); border-radius: 50%; width: 32px; height: 32px; font-size: 20px; cursor: pointer; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
.detail-img { width: 100%; max-width: 360px; margin: 0 auto 12px; display: block; border-radius: 4.75% / 3.5%; box-shadow: var(--shadow); }
.detail-img .textcard { aspect-ratio: 488/680; }
.oracle { white-space: pre-wrap; background: var(--panel-2); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 10px 0; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.rowlist { list-style: none; padding: 0; margin: 6px 0; font-size: .88rem; }
.rowlist li { padding: 6px 0; border-top: 1px solid var(--line); }

/* decks */
.deck-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 26px; }
.deck-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.deck-card:hover { border-color: var(--accent); }
.deck-card .hero { display: flex; gap: 6px; height: 92px; overflow: hidden; }
.deck-card .hero .art { width: 66px; flex: none; box-shadow: none; }
.tag { display: inline-block; font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); margin-right: 4px; }
.tag.built { color: var(--ok); } .tag.sealed { color: #5b8fd6; } .tag.draft { color: var(--warn); }
.curve { display: flex; align-items: flex-end; gap: 4px; height: 70px; padding-top: 4px; }
.curve div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; position: relative; min-height: 2px; }
.curve div::after { content: attr(data-n); position: absolute; top: -16px; width: 100%; text-align: center; font-size: .7rem; color: var(--muted); }
.curve-x { display: flex; gap: 4px; font-size: .7rem; color: var(--muted); } .curve-x span { flex: 1; text-align: center; }
.deck-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 22px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.panel + .panel { margin-top: 12px; }
.group-h { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: grid; grid-template-columns: 2.2em minmax(0,1fr) auto; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.lines li .nm { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lines li .nm:hover { color: var(--accent); }
.short { color: var(--warn); font-size: .8rem; } .okc { color: var(--ok); font-size: .8rem; }
.potential { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.pot { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; } .bar i { display: block; height: 100%; background: var(--accent); }
.spec { margin-top: 26px; }
.md table { border-collapse: collapse; width: 100%; font-size: .88rem; margin: 8px 0 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--panel-2); } .md code { background: var(--panel-2); padding: 0 4px; border-radius: 4px; }
.md h1 { font-size: 1.3rem; } .md h2 { font-size: 1.1rem; margin-top: 1.2em; } .md h3 { font-size: 1rem; margin-top: 1em; }

/* builder */
.builder { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 18px; align-items: start; }
.pool { max-height: 72vh; overflow-y: auto; }
.prow { display: grid; grid-template-columns: 40px minmax(0,1fr) auto auto; gap: 8px; align-items: center; padding: 5px 4px; border-bottom: 1px solid var(--line); }
.prow .thumb { width: 40px; aspect-ratio: 488/680; border-radius: 3px; overflow: hidden; background: var(--panel-2); cursor: pointer; }
.prow .thumb img { width: 100%; height: 100%; object-fit: cover; }
.prow .meta { min-width: 0; } .prow .meta b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; font-size: .9rem; }
.prow .meta small { color: var(--muted); }
.avail { font-size: .8rem; color: var(--muted); min-width: 3.5em; text-align: right; }
.stepper { display: inline-flex; align-items: center; gap: 2px; }
.stepper button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.stepper button:hover:not(:disabled) { border-color: var(--accent); }
.stepper b { min-width: 1.6em; text-align: center; }
.sticky { position: sticky; top: 70px; }
textarea.field { width: 100%; min-height: 110px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 60; font-size: .9rem; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .85rem; color: var(--muted); }
.prose { max-width: 760px; } .prose li { margin: 4px 0; }

@media (max-width: 900px) {
  .deck-layout, .builder { grid-template-columns: 1fr; }
  .sticky { position: static; }
  .owner-switch { margin-left: 0; }
  .pool { max-height: none; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
  .tabs a { padding: 6px 7px; }
}
