:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --border: #e4dfd4;
  --text: #22201c;
  --muted: #6b665c;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --danger: #b3401f;
  --danger-soft: #f8e4dc;
  --warn: #9a6a00;
  --warn-soft: #fbf0d3;
  --shadow: 0 1px 2px rgba(34, 32, 28, .06), 0 4px 16px rgba(34, 32, 28, .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --surface: #211f1c;
    --surface-2: #1b1a17;
    --border: #35322c;
    --text: #efebe3;
    --muted: #a39d91;
    --accent: #5fb39a;
    --accent-ink: #0f1d18;
    --accent-soft: #1f3530;
    --danger: #ef8a6a;
    --danger-soft: #3a221a;
    --warn: #e5b94f;
    --warn-soft: #36301c;
    --shadow: none;
    color-scheme: dark;
  }
}

/* Manuell gewählter Dunkelmodus (Profil → Darstellung). Werte wie oben. */
:root[data-theme="dark"] {
  --bg: #161513;
  --surface: #211f1c;
  --surface-2: #1b1a17;
  --border: #35322c;
  --text: #efebe3;
  --muted: #a39d91;
  --accent: #5fb39a;
  --accent-ink: #0f1d18;
  --accent-soft: #1f3530;
  --danger: #ef8a6a;
  --danger-soft: #3a221a;
  --warn: #e5b94f;
  --warn-soft: #36301c;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* --- Darstellung: Segment-Auswahl System / Hell / Dunkel --- */
.segmented {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  max-width: 100%;
}
.segmented label {
  margin: 0; position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; min-height: 40px; border-radius: 9px;
  font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow); outline: 1px solid var(--border); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-footer { display: flex; justify-content: center; margin-top: 8px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 760px; margin: 0 auto; padding: 16px 16px 96px; }

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; letter-spacing: -.02em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 24px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* --- Karten --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card.soft { background: var(--surface-2); box-shadow: none; }

/* --- Formulare --- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=number], input[type=date], select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.code-input { text-transform: uppercase; letter-spacing: .15em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
}
button:disabled { opacity: .55; cursor: default; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-block { width: 100%; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 12px; min-height: 32px; font-weight: 500; font-size: .875rem;
}
.chip[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

.checklist { display: grid; gap: 6px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 0; padding: 6px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-weight: 500; margin: 0; }
.switch input { width: 44px; height: 24px; accent-color: var(--accent); }

/* --- Kopf & Navigation --- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 18px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 1.6rem; }
.brand select { width: auto; max-width: 60vw; font-weight: 700; font-size: 1.1rem; background: transparent; border-color: transparent; padding: 4px 6px; }
.brand-title { font-weight: 700; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs a {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 600;
}
.tabs a .ico { font-size: 1.25rem; line-height: 1; }
.tabs a[aria-current=page] { color: var(--accent); background: var(--accent-soft); }

/* --- Aufgaben --- */
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 0 10px; }
.section-title:first-child { margin-top: 0; }
.task { display: grid; gap: 12px; }
.task.mine { border-color: var(--accent); }
.task-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.task-name { font-size: 1.1rem; font-weight: 700; }
.task-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.task-actions .primary { flex: 1; min-width: 140px; }

.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.pill.overdue { background: var(--danger-soft); color: var(--danger); }
.pill.today { background: var(--warn-soft); color: var(--warn); }
.pill.soon, .pill.later { background: var(--accent-soft); color: var(--accent); }
.pill.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.avatar {
  --c: var(--accent);
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--c); color: #fff; font-weight: 700; font-size: .85rem;
}
.avatar.sm { width: 22px; height: 22px; font-size: .7rem; }
.avatar.emoji { background: color-mix(in srgb, var(--c) 22%, transparent); font-size: 1.05rem; font-weight: 400; line-height: 1; }
.avatar.sm.emoji { font-size: .8rem; }

