:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1d1c1a;
  --muted: #6b6760;
  --border: #dcd8d0;
  --grid-line: #e8e5df;
  --implicit: #6d7a8c;
  --tag-bg: #e6eef7;
  --tag-text: #2f5a85;
  --accent: #b4441f;
  --accent-text: #ffffff;
  --good: #2f7d3b;
  --bad: #b3261e;
  --ok-bg: #e3f1e4;
  --err-bg: #f9e1df;
  --warn-bg: #fbf0d6;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #201f1d;
    --surface-2: #2a2826;
    --text: #ebe8e3;
    --muted: #a19c94;
    --border: #3a3734;
    --grid-line: #2e2c2a;
    --implicit: #8f9cb0;
    --tag-bg: #1f2b38;
    --tag-text: #9cc0e6;
    --accent: #e0703f;
    --accent-text: #160c06;
    --good: #6cc27a;
    --bad: #f08a80;
    --ok-bg: #1f3322;
    --err-bg: #3d2120;
    --warn-bg: #3a3119;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
.panel h2:first-child { margin-top: 0; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }
.empty { color: var(--muted); padding: 2rem 0; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { padding: .35rem .7rem; border-radius: var(--radius); color: var(--text); }
.topbar nav a.active { background: var(--surface-2); }
.topbar nav a.nav-add { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.topbar nav a:hover { text-decoration: none; }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.page-head { margin-bottom: 1rem; }
.page-head p { margin: .2rem 0; }

/* Meldungen */
.flash { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); }
.flash.err { background: var(--err-bg); }
.flash.warn { background: var(--warn-bg); }

/* Formulare */
input, select, button {
  font: inherit; color: inherit;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: .35rem .6rem;
}
input[type="checkbox"] { min-height: 0; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
select { max-width: 100%; }
button {
  cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  border-color: transparent; font-weight: 600;
}
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 400; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.qty { width: 4.5em; }
label.check { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; }
form.inline { display: inline; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.row .grow { flex: 1 1 220px; }
.row .label { font-weight: 600; min-width: 6.5rem; }

.grid-form {
  display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
.grid-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.grid-form label > input, .grid-form label > select, .grid-form .ac-wrap input { color: var(--text); font-size: 15px; width: 100%; }
.grid-form .wide { grid-column: span 2; }
.grid-form .actions { grid-column: 1 / -1; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}
details.panel > summary { cursor: pointer; font-weight: 600; }
details.panel[open] > summary { margin-bottom: .75rem; }
details.panel form + form { margin-top: 1rem; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input[type="search"] { flex: 1 1 240px; }

/* Tabellen */
table.cards { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.cards th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
table.cards td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.cards tr:last-child td { border-bottom: none; }
.num { white-space: nowrap; }
.qty-col { width: 3rem; font-weight: 600; }
strong.avail { color: var(--good); }
strong.zero { color: var(--muted); }
.pager { display: flex; justify-content: center; gap: 1rem; margin: 1rem 0; }

.badge {
  display: inline-block;
  font-size: .72rem; line-height: 1.5;
  padding: 0 .45rem; margin-left: .25rem;
  border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap; vertical-align: middle;
}
.badge.accent { background: var(--accent); color: var(--accent-text); }

/* Manasymbole */
img.ms { height: 1em; width: 1em; vertical-align: -0.12em; margin: 0 1px; }
.mana { white-space: nowrap; }

/* Kartendetail */
.card-layout { display: grid; grid-template-columns: 280px 1fr; gap: 1.5rem; align-items: start; }
.card-image img { width: 100%; border-radius: 4.5% / 3.2%; display: block; }
.card-info .type { font-weight: 600; margin: .25rem 0 .5rem; }
.oracle { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; }
.stats { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 .5rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .8rem; color: var(--muted); font-size: .85rem; }
.stat strong { display: block; font-size: 1.5rem; color: var(--text); line-height: 1.1; }
.stat.good strong { color: var(--good); }

.stack { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem .75rem; margin-bottom: .5rem; }
.stack-head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.stack-head .version { color: var(--muted); font-size: .9rem; }
.qty-pill { font-weight: 700; min-width: 2.2rem; display: inline-block; }
.stack-actions > summary { cursor: pointer; color: var(--accent); font-size: .85rem; margin-top: .3rem; }
.stack-actions form { margin-top: .6rem; }

/* Ortsansicht */
.location-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.location-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .55rem .75rem; border-bottom: 1px solid var(--border); }
.location-list li:last-child { border-bottom: none; }
.location-list .loc-name { font-weight: 600; margin-right: auto; }
.row-actions { width: 2.5rem; text-align: right; position: relative; }
.row-actions summary { cursor: pointer; list-style: none; padding: .2rem .5rem; border-radius: var(--radius); color: var(--accent); }
.row-actions summary::-webkit-details-marker { display: none; }
.row-actions details[open] summary { background: var(--surface-2); }
.popover {
  position: absolute; right: 0; top: 100%; z-index: 5;
  min-width: min(440px, 90vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / .18);
  padding: .75rem; text-align: left;
  display: grid; gap: .6rem;
}

/* Hinzufügen */
.add-layout { display: grid; grid-template-columns: 1fr 244px; gap: 1rem; align-items: start; }
.add-layout .panel { margin: 0; }
.add-preview { width: 244px; border-radius: 4.5% / 3.2%; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .3rem 0; border-bottom: 1px solid var(--border); }

/* Autovervollständigung */
.ac-wrap { position: relative; display: block; }
.ac-wrap input { width: 100%; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 20;
  list-style: none; margin: 0; padding: .25rem 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / .18);
  max-height: 320px; overflow-y: auto;
}
.ac-list li { padding: .45rem .7rem; cursor: pointer; display: flex; justify-content: space-between; gap: 1rem; color: var(--text); }
.ac-list li small { color: var(--muted); white-space: nowrap; }
.ac-list li.active, .ac-list li:hover { background: var(--surface-2); }

/* Bildvorschau beim Überfahren */
.hover-preview {
  position: fixed; z-index: 50; width: 244px; pointer-events: none;
  border-radius: 4.5% / 3.2%; box-shadow: 0 8px 30px rgb(0 0 0 / .35);
}

.show-sm { display: none; }
.show-sm-inline { display: none; }

@media (max-width: 720px) {
  .card-image img { max-width: 260px; }
  .hide-sm { display: none; }
  .show-sm { display: block; }
  .card-layout { grid-template-columns: 1fr; }
  .card-image img { max-width: 280px; margin: 0 auto; }
  .add-layout { grid-template-columns: 1fr; }
  .add-preview { display: none; }
  .grid-form .wide { grid-column: 1 / -1; }
  .row .label { min-width: 0; width: 100%; }
  .topbar { flex-wrap: wrap; gap: .4rem; }
}

/* --- Übersicht mit Seitenleiste ------------------------------------------ */
main.wide { max-width: 1500px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
/* Listenzeile Name … Wert: lange Namen brechen links um, der Wert bleibt rechts */
.name-value { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.name-value > :first-child { min-width: 0; }
.name-value > :last-child { flex: none; white-space: nowrap; }
button.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); font-weight: 500; }

.with-sidebar { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.with-sidebar.collapsed { grid-template-columns: minmax(0, 1fr); }
.with-sidebar.collapsed .sidebar { display: none; }
.sidebar {
  position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem;
}
.filter-form { display: grid; gap: .65rem; }
.filter-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
.filter-form label.check { flex-direction: row; color: var(--text); font-size: .9rem; }
.filter-form input, .filter-form select, .filter-form textarea { color: var(--text); font-size: 14px; width: 100%; }
.filter-form .row input.qty { width: 5em; }
.filter-form .row select { width: auto; }
.filter-form textarea {
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: .4rem .5rem; resize: vertical;
}
.filter-form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .6rem .55rem; margin: 0; display: grid; gap: .4rem; }
.filter-form legend { font-size: .8rem; color: var(--muted); padding: 0 .25rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.color-picks { display: flex; gap: .35rem; flex-wrap: wrap; }
.color-pick { flex-direction: row !important; align-items: center; gap: .15rem !important; }
.color-pick input { width: auto !important; }
.color-pick img.ms { height: 1.25em; width: 1.25em; }
.syntax-help summary { cursor: pointer; font-size: .8rem; color: var(--accent); }
.syntax-help table { font-size: .75rem; border-collapse: collapse; margin-top: .4rem; }
.syntax-help td { padding: .15rem .25rem; vertical-align: top; border-bottom: 1px solid var(--grid-line); }
.syntax-help code { white-space: nowrap; }
code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 0 .25rem; border-radius: 4px; }

.toolbar { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: center; margin-bottom: .6rem; }
.segmented { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px; background: var(--surface-2); border-radius: var(--radius); padding: 2px; }
.segmented a { padding: .25rem .6rem; border-radius: 6px; color: var(--text); font-size: .88rem; }
.segmented a.active { background: var(--surface); box-shadow: 0 1px 2px rgb(0 0 0 / .15); font-weight: 600; }
.segmented a:hover { text-decoration: none; }
.segmented.small a { font-size: .8rem; }
.seg-label { font-size: .8rem; color: var(--muted); padding: 0 .4rem; }
.query-line { margin: .2rem 0 .6rem; }
.group-head { margin: 1.2rem 0 .4rem; font-size: 1.05rem; }

.bulk-bar {
  position: sticky; top: 56px; z-index: 4;
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .4rem .6rem; margin-bottom: .6rem;
}
.bulk-bar select, .bulk-bar button { min-height: 32px; padding: .2rem .55rem; font-size: .88rem; }

/* Tabellen mit Spaltenlinien, alles linksbündig */
.table-wrap { overflow-x: auto; }
table.cards.grid th, table.cards.grid td { text-align: left; }
table.cards.grid th + th, table.cards.grid td + td { border-left: 1px solid var(--grid-line); }
table.cards td.sel, table.cards th.sel { width: 2rem; padding-right: .3rem; }
table.cards td.img, table.cards th.img { width: 44px; padding: .25rem .4rem; }
tr.implicit td { font-style: italic; color: var(--implicit); }
tr.implicit td a { color: var(--implicit); }
.implicit { font-style: italic; color: var(--implicit); }

.thumb { width: 34px; height: 47px; object-fit: cover; border-radius: 3px; display: block; background: var(--surface-2); }
.thumb-empty { display: inline-block; }
.stack-head .thumb, .plain-list .thumb { display: inline-block; vertical-align: middle; margin-right: .3rem; }
.badge.tag { background: var(--tag-bg); color: var(--tag-text); }
a.badge:hover { text-decoration: none; filter: brightness(.95); }
.set-icon { height: 1.15em; width: 1.4em; vertical-align: -0.2em; object-fit: contain; }
@media (prefers-color-scheme: dark) { .set-icon { filter: invert(1); } }

.set-banner { display: flex; gap: .9rem; align-items: center; padding: .7rem .9rem; margin: .5rem 0 .8rem; }
.set-banner > .set-icon { height: 2.2rem; width: 2.6rem; }
.set-banner .segmented { margin-top: .35rem; }

/* Kartenseite */
.panel.compact { padding: .5rem .7rem; margin: .6rem 0; }
.stack-form { display: grid; gap: .5rem; margin-top: .5rem; }
.stack-form select { width: 100%; }
.image-choice { width: 100%; border-radius: 4.5% / 3.2%; }
.price-bar {
  display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-items: baseline;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem .75rem; margin: .5rem 0;
}
.price-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.price-bar strong { font-size: 1.1rem; }
.oracle + .oracle { margin-top: .5rem; }
.oracle p { margin: .35rem 0; }
.oracle .face-head { display: flex; justify-content: space-between; gap: .5rem; }
.oracle .pt { font-weight: 700; text-align: right; }
.oracle .flavor { font-style: italic; color: var(--muted); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; margin: .9rem 0; font-size: .9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts .badge { margin: 0 .25rem .2rem 0; }
.legalities { display: flex; flex-wrap: wrap; gap: .3rem; margin: .5rem 0; }
.legal { font-size: .72rem; padding: .1rem .45rem; border-radius: 4px; background: var(--surface-2); color: var(--muted); }
.legal-legal { background: var(--ok-bg); color: var(--good); }
.legal-restricted { background: var(--warn-bg); }
.legal-banned { background: var(--err-bg); color: var(--bad); }
.rulings { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .6rem; }
.rulings li { border-left: 3px solid var(--border); padding-left: .7rem; }

/* Keywords */
.keyword-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .4rem; }
.keyword { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .65rem; }
.keyword summary { cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.keyword.none .kw-name { color: var(--muted); }
.keyword .kw-body p { margin: .4rem 0; font-size: .9rem; }
.keywords-owned-only .keyword.none { display: none; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag-cloud .badge { margin: 0; }

/* --- Statistik ------------------------------------------------------------ */
/* Eine Datenfarbe (Blau) für alle Balken; Identität tragen Beschriftung und Symbol. */
.viz { --viz-bar: #2a78d6; }
@media (prefers-color-scheme: dark) { .viz { --viz-bar: #3987e5; } }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.kpi, .fact { display: flex; flex-direction: column; gap: .15rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; margin: 0; }
.kpi-label { font-size: .8rem; color: var(--muted); }
.kpi-value { font-size: 1.7rem; font-weight: 650; line-height: 1.15; }
.kpi.hero .kpi-value { font-size: 2.6rem; }
.kpi-detail { font-size: .8rem; color: var(--muted); }
.fact-value { font-size: 1.15rem; font-weight: 600; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stats-grid > .panel, .chart-grid > .panel { margin: 0; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.facts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .6rem; }
.panel h3 { margin: 0 0 .6rem; font-size: 1rem; }
.panel h3 + .hint { margin: -.4rem 0 .6rem; }
table.cards.compact td, table.cards.compact th { padding: .3rem .5rem; }

.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.bars li { display: grid; grid-template-columns: minmax(90px, 40%) 1fr auto; align-items: center; gap: .5rem; font-size: .85rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; }
.bar-fill { display: block; height: 100%; min-width: 2px; background: var(--viz-bar); border-radius: 0 4px 4px 0; }
.bars li:hover .bar-fill { filter: brightness(1.15); }
.bar-value { font-variant-numeric: tabular-nums; min-width: 2.5rem; }

.columns, .col-labels { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; }
.columns { height: 155px; align-items: end; border-bottom: 1px solid var(--grid-line); }
.col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.col-fill { width: min(24px, 80%); min-height: 2px; background: var(--viz-bar); border-radius: 4px 4px 0 0; }
.col:hover .col-fill { filter: brightness(1.15); }
.col-value { font-size: .72rem; font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.col-labels span { font-size: .7rem; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; padding-top: 3px; }

.refresh { margin: 0 0 1rem; }
.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: .4rem; }
.meter span { display: block; height: 100%; background: var(--viz-bar); transition: width .4s; }

/* --- Decks ---------------------------------------------------------------- */
.deck-head { display: grid; grid-template-columns: auto 1fr minmax(240px, 320px); gap: 1rem; align-items: start; margin-bottom: .8rem; }
.deck-commanders { display: flex; gap: .4rem; }
.deck-commanders img { width: 120px; border-radius: 4.5% / 3.2%; display: block; }
.deck-title h1 { margin-bottom: .2rem; }
.deck-title p { margin: .15rem 0 .35rem; }
.deck-description { white-space: pre-line; color: var(--muted); }
.deck-physical { margin: 0; display: grid; gap: .4rem; }
.deck-physical form { margin: 0; }
.legal-chip { display: inline-block; font-size: .8rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; }
.legal-chip.good { background: var(--ok-bg); color: var(--good); }
.legal-chip.bad { background: var(--err-bg); color: var(--bad); }
.issues summary { cursor: pointer; list-style: none; }
.issues ul { margin: .4rem 0; padding-left: 1.2rem; font-size: .88rem; }
.issues li.error { color: var(--bad); }
.deck-tabs { margin: .2rem 0 1rem; }
.deck-add { margin-top: 0; }
.deck-add .category-input { width: 11rem; }
.toolbar .legend { display: inline-flex; gap: .35rem; align-items: center; flex-wrap: wrap; }

.deck-board h2 { margin: 1rem 0 .4rem; }
.deck-columns { columns: 300px; column-gap: 1.5rem; }
.deck-group { break-inside: avoid; margin-bottom: .9rem; }
.deck-group h3 { font-size: .9rem; margin: 0 0 .25rem; color: var(--muted); font-weight: 600; }
.deck-lines { list-style: none; padding: 0; margin: 0; }
ul.deck-columns > li { break-inside: avoid; }
.deck-line { display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) auto auto 1.8rem; align-items: center; gap: .35rem; padding: .18rem .3rem; border-radius: 6px; font-size: .9rem; }
.deck-line:hover { background: var(--surface-2); }
.dl-qty { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.dl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-name .badge { font-size: .65rem; }
.dl-mana img.ms { height: .9em; width: .9em; }
.dl-menu { width: auto; }
.dl-menu summary { padding: 0 .35rem; }
.dl-menu .popover { min-width: min(360px, 90vw); }
.own { font-size: .7rem; font-weight: 600; padding: 0 .4rem; border-radius: 999px; white-space: nowrap; line-height: 1.6; }
.own-ok { background: var(--ok-bg); color: var(--good); }
.own-available { background: var(--tag-bg); color: var(--tag-text); }
.own-missing { background: var(--err-bg); color: var(--bad); }

.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.deck-card { display: grid; grid-template-columns: 80px 1fr; gap: .7rem; margin: 0; color: var(--text); align-items: start; }
.deck-card:hover { text-decoration: none; border-color: var(--accent); }
.deck-card img { width: 80px; border-radius: 4.5% / 3.2%; display: block; }
.deck-cover-empty { width: 80px; height: 112px; border-radius: 6px; background: var(--surface-2); display: block; }
.deck-card-body { display: grid; gap: .25rem; }

.token-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .8rem; }
.token { margin: 0; display: grid; gap: .5rem; align-content: start; }
.token img { width: 100%; border-radius: 4.5% / 3.2%; display: block; }
.token-placeholder { aspect-ratio: 63 / 88; display: grid; place-items: center; background: var(--surface-2); border-radius: 8px; color: var(--muted); }
.token figcaption { display: grid; gap: .2rem; }

textarea.code { width: 100%; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .6rem; resize: vertical; }
.stack-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.stack-form label.check { flex-direction: row; align-items: center; color: var(--text); font-size: .9rem; }
.bar-track.inline { display: inline-block; width: 3.5rem; height: 10px; vertical-align: middle; margin-right: .3rem; }
td .bar-track.inline + * , td:has(.bar-track.inline) { white-space: nowrap; }

/* --- Login, Konto, Freigaben ------------------------------------------------ */
.auth-box { max-width: 420px; margin: 3rem auto; }
.auth-box h1 { margin-bottom: .6rem; }
.code-input { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.nav-logout { color: var(--muted) !important; padding: .35rem .5rem !important; font-size: .9rem; }
.share-list { display: grid; gap: .6rem; margin-bottom: 1rem; }
.share { margin: 0; display: grid; gap: .5rem; }
.share.expired { opacity: .65; }
.share form { margin: 0; }
.token-reveal { border-color: var(--accent); }
.deck-line.shared { grid-template-columns: 1.6rem minmax(0, 1fr) auto; }

/* --- Deck: Kategorien, Tabelle, Stapel --------------------------------------- */
.badge.category { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.category-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .15rem .6rem; }
.category-picks label.check { font-size: .85rem; }
.category-dropdown { position: relative; }
.category-dropdown > summary { list-style: none; cursor: pointer; }
.category-dropdown > summary::-webkit-details-marker { display: none; }
.secondary-button { display: inline-flex; align-items: center; min-height: 38px; padding: .35rem .7rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); font-size: .95rem; }
.category-dropdown .popover { right: 0; min-width: min(420px, 90vw); }
.entry-menu { display: grid; gap: .55rem; }
.entry-menu form { margin: 0; }
.legend { margin: -.2rem 0 .6rem; display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }

.deck-table th[data-sort] { cursor: pointer; user-select: none; }
.deck-table th[data-sort]::after { content: " ↕"; color: var(--muted); font-weight: 400; }
.deck-table th.sorted-asc::after { content: " ↑"; color: var(--text); }
.deck-table th.sorted-desc::after { content: " ↓"; color: var(--text); }
.qty-stepper { display: inline-flex; align-items: center; gap: .35rem; margin: 0; }
.qty-stepper button.link { font-size: 1.05rem; padding: 0 .2rem; min-height: 0; }
.deck-table .row-actions { width: 2.4rem; }

.piles { --pile-w: 168px; --pile-card-h: 234px; --pile-peek: 30px; display: flex; flex-wrap: wrap; gap: 1.2rem .9rem; align-items: flex-start; padding: .2rem .1rem 1rem; }
.piles.busy { opacity: .55; pointer-events: none; }
.pile { flex: 0 0 var(--pile-w); border-radius: var(--radius); padding: .3rem; border: 1px dashed transparent; }
.pile.drop-target { border-color: var(--accent); background: var(--surface-2); }
.pile-empty .pile-cards { min-height: 80px; border: 1px dashed var(--border); border-radius: var(--radius); display: grid; place-items: center; }
.pile-board { border-left: 1px solid var(--grid-line); padding-left: .7rem; }
.pile-head { display: flex; justify-content: space-between; gap: .4rem; font-size: .88rem; margin-bottom: .35rem; white-space: nowrap; overflow: hidden; }
.pile-hint { color: var(--muted); font-size: .75rem; margin: 0; }
.pile-cards { display: flex; flex-direction: column; }
.pile-card { position: relative; }
.pile-card:not(:first-child) { margin-top: calc(var(--pile-peek) - var(--pile-card-h)); }
.pile-card > summary { list-style: none; cursor: grab; position: relative; display: block; }
.pile-card > summary::-webkit-details-marker { display: none; }
.pile-card img { width: var(--pile-w); height: var(--pile-card-h); object-fit: cover; border-radius: 4.5% / 3.2%; display: block; box-shadow: 0 1px 3px rgb(0 0 0 / .35); }
.pile-card:hover { z-index: 6; }
.pile-card[open] { z-index: 30; }
.pile-card.dragging { opacity: .4; }
.pile-noimg { display: grid; place-items: center; width: var(--pile-w); height: var(--pile-card-h); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: .8rem; padding: .5rem; text-align: center; }
/* Anzahl links, Status rechts in einer Zeile: wird es eng, kürzt der Status statt zu überlappen */
.pile-badges { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; align-items: center; gap: 4px; }
.pile-qty { flex: none; background: rgb(0 0 0 / .75); color: #fff; font-size: .75rem; font-weight: 700; border-radius: 4px; padding: 0 .35rem; }
.pile-badges .own { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 0 0 1px rgb(0 0 0 / .3); }
/* fest positioniert (app.js setzt left/top), damit der scrollende Stapelbereich das Menü nicht abschneidet */
.pile-card .popover { position: fixed; top: 0; right: auto; left: 0; min-width: 0; width: min(360px, calc(100% - 16px)); max-height: calc(100vh - 16px); overflow: auto; z-index: 40; }

/* Schmale Bildschirme: muss am Ende stehen, damit es die Regeln oben überschreibt. */
@media (max-width: 720px) {
  .with-sidebar, .with-sidebar.collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-height: none; }
  .with-sidebar .sidebar, .with-sidebar.collapsed .sidebar { display: none; }
  .with-sidebar.mobile-open .sidebar { display: block; }
  table.cards td, table.cards th { padding: .35rem .4rem; }
  table.cards td.sel, table.cards th.sel { width: 1.6rem; padding-right: .2rem; }
  table.cards td.img, table.cards th.img { width: 34px; padding: .2rem .3rem; }
  .thumb { width: 26px; height: 36px; }
  .show-sm-inline { display: inline; }
  .hide-sm-inline { display: none; }
  .bulk-bar { top: 0; position: static; }
  .facts { grid-template-columns: 1fr; gap: 0 .5rem; }
  .facts dd { margin-bottom: .35rem; }
  .stats-grid { grid-template-columns: minmax(0, 1fr); }
  .deck-head { grid-template-columns: 1fr; }
  .deck-commanders img { width: 90px; }
  .deck-add .category-input { width: 100%; }
  .deck-line { grid-template-columns: 1.4rem minmax(0, 1fr) auto 1.6rem; }
  .deck-line .dl-mana { display: none; }
  .piles { --pile-w: 120px; --pile-card-h: 167px; --pile-peek: 24px; }
  .kpi.hero .kpi-value { font-size: 2rem; }
}
