:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1b1b1f;
  --muted: #676771;
  --line: #e2e0d8;
  --accent: #ffcf00;
  --accent-ink: #1b1b1f;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --info: #2563eb;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121215;
    --surface: #1c1c21;
    --surface-2: #26262d;
    --text: #f1f0ec;
    --muted: #a3a3ad;
    --line: #303038;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121215; --surface: #1c1c21; --surface-2: #26262d; --text: #f1f0ec; --muted: #a3a3ad; --line: #303038;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: clamp(1.6rem, 5vw, 2.2rem); letter-spacing: -0.02em; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pad { padding: 12px 4px; }
.error { color: var(--bad); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Grundbausteine ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 600; font-size: .95rem; white-space: nowrap;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { min-height: 52px; padding: 0 22px; font-size: 1.05rem; }
.btn.subtle { background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-col { display: grid; gap: 8px; margin: 12px 0; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; font-size: .85rem; }
.icon { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 999px; border: 0; flex: none;
  display: inline-grid; place-items: center; background: var(--surface-2); color: var(--text); font-size: 1.1rem;
}
.icon-btn.on { background: var(--accent); color: var(--accent-ink); }
.round {
  width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); display: inline-grid; place-items: center; font-size: 1.15rem; font-weight: 700; padding: 0;
}
.round.plus { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 6px; background: var(--surface-2); font-size: .72rem; color: var(--muted); vertical-align: 1px; }

.swatch {
  --c: #888; display: inline-block; width: 16px; height: 16px; border-radius: 5px; flex: none;
  background: var(--c); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.18); vertical-align: -3px;
}
.swatch.sm { width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; }
.swatch.lg { width: 56px; height: 56px; border-radius: 12px; }
.swatch.trans { background: linear-gradient(135deg, var(--c) 0 50%, color-mix(in srgb, var(--c) 45%, transparent) 50% 100%); }

