:root {
  --bg: #0f1117; --bg-2: #161b24; --surface: #1a2130; --surface-2: #222b3c; --border: #2a3242;
  --text: #e7eaf1; --text-muted: #8b93a7; --accent: #9d7bfe; --accent-2: #b9a0ff;
  --good: #4ade80; --bad: #eb5757;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

header { border-bottom: 1px solid var(--border); background: var(--bg-2); }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1.25rem; }
h1 { font-size: 1.2rem; font-weight: 750; }
h1::before { content: "🗃️ "; }
.hbtns { display: flex; gap: .5rem; }

.btn { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: .5rem .9rem; transition: all .15s; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #12131a; border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: .35rem .7rem; font-size: .82rem; }
.btn.block { width: 100%; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }

.app { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--border); padding: 1rem; display: flex; flex-direction: column; gap: .6rem; background: var(--bg-2); overflow-y: auto; }
.search { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: .45rem .7rem; font: inherit; font-size: .85rem; }
.search:focus, textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent); }
.sidebar-controls { display: flex; gap: .4rem; }
.mini-select { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: .35rem .4rem; font: inherit; font-size: .78rem; cursor: pointer; }
.mini-select:focus { outline: none; border-color: var(--accent); }
.deck-list { display: flex; flex-direction: column; gap: .3rem; }
.deck-item { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; cursor: pointer; }
.deck-item:hover { border-color: var(--accent); }
.deck-item.active { border-color: var(--accent); background: var(--surface-2); }
.deck-item .di-name { font-weight: 600; font-size: .9rem; }
.deck-item .di-sub { font-size: .72rem; color: var(--text-muted); margin-top: .1rem; }

.editor { padding: 1.25rem; overflow-y: auto; }
.empty { text-align: center; color: var(--text); padding: 4rem 1rem; }
.empty .muted { margin-top: .5rem; }
.muted { color: var(--text-muted); }

.deck-head { margin-bottom: 1rem; }
.deck-name { width: 100%; background: transparent; border: none; color: var(--text); font-size: 1.5rem; font-weight: 750; padding: .2rem 0; border-bottom: 1px solid transparent; }
.deck-name:hover, .deck-name:focus { border-bottom-color: var(--border); }
.deck-meta { display: flex; gap: .6rem; align-items: center; margin-top: .5rem; }
.fmt { flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: .35rem .6rem; font: inherit; font-size: .82rem; }

