:root {
  --bg: #0f1118;
  --surface: #181b26;
  --surface-2: #212534;
  --border: #2d3245;
  --text: #eceef5;
  --muted: #9aa1b8;
  --accent: #ffcb05;
  --accent-ink: #1a1400;
  --red: #ef4b4b;
  --green: #3ecf8e;
  --blue: #5b8cff;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
h2 { font-size: 1.25rem; margin: 18px 0 10px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: .9rem; margin: 6px 0 12px; }
.small { font-size: .8rem; }
.center { text-align: center; margin: 16px 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; }

/* Topbar & Navigation */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(15,17,24,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav button {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: .75rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button.active { color: var(--accent); }

@media (min-width: 820px) {
  body { padding-bottom: 24px; }
  .nav { position: static; display: flex; height: auto; background: none; border: 0; padding: 0; gap: 4px; }
  .nav button { flex-direction: row; font-size: .9rem; padding: 8px 14px; border-radius: 999px; gap: 8px; }
  .nav button.active { background: var(--surface-2); }
  .nav svg { width: 18px; height: 18px; }
}

main { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--red); border-color: rgba(239,75,75,.4); }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }

/* Suche */
.searchbar { display: grid; grid-template-columns: 1fr 76px auto; gap: 8px; margin-top: 16px; }
@media (max-width: 480px) {
  .searchbar { grid-template-columns: 1fr 66px; }
  .searchbar .btn { grid-column: 1 / -1; }
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
@media (max-width: 480px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; text-align: left;
  color: inherit; font: inherit; transition: transform .12s, border-color .12s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile .img { aspect-ratio: 63 / 88; border-radius: 8px; background: var(--surface-2); overflow: hidden; display: grid; place-items: center; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .name { font-weight: 600; font-size: .9rem; line-height: 1.2; }
.tile .meta { color: var(--muted); font-size: .75rem; }
.tile .price { color: var(--accent); font-weight: 700; font-size: .9rem; }
.tile .badge-score { font-size: .7rem; color: var(--green); }
.noimg { color: var(--muted); font-size: .75rem; padding: 8px; text-align: center; }

.backup-warn { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(239,75,75,.1); border: 1px solid rgba(239,75,75,.4); display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: .88rem; }
.check { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; font-size: .9rem; color: var(--muted); cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Sets */
.serie-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
@media (max-width: 480px) { .set-grid { grid-template-columns: repeat(2, 1fr); } }
.set-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
  cursor: pointer; text-align: left; color: inherit; font: inherit; display: flex; flex-direction: column; gap: 8px;
}
.set-card:hover { border-color: var(--accent); }
.set-logo { height: 54px; display: grid; place-items: center; }
.set-logo img { max-height: 54px; max-width: 100%; object-fit: contain; }
.set-logo .ph-text { color: var(--muted); font-size: .75rem; }
.set-card .name { font-weight: 600; font-size: .9rem; line-height: 1.25; }
.set-card .meta { color: var(--muted); font-size: .75rem; }
.bar { height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > div { height: 100%; background: var(--green); }
.set-head { display: flex; align-items: center; gap: 14px; margin: 16px 0 8px; flex-wrap: wrap; }
.set-head img { max-height: 56px; max-width: 160px; object-fit: contain; }
.set-head h2 { margin: 0; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { background: none; border: 0; color: var(--muted); font: inherit; font-size: .85rem; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg button.active { background: var(--surface-2); color: var(--text); }
.tile.owned { border-color: rgba(62,207,142,.5); }
.tile.missing .img { opacity: .55; }
.own-badge { font-size: .72rem; color: var(--green); font-weight: 600; }

/* Neuheiten */
.news { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius); background: rgba(62,207,142,.08); border: 1px solid rgba(62,207,142,.35); }
.news-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.news-item:first-of-type { border-top: 0; }
.news .row-between { margin-bottom: 4px; }

/* Scan */
.scan-wrap { max-width: 520px; margin: 16px auto; }
.camera {
  position: relative; aspect-ratio: 3 / 4; background: #000; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--border);
}
.camera video, .camera canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera .frame {
  position: absolute; inset: 8% 14%; border: 2px dashed rgba(255,203,5,.7); border-radius: 12px; pointer-events: none;
}
.cam-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center; color: var(--muted); }
.scan-actions { display: flex; gap: 8px; justify-content: center; margin: 12px 0; flex-wrap: wrap; }
.scan-status { text-align: center; color: var(--muted); min-height: 1.4em; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.ocr-text { margin: 10px 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.ocr-text summary { cursor: pointer; color: var(--muted); }
.ocr-text textarea { margin: 8px 0; font-family: ui-monospace, monospace; font-size: .8rem; }

/* Dialoge */
dialog.sheet {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 18px; padding: 0; width: min(960px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
}
dialog.small-sheet { width: min(460px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(3px); }
dialog .close {
  position: sticky; top: 10px; float: right; margin: 10px 10px 0 0; z-index: 2;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 50%;
  width: 36px; height: 36px; cursor: pointer; font-size: 1rem;
}
@media (max-width: 640px) {
  dialog.sheet { width: 100vw; max-width: 100vw; max-height: 94vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
}

.detail { display: grid; grid-template-columns: minmax(220px, 340px) 1fr; gap: 24px; padding: 20px; }
@media (max-width: 700px) { .detail { grid-template-columns: 1fr; padding: 16px; } .detail .bigimg { max-width: 300px; margin: 0 auto; } }
.bigimg { width: 100%; aspect-ratio: 63 / 88; border-radius: 14px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; }
.bigimg img { width: 100%; height: 100%; object-fit: contain; }
.detail h2 { margin: 0 0 4px; font-size: 1.5rem; }
.detail .sub { color: var(--muted); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.detail .sub img { height: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: .8rem; }
.chip.yellow { background: rgba(255,203,5,.12); border-color: rgba(255,203,5,.4); color: var(--accent); }
.chip.green { background: rgba(62,207,142,.12); border-color: rgba(62,207,142,.4); color: var(--green); }
.chip.red { background: rgba(239,75,75,.12); border-color: rgba(239,75,75,.4); color: var(--red); }

.price-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.price-main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.price-main .big { font-size: 1.9rem; font-weight: 800; color: var(--accent); }
.price-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: .88rem; }
.price-table th, .price-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); text-align: right; }
.price-table th:first-child, .price-table td:first-child { text-align: left; color: var(--muted); font-weight: 400; }
.price-table thead th { color: var(--muted); font-weight: 600; font-size: .78rem; }

.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.attack { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.attack .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.attack .cost { color: var(--muted); font-size: .8rem; font-weight: 400; }
.attack p { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* Hinzufügen-Formular */
#addForm { padding: 20px; }
#addForm h3 { font-size: 1.15rem; margin-bottom: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.calc { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 6px 0 14px; }
.calc .big { font-size: 1.4rem; font-weight: 800; color: var(--accent); }

/* Sammlungen */
.total-card {
  margin-top: 16px; padding: 18px; border-radius: var(--radius);
  background: linear-gradient(135deg, #2a2310 0%, #1b1e2b 60%);
  border: 1px solid rgba(255,203,5,.3);
}
.total-card .label { color: var(--muted); font-size: .85rem; }
.total-card .value { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.total-card .meta { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.coll-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.coll-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  cursor: pointer; display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; text-align: left; color: inherit; font: inherit;
}
.coll-card:hover { border-color: var(--accent); }
.coll-thumbs { width: 64px; height: 84px; position: relative; }
.coll-thumbs img, .coll-thumbs .ph { position: absolute; width: 50px; height: 70px; border-radius: 5px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.coll-thumbs > :nth-child(1) { left: 0; top: 0; }
.coll-thumbs > :nth-child(2) { left: 7px; top: 7px; }
.coll-thumbs > :nth-child(3) { left: 14px; top: 14px; }
.coll-card .name { font-weight: 700; }
.coll-card .val { color: var(--accent); font-weight: 700; font-size: 1.15rem; }
.coll-card .meta { color: var(--muted); font-size: .8rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; border: 1px dashed var(--border); border-radius: var(--radius); }

.coll-head { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; flex-wrap: wrap; }
.coll-head h2 { margin: 0; flex: 1; min-width: 150px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.toolbar select, .toolbar input { width: auto; flex: 1; min-width: 140px; }
.entries { display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px 8px 8px;
}
.entry img, .entry .ph { width: 54px; height: 75px; object-fit: cover; border-radius: 6px; background: var(--surface-2); cursor: pointer; }
.entry .name { font-weight: 600; cursor: pointer; }
.entry .meta { color: var(--muted); font-size: .8rem; }
.entry .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.entry .tags .chip { font-size: .72rem; padding: 1px 8px; }
.entry .right { text-align: right; }
.entry .val { color: var(--accent); font-weight: 700; }
.entry .unit { color: var(--muted); font-size: .75rem; }
.entry .acts { display: flex; gap: 4px; justify-content: flex-end; margin-top: 4px; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: .85rem; }
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.icon-btn.del { display: inline-grid; place-items: center; }
.icon-btn.del:hover { color: var(--red); border-color: var(--red); }
.gain { font-size: .85rem; }
.gain.up { color: var(--green); }
.gain.down { color: var(--red); }
.spark { width: 100%; height: 48px; margin-top: 8px; display: block; }

/* Einstellungen */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.factor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.factor-grid label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .88rem; background: var(--surface-2); padding: 6px 6px 6px 10px; border-radius: 8px; }
.factor-grid input { width: 72px; padding: 6px 8px; text-align: right; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 820px) { .toast { bottom: 24px; } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Anmeldung & Synchronisierung (sync.js) */
.sync-badge { width: 12px; height: 12px; padding: 0; border-radius: 50%; border: 2px solid var(--muted); background: transparent; cursor: pointer; flex: none; }
.sync-badge.ok { background: var(--green); border-color: var(--green); }
.sync-badge.pending { background: var(--accent); border-color: var(--accent); }
.sync-badge.syncing { border-color: var(--blue); border-top-color: transparent; animation: spin 1s linear infinite; }
.sync-badge.offline { border-color: var(--muted); background: transparent; border-style: dashed; }
.sync-badge.error { background: var(--red); border-color: var(--red); }
@keyframes spin { to { transform: rotate(360deg); } }
body.auth-open { overflow: hidden; }
.auth { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.auth-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
.auth-card input { width: 100%; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-size: 1.6rem; font-weight: 800; }
.auth-error { color: var(--red); font-size: .9rem; }
.auth-notice { padding: 10px 12px; border-radius: 10px; background: rgba(91,140,255,.12); border: 1px solid rgba(91,140,255,.4); font-size: .9rem; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; font-size: .85rem; cursor: pointer; padding: 4px; }
.acc-more { margin-top: 12px; }
.acc-more summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.acc-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; max-width: 360px; }