.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.emoji-opt {
  aspect-ratio: 1; min-height: 44px; padding: 0; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.35rem; line-height: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.emoji-opt.initial { font-size: 1rem; font-weight: 700; color: var(--muted); }
.emoji-opt:hover { border-color: var(--accent); }
.emoji-opt:active { transform: scale(.92); }
.emoji-opt[aria-checked=true] { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.emoji-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.person { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.upcoming { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.upcoming .sep { opacity: .5; }

.empty { text-align: center; padding: 32px 18px; }
.empty .big { font-size: 2.5rem; }

/* --- Listen --- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }

/* Mitgliederliste: Name + Zahl in einer Zeile, Admin-Knöpfe auf schmalen Bildschirmen darunter */
.list li.member { flex-wrap: wrap; row-gap: 4px; }
.member .count { order: 2; min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }
.member-actions { order: 3; flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px; padding-left: 30px; }
@media (min-width: 600px) {
  .list li.member { flex-wrap: nowrap; }
  .member-actions { order: 1; flex-basis: auto; padding-left: 0; }
}
.badge { font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

.invite-link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem;
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px;
  padding: 10px 12px; overflow-wrap: anywhere;
}
.code-big { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.5rem; font-weight: 700; letter-spacing: .2em; }

/* --- Startseite --- */
.hero { text-align: center; padding: 28px 0 8px; }
.hero .logo { font-size: 3rem; }
.hero p { max-width: 460px; margin: 10px auto 0; }
.grid-2 { display: grid; gap: 16px; }
@media (min-width: 680px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.notice { text-align: center; padding: 48px 16px; }
.notice .big { font-size: 3rem; }

/* --- Dialog & Toast --- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem;
  max-width: calc(100vw - 32px); z-index: 20; box-shadow: var(--shadow);
}
#toast.error { background: var(--danger); color: #fff; }

.error-text { color: var(--danger); font-size: .9rem; }
.spinner { padding: 48px; text-align: center; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* =========================================================================
   Bewegung & Interaktion – dezent, kurz, mit weicher Ausklang-Kurve
   ========================================================================= */
:root {
  --ease: cubic-bezier(.2, .8, .2, 1);      /* weiches Ausklingen */
  --ease-spring: cubic-bezier(.3, 1.4, .5, 1); /* minimales Nachfedern */
  --t-fast: 140ms;
  --t: 240ms;
  --t-slow: 420ms;
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* Weicher Farbwechsel beim Umschalten Hell/Dunkel (nur während des Wechsels aktiv). */
html.theme-fade, html.theme-fade * {
  transition: background-color var(--t-slow) var(--ease), border-color var(--t-slow) var(--ease), color var(--t-slow) var(--ease) !important;
}

/* --- Bedienelemente --- */
button, .btn, .chip, .tabs a, .segmented label {
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease), border-color var(--t) var(--ease),
    box-shadow var(--t) var(--ease), transform var(--t-fast) var(--ease), opacity var(--t) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
button:not(:disabled):active, .btn:active, .chip:active { transform: scale(.97); }
input, select { transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background-color var(--t) var(--ease); }
input:focus-visible, select:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

@media (hover: hover) {
  button:not(:disabled):hover, .btn:hover { filter: brightness(1.06); }
  .btn-secondary:not(:disabled):hover, .chip:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); filter: none; }
  .btn-ghost:not(:disabled):hover { background: var(--surface-2); color: var(--text); filter: none; }
  .tabs a:not([aria-current=page]):hover { color: var(--text); background: var(--surface-2); }
  .card.task { transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease), border-color var(--t) var(--ease); }
  .card.task:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(34, 32, 28, .06), 0 10px 28px rgba(34, 32, 28, .08); }
}
.tabs a .ico { transition: transform var(--t) var(--ease-spring); }
.tabs a[aria-current=page] .ico { transform: translateY(-1px) scale(1.08); }

/* --- Eintritt von Ansichten und Karten --- */
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.enter > *, .enter .stagger > * { animation: rise-in var(--t-slow) var(--ease) both; }
:is(.enter .stagger, .enter.stagger) > *:nth-child(2) { animation-delay: 40ms; }
:is(.enter .stagger, .enter.stagger) > *:nth-child(3) { animation-delay: 80ms; }
:is(.enter .stagger, .enter.stagger) > *:nth-child(4) { animation-delay: 120ms; }
:is(.enter .stagger, .enter.stagger) > *:nth-child(5) { animation-delay: 160ms; }
:is(.enter .stagger, .enter.stagger) > *:nth-child(n+6) { animation-delay: 200ms; }

/* --- Kopfzeile: beim Scrollen leicht abgesetzt --- */
.topbar {
  position: sticky; top: 0; z-index: 6;
  margin: -16px -16px 18px; padding: 14px 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.topbar.scrolled { border-bottom-color: var(--border); }

/* --- Aufgabe erledigt: kurzes Bestätigen, dann neuer Stand --- */
@keyframes done-pop { 0% { transform: scale(1); } 40% { transform: scale(.985); } 100% { transform: scale(1); } }
@keyframes check-in { from { transform: scale(.4) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
.task.is-done { animation: done-pop var(--t-slow) var(--ease); border-color: var(--accent); box-shadow: var(--ring); }
.task.is-done .primary { background: var(--accent); }
.task.is-done .primary .tick { display: inline-block; animation: check-in var(--t) var(--ease-spring) both; }
.task.is-passed { opacity: .6; transform: translateX(6px); transition: opacity var(--t) var(--ease), transform var(--t) var(--ease); }

@keyframes flash { from { background-color: var(--accent-soft); } to { background-color: var(--surface); } }
.task.flash { animation: flash 1.2s var(--ease) both; }

/* --- Ladezustand: Platzhalter mit sanftem Schimmer statt Text --- */
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.skeleton {
  border-radius: var(--radius); border: 1px solid var(--border);
  background: linear-gradient(90deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite, fade-in var(--t) var(--ease) both;
}
.skeleton.line { height: 18px; border-radius: 8px; border: 0; }
.skeleton.card-ph { height: 132px; }

/* --- Dialog: einblenden und sanft ausblenden --- */
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes backdrop-out { to { opacity: 0; } }
dialog[open] { animation: dialog-in var(--t) var(--ease); }
dialog[open]::backdrop { animation: backdrop-in var(--t) var(--ease); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
dialog.closing { animation: dialog-out 180ms var(--ease) forwards; }
dialog.closing::backdrop { animation: backdrop-out 180ms var(--ease) forwards; }

/* Auf dem Handy kommt der Dialog als Sheet von unten. */
@media (max-width: 599px) {
  dialog { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 20px 20px 0 0; border-bottom: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  @keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
  @keyframes sheet-out { to { transform: translateY(100%); } }
  dialog[open] { animation: sheet-in 320ms var(--ease); }
  dialog.closing { animation: sheet-out 220ms var(--ease) forwards; }
}

/* --- Toast --- */
#toast {
  transform: translate(-50%, 12px); opacity: 0;
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease-spring);
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- Breitere Bildschirme: Navigation oben, Aufgaben zweispaltig --- */
@media (min-width: 900px) {
  #app { max-width: 1040px; padding: 16px 32px 48px; }
  .topbar { margin: -16px -32px 0; padding: 18px 32px 12px; }
  .tabs {
    position: sticky; top: 64px; bottom: auto; z-index: 5;
    justify-content: flex-start; gap: 4px;
    width: max-content; margin: 0 0 24px; padding: 4px;
    border: 1px solid var(--border); border-radius: 12px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  }
  .tabs a { flex: none; flex-direction: row; gap: 8px; padding: 8px 16px; font-size: .92rem; }
  .tabs a .ico { font-size: 1rem; }
  .tabs a[aria-current=page] .ico { transform: none; }
  #toast { bottom: 28px; }
  .task-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
  .task-grid > * + * { margin-top: 0; }
  .grid-2 { gap: 20px; }
  .stats { gap: 16px; }
}
@media (min-width: 900px) and (hover: hover) {
  .task-grid .card.task:hover { transform: translateY(-2px); }
}

/* --- Wer weniger Bewegung möchte, bekommt (fast) keine --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, dialog::backdrop {
    animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
  .card.task:hover { transform: none; }
}

/* Bearbeiten: auf dem Handy nur als Symbol, damit die Aktionen in eine Zeile passen. */
.btn-edit .ico { display: none; font-size: 1.1rem; }
@media (max-width: 599px) {
  .task-actions { flex-wrap: nowrap; }
  .task-actions .primary { min-width: 0; }
  .btn-edit { width: 44px; padding: 0; flex: none; }
  .btn-edit .ico { display: inline; }
  .btn-edit .label { display: none; }
}
