:root {
  color-scheme: light dark;
  --bg: #f3f4f7;
  --card: #ffffff;
  --ink: #14161b;
  --muted: #6a7280;
  --line: #e0e4ea;
  --line-soft: #eef0f4;
  --accent: #c8322b;
  --accent-ink: #ffffff;
  --red: #c33b2c;
  --ok: #2f8f4e;
  --wish: #8a6d1f;
  --pocket: #e9ecf1;
  --sheet: #fbfcfd;
  --radius: 12px;
  --top-h: 56px;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116; --card: #171a21; --ink: #e7eaef; --muted: #98a1b0; --line: #262b36; --line-soft: #1f242e;
    --accent: #ff6b5e; --accent-ink: #1a0806; --red: #f0806f; --ok: #5fcf86; --wish: #e3c46b;
    --pocket: #202530; --sheet: #1a1e26;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 0.45rem 0.8rem; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--red); }
button.link { border: 0; background: none; padding: 0; text-decoration: underline; text-align: left; }
button[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: -2px; font-weight: 600; }
input, select { padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
label { display: grid; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
label.inline { display: flex; align-items: center; gap: 0.5rem; color: var(--ink); }
.error { color: var(--red); min-height: 1.2em; margin: 0; }
.muted { color: var(--muted); }
.fatal { padding: 2rem; text-align: center; color: var(--muted); }
.spacer { flex: 1; }

/* Login */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(360px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.auth-card form { display: grid; gap: 0.8rem; }
.auth-card input { width: 100%; }
.auth-logo { width: 56px; height: 56px; }
.auth h1 { margin: 0.5rem 0 1rem; font-size: 1.4rem; }

/* Rahmen */
.page { min-height: 100dvh; display: flex; flex-direction: column; }
/* Drei Spalten: Suche bleibt mittig, egal wie breit links und rechts sind. */
.top { position: sticky; top: 0; z-index: 5; height: var(--top-h); display: grid; grid-template-columns: minmax(max-content, 1fr) minmax(220px, 420px) minmax(max-content, 1fr); align-items: center; gap: 1.5rem; padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.top-left { display: flex; align-items: center; gap: 1.25rem; }
.top-right { display: flex; align-items: center; gap: 0.5rem; justify-self: end; }
.settings-link { text-decoration: none; padding: 0.45rem 0.8rem; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.settings-link:hover { color: var(--ink); }
.settings-link[aria-current="page"] { background: var(--bg); color: var(--ink); font-weight: 600; }
.brand { display: flex; align-items: center; gap: 0.5rem; text-decoration: none; }
.brand img { width: 32px; height: 32px; }
.brand h1 { font-size: 1.15rem; margin: 0; }
.tabs { display: flex; gap: 0.25rem; }
.tabs a { text-decoration: none; padding: 0.45rem 0.8rem; border-radius: 8px; color: var(--muted); }
.tabs a[aria-current="page"] { background: var(--bg); color: var(--ink); font-weight: 600; }
.menu { position: relative; }

/* Suche im Kopf */
.search-wrap { position: relative; width: 100%; }
.global-search { width: 100%; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; max-height: 70vh; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgb(0 0 0 / 0.25); padding: 0.25rem; z-index: 7; }
.search-results p { margin: 0.6rem; }
.search-hit { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 0.6rem; align-items: center; padding: 0.35rem 0.5rem; border-radius: 8px; cursor: pointer; font-size: 0.88rem; }
.search-hit.active { background: var(--line-soft); }
.search-hit > div { display: grid; min-width: 0; }
.search-hit .card-img figcaption { display: none; }
.badge-inline { background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.78rem; padding: 0 0.45rem; border-radius: 999px; }
.to-set { font-size: 0.8rem; color: var(--muted); }
.who { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-list { position: absolute; right: 0; top: 110%; display: grid; min-width: 180px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.25rem; z-index: 6; }
.menu-list button { border: 0; text-align: left; }
.view { flex: 1; padding: 16px 24px 32px; }
.toolbar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar h1 { font-size: 1.4rem; margin: 0; }
.back { text-decoration: none; color: var(--muted); }
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.lang-tag, .kind-tag { font-size: 0.75rem; font-weight: 700; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--line-soft); color: var(--muted); }
.kind-tag.plan { background: color-mix(in srgb, var(--wish) 20%, transparent); color: var(--wish); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 0.6rem 1rem; border-radius: 8px; z-index: 30; max-width: 80vw; }
dialog.sheet { margin: 8vh auto auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); width: min(440px, calc(100vw - 32px)); padding: 1.25rem; }
dialog.sheet.wide { width: min(1000px, calc(100vw - 32px)); }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
dialog.sheet form { display: grid; gap: 0.8rem; }
dialog.sheet h2 { margin: 0; font-size: 1.15rem; }
.actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }

/* Kartenbild: Kartenruecken mit Name/Nummer, bis das echte Bild geladen ist */
.card-img { position: relative; margin: 0; aspect-ratio: 63 / 88; border-radius: 4.5% / 3.2%; overflow: hidden; background: var(--pocket); }
.card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-img figcaption { position: absolute; left: 0; right: 0; bottom: 0; padding: 0.3rem; background: rgb(0 0 0 / 0.55); color: #fff; font-size: 0.72rem; display: grid; text-align: center; }
.card-img.loaded figcaption { display: none; }
.cap-nr { opacity: 0.8; }

/* Sets */
.set-group h2 { font-size: 1.05rem; display: flex; gap: 0.5rem; align-items: center; margin: 1.5rem 0 0.6rem; }
.set-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.75rem; }
.set-tile { display: grid; gap: 0.3rem; padding: 0.75rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }
.set-tile:hover { border-color: var(--accent); }
.set-logo { height: 48px; width: 100%; object-fit: contain; }
.set-logo.empty { display: grid; place-items: center; color: var(--muted); font-weight: 700; background: var(--line-soft); border-radius: 8px; }
.meter { height: 6px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }
.capture-options { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; padding: 0.75rem 1rem; margin-bottom: 1rem; background: var(--card); border: 1px solid var(--accent); border-radius: var(--radius); }
.capture-options p { margin: 0; }
.price-input { width: 9rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; }
.card-tile { position: relative; padding: 0; border: 0; background: none; border-radius: 6px; }
.card-tile.missing .card-img { opacity: 0.35; filter: grayscale(1); }
.card-grid.capturing .card-tile { cursor: copy; }
.card-grid.capturing .card-tile:hover { outline: 2px solid var(--accent); }
.badge { position: absolute; top: 6px; right: 6px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.8rem; padding: 0 0.4rem; border-radius: 999px; }
.badge:empty { display: none; }

/* Kartendetail */
.card-detail { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.card-facts { display: grid; gap: 0.75rem; min-width: 0; }
.card-facts h2, .card-facts h3 { margin: 0; }
.card-facts dl, .settings dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 1rem; margin: 0; }
.card-facts dt, .settings dt { color: var(--muted); }
.card-facts dd, .settings dd { margin: 0; }
.copy-list { display: grid; gap: 0.5rem; }
.copy-row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; padding: 0.5rem; border: 1px solid var(--line); border-radius: 10px; }
.copy-row.add, dialog.sheet form.copy-row { display: flex; border-style: dashed; }
.copy-row select { width: 9.5rem; }
.copy-row select.lang { width: 7.5rem; }
.copy-row input.price { width: 6.5rem; }
.copy-row input[type="date"] { width: 9.5rem; }
.copy-row input.note { flex: 1 1 8rem; min-width: 8rem; }
.copy-row input.count { width: 4rem; }
.copy-row .place { font-size: 0.85rem; flex: 1 1 auto; }

/* Sammlung */
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.filters input[type="search"] { min-width: 16rem; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100dvh - var(--top-h) - 190px); }
table.copies, table.list { width: 100%; border-collapse: collapse; }
table.copies th, table.copies td, table.list th, table.list td { padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
table.copies th { position: sticky; top: 0; background: var(--card); z-index: 1; }
th .sort { border: 0; background: none; padding: 0; font-weight: 600; }
td.thumb { width: 52px; }
td.thumb .card-img { width: 40px; }
td.thumb .card-img figcaption { display: none; }
input.cell, td select, td input[type="date"] { width: 8rem; padding: 0.25rem 0.4rem; }
.saved { border-color: var(--ok) !important; }
.sum-bar { display: flex; justify-content: space-between; padding: 0.75rem 0.25rem; font-weight: 600; }
td.empty { text-align: center; padding: 2rem; }

/* Binder-Uebersicht */
.binder-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.binder-tile { display: grid; grid-template-columns: 90px 1fr; gap: 0.75rem; padding: 0.75rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.binder-tile.plan { border-style: dashed; }
.binder-meta { display: grid; gap: 0.3rem; align-content: start; }
.binder-meta a { text-decoration: none; }
.binder-meta .actions { justify-content: flex-start; }
.cover-empty { aspect-ratio: 63 / 88; display: grid; place-items: center; background: var(--line-soft); border-radius: 6px; color: var(--muted); }

/* Binder-Ansicht */
.binder-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.binder-nav { display: flex; align-items: center; gap: 0.5rem; justify-content: center; margin-bottom: 0.75rem; }
.page-label { min-width: 8rem; text-align: center; font-weight: 600; }
.jump { width: 5rem; }
.stage { position: relative; }
.spread { display: grid; grid-template-columns: 1fr 1fr; margin: 0 auto; max-width: calc((100dvh - var(--top-h) - 170px) * 2 * var(--cols) * 63 / (var(--rows) * 88)); }
.page-sheet { background: var(--sheet); border: 1px solid var(--line); padding: 14px; display: grid; gap: 6px; align-content: start; }
.page-sheet.left { border-radius: 10px 0 0 10px; border-right-width: 3px; }
.page-sheet.right { border-radius: 0 10px 10px 0; }
.page-sheet.blank { background: transparent; border-color: transparent; }
.pockets { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 8px; }
.pocket { position: relative; aspect-ratio: 63 / 88; background: var(--pocket); border-radius: 6px; border: 1px dashed var(--line); }
.pocket .card-img { position: absolute; inset: 0; }
.pocket.filled { border-style: solid; cursor: grab; }
.pocket.over { outline: 3px solid var(--accent); }
.pocket.wish .card-img { opacity: 0.4; filter: grayscale(1); }
.pocket.wish.fulfilled .card-img { opacity: 0.75; filter: none; }
.pocket .tag { position: absolute; left: 4px; top: 4px; z-index: 1; font-size: 0.7rem; font-weight: 700; padding: 0 0.35rem; border-radius: 999px; background: var(--wish); color: #fff; }
.pocket.fulfilled .tag { background: var(--ok); }
.pocket .tag.cond { left: auto; right: 4px; background: rgb(0 0 0 / 0.6); }
.page-nr { justify-self: center; font-size: 0.8rem; color: var(--muted); }
.edge { position: absolute; top: 0; bottom: 0; width: 56px; z-index: 2; display: none; }
.edge.prev { left: -8px; }
.edge.next { right: -8px; }
body.dragging .edge { display: block; }
.edge.armed { background: color-mix(in srgb, var(--accent) 25%, transparent); border-radius: 10px; }
.side { position: sticky; top: calc(var(--top-h) + 16px); display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 0.5rem; height: calc(100dvh - var(--top-h) - 32px); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; }
.side input { width: 100%; }
.side-results { overflow: auto; display: grid; gap: 0.4rem; align-content: start; }
.side-item { display: grid; grid-template-columns: 48px 1fr; gap: 0.5rem; align-items: center; padding: 0.3rem; border-radius: 8px; cursor: grab; font-size: 0.85rem; }
.side-item:hover { background: var(--line-soft); }
.side-item > div { display: grid; }
.side-item .card-img figcaption { display: none; }
.context-menu { position: fixed; z-index: 20; display: grid; min-width: 220px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.25rem; box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); }
.context-menu button { border: 0; text-align: left; }
.plan-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.plan-panel h2 { margin-top: 0; font-size: 1.1rem; }

/* Einstellungen */
.settings { display: grid; gap: 1rem; max-width: 720px; }
.settings h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.settings .panel { display: grid; gap: 0.5rem; justify-items: start; }

/* Eigene Karten */
.settings-area { display: contents; }
.settings-area > .settings { display: contents; }
.custom-set { display: grid; gap: 0.4rem; width: 100%; }
.custom-set h3 { margin: 0.75rem 0 0; font-size: 1rem; display: flex; gap: 0.4rem; align-items: center; }
.custom-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 0.6rem; align-items: center; }
.custom-row > div { display: grid; }
.custom-row .card-img figcaption { display: none; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.custom-preview { max-width: 160px; border-radius: 6px; }
.add-custom { margin: 0 0.6rem 0.6rem; }
.actions .more { margin-right: auto; }
