:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --accent: #c8102e;
  --accent-soft: #fde8eb;
  --ok: #1f8a4c;
  --ok-soft: #e3f5ea;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --line: #2c2c2e;
    --accent: #ff4d5e;
    --accent-soft: #3a1418;
    --ok: #4cd681;
    --ok-soft: #10301d;
    --warn: #ffb547;
    --warn-soft: #3a2a10;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.loading { display: grid; place-items: center; min-height: 100vh; font-size: 48px; animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 50% { transform: scale(1.15); } }

/* ---------- Layout */
.shell { min-height: 100vh; padding-bottom: calc(76px + var(--safe-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  display: flex; align-items: center; gap: 8px; min-height: 52px;
}
.topbar h1 { font-size: 28px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar.sub h1 { font-size: 20px; }
.icon-btn {
  border: 0; background: var(--card); box-shadow: var(--shadow);
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; flex: none; font-size: 18px;
}
.icon-btn.accent { background: var(--accent); color: #fff; font-size: 24px; }
.icon-btn svg { width: 20px; height: 20px; }

main { padding: 4px 16px 24px; max-width: 640px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; padding: 4px 0;
  position: relative;
}
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.active { color: var(--accent); }
.tabbar .badge {
  position: absolute; top: 0; left: calc(50% + 6px);
  background: var(--accent); color: #fff; border-radius: 9px; min-width: 18px; height: 18px;
  font-size: 11px; line-height: 18px; text-align: center; padding: 0 5px;
}

/* ---------- Bausteine */
.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 22px 4px 8px; font-weight: 600;
  display: flex; justify-content: space-between; gap: 8px;
}
.section-title:first-child { margin-top: 8px; }

.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  text-decoration: none; color: inherit; border: 0; background: none; width: 100%; text-align: left;
}
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .meta { color: var(--muted); font-size: 14px; }
.row .chev { color: var(--muted); font-size: 20px; }

.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px;
}
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.emoji-badge { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: var(--accent-soft); flex: none; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 10px;
}
.card.dim { opacity: .62; }
.card.clickable { cursor: pointer; }
.wish-head { display: flex; gap: 10px; align-items: flex-start; }
.wish-head .grow { flex: 1; min-width: 0; }
.wish-title { font-weight: 600; font-size: 17px; word-wrap: break-word; }
.wish-desc { color: var(--muted); font-size: 15px; margin-top: 4px; white-space: pre-wrap; word-wrap: break-word; }
.wish-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.chip {
  font-size: 13px; padding: 3px 9px; border-radius: 20px; background: var(--bg); color: var(--muted);
  text-decoration: none; display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.link { color: var(--accent); background: var(--accent-soft); }
.chip.ok { color: var(--ok); background: var(--ok-soft); }
.chip.warn { color: var(--warn); background: var(--warn-soft); }
.prio { color: #f5a623; font-size: 14px; letter-spacing: 1px; white-space: nowrap; }

.wish-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 11px; padding: 10px 16px; font-weight: 600; font-size: 15px;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.secondary { background: var(--bg); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); padding-left: 8px; padding-right: 8px; }
.btn.danger { background: transparent; color: var(--accent); }
.btn.block { width: 100%; padding: 14px; font-size: 17px; }
.btn:disabled { opacity: .5; }
.check {
  display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500;
  border: 0; background: var(--bg); border-radius: 11px; padding: 10px 14px;
}
.check.on { background: var(--ok-soft); color: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }

.note {
  background: var(--accent-soft); color: var(--text); border-radius: var(--radius);
  padding: 12px 14px; font-size: 14px; margin: 8px 0 4px; display: flex; gap: 10px; align-items: flex-start;
}

.hero { display: flex; align-items: center; gap: 14px; margin: 6px 0 4px; }
.hero .avatar { width: 64px; height: 64px; font-size: 28px; }
.hero .emoji-badge { width: 64px; height: 64px; font-size: 32px; border-radius: 18px; }
.hero .meta { color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 0; }
.stat { background: var(--card); border-radius: 12px; padding: 10px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

.segmented { display: flex; background: var(--line); border-radius: 10px; padding: 2px; margin: 4px 0 8px; }
.segmented button { flex: 1; border: 0; background: none; padding: 7px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.segmented button.on { background: var(--card); box-shadow: var(--shadow); }

details.past summary { list-style: none; cursor: pointer; }
details.past summary::-webkit-details-marker { display: none; }

/* ---------- Login */
.login { min-height: 100vh; padding: calc(40px + var(--safe-top)) 20px 40px; max-width: 480px; margin: 0 auto; }
.login .logo { font-size: 64px; text-align: center; }
.login h1 { text-align: center; margin: 8px 0 4px; font-size: 30px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 28px; }
.member-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px 10px; }
.member-grid button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 500; }
.member-grid .avatar { width: 68px; height: 68px; font-size: 28px; }

.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 24px 0; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--text); }
.pin-dots span.on { background: var(--text); }
.pin-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 24px; justify-content: center; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow);
  font-size: 30px; font-weight: 400;
}
.keypad button.plain { background: none; box-shadow: none; font-size: 16px; color: var(--accent); }
.keypad button:active { background: var(--line); }

/* ---------- Formulare & Sheets */
.form label { display: block; font-size: 13px; color: var(--muted); margin: 14px 4px 6px; font-weight: 600; }
.form input, .form select, .form textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 11px;
  padding: 12px; font-size: 16px; /* 16px verhindert Auto-Zoom auf iOS */
  appearance: none; -webkit-appearance: none;
}
.form select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.form textarea { min-height: 84px; resize: vertical; }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .hint { font-size: 13px; color: var(--muted); margin: 6px 4px 0; }
.form .error { color: var(--accent); font-size: 14px; margin-top: 12px; min-height: 1em; }
.form .switch { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; margin-top: 14px; }
.form .switch input { width: auto; appearance: auto; -webkit-appearance: auto; transform: scale(1.3); }
.prio-pick { display: flex; gap: 8px; }
.prio-pick button { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 11px; padding: 10px 4px; font-size: 13px; }
.prio-pick button.on { border-color: var(--accent); background: var(--accent-soft); }
.prio-pick button b { display: block; color: #f5a623; font-size: 15px; }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 50;
  animation: fade .2s ease-out;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: calc(100vh - 40px - var(--safe-top)); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  animation: up .25s ease-out;
  max-width: 640px; margin: 0 auto;
}
.sheet .grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.sheet-head h2 { font-size: 18px; margin: 0; flex: 1; text-align: center; }
.sheet-head .btn { min-width: 76px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 18px; border-radius: 22px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: calc(100% - 40px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
