:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe7d6;
  --ink: #2a2621;
  --muted: #7a716444;
  --muted-ink: #6b6258;
  --line: #e0d6c2;
  --primary: #6b3fa0;
  --primary-ink: #ffffff;
  --primary-weak: #ede4f6;
  --yes: #3f8f5b;
  --ifneedbe: #c99a2e;
  --no: #b7442f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(40, 32, 20, 0.08), 0 6px 18px rgba(40, 32, 20, 0.06);
  --maxw: 960px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17151f;
    --surface: #201d2b;
    --surface-2: #2a2637;
    --ink: #ece7f2;
    --muted-ink: #a79fb5;
    --line: #352f45;
    --primary: #9b6fd4;
    --primary-weak: #2c2540;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

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

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark { color: var(--primary); }
.topnav { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted-ink); font-size: 0.9rem; }
.inline { display: inline; margin: 0; }

/* Buttons */
.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  background: var(--surface-2);
  color: var(--ink);
  transition: filter 0.12s ease, background 0.12s ease;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--no); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards & layout */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 40px auto; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px;
}
h1 { font-size: 1.6rem; margin: 0 0 4px; }
.muted { color: var(--muted-ink); }
.lede { font-size: 1.1rem; color: var(--muted-ink); max-width: 52ch; }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 10px; }
label { font-weight: 600; font-size: 0.9rem; }
input[type=text], input[type=email], input[type=datetime-local],
input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; }
.field { margin-bottom: 16px; }
.field .hint { font-size: 0.82rem; color: var(--muted-ink); margin-top: 4px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }

/* Flash messages */
.flashes { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); }
.flash-error { background: #fbecea; border-color: #edccc4; color: #8f2f1e; }
.flash-success { background: #eaf4ee; border-color: #c5e2d0; color: #2c6b45; }

/* Hero / landing */
.hero { padding: 24px 0; }
.hero h1 { font-size: 2.1rem; max-width: 18ch; }
.hero-actions { margin: 20px 0 32px; }
.feature-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px; margin-top: 24px;
}
.feature {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.feature h3 { margin: 0 0 6px; }
.feature p { margin: 0; color: var(--muted-ink); }

/* Event list */
.event-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.event-card {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
}
.event-title { font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--ink); }
.event-meta { display: flex; gap: 10px; align-items: center; margin-top: 6px; flex-wrap: wrap; font-size: 0.85rem; }
.tag {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 999px; font-weight: 700;
  background: var(--surface-2); color: var(--muted-ink);
}
.tag-poll { background: var(--primary-weak); color: var(--primary); }
.tag-grid { background: #e5eef7; color: #35618e; }
.tag-status-closed { background: #eee; color: #776; }
.tag-status-open { background: #eaf4ee; color: #2c6b45; }

/* Empty state */
.empty {
  text-align: center; padding: 48px 20px; border: 1px dashed var(--line);
  border-radius: var(--radius); color: var(--muted-ink);
}
.empty p { margin-top: 0; }

/* Footer */
.site-footer {
  text-align: center; padding: 24px; color: var(--muted-ink);
  font-size: 0.85rem; border-top: 1px solid var(--line);
}

/* Poll results table */
.results-table { width: 100%; border-collapse: collapse; }
.results-table th, .results-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: center;
}
.results-table th.opt { text-align: left; }
.results-table .best { background: var(--primary-weak); }
.cell-yes { color: var(--yes); font-weight: 700; }
.cell-no { color: var(--no); }
.cell-ifneedbe { color: var(--ifneedbe); font-weight: 700; }

/* Vote buttons */
.vote-group { display: inline-flex; gap: 6px; }
.vote-btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-weight: 600;
}
.vote-btn[aria-pressed=true].v-yes { background: var(--yes); color: #fff; border-color: var(--yes); }
.vote-btn[aria-pressed=true].v-no { background: var(--no); color: #fff; border-color: var(--no); }
.vote-btn[aria-pressed=true].v-ifneedbe { background: var(--ifneedbe); color: #fff; border-color: var(--ifneedbe); }

.share-link {
  display: flex; gap: 8px; align-items: center; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem;
  word-break: break-all;
}

[x-cloak] { display: none !important; }

/* Create-event form */
.mode-toggle { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.mode-opt {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-weight: 400;
}
.mode-opt input { margin-top: 3px; }
.slot-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.slot-row input { flex: 1; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; flex-wrap: wrap; }

/* Voting (poll respond) */
.respond-head { margin-bottom: 18px; }
.vote-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.vote-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; flex-wrap: wrap;
}
.vote-when { font-weight: 600; }
.vote-choices { display: inline-flex; gap: 6px; }
.choice {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: 0.9rem;
  font-weight: 600; user-select: none;
}
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }
.choice:has(input:checked).c-yes { background: var(--yes); color: #fff; border-color: var(--yes); }
.choice:has(input:checked).c-ifneedbe { background: var(--ifneedbe); color: #fff; border-color: var(--ifneedbe); }
.choice:has(input:checked).c-no { background: var(--no); color: #fff; border-color: var(--no); }

.pill-best {
  display: inline-block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--primary); color: #fff; border-radius: 999px; padding: 1px 8px;
  margin-left: 6px; vertical-align: middle; font-weight: 700;
}

/* Finalized banner */
.banner-final { border-color: var(--yes); }
.final-time { font-size: 1.3rem; font-weight: 700; margin: 6px 0 14px; }

.invitee-status { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { font-size: 0.8rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); }
.chip-done { background: #eaf4ee; color: #2c6b45; border-color: #c5e2d0; }
.chip-wait { background: var(--surface-2); color: var(--muted-ink); }

.table-scroll { overflow-x: auto; }
.danger-zone { border-color: #e5c3bb; background: transparent; }

/* Mobile refinements */
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
  .brand { font-size: 1.05rem; }
  .who { display: none; }
  .container { padding: 20px 16px 56px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .hero h1 { font-size: 1.7rem; }
  .btn { padding: 8px 13px; }
  .vote-row { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* Availability grid (paint UI + heatmap) */
.grid-wrap { overflow-x: auto; }
.avail-grid { border-collapse: collapse; user-select: none; }
.avail-grid th { font-size: 0.75rem; font-weight: 600; padding: 4px 6px; color: var(--muted-ink); }
.avail-grid td.slot {
  width: 46px; height: 22px; border: 1px solid var(--line); cursor: pointer; background: var(--surface);
}
.avail-grid td.slot.on { background: var(--yes) !important; }
.avail-grid td.slot.clickable { cursor: pointer; }
.avail-grid td.slot.picked { outline: 3px solid var(--primary); outline-offset: -3px; }
/* Per-person highlight: emphasize the selected person's free slots, fade the rest. */
.avail-grid td.slot.hl { outline: 2px solid var(--primary); outline-offset: -2px; }
.avail-grid.highlighting td.slot:not(.hl) { opacity: 0.18; }

.respondents { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 12px 0 4px; }
.resp-chip { cursor: pointer; background: var(--surface-2); color: var(--ink); }
.resp-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.linklike { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.avail-grid td.heat { position: relative; text-align: center; }
.avail-grid td.heat .heat-num { font-size: 0.68rem; color: #12331f; font-weight: 700; }
.avail-grid td.timelabel { font-size: 0.72rem; color: var(--muted-ink); padding-right: 8px; text-align: right; white-space: nowrap; }
.heat-legend { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 0.85rem; color: var(--muted-ink); }
.heat-swatch { width: 18px; height: 18px; border: 1px solid var(--line); border-radius: 3px; }