.chips { display: flex; gap: 6px; }
.chips.wrap { flex-wrap: wrap; }
.scroll-x { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.scroll-x::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: .85rem; white-space: nowrap;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chip small { color: var(--muted); font-size: .75rem; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.active small { color: inherit; opacity: .7; }
.chip.ghost { background: transparent; }

.toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: .95rem; }
.toggle input { width: 20px; height: 20px; accent-color: var(--text); flex: none; }
.toggle small { display: block; }

.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.spinner.sm { display: inline-block; width: 14px; height: 14px; border-width: 2px; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { min-height: 70vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.loading.dark { background: #0b0b0d; color: #bbb; min-height: 100dvh; }
.page { max-width: 720px; margin: 0 auto; padding: 24px 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 440px); padding: 10px 16px; border-radius: 12px;
  background: #1b1b1f; color: #fff; font-size: .92rem; box-shadow: 0 8px 30px rgb(0 0 0 / .3);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--bad); }
.toast.ok { background: #14532d; }

/* ---------- Bottom-Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .45); opacity: 0; transition: opacity .2s; z-index: 50; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 88dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--surface); color: var(--text);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s ease;
  box-shadow: 0 -10px 40px rgb(0 0 0 / .25);
}
.sheet.open { transform: translateY(0); }
@media (min-width: 720px) {
  .sheet { left: 50%; right: auto; width: 560px; transform: translate(-50%, 100%); }
  .sheet.open { transform: translate(-50%, 0); }
}
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; }

/* ---------- Startseite ---------- */
.home { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.hero { padding: 40px 0 12px; }
.brick-logo { display: grid; grid-template-columns: repeat(4, 18px); gap: 4px; margin-bottom: 18px; }
.brick-logo span { height: 18px; border-radius: 5px; background: var(--accent); box-shadow: inset 0 -3px 0 rgb(0 0 0 / .12); }
.brick-logo span:nth-child(2) { background: #e3000b; }
.brick-logo span:nth-child(3) { background: #0055bf; }
.brick-logo span:nth-child(4) { background: #237841; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 36ch; }
.search { display: flex; gap: 8px; margin-top: 20px; }
.search-input {
  flex: 1; min-width: 0; min-height: 52px; padding: 0 18px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--surface); font-size: 1.05rem;
}
.search-input:focus { border-color: var(--text); outline: none; }
.search-input.small { min-height: 44px; font-size: .95rem; border-width: 1px; }
.search-results { display: grid; gap: 6px; margin-top: 10px; }
.set-row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.set-row img { width: 64px; height: 48px; object-fit: contain; background: #fff; border-radius: 8px; flex: none; }
.set-row-text { display: grid; min-width: 0; }
.set-row-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-row-text small { color: var(--muted); }
.block { padding: 20px 0; }
.recent { display: grid; gap: 6px; }
.steps { padding-left: 1.2em; margin: 0; display: grid; gap: 8px; color: var(--muted); }
.steps strong { color: var(--text); }
.footer { padding: 24px 0 calc(32px + env(safe-area-inset-bottom)); color: var(--muted); font-size: .8rem; }
.footer p { margin: 0 0 4px; }

/* ---------- Set-Ansicht ---------- */
.setview { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.set-hero { position: relative; display: grid; gap: 16px; padding: 16px 0; }
.set-hero .back { position: absolute; top: 20px; left: 4px; z-index: 1; background: var(--surface); box-shadow: var(--shadow); }
.set-img { width: 100%; max-height: 260px; object-fit: contain; background: #fff; border-radius: var(--radius); padding: 12px; }
.eyebrow { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.progress { height: 10px; border-radius: 10px; background: var(--surface-2); overflow: hidden; margin: 14px 0 6px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ff9f00); transition: width .3s ease; }
.progress-text { font-size: .9rem; color: var(--muted); }
@media (min-width: 760px) {
  .set-hero { grid-template-columns: 340px 1fr; align-items: center; }
  .set-hero .back { top: 24px; }
}
.toolbar {
  position: sticky; top: 0; z-index: 5; display: grid; gap: 8px;
  padding: 10px 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
}
.toolbar-row { display: flex; gap: 12px; align-items: center; }
.toolbar-row .search-input { flex: 1; }
.group { margin: 18px 0 8px; }
.group-head { display: flex; align-items: center; gap: 8px; font-size: 1rem; margin-bottom: 10px; flex-wrap: wrap; }
.group-head small { color: var(--muted); font-weight: 500; }
.group-head .link { margin-left: auto; }
.part-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.part {
  display: grid; grid-template-rows: auto 1fr auto; gap: 6px;
  padding: 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  transition: opacity .2s;
}
.part.complete { opacity: .5; }
.part.complete .part-count .count { color: var(--ok); font-weight: 700; }
.part-img { border: 0; padding: 0; background: #fff; border-radius: 10px; aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden; }
.part-img img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.img-missing { min-height: 40px; background: repeating-linear-gradient(45deg, var(--surface-2) 0 6px, transparent 6px 12px); }
.part-info { display: grid; min-width: 0; }
.part-name { font-size: .82rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.part-num { font-size: .75rem; color: var(--muted); }
.part-count { display: flex; align-items: center; justify-content: space-between; }
.count { font-variant-numeric: tabular-nums; font-weight: 600; }
.minifigs { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.minifig { margin: 0; width: 120px; font-size: .8rem; color: var(--muted); }
.minifig img { width: 120px; height: 120px; object-fit: contain; background: #fff; border-radius: 12px; }
.part-detail { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: start; }
.part-detail-img { width: 120px; height: 120px; object-fit: contain; background: #fff; border-radius: 12px; padding: 6px; }
.part-detail-name { font-weight: 700; font-size: 1.05rem; margin-bottom: 2px; }
.color-line { display: flex; align-items: center; gap: 8px; }

/* ---------- Scanner ---------- */
body.scan-mode { background: #0b0b0d; overflow: hidden; overscroll-behavior: none; }
.scan {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: #0b0b0d; color: #f4f4f5; --line: #2e2e36; --surface: #1c1c21; --surface-2: #2a2a31; --text: #f4f4f5; --muted: #a1a1aa;
}
.scan-top {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px; background: #0b0b0d;
}
.scan-title { flex: 1; min-width: 0; }
.scan-title > span { display: grid; min-width: 0; }
.scan-title small { color: #a1a1aa; font-size: .75rem; }
.scan-title strong { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-title .focus { display: flex; align-items: center; gap: 8px; }
.scan-title .focus img { width: 36px; height: 36px; object-fit: contain; background: #fff; border-radius: 8px; padding: 2px; flex: none; }
.scan-title .focus > span { display: grid; min-width: 0; }

.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; touch-action: manipulation; }
.stage.picking { cursor: crosshair; }
.stage .cam { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.stage .cam.visible { inset: 0; width: 100%; height: 100%; opacity: 1; object-fit: contain; }
.stage .live { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage-error { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 24px; text-align: center; }
.hint {
  position: absolute; left: 50%; top: 12px; transform: translate(-50%, -8px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 8px 14px; border-radius: 12px;
  background: rgb(0 0 0 / .72); color: #fff; font-size: .88rem; text-align: center; transition: opacity .25s, transform .25s;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

.result-layer { position: absolute; inset: 0; }
.frame { position: absolute; }
.frame .photo, .frame .overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.badges { position: absolute; inset: 0; }
.badge {
  position: absolute; transform: translate(-50%, -100%); margin-top: -4px;
  width: 38px; height: 38px; padding: 2px; border-radius: 10px; border: 3px solid #fff;
  background: #fff; display: grid; place-items: center; box-shadow: 0 2px 8px rgb(0 0 0 / .5);
  color: #111; font-weight: 800;
}
.badge img { width: 100%; height: 100%; object-fit: contain; }
.badge.st-match { border-color: #22c55e; }
.badge.st-shape { border-color: #f59e0b; }
.badge.st-done { border-color: #60a5fa; }
.badge.st-none, .badge.st-other { border-color: #ef4444; opacity: .8; }
.badge.sure.st-match { box-shadow: 0 0 0 3px rgb(34 197 94 / .35), 0 2px 8px rgb(0 0 0 / .5); }
.badge.pulse { animation: pulse 1s ease 2; }
@keyframes pulse { 50% { transform: translate(-50%, -100%) scale(1.35); } }

.scan-bottom { padding: 8px 0 calc(10px + env(safe-area-inset-bottom)); background: #0b0b0d; }
.scan-bottom .chips { padding: 0 10px 8px; }
.chips.dark .chip { background: #1c1c21; border-color: #2e2e36; color: #e4e4e7; }
.chips.dark .chip.active { background: #f4f4f5; color: #111; border-color: #f4f4f5; }
.chips.dark .chip:not(.active):not(.ghost) { opacity: .55; }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 16px; }
.ctrl {
  justify-self: center; display: grid; justify-items: center; gap: 2px; min-width: 64px; min-height: 52px;
  border: 0; background: none; color: #d4d4d8; font-size: .75rem; border-radius: 12px; padding: 6px;
}
.ctrl.on { color: var(--accent); }
.shutter {
  width: 84px; height: 84px; border-radius: 999px; border: 4px solid #fff;
  background: var(--accent); color: var(--accent-ink); display: grid; place-content: center; justify-items: center;
  font-size: .75rem; font-weight: 800; box-shadow: 0 0 0 4px rgb(255 207 0 / .25);
}
.shutter:active { transform: scale(.95); }
.shutter .icon { width: 28px; height: 28px; }

.result-panel {
  max-height: 46dvh; overflow: auto; overscroll-behavior: contain;
  background: #141418; border-top: 1px solid #2e2e36; padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
}
.panel-head { display: flex; align-items: center; gap: 8px; }
.panel-head .btn { min-height: 40px; padding: 0 12px; }
.panel-head .btn.ghost { color: #e4e4e7; }
.panel-stats { flex: 1; text-align: center; font-size: .85rem; color: #a1a1aa; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 10px 2px; font-size: .82rem; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: currentColor; vertical-align: -1px; }
.st-match { color: #22c55e; }
.st-shape { color: #f59e0b; }
.st-done { color: #60a5fa; }
.st-none, .st-other, .st-error { color: #ef4444; }
.result-list { display: grid; gap: 6px; }
.result-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 12px;
  background: #1c1c21; border-left: 4px solid currentColor; cursor: pointer;
}
.result-row > img, .result-row .noimg { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 8px; padding: 2px; flex: none; display: grid; place-items: center; color: #111; }
.result-text { flex: 1; min-width: 0; display: grid; color: #f4f4f5; }
.result-text strong { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-text small { color: #a1a1aa; }

.result-detail .compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 10px; }
.result-detail figure { margin: 0; }
.result-detail figure img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; border-radius: 12px; }
.result-detail figcaption { font-size: .75rem; color: var(--muted); margin-top: 4px; text-align: center; }
.status-line { font-weight: 700; }
.alt-list { display: grid; gap: 6px; }
.alt { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); text-align: left; }
.alt img { width: 36px; height: 36px; object-fit: contain; background: #fff; border-radius: 6px; }
.alt small { color: var(--muted); }

.calib-sample { display: flex; align-items: center; gap: 14px; }
.settings { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field-label { display: flex; justify-content: space-between; font-weight: 600; font-size: .95rem; }
.field output { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
