/* ManaVault — single stylesheet, no framework. Dark theme by default, light theme follows the OS. */
:root {
  --bg: #13151a;
  --bg2: #1b1e25;
  --panel: #20242d;
  --line: #2f3440;
  --text: #e7e9ee;
  --muted: #9aa1ae;
  --accent: #d8a24a;
  --accent2: #6aa7ff;
  --danger: #e5645a;
  --ok: #54b87a;
  --r-common: #c9ccd3;
  --r-uncommon: #8fb3cf;
  --r-rare: #e0b43c;
  --r-mythic: #f0662b;
  --r-special: #b278f5;
  --foil: #c9a4ff;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f2ee; --bg2: #ebe8e2; --panel: #ffffff; --line: #d9d4ca; --text: #1d1f24; --muted: #686d78;
    --accent: #a8741a; --accent2: #2f6fd6; --r-common: #333; --r-uncommon: #5b7c95; --r-rare: #b88a12;
    --shadow: 0 2px 8px rgba(0, 0, 0, .12); --foil: #7b3fd0; color-scheme: light;
  }
}
* { box-sizing: border-box; }
/* `display` rules below would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2em 0 .4em; }
h2 { font-size: 1.2rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1rem; margin: 1em 0 .4em; }
main { max-width: 1500px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.hint { color: var(--muted); font-size: .85em; font-weight: normal; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; }

/* ---------- top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 8px 16px;
  background: var(--bg2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.mainnav a:hover, .mainnav a.active { color: var(--text); background: var(--panel); text-decoration: none; }
.quicksearch { flex: 1; min-width: 160px; max-width: 380px; margin-left: auto; }
.quicksearch input { width: 100%; }
.count-badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; font-size: .75em; font-weight: 700; }
.usermenu { display: flex; gap: 10px; align-items: center; font-size: .9em; }
.usermenu a { color: var(--text); }
.usermenu a.active { color: var(--accent); }
.usermenu form { margin: 0; }
.auth-box { max-width: 420px; margin: 40px auto; }
.recovery-codes { columns: 2; font-size: 1.1em; }
.two-factor-setup { max-width: 560px; }
.qr svg { width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: 8px; }
.secret { word-break: break-all; }
.user-actions summary { cursor: pointer; color: var(--accent2); }
.inline-form { display: flex; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.panel.narrow { max-width: 520px; margin-top: 20px; }
.stack-form { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.currency { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.currency a { padding: 4px 10px; color: var(--muted); }
.currency a.on { background: var(--accent); color: #111; font-weight: 700; }
.currency a:hover { text-decoration: none; }
footer { max-width: 1500px; margin: 40px auto 20px; padding: 0 16px; color: var(--muted); font-size: .8rem; }

.banner { padding: 8px 16px; text-align: center; font-size: .9rem; }
.banner.info { background: #1f3a5c; color: #dce9ff; }
.banner.warn { background: #5a4516; color: #fff1cf; }
.banner.viewing { background: #3b2a5c; color: #efe6ff; }
.banner form.inline { display: inline; margin-left: 10px; }
.banner.error { background: #5c2020; color: #ffdede; text-align: left; border-radius: 8px; }
.flash { background: #1f4a31; color: #d9ffe6; padding: 8px 14px; border-radius: 8px; margin-bottom: 12px; }

/* ---------- forms */
input, select, textarea, button { font: inherit; color: var(--text); }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }
input[type=number] { width: 7em; }
input[type=checkbox] { accent-color: var(--accent); }
button, .button { display: inline-block; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px;
  cursor: pointer; color: var(--text); }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #151515; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: none; padding: 0; color: var(--accent2); }
button.danger, .danger { color: var(--danger); }
button.wished { border-color: var(--danger); color: var(--danger); }
label { display: flex; flex-direction: column; gap: 3px; font-size: .9em; }
label.check, label.inline { flex-direction: row; align-items: center; gap: 6px; }
.row { display: flex; gap: 10px; }
.grow { flex: 1; }