.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .app { grid-template-columns: 1fr; } .sidebar { border-right: none; border-bottom: 1px solid var(--border); } .panes { grid-template-columns: 1fr; } }
.pane { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; flex-wrap: wrap; }
.pane-head h2 { font-size: 1rem; }
#paste-hint { font-size: .7rem; }
.url-import { display: flex; gap: .4rem; margin-bottom: .5rem; }
.url-in { flex: 1; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: .45rem .6rem; font: inherit; font-size: .82rem; }
.url-in:focus { outline: none; border-color: var(--accent); }
textarea { width: 100%; height: 300px; resize: vertical; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: .7rem; font: 13px/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.status { font-size: .8rem; margin-top: .5rem; min-height: 1.1em; }

.copy-row { display: flex; gap: .4rem; }
.fmt-select { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 7px; padding: .3rem .5rem; font: inherit; font-size: .8rem; }
.warnings { background: rgba(235,87,87,.1); border: 1px solid var(--bad); color: #ffb3b3; border-radius: 8px; padding: .5rem .7rem; margin-bottom: .6rem; font-size: .82rem; }
.miss-list { list-style: none; margin: .35rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.miss-list li { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.fix-btn { font: inherit; font-size: .78rem; cursor: pointer; background: var(--surface-2); color: var(--accent-2); border: 1px solid var(--accent); border-radius: 20px; padding: .1rem .55rem; }
.fix-btn:hover { background: var(--accent); color: #12131a; }
.card-grid { display: flex; flex-direction: column; gap: .25rem; max-height: 420px; overflow-y: auto; }
.card-row { display: grid; grid-template-columns: 30px 34px 1fr auto; gap: .5rem; align-items: center; padding: .2rem .3rem; border-radius: 6px; }
.card-row:hover { background: var(--bg-2); }
.card-row .cc { color: var(--text-muted); font-variant-numeric: tabular-nums; text-align: right; font-size: .85rem; }
.card-row img { width: 34px; height: 47px; object-fit: cover; border-radius: 3px; background: var(--bg-2); }
.card-row .cn { font-size: .85rem; }
.card-row .cset { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; font-variant-numeric: tabular-nums; }
.card-row.missing .cn { color: var(--bad); }
.cset-btn { cursor: pointer; border-radius: 5px; padding: .05rem .25rem; transition: background .12s, color .12s; }
.cset-btn:hover { background: var(--accent); color: #12131a; }
.cset.pinned { color: var(--accent-2); }

/* Printing picker modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 80; padding: 1rem; }
.modal[hidden] { display: none; } /* class+attr beats the bare .modal rule so `hidden` actually hides */
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: min(720px, 100%); max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .9rem 1rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 1rem; }
.modal-actions { display: flex; gap: .4rem; }
.print-grid { padding: 1rem; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.print-opt { display: flex; flex-direction: column; align-items: center; gap: .25rem; text-align: center; cursor: pointer; background: var(--bg-2); border: 1px solid var(--border); border-radius: 9px; padding: .5rem; color: var(--text); font: inherit; }
.print-opt:hover { border-color: var(--accent); }
.print-opt img, .po-noimg { width: 96px; height: 134px; object-fit: cover; border-radius: 5px; background: var(--surface-2); }
.po-set { font-size: .8rem; font-weight: 650; }
.po-name { font-size: .68rem; }
.po-price { font-size: .72rem; }

/* Deck stats (feature 1) */
#stats, #tokens { margin-top: 1rem; }
.val { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .7rem; }
.val-row { font-size: .8rem; padding: .4rem .65rem; border-radius: 7px; }
.val-row.bad { background: rgba(235,87,87,.1); border: 1px solid var(--bad); color: #ffb3b3; }
.val-row.ok { background: rgba(74,222,128,.08); border: 1px solid rgba(74,222,128,.4); color: #a6f0c2; }
.stats-grid { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: .8rem; }
@media (max-width: 760px) { .stats-grid { grid-template-columns: 1fr; } }
.stat-block { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; }
.sb-title { font-size: .8rem; font-weight: 650; margin-bottom: .55rem; }
.sb-title .muted { font-weight: 400; }
.curve { display: flex; align-items: flex-end; gap: .3rem; height: 92px; }
.cv-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: .12rem; height: 100%; }
.cv-bar { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
.cv-n { font-size: .62rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.cv-x { font-size: .68rem; color: var(--text-muted); }
.kvs { display: flex; flex-direction: column; gap: .22rem; }
.kv { display: flex; justify-content: space-between; font-size: .82rem; }
.kv span:last-child { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pips { display: flex; flex-wrap: wrap; gap: .35rem; }
.pip { font-size: .78rem; font-weight: 650; padding: .15rem .5rem; border-radius: 20px; font-variant-numeric: tabular-nums; }
.pip-W { background: #f8f6d8; color: #23200f; }
.pip-U { background: #a9e0fa; color: #062430; }
.pip-B { background: #b7aca8; color: #201a19; }
.pip-R { background: #f6a58c; color: #340f06; }
.pip-G { background: #9ad3ac; color: #0a2413; }
.pip-C { background: #c9c4c0; color: #23201d; }

/* Tokens & emblems (feature 2) */
.tok-hint { font-size: .74rem; margin-bottom: .55rem; }
.tok-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.tok { background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: .2rem .6rem; font-size: .8rem; }

/* Card hover preview */
#card-preview { position: fixed; width: 230px; border-radius: 11px; box-shadow: 0 12px 32px rgba(0,0,0,.55); pointer-events: none; z-index: 60; }
.card-row[data-img] { cursor: help; }

.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--accent); color: var(--text); padding: .6rem 1.1rem; border-radius: 8px; font-size: .9rem; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.4); }

footer { border-top: 1px solid var(--border); padding: 1rem 1.25rem; text-align: center; color: var(--text-muted); font-size: .78rem; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }
