:root {
  --bg: #f4f6f1;
  --surface: #ffffff;
  --surface-2: #eef2ea;
  --text: #17201a;
  --muted: #5d6b61;
  --border: #dbe2d6;
  --brand: #1f6f43;
  --brand-ink: #ffffff;
  --brand-soft: #e2f2e7;
  --accent: #d4f24a;
  --good: #1f7a45;
  --good-soft: #def3e5;
  --warn: #8a5a00;
  --warn-soft: #fbefd2;
  --bad: #b3261e;
  --bad-soft: #fbe3e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 4px 16px rgb(0 0 0 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101512;
    --surface: #18201b;
    --surface-2: #202a23;
    --text: #e8efe9;
    --muted: #9aab9f;
    --border: #2d3a31;
    --brand: #4fbf7d;
    --brand-ink: #0b1a10;
    --brand-soft: #1c3526;
    --accent: #d4f24a;
    --good: #6fd497;
    --good-soft: #193524;
    --warn: #f2c35b;
    --warn-soft: #3a2f14;
    --bad: #ff8a80;
    --bad-soft: #3d1c1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

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

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 0 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.ball {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent);
  box-shadow: inset -3px -3px 0 rgb(0 0 0 / 12%); position: relative; flex: none;
}
.ball::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 30% 35%, #0003 2px, transparent 3px),
    radial-gradient(circle at 65% 30%, #0003 2px, transparent 3px),
    radial-gradient(circle at 55% 68%, #0003 2px, transparent 3px),
    radial-gradient(circle at 28% 70%, #0003 2px, transparent 3px);
}

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats.four { grid-template-columns: repeat(4, 1fr); }
.stat { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .stats.four { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .stat .value { font-size: 1.15rem; } }

button, .btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 10px 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  text-decoration: none;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--bad); }
button.small { min-height: 34px; padding: 5px 10px; font-size: 0.875rem; }
button.link { border: 0; background: none; color: var(--brand); padding: 4px; min-height: 0; }
button.block { width: 100%; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 140px; margin-bottom: 0; }
.row > .field.tight { flex: 0 1 110px; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  white-space: nowrap;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }

.session {
  display: flex; gap: 14px; align-items: center; padding: 14px 0; border-top: 1px solid var(--border);
}
.session:first-of-type { border-top: 0; padding-top: 0; }
.date-badge {
  flex: none; width: 56px; text-align: center; border-radius: 10px; background: var(--brand-soft);
  color: var(--brand); padding: 6px 0; line-height: 1.1;
}
.date-badge .d { font-size: 1.35rem; font-weight: 800; }
.date-badge .m { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.session .info { flex: 1; min-width: 0; }
.session .who { font-size: 0.85rem; color: var(--muted); }
.rsvp { display: flex; gap: 6px; flex: none; }
.rsvp button { min-width: 44px; padding: 8px 12px; }
.rsvp button[aria-pressed="true"].yes { background: var(--good); border-color: var(--good); color: var(--brand-ink); }
.rsvp button[aria-pressed="true"].no { background: var(--surface-2); border-color: var(--muted); }
@media (max-width: 480px) {
  .session { flex-wrap: wrap; }
  .session .info { flex-basis: calc(100% - 70px); }
  .rsvp { width: 100%; }
  .rsvp button { flex: 1; }
}

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

.balance-hero { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.balance-hero .amount { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog .body { padding: 20px; }
.copy-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
}
.copy-row .k { font-size: 0.78rem; color: var(--muted); }
.copy-row .v { font-weight: 700; font-size: 1.05rem; word-break: break-all; }
.amounts { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.amounts button[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  opacity: 0; transition: 0.2s; pointer-events: none; z-index: 10; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); color: #fff; }

.hidden { display: none !important; }
.center-card { max-width: 420px; margin: 8vh auto 0; }

/* admin */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button {
  border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; color: var(--muted);
  padding: 10px 12px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { background: var(--surface-2); font-size: 0.8rem; color: var(--muted); font-weight: 700; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { background: var(--surface-2); font-weight: 700; }
td input, td select { min-height: 36px; padding: 6px 8px; }
.grid th.sticky, .grid td.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.grid thead th.sticky, .grid tfoot td.sticky { background: var(--surface-2); z-index: 2; }
.grid td.cell { text-align: center; padding: 4px; }
.grid th.col { text-align: center; }
.grid .past { }
.grid .future { opacity: 0.55; }
.grid .cancelled { text-decoration: line-through; opacity: 0.5; }
.cellbox { display: inline-flex; align-items: center; justify-content: center; position: relative; width: 34px; height: 34px; border-radius: 8px; }
.cellbox.rsvp-yes { box-shadow: inset 0 0 0 2px var(--good); }
.cellbox.rsvp-no { background: var(--surface-2); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); margin: 10px 0 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }
.alert { border-left: 4px solid var(--warn); background: var(--warn-soft); padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
