:root {
  --bg: #111214;
  --card: #1c1e22;
  --card-2: #26292e;
  --text: #f2f3f5;
  --muted: #9aa0a8;
  --accent: #ff6b6b;
  --accent-2: #ffb36b;
  --danger: #e5484d;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
}

body { min-height: 100vh; padding-bottom: calc(var(--safe-bottom) + 90px); }

.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: rgba(17, 18, 20, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid #22252a;
}
.topbar h1 {
  flex: 1; margin: 0; font-size: 20px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.icon-btn {
  background: none; border: 0; color: var(--text);
  font-size: 22px; width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; text-decoration: none;
}
.icon-btn:active { background: var(--card-2); }

main { padding: 16px; max-width: 900px; margin: 0 auto; }

.btn {
  display: block; width: 100%;
  padding: 14px 16px; border: 0; border-radius: var(--radius);
  font-size: 16px; font-weight: 600; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; text-align: center; text-decoration: none;
}
.btn.secondary { background: var(--card-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid #3a2224; }
.btn:disabled { opacity: .5; }
.btn + .btn { margin-top: 10px; }

input[type=text], input[type=password] {
  width: 100%; padding: 14px 16px; margin-bottom: 12px;
  background: var(--card); color: var(--text);
  border: 1px solid #2c2f35; border-radius: var(--radius);
  font-size: 16px; outline: none;
}
input[type=text]:focus, input[type=password]:focus { border-color: var(--accent); }
.hint { margin-top: 24px; }
.warn { color: #ffb36b; }

.center-box { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.center-box img.logo { width: 96px; height: 96px; margin-bottom: 12px; }
.center-box h2 { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.group-list { display: grid; gap: 12px; margin: 16px 0; }
.group-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: var(--radius); padding: 12px;
  color: inherit; text-decoration: none;
}
.group-card .cover {
  width: 64px; height: 64px; border-radius: 10px; flex: none;
  background: var(--card-2) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.group-card .name { font-weight: 600; font-size: 17px; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

.grid {
  display: grid; gap: 3px;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 -14px;
}
@media (min-width: 600px) { .grid { grid-template-columns: repeat(4, 1fr); margin: 0; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(5, 1fr); } }
.grid .tile {
  position: relative; aspect-ratio: 1; overflow: hidden; background: var(--card);
  cursor: pointer; border: 0; padding: 0;
}
.grid .tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

.fab {
  position: fixed; right: 20px; bottom: calc(var(--safe-bottom) + 20px); z-index: 20;
  width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 34px; line-height: 1;
  box-shadow: 0 8px 24px rgba(255, 107, 107, .4);
  cursor: pointer;
}

.progress {
  position: fixed; left: 16px; right: 100px; bottom: calc(var(--safe-bottom) + 34px); z-index: 20;
  background: var(--card); border-radius: 999px; padding: 10px 14px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.progress .bar { height: 4px; background: var(--card-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 70px); transform: translateX(-50%);
  background: #2d3036; color: var(--text); padding: 10px 16px; border-radius: 999px;
  z-index: 100; font-size: 14px; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.toast.error { background: #4a1e21; }

.lightbox {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; }
.lb-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 8px) 8px 8px 16px;
  background: linear-gradient(rgba(0,0,0,.7), transparent);
  font-size: 14px;
}
.lb-actions { display: flex; gap: 4px; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,.35); color: #fff; border: 0;
  font-size: 40px; width: 48px; height: 72px; cursor: pointer;
}
.lb-nav.left { left: 0; border-radius: 0 10px 10px 0; }
.lb-nav.right { right: 0; border-radius: 10px 0 0 10px; }

/* Solange ein Sheet offen ist: Seite dahinter fixieren, kein Pull-to-Refresh/Gummiband */
html.sheet-open, html.sheet-open body { overflow: hidden; overscroll-behavior: none; }
.sheet {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
  overscroll-behavior: contain;
}
.sheet-inner {
  width: 100%; max-width: 520px;
  /* dvh = tatsächlich sichtbare Höhe (ohne Adressleiste); vh als Fallback für ältere Browser */
  max-height: calc(100vh - var(--safe-top) - 24px);
  max-height: calc(100dvh - var(--safe-top) - 24px);
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(var(--safe-bottom) + 20px);
}
.sheet-inner h3 { margin: 0 0 12px; }
.qr { background: #fff; border-radius: var(--radius); padding: 12px; width: 240px; margin: 0 auto 12px; }
.qr img { width: 100%; display: block; }
.code { text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 22px; letter-spacing: 3px; margin-bottom: 14px; }
.members { list-style: none; padding: 0; margin: 0 0 16px; }
.members li { padding: 8px 0; border-bottom: 1px solid #2a2d33; display: flex; justify-content: space-between; align-items: center; }
.members .kick { color: var(--danger); font-size: 18px; }
.check { display: flex; gap: 12px; align-items: flex-start; margin: 0 0 16px; cursor: pointer; }
.check input { width: 22px; height: 22px; flex: none; margin: 2px 0 0; accent-color: var(--accent); }
.section { margin-top: 22px; }
.center { text-align: center; }
