:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1f1d1a;
  --muted: #6d675f;
  --line: #ddd6cb;
  --accent: #b9770e;
  --accent-text: #ffffff;
  --accent-soft: #f6e7cc;
  --good: #2e7d32;
  --good-soft: #dcefdc;
  --bad: #c62828;
  --bad-soft: #f8dcdc;
  --warn: #a86600;
  --warn-soft: #f7e6c7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1f1e1b;
    --surface-2: #2a2925;
    --text: #f1ede6;
    --muted: #a39d93;
    --line: #34322d;
    --accent: #e8a33a;
    --accent-text: #1a1408;
    --accent-soft: #3b2e17;
    --good: #6cc070;
    --good-soft: #1e3320;
    --bad: #ef6b6b;
    --bad-soft: #3d1f1f;
    --warn: #e8a33a;
    --warn-soft: #3b2e17;
    --shadow: none;
    color-scheme: dark;
  }
}

/* Schrift aus dem Logo (Courgette, SIL Open Font License) */
@font-face {
  font-family: 'Courgette';
  src: url('fonts/courgette-latin.woff2') format('woff2');
  font-display: swap;
}

* { box-sizing: border-box; }

/* Logo: Linienfarbe = Akzentfarbe, Flächen in der Farbe des Untergrunds */
.logo { color: var(--accent); --logo-bg: var(--surface); }
.logo svg { display: block; width: 100%; height: auto; }
.login .logo { width: 240px; max-width: 80%; margin: 0 auto 8px; }
.top .logo { width: 40px; flex-shrink: 0; --logo-bg: var(--bg); }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

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

button { cursor: pointer; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}
.top .wrap { display: flex; align-items: center; gap: 12px; height: 56px; }
.top h1 { font-size: 1.1rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { font-size: .85rem; color: var(--muted); text-align: right; line-height: 1.2; }
.who b { color: var(--text); }

/* Terminleiste unter der Kopfzeile (Abend / Schocken) */
.mbar { border-top: 1px solid var(--line); }
.mbar .wrap { display: flex; align-items: center; height: 38px; }
.mbar-main { flex: 1; min-width: 0; display: flex; align-items: baseline; justify-content: center; gap: 8px; white-space: nowrap; overflow: hidden; }
.mbar-date { font-weight: 700; font-size: .92rem; }
.mbar-rel { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.mbar-rel.now { color: var(--accent); font-weight: 600; }

/* Startseite */
.hello { font-size: 1.25rem; margin: 4px 0 14px; }
.hero { border-color: var(--accent); }
.hero-kicker { font-size: .85rem; font-weight: 700; color: var(--accent); }
.hero-date { font-size: 1.5rem; font-weight: 800; margin-top: 2px; }
.card.click { cursor: pointer; }

/* Rückblick */
.rounds-detail { margin-top: 6px; }
.rounds-detail > summary { cursor: pointer; font-size: .85rem; color: var(--accent); font-weight: 600; padding: 4px 0; }

/* Kalender */
.cal-date {
  width: 44px; flex-shrink: 0; text-align: center; line-height: 1.1;
  border-radius: 10px; padding: 5px 0; background: var(--surface-2);
}
.cal-date b { display: block; font-size: 1.15rem; }
.cal-date span { font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.cal-date.st { background: var(--accent-soft); }
.cal-date.st b, .cal-date.st span { color: var(--warn); }

/* Ämter & Satzung */
details.card > summary.summary { cursor: pointer; font-weight: 700; display: flex; gap: 10px; align-items: baseline; list-style: none; }
details.card > summary.summary::-webkit-details-marker { display: none; }
details.card > summary.summary::before { content: '›'; color: var(--muted); transition: transform .15s; }
details.card[open] > summary.summary::before { transform: rotate(90deg); }
details.card[open] > summary.summary { margin-bottom: 10px; }
.statute { font-size: .95rem; line-height: 1.55; }
.statute h3 { font-size: 1rem; margin: 18px 0 6px; }
.statute h3:first-child { margin-top: 0; }
.statute p { margin: 0 0 10px; }
.statute ul { margin: 0 0 10px; padding-left: 20px; }
textarea.statute-edit { min-height: 55vh; font-size: .9rem; line-height: 1.45; }

.lock-note { background: var(--surface-2); font-size: .9rem; color: var(--muted); }
.att-line { font-size: .9rem; line-height: 1.5; }

main { padding: 16px 0 calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }

/* Navigation unten */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .wrap { display: flex; padding: 0; }
.nav button {
  flex: 1; height: var(--nav-h);
  border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .72rem; color: var(--muted);
}
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--accent); font-weight: 600; }

/* Karten */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .sp { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 4px; }

/* Formulare */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.check input { width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--accent); }

/* Listen */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.list .sub { font-size: .8rem; color: var(--muted); font-weight: 400; }
.list li.click { cursor: pointer; }
.cancelled { opacity: .55; }
.cancelled .strike { text-decoration: line-through; }

/* Segment-Schalter Anwesenheit */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.seg button { border: 0; background: var(--surface); min-width: 44px; height: 38px; padding: 0 8px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on.present { background: var(--good); color: #fff; }
.seg button.on.excused { background: var(--warn); color: #fff; }
.seg button.on.absent { background: var(--bad); color: #fff; }

/* Auswahl-Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px;
  border-radius: 20px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .amt { font-weight: 400; opacity: .8; margin-left: 4px; }

/* Schocken-Raster */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.player {
  position: relative;
  min-height: 72px; padding: 8px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2);
  font-weight: 700; font-size: 1rem;
  overflow-wrap: anywhere;
}
.player:active { transform: scale(.97); }
.player .badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  background: var(--bad); color: #fff; font-size: .8rem; line-height: 24px;
}
.round-no { font-size: 1.6rem; font-weight: 800; }

/* Beträge */
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.owes { color: var(--bad); }
.credit { color: var(--good); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.stat .v { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .8rem; color: var(--muted); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .75rem; font-weight: 700; background: var(--accent-soft); color: var(--warn); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* Tabelle */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 6px; text-align: right; border-top: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { font-size: .75rem; color: var(--muted); border-top: 0; cursor: pointer; user-select: none; }
th.sorted { color: var(--accent); }

/* Modal */
.backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) {
  .backdrop { align-items: center; }
  .modal { border-radius: 18px; }
}
.modal h3 { margin: 0 0 16px; font-size: 1.15rem; display: flex; align-items: center; }
.modal h3 span { flex: 1; }
.modal .actions { display: flex; gap: 8px; margin-top: 20px; }
.modal .actions .btn { flex: 1; }
.label { font-size: .85rem; color: var(--muted); margin: 16px 0 8px; }

/* Hinweis unten */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); color: #fff; }

/* Anmelden */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; text-align: center; }
.login h1 { font-size: 1.3rem; margin: 12px 0 4px; }
.login .input { text-align: center; font-size: 1.4rem; letter-spacing: .2em; margin: 16px 0; }
.login .input::placeholder { font-size: 1rem; letter-spacing: normal; }

.empty { color: var(--muted); text-align: center; padding: 12px 0; font-size: .9rem; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