/* ---------- filters */
.filters { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 14px; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-bar input[type=search] { min-width: 200px; }
.filter-panel { margin-top: 8px; }
.filter-panel > summary { cursor: pointer; color: var(--muted); padding: 4px 0; user-select: none; }
.filter-panel > summary .count { background: var(--accent); color: #111; border-radius: 10px; padding: 0 7px; font-size: .8em; font-weight: 700; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 8px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 10px; margin: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
fieldset.wide { grid-column: 1 / -1; }
legend { padding: 0 4px; font-weight: 600; font-size: .9em; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checks.effects label { min-width: 150px; }
.treat-group { display: flex; flex-direction: column; gap: 2px; }
.colors { display: flex; gap: 6px; }
.mana-check { position: relative; cursor: pointer; }
.mana-check input { position: absolute; opacity: 0; }
.mana-check img { width: 30px; height: 30px; border-radius: 50%; opacity: .35; transition: opacity .15s, transform .15s; }
.mana-check input:checked + img { opacity: 1; transform: scale(1.1); box-shadow: 0 0 0 2px var(--accent); }
.mana-check input:focus-visible + img { outline: 2px solid var(--accent2); }
.filter-actions { display: flex; gap: 14px; align-items: center; margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-block; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 2px 10px; font-size: .85em; color: var(--text); }
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.kw { border-color: #6b5a2a; }
.chip.fx { border-color: #2a4f6b; }
.criteria { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin-top: 10px; padding: 8px; background: var(--bg2); border-radius: 8px; }

/* autocomplete dropdown */
.suggest-box { position: absolute; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; min-width: 220px; }
.suggest-box div { padding: 5px 10px; cursor: pointer; font-size: .9em; }
.suggest-box div:hover, .suggest-box div.sel { background: var(--bg2); color: var(--accent); }

/* ---------- page heads & stats */
.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 10px 0 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat .label { color: var(--muted); font-size: .8em; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.5rem; font-weight: 700; }
.progress { display: block; height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #f3d27a); }

/* ---------- card grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.tile { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: flex; flex-direction: column; }
.tile.owned { border-color: var(--ok); }
.tile-img { position: relative; display: block; aspect-ratio: 488 / 680; border-radius: 4.75% / 3.5%; overflow: hidden; background: var(--bg2); }
.tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .35s, opacity .35s; backface-visibility: hidden; }
.tile-img .back, .flip-card .back { position: absolute; inset: 0; opacity: 0; transform: rotateY(180deg); }
.tile-img.flipped .front, .flip-card.flipped .front { opacity: 0; transform: rotateY(180deg); }
.tile-img.flipped .back, .flip-card.flipped .back { opacity: 1; transform: none; }
.noimg { display: flex; align-items: center; justify-content: center; height: 100%; padding: 10px; text-align: center; color: var(--muted); }
.flip { position: absolute; top: 38%; right: 12px; border-radius: 50%; width: 34px; height: 34px; padding: 0; font-size: 1.1rem;
  background: rgba(0, 0, 0, .65); color: #fff; border: 1px solid rgba(255, 255, 255, .4); }
.score { background: var(--accent); color: #111; font-weight: 700; font-size: .75rem; padding: 0 8px; border-radius: 10px; }
.tile-meta { padding: 6px 2px 0; font-size: .82rem; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.tile-line { display: flex; justify-content: space-between; gap: 6px; }
.tile-line.sub { margin-top: -3px; }
.set-code { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.price { font-weight: 600; white-space: nowrap; }
.foil-price { color: var(--foil); white-space: nowrap; }
.tile-line.target { font-size: .78rem; color: var(--muted); }
.tile-line.target.reached, .target-status.reached { color: var(--ok); font-weight: 600; }
.target-status { font-size: .9em; }
.target-form { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.target-form input[type=number] { width: 6em; }
.deal-list b { color: var(--ok); }
.shared { display: flex; flex-wrap: wrap; gap: 3px; }
.shared span { background: var(--bg2); border-radius: 8px; padding: 0 6px; font-size: .75rem; color: var(--muted); }
.tile-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 4px; margin-top: auto; padding-top: 4px; }
.tile-actions .spacer { flex: 1; }
.tile-actions button { padding: 2px 8px; font-size: .8rem; }
.quick-add.foil, .quick-remove.foil { color: var(--foil); }
.quick-remove { opacity: .8; }
.owned-badge { background: var(--ok); color: #0c2415; border-radius: 10px; padding: 0 7px; font-size: .78rem; }
.wish-badge { color: var(--danger); }
.rarity-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: baseline; background: var(--r-common); }
.r-uncommon { background: var(--r-uncommon); } .r-rare { background: var(--r-rare); } .r-mythic { background: var(--r-mythic); }
.r-special, .r-bonus { background: var(--r-special); }

.pager { display: flex; gap: 6px; justify-content: center; margin: 20px 0; flex-wrap: wrap; }
.pager a, .pager span { padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); }
.pager .current { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 700; }
.pager .disabled, .pager .gap { color: var(--muted); border-color: transparent; }

/* ---------- card detail */
.card-detail { display: grid; grid-template-columns: minmax(260px, 400px) 1fr; gap: 28px; align-items: start; }
.flip-card { position: relative; border-radius: 4.75% / 3.5%; overflow: hidden; box-shadow: var(--shadow); aspect-ratio: 672 / 936; background: var(--bg2); }
.flip-card img { width: 100%; height: 100%; display: block; transition: transform .45s, opacity .45s; backface-visibility: hidden; }
.flip-btn { width: 100%; margin-top: 8px; }
.ext-links { display: flex; gap: 12px; margin-top: 10px; flex-wrap: wrap; font-size: .9em; }
.card-info h1 { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.subtitle { color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.set-icon { width: 20px; height: 20px; vertical-align: middle; filter: invert(.85); }
@media (prefers-color-scheme: light) { .set-icon { filter: none; } }
.set-icon.big { width: 56px; height: 56px; }
.face { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.face h3 { margin-top: 0; display: flex; gap: 8px; align-items: center; }
.type-line { font-weight: 600; margin: 0 0 6px; }
.oracle { line-height: 1.55; }
.reminder { color: var(--muted); }
.flavor { font-style: italic; color: var(--muted); border-top: 1px solid var(--line); padding-top: 6px; }
.face .pt { text-align: right; margin: 6px 0 0; font-weight: 700; }
img.ms { width: 1.05em; height: 1.05em; vertical-align: -.15em; margin: 0 1px; }
.mana img.ms { width: 1.3em; height: 1.3em; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.badge { background: #3a2f18; color: #f3d27a; border-radius: 6px; padding: 1px 8px; font-size: .8em; }
@media (prefers-color-scheme: light) { .badge { background: #f6e7c1; color: #6d4c07; } }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 10px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.feature-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.feature-row .hint { min-width: 70px; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin: 20px 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.panel.wide { grid-column: 1 / -1; }
.panel h2 { margin-top: 0; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .85em; }
td.num { text-align: right; white-space: nowrap; }
td.qty { white-space: nowrap; }
td.qty form { display: inline; }
td.qty button { padding: 0 8px; }
tr.notes td { color: var(--muted); font-size: .85em; border-bottom: none; }
table.plain td:first-child { color: var(--muted); }
.legal td { padding: 2px 8px; }
table.guide { font-size: .9em; }
table.guide td, table.guide th { padding: 4px 6px; white-space: nowrap; }
.up { color: var(--ok); } .down { color: var(--danger); }
.legal-legal { color: var(--ok); } .legal-restricted { color: var(--accent); } .legal-banned { color: var(--danger); } .legal-not_legal { color: var(--muted); }
.add-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin: 14px 0 8px; }
.add-form input[type=number] { width: 5em; }
.chart { width: 100%; height: auto; max-height: 280px; display: block; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 13px; }
.chart .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .dot { stroke: none; }
.line.s0 { stroke: var(--accent); } .dot.s0, .swatch.s0 { fill: var(--accent); background: var(--accent); }
.line.s1 { stroke: #c9a4ff; } .dot.s1, .swatch.s1 { fill: #c9a4ff; background: #c9a4ff; }
.line.s2 { stroke: var(--accent2); } .dot.s2, .swatch.s2 { fill: var(--accent2); background: var(--accent2); }
.legend { display: flex; gap: 14px; font-size: .85em; color: var(--muted); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

/* ---------- similar */
.similar-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 12px; }
.similar-head img { border-radius: 6px; box-shadow: var(--shadow); }

/* ---------- sets */
.year h2 { display: flex; align-items: baseline; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.set-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.set-card { display: grid; grid-template-columns: 34px 1fr; column-gap: 8px; row-gap: 2px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--text); }
.set-card:hover { border-color: var(--accent); text-decoration: none; }
.set-card.has-owned { border-left: 3px solid var(--ok); }
.set-card .set-icon { grid-row: span 2; width: 28px; height: 28px; }
.set-card .set-name { font-weight: 600; }
.set-card .set-meta { grid-column: 2; color: var(--muted); font-size: .8em; }
.set-card .progress { grid-column: 2; }
.set-head { display: flex; gap: 16px; align-items: center; }
.completion-opts { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.rarity-breakdown { display: flex; gap: 16px; flex-wrap: wrap; font-size: .9em; }
.quick-links { display: flex; gap: 16px; flex-wrap: wrap; }
.set-progress { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.set-progress li { display: grid; grid-template-columns: 1fr 90px 60px; gap: 8px; align-items: center; }
.set-progress li a { display: flex; gap: 6px; align-items: center; }
.top-list { list-style: none; padding: 0; margin: 0; }
.top-list a { display: flex; gap: 10px; align-items: center; padding: 4px 0; color: var(--text); border-bottom: 1px solid var(--line); }
.top-list a span { flex: 1; }
.top-list img { border-radius: 3px; }

/* ---------- collection */
table.collection td.thumb img { border-radius: 3px; display: block; }
.import-form { display: flex; flex-direction: column; gap: 12px; max-width: 700px; }
.errors { max-height: 300px; overflow: auto; color: var(--danger); font-size: .9em; }

/* ---------- home */
.hero { text-align: center; padding: 20px 0 6px; }
.hero-search { display: flex; gap: 8px; max-width: 640px; margin: 0 auto 10px; }
.hero-search input { flex: 1; font-size: 1.1rem; padding: 10px 14px; }
.hero .quick-links { justify-content: center; }

.error-page { max-width: 600px; margin: 60px auto; text-align: center; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line);
  padding: 8px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 100; }
.toast.error { border-color: var(--danger); }

@media (max-width: 760px) {
  .topbar { position: static; padding: 6px 10px; gap: 6px 10px; }
  .mainnav a { padding: 4px 7px; }
  main { padding: 10px; }
  .card-detail { grid-template-columns: 1fr; gap: 14px; }
  .card-visual { max-width: 300px; margin: 0 auto; width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .tile-actions button { padding: 2px 6px; }
  .quicksearch { order: 5; max-width: none; flex-basis: 100%; }
  table.collection th:nth-child(5), table.collection td:nth-child(5), table.collection th:nth-child(6), table.collection td:nth-child(6) { display: none; }
}
