:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dfe2e7;
  --text: #16181d;
  --muted: #646b78;
  --accent: #2f6df6;
  --accent-hover: #255be0;
  --accent-soft: #e6eeff;
  --danger: #d6363b;
  --danger-soft: #fdecec;
  --success: #1f9d55;
  --warn: #c27803;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --border: #2c313a;
    --text: #eceef2;
    --muted: #9aa2b1;
    --accent: #5b8cff;
    --accent-hover: #7aa2ff;
    --accent-soft: #1d2a47;
    --danger: #f06368;
    --danger-soft: #3a1d20;
    --success: #3ecf7e;
    --warn: #f0b429;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: clip; max-width: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select { font: inherit; color: inherit; }

/* ------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.btn svg { width: 18px; height: 18px; flex: none; }
.icon-btn {
  width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 9px; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn svg { width: 18px; height: 18px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  height: 63px; padding: 0 24px; /* feste Höhe: Statuswechsel dürfen nichts verschieben */
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; flex: none; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.brand-logo svg { width: 18px; height: 18px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-by { font-size: 11px; font-weight: 500; letter-spacing: .02em; color: var(--muted); margin-top: 2px; }
.conn {
  display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px;
  height: 20px; line-height: 20px; white-space: nowrap; min-width: 0; overflow: hidden;
}
.conn::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.ok::before { background: var(--success); }
.conn.bad::before { background: var(--danger); }
.conn.retry { color: var(--warn); }
.conn.retry::before { background: var(--warn); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.spacer { flex: 1; }
.topbar .actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------ Connect-Karte */
.connect {
  display: grid; place-items: center;
  min-height: calc(100vh - 63px); padding: 32px 16px;
}
.connect-card {
  display: grid; grid-template-columns: auto 1fr; gap: 40px; align-items: center;
  max-width: 860px; width: 100%;
  padding: 36px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; box-shadow: var(--shadow);
}
.qr-box {
  width: 300px; height: 300px; padding: 14px; border-radius: 16px; background: #fff;
  border: 1px solid var(--border); display: grid; place-items: center;
}
.qr-box img { width: 100%; height: 100%; image-rendering: pixelated; }
.connect-card h1 { font-size: 28px; letter-spacing: -.02em; margin-bottom: 8px; }
.connect-card .lead { color: var(--muted); margin: 0 0 22px; }
.steps { list-style: none; margin: 0 0 22px; padding: 0; display: grid; gap: 12px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps .num {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px;
  display: grid; place-items: center;
}
.url-line {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 8px 8px 12px; border-radius: 10px; background: var(--surface-2);
  font: 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--muted);
}
.url-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.warn {
  margin-top: 14px; padding: 10px 12px; border-radius: 10px;
  background: var(--danger-soft); color: var(--danger); font-size: 13.5px;
}
.waiting { display: flex; align-items: center; gap: 10px; margin-top: 18px; color: var(--muted); font-size: 14px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }

/* ------------------------------------------------------------ Galerie */
.gallery { max-width: 1400px; margin: 0 auto; padding: 24px; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.toolbar h2 { font-size: 22px; letter-spacing: -.01em; }
.toolbar .sub { color: var(--muted); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
  animation: pop .25s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.card .thumb {
  position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); overflow: hidden; cursor: default;
}
.card.done .thumb { cursor: zoom-in; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter .3s; }
.card:not(.done) .thumb img { filter: blur(6px) saturate(.8) brightness(.9); transform: scale(1.08); }
.card .overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, .28); color: #fff;
}
.card.done .overlay { display: none; }
.card.error .overlay { background: rgba(120, 10, 15, .45); }
.ring { position: relative; width: 64px; height: 64px; }
.ring svg { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring .track { stroke: rgba(255, 255, 255, .3); }
.ring .bar { stroke: #fff; stroke-linecap: round; transition: stroke-dashoffset .15s linear; }
.ring.spin svg { animation: spin 1s linear infinite; }
.ring .pct {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; text-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
@keyframes spin { to { transform: rotate(270deg); } }
.state-label {
  position: absolute; left: 0; right: 0; bottom: 10px; text-align: center;
  font-size: 12.5px; font-weight: 600; text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}
.err-icon svg { width: 34px; height: 34px; }
.card .meta { padding: 10px 12px 4px; min-width: 0; }
.card .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .info { color: var(--muted); font-size: 12.5px; }
.card .info.err { color: var(--danger); }
.card .card-actions { display: flex; gap: 2px; padding: 4px 6px 8px; margin-top: auto; }
.card:not(.done) .card-actions .needs-done { visibility: hidden; }
.card .card-actions .push { margin-left: auto; }

.empty {
  grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 20px;
  border: 2px dashed var(--border); border-radius: var(--radius);
}

/* ------------------------------------------------------------ Dialoge */
dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  max-width: min(920px, calc(100vw - 32px)); width: 100%;
}
dialog::backdrop { background: rgba(10, 12, 16, .55); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dlg-head h3 { font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 20px; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }
.dlg-foot .left { margin-right: auto; color: var(--muted); font-size: 13px; align-self: center; }

.compress-layout { display: grid; grid-template-columns: 1fr 320px; gap: 22px; }
.preview {
  position: relative; background: var(--surface-2); border-radius: 12px; overflow: hidden;
  min-height: 300px; display: grid; place-items: center;
  background-image: conic-gradient(var(--surface-2) 25%, var(--bg) 0 50%, var(--surface-2) 0 75%, var(--bg) 0);
  background-size: 20px 20px;
}
.preview img { max-width: 100%; max-height: 460px; display: block; }
.preview .busy {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .25);
}
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: spin2 .8s linear infinite;
}
@keyframes spin2 { to { transform: rotate(360deg); } }
.preview .tag {
  position: absolute; left: 10px; top: 10px; padding: 3px 9px; border-radius: 999px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; font-weight: 600;
}

.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 13.5px; font-weight: 550;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.custom-size { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.input, select.input {
  height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); min-width: 0;
}
.custom-size .input { width: 110px; }
select.input { width: 100%; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

.result {
  padding: 14px; border-radius: 12px; background: var(--surface-2); font-size: 14px;
}
.result .big { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.result .saving { color: var(--success); font-weight: 650; }
.result .row { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; }
.result.error { background: var(--danger-soft); color: var(--danger); }

.check { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 14px; font-weight: 550; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; cursor: pointer; }
.dlg-foot .check { margin-right: auto; }
.dlg-foot .note { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.profile-badge {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 600;
}
.confirm-text { margin: 0; color: var(--muted); }
.card.stalled .ring .bar { stroke: var(--warn); }
dialog.narrow { max-width: min(460px, calc(100vw - 32px)); }
.qr-dialog { max-width: min(420px, calc(100vw - 32px)); }
.qr-dialog .dlg-body { display: grid; justify-items: center; gap: 14px; text-align: center; }

/* ------------------------------------------------------------ Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 9, 12, .94);
  display: grid; grid-template-rows: auto 1fr; color: #fff;
}
.lightbox .lb-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.lightbox .lb-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .lb-sub { color: #aab; font-weight: 400; font-size: 13px; margin-left: 8px; }
.lightbox .icon-btn { color: #fff; }
.lightbox .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.lightbox .lb-stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 0 64px 24px; }
.lightbox .lb-stage img { max-width: 100%; max-height: calc(100vh - 90px); object-fit: contain; }
.lightbox .nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border-radius: 50%; background: rgba(255, 255, 255, .1);
}
.lightbox .nav.prev { left: 10px; }
.lightbox .nav.next { right: 10px; }
.lightbox .btn { background: rgba(255, 255, 255, .1); border-color: transparent; color: #fff; }
.lightbox .btn:hover { background: rgba(255, 255, 255, .2); }

/* ------------------------------------------------------------ Footer */
/* Desktop: Footer immer am unteren Rand, Inhalt füllt den Rest */
body:has(> main) { display: flex; flex-direction: column; }
body:has(> main) > main { flex: 1; display: flex; flex-direction: column; }
body:has(> main) > main > .connect { flex: 1; min-height: 0; }
.site-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 20px; flex-wrap: wrap;
  padding: 14px 24px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 13px;
}
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; }
.footer-link { color: var(--muted); text-decoration: none; }
/* Noch ohne Ziel: sieht aus wie ein Link, reagiert aber nicht */
.footer-link[aria-disabled="true"] { cursor: default; }
.footer-link:not([aria-disabled="true"]):hover { color: var(--text); text-decoration: underline; }
.phone .site-footer { margin: 28px -16px 0; padding: 14px 16px; justify-content: center; text-align: center; }

/* ------------------------------------------------------------ Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 16px; border-radius: 10px; background: #111; color: #fff; font-size: 14px;
  box-shadow: var(--shadow); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ Handy */
.phone { max-width: 560px; margin: 0 auto; padding: 16px 16px 120px; overflow-x: clip; }
.phone .topbar { margin: -16px -16px 18px; padding: 0 16px; }
.phone-hero {
  text-align: center; padding: 28px 20px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.phone-hero h1 { font-size: 22px; margin-bottom: 6px; }
.phone-hero p { color: var(--muted); margin: 0 0 20px; }
.pick-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 56px; border-radius: 14px; background: var(--accent); color: #fff;
  font-weight: 650; font-size: 17px; cursor: pointer; border: 0;
}
.pick-btn:active { background: var(--accent-hover); }
.pick-btn svg { width: 22px; height: 22px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.summary { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0 4px 10px; }
.summary strong { font-size: 16px; }
.summary span { color: var(--muted); font-size: 13.5px; white-space: nowrap; flex: none; }
.overall { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 0 4px 14px; }
.overall > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.up-item {
  display: grid; grid-template-columns: 52px minmax(0, 1fr) auto auto; gap: 8px 10px; align-items: center;
  padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.up-item .t { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.up-item .txt { min-width: 0; }
/* Lange Dateinamen umbrechen (max. 2 Zeilen), nie seitlich scrollen */
.up-item .n {
  font-weight: 600; font-size: 14px; line-height: 1.3;
  overflow-wrap: anywhere; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.up-item.wait .s { color: var(--warn); }
.up-item .s { color: var(--muted); font-size: 12.5px; }
.up-item .s.err { color: var(--danger); }
.up-item .bar { height: 4px; border-radius: 99px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.up-item .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.up-item .st { width: 26px; height: 26px; display: grid; place-items: center; }
.up-item .st svg { width: 22px; height: 22px; }
.up-item.ok .st { color: var(--success); }
.up-item.err .st { color: var(--danger); }
.mini-spin { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent); animation: spin2 .8s linear infinite; }
.sticky-foot {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.sticky-foot .pick-btn { max-width: 528px; margin: 0 auto; }
.fatal { text-align: center; padding: 40px 20px; }
.fatal h1 { font-size: 20px; margin: 12px 0 8px; }
.fatal p { color: var(--muted); }
.fatal svg { width: 48px; height: 48px; color: var(--danger); }

/* ------------------------------------------------------------ Responsiv */
@media (max-width: 820px) {
  .connect-card { grid-template-columns: 1fr; justify-items: center; text-align: left; padding: 24px; gap: 24px; }
  .qr-box { width: 240px; height: 240px; }
  .compress-layout { grid-template-columns: 1fr; }
  .topbar { padding: 0 16px; }
  .gallery { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .lightbox .lb-stage { padding: 0 8px 16px; }
}
