:root {
  --bg: #f7f3ee;
  --card: #ffffff;
  --text: #2a2522;
  --muted: #7a706a;
  --border: #e6ddd4;
  --accent: #d9576b;
  --accent-text: #ffffff;
  --ok: #3a9d5d;
  --danger: #c0392b;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1917;
    --card: #262320;
    --text: #f2ece6;
    --muted: #a99f97;
    --border: #3a3531;
    --accent: #ee7486;
    --accent-text: #1b1917;
  }
}

* { box-sizing: border-box; }

/* „hidden“ muss gewinnen, auch gegen display-Regeln einzelner Komponenten. */
[hidden] { display: none !important; }

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

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 32px);
}

h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 32px 0 4px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; margin: 2px 0 0; }

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button.wide { width: 100%; margin: 16px 0 4px; }
button.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}
button.danger { color: var(--danger); }
button:disabled { opacity: .5; }

input, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  margin-top: 4px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { font-size: .9rem; color: var(--muted); }
.stack label input, .stack label textarea { color: var(--text); font-size: 1rem; }
.row { display: flex; gap: 10px; justify-content: flex-end; }
.error { color: var(--danger); margin: 0; }

.login { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.login form { text-align: left; margin-top: 24px; }
.login-icon { width: 72px; height: 72px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.badge {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 6px;
  padding: 0 6px;
  font-size: .75rem;
  font-weight: 600;
}
.live { color: var(--muted); font-size: .8rem; padding-top: 8px; }
.live.on { color: var(--ok); }

.cards { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
}
.card.no-image { grid-template-columns: 1fr; }
.card img {
  width: 84px;
  height: 84px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
}
.card h3 { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: .9rem; margin: 2px 0 0; }
.card .note { margin: 6px 0 0; font-size: .95rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.card .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.card .actions a {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.compact .card { padding: 10px 14px; }
.compact .card img { width: 52px; height: 52px; }
.compact .actions { margin-top: 8px; }

.empty { text-align: center; color: var(--muted); margin: 32px 0; }

dialog {
  border: 0;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}

.preview {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
}
.preview img { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; background: #fff; }
.preview img[src=""] { display: none; }

.setup {
  margin-top: 40px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.setup summary { cursor: pointer; font-weight: 600; }
.setup h3 { font-size: 1rem; margin: 20px 0 4px; }
.setup ol { padding-left: 20px; }
.setup li { margin-bottom: 8px; }
.setup textarea { font: 12px/1.3 ui-monospace, Menlo, monospace; margin: 6px 0; }
.bookmarklet {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
}

.chips {
  display: flex;
  gap: 8px;
  margin: 16px -16px 0;
  padding: 0 16px 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: .9rem;
  white-space: nowrap;
}
.chips button[aria-pressed="true"] {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}
.chips .count { opacity: .6; margin-left: 4px; }
.chips button:disabled { opacity: .4; }

#add-gift::before { content: "+ "; }

.theme-picker { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; }
.theme-picker select {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 6px;
}

/* ---------- Name der Liste & Monogramm ---------- */

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title live" "who who";
  gap: 10px 12px;
  align-items: start;
}
.title-row { grid-area: title; display: flex; align-items: center; gap: 14px; min-width: 0; }
.who { grid-area: who; }
.who .small { margin: 0; }
.live { grid-area: live; }

.kicker {
  margin: 0 0 2px;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.topbar .list-name { font-size: 2.1rem; line-height: 1.05; overflow-wrap: anywhere; }

.monogram {
  --size: 54px;
  flex: none;
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border-radius: 30%;
  background: var(--person, var(--accent));
  color: #fff;
  font: 700 calc(var(--size) * .52) / 1 var(--serif, Georgia, serif);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--person, var(--accent)) 35%, transparent);
}
.monogram:empty { display: none; }

.login .monogram { --size: 84px; margin: 0 auto 14px; transform: rotate(-4deg); }
.login .monogram:not(:empty) + .login-icon { display: none; }
.login .kicker { margin-top: 4px; }
.login .list-name { font-size: 2.2rem; }

/* ---------- Mehrere Listen: „Für wen?“ & Wechsel ---------- */

.target-picker { display: flex; flex-direction: column; gap: 6px; }
.target-options { display: flex; flex-wrap: wrap; gap: 8px; }
.target-options button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 5px;
  border-radius: 999px;
}
.target-options button[aria-pressed="true"] {
  border-color: var(--c);
  box-shadow: inset 0 0 0 1.5px var(--c);
  font-weight: 600;
}
.person-dot {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 30%;
  background: var(--c);
  color: #fff;
  font: 700 .8rem / 1 var(--serif, Georgia, serif);
}
/* Monogramm in der Kopfzeile: öffnet das Menü mit den anderen Listen */
.list-switch { position: relative; flex: none; }
.monogram-button {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 30%;
  background: none;
}
.monogram-button:disabled { opacity: 1; cursor: default; }
.monogram-button:not(:disabled)::after {
  content: "▾";
  position: absolute;
  right: -5px;
  bottom: -5px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: .7rem;
  box-shadow: 0 1px 3px rgb(0 0 0 / .15);
}
.list-menu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 10;
  min-width: 210px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 10px 30px rgb(0 0 0 / .18);
}
.list-menu p { margin: 0 4px 6px; }
.list-menu nav { display: flex; flex-direction: column; gap: 2px; }
.list-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.list-menu a:hover, .list-menu a:focus-visible { background: var(--bg); }
.list-menu .person-dot { width: 30px; height: 30px; font-size: .9rem; }
