:root {
  --bg: #f6f1ea;
  --surface: #ffffff;
  --surface-2: #f0e9df;
  --text: #1d2230;
  --muted: #6b6f7b;
  --line: #e3dace;
  --accent: #e0662b;
  --accent-ink: #ffffff;
  --accent-soft: #fbe3d4;
  --yes: #1f8a5b;
  --yes-soft: #dcf1e6;
  --maybe: #b07a0c;
  --maybe-soft: #f8ecc9;
  --no: #8a8f99;
  --no-soft: #ebe8e3;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgb(40 30 20 / 6%), 0 4px 16px rgb(40 30 20 / 6%);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161f;
    --surface: #1b212d;
    --surface-2: #232a38;
    --text: #eef0f4;
    --muted: #9aa1b0;
    --line: #2c3444;
    --accent: #ff8a4c;
    --accent-ink: #1a0f08;
    --accent-soft: #3a2619;
    --yes: #4cc78d;
    --yes-soft: #173828;
    --maybe: #e8b441;
    --maybe-soft: #3a3016;
    --no: #9aa1b0;
    --no-soft: #2a303c;
    --danger: #ff6b5b;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }

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

.muted { color: var(--muted); }

/* ---------- header ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.top-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  padding-bottom: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.4;
  stroke-linecap: round;
}
.brand-mark circle { fill: var(--accent-soft); clip-path: inset(0 0 50% 0); }

.whoami {
  font: inherit;
  font-size: 0.875rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 10px 12px 9px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  border-bottom: 2.5px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

/* .wrap sets side padding only; this needs to outrank it. */
main.wrap { padding-top: 20px; padding-bottom: 24px; }

.foot { padding-bottom: 32px; text-align: center; font-size: 0.85rem; }
.foot a { color: var(--muted); }

/* ---------- run cards ---------- */

.stack { display: grid; gap: 14px; }

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

.card.next { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card.cancelled { opacity: 0.75; }

.run-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }

.run-when { font-weight: 750; font-size: 1.15rem; letter-spacing: -0.01em; }
.run-when .rel {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: 2px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 999px;
}

.run-time { font-weight: 700; font-size: 1.15rem; white-space: nowrap; font-variant-numeric: tabular-nums; }

.run-where { margin-top: 2px; color: var(--muted); }
.run-where a { color: inherit; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); text-underline-offset: 2px; }
.run-where a::after { content: " ↗"; font-size: 0.8em; }

.run-note {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  font-size: 0.925rem;
}

.cancel-banner {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--no-soft);
  color: var(--danger);
  font-weight: 650;
}

.rsvp { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-top: 14px; }

.rsvp button {
  font: inherit;
  font-weight: 650;
  font-size: 0.95rem;
  padding: 11px 6px;
  border-radius: 11px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.rsvp button:active { transform: scale(0.97); }
.rsvp button:disabled { cursor: progress; }
.rsvp button[aria-pressed="true"][data-status="yes"] { background: var(--yes); border-color: var(--yes); color: #fff; }
.rsvp button[aria-pressed="true"][data-status="maybe"] { background: var(--maybe-soft); border-color: var(--maybe); color: var(--maybe); }
.rsvp button[aria-pressed="true"][data-status="no"] { background: var(--no-soft); border-color: var(--no); color: var(--text); }

.tally { margin-top: 14px; display: grid; gap: 8px; }
.tally-row { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tally-label { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); min-width: 64px; }
.tally-label.yes { color: var(--yes); }
.tally-label.maybe { color: var(--maybe); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.chip {
  font-size: 0.875rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}
.chip.yes { background: var(--yes-soft); }
.chip.maybe { background: var(--maybe-soft); }
.chip.me { outline: 1.5px solid currentColor; outline-offset: -1.5px; font-weight: 650; }

.empty-row { font-size: 0.9rem; color: var(--muted); }

.admin-row { margin-top: 12px; display: flex; justify-content: flex-end; }

.link-btn {
  font: inherit;
  font-size: 0.875rem;
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 0;
}

/* ---------- history ---------- */

.section-title { font-size: 0.8rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 24px 0 10px; }
.section-title:first-child { margin-top: 0; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.8rem; color: var(--muted); }

.board { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.board th, .board td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 0.925rem; }
.board tr:last-child td { border-bottom: 0; }
.board th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; background: var(--surface-2); }
.board td.num, .board th.num { text-align: right; font-variant-numeric: tabular-nums; }
.board tr.me td { font-weight: 700; }

.past { display: grid; gap: 8px; }
.past-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.past-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.past-head b { font-weight: 700; }
.past-count { font-weight: 700; color: var(--yes); white-space: nowrap; }
.past-where { font-size: 0.875rem; color: var(--muted); }
.past-names { margin-top: 6px; font-size: 0.9rem; }
.past-actions { margin-top: 6px; }

/* ---------- forms / organizer ---------- */

label { display: grid; gap: 4px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.95rem; }

input, select {
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

form.card, .card form { display: grid; gap: 12px; }

.actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

button.primary, button.ghost {
  font: inherit;
  font-weight: 650;
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  border: 1.5px solid transparent;
}
button.primary { background: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
button.danger { color: var(--danger); }

.error { color: var(--danger); font-size: 0.9rem; margin: 0; min-height: 0; }
.error:empty { display: none; }

.sched-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sched-head h3 { margin: 0; font-size: 1rem; }
.pill { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--no-soft); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.hint { font-size: 0.875rem; color: var(--muted); margin: 0; }

/* ---------- dialogs ---------- */

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(10 12 20 / 45%); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h2 { margin: 0; font-size: 1.2rem; }
dialog p { margin: 0; }

/* ---------- misc ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.925rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.placeholder { text-align: center; color: var(--muted); padding: 40px 0; }

.skeleton { height: 190px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.55; } to { opacity: 1; } }

@media (max-width: 380px) {
  .rsvp button { font-size: 0.875rem; }
  .summary { gap: 6px; }
  .stat { padding: 10px; }
}

/* ---------- organizer: people ---------- */

.people { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.person { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person-main { flex: 1; min-width: 0; display: grid; }
.person-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-meta { font-size: 0.8rem; color: var(--muted); }
label.check.small { font-size: 0.875rem; gap: 6px; white-space: nowrap; }
label.check.small input { width: 18px; height: 18px; }

/* ---------- photos ---------- */

.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 10px; }
.thumb {
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--surface-2);
  cursor: zoom-in;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.photo-group { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.photo-group .past-head { align-items: baseline; }
.photo-group .past-where { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.past-actions { display: flex; flex-wrap: wrap; gap: 4px 18px; }

dialog.lightbox {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 0;
  background: #000;
  color: #fff;
  padding: 0;
}
dialog.lightbox[open] { display: grid; grid-template-rows: 1fr auto; }
dialog.lightbox::backdrop { background: #000; }
.lightbox figure { margin: 0; min-height: 0; display: grid; grid-template-rows: 1fr auto; padding-top: env(safe-area-inset-top); }
.lightbox img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.lightbox figcaption { text-align: center; font-size: 0.9rem; color: #ccc; padding: 8px 16px 0; }
.lb-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  border: 0;
  border-radius: 10px;
  background: rgb(255 255 255 / 12%);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}
.lb-prev { left: 8px; }
.lb-next { right: 8px; }
.lb-bar { display: flex; align-items: center; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); }
.lb-bar .spacer { flex: 1; }
.lb-text { font: inherit; font-weight: 650; background: none; border: 0; color: #fff; padding: 8px 4px; cursor: pointer; }
.lb-text.danger { color: #ff7b6b; }

@media (max-width: 400px) {
  .tabs a { padding-left: 9px; padding-right: 9px; }
}

.jump { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.jump button {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.section-title { scroll-margin-top: 110px; }
.person-actions { display: flex; gap: 16px; margin-top: 2px; }
.person-actions .link-btn { padding: 2px 0; font-size: 0.825rem; }
.link-btn.danger { color: var(--danger); }
