:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --text: #171a21;
  --muted: #5f6778;
  --border: #e1e4ec;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-soft: #e6eeff;
  --yes: #1f9d55;
  --yes-soft: #dcf5e6;
  --maybe: #d18a00;
  --maybe-soft: #fdf0d2;
  --no: #c2412f;
  --no-soft: #fbe4e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --text: #e8ebf2;
    --muted: #9aa3b5;
    --border: #2a303d;
    --accent: #5b8cff;
    --accent-ink: #0b1020;
    --accent-soft: #1d2a4a;
    --yes: #3ecf7c;
    --yes-soft: #163828;
    --maybe: #f0b13a;
    --maybe-soft: #3a2e12;
    --no: #f0705d;
    --no-soft: #3d1f1b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
.wrap { max-width: 820px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: 28px 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: .95rem; margin: 24px 0 10px; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.lede { color: var(--muted); margin: 0 0 20px; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 7px; top: 4px; width: 6px; height: 10px; border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }

/* Cards & fields */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 16px 0; box-shadow: var(--shadow); }
.field { display: block; margin-bottom: 18px; }
.field > span, .label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field em, .label em { font-style: normal; font-weight: 400; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
input[type=text], input[type=time] {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-error { color: var(--no); min-height: 0; margin: 0 0 12px; font-size: .9rem; }
.form-error:empty { display: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid transparent;
  padding: 9px 16px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost.danger { color: var(--no); }
.btn-sm { padding: 5px 11px; font-size: .85rem; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }

.segmented { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.segmented button { font: inherit; font-weight: 600; font-size: .92rem; border: 0; background: transparent; color: var(--muted); padding: 8px 16px; border-radius: 9px; cursor: pointer; }
.segmented button[aria-checked=true] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Calendar */
.calendar { border: 1px solid var(--border); border-radius: 12px; padding: 12px; max-width: 380px; user-select: none; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head strong { font-size: .98rem; }
.cal-nav { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 1.1rem; line-height: 1; }
.cal-nav:disabled { opacity: .35; cursor: default; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .75rem; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal-day { font: inherit; font-size: .92rem; aspect-ratio: 1; border: 0; border-radius: 9px; background: transparent; color: var(--text); cursor: pointer; }
.cal-day:hover:not(:disabled):not(.selected) { background: var(--surface-2); }
.cal-day:disabled { color: var(--muted); opacity: .4; cursor: default; }
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--border); }
.cal-day.selected { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* Time editor */
.times-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.times-head .label { margin: 0; }
.day-times { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.day-times-title { font-weight: 600; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.slot { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.slot input[type=time] { width: auto; flex: 1; max-width: 150px; padding: 7px 10px; }
.slot .dash { color: var(--muted); }
.icon-btn { font: inherit; border: 0; background: transparent; color: var(--muted); cursor: pointer; width: 32px; height: 32px; border-radius: 8px; font-size: 1.15rem; }
.icon-btn:hover { background: var(--surface-2); color: var(--no); }
.empty-note { color: var(--muted); font-size: .9rem; margin: 0; }

/* Recent */
.recent h2 { font-size: 1rem; margin: 28px 0 8px; }
.recent ul { list-style: none; padding: 0; margin: 0; }
.recent li { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; }
.recent li span { color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* Event view */
.meta { color: var(--muted); margin: 0 0 4px; }
.desc { margin: 4px 0 0; white-space: pre-wrap; }
.banner { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 16px; margin-top: 20px; }
.share label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.share-row { display: flex; gap: 8px; }
.share-row input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.bulk { display: flex; gap: 6px; }
.count { color: var(--muted); font-weight: 500; font-size: .95rem; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--yes); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.vote-options { margin-bottom: 16px; }
.vote-group { font-weight: 700; font-size: .9rem; margin: 14px 0 6px; color: var(--muted); }
.vote-group:first-child { margin-top: 0; }
.vote-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 6px; }
.vote-row[data-v=yes] { background: var(--yes-soft); border-color: transparent; }
.vote-row[data-v=maybe] { background: var(--maybe-soft); border-color: transparent; }
.vote-label { font-weight: 500; }
.choices { display: flex; gap: 4px; flex-shrink: 0; }
.choice { font: inherit; font-size: .85rem; font-weight: 600; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; }
.choice[aria-pressed=true][data-c=yes] { background: var(--yes); border-color: var(--yes); color: #fff; }
.choice[aria-pressed=true][data-c=maybe] { background: var(--maybe); border-color: var(--maybe); color: #fff; }
.choice[aria-pressed=true][data-c=no] { background: var(--no); border-color: var(--no); color: #fff; }
.vote-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Results */
.best { background: var(--yes-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.best strong { display: block; font-size: .85rem; color: var(--yes); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.summary-group { font-weight: 700; font-size: .9rem; margin: 16px 0 6px; color: var(--muted); }
.summary-group:first-child { margin-top: 0; }
.sum-row { display: grid; grid-template-columns: minmax(130px, 200px) 1fr auto; align-items: center; gap: 12px; padding: 6px 0; }
.sum-label { font-weight: 500; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tag-best { font-size: .7rem; font-weight: 700; background: var(--yes); color: #fff; padding: 1px 7px; border-radius: 99px; text-transform: uppercase; letter-spacing: .03em; }
.bar { height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar .y { background: var(--yes); }
.bar .m { background: var(--maybe); }
.sum-count { font-size: .85rem; color: var(--muted); white-space: nowrap; text-align: right; min-width: 92px; }
.sum-count b { color: var(--text); }
.sum-names { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); margin-top: -4px; }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table { border-collapse: collapse; font-size: .85rem; min-width: 100%; }
th, td { padding: 8px 10px; text-align: center; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
thead th { background: var(--surface-2); font-weight: 600; font-size: .78rem; line-height: 1.3; }
th.name, td.name { text-align: left; position: sticky; left: 0; background: var(--surface); font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
thead th.name { background: var(--surface-2); }
tr.me td.name::after { content: " (you)"; color: var(--muted); font-weight: 400; }
td.c-yes { color: var(--yes); background: var(--yes-soft); font-weight: 700; }
td.c-maybe { color: var(--maybe); background: var(--maybe-soft); font-weight: 700; }
td.c-no { color: var(--no); opacity: .7; }
tfoot td { background: var(--surface-2); font-weight: 700; }
tfoot td.name { background: var(--surface-2); }

.footer { margin-top: 40px; padding: 24px 0 32px; border-top: 1px solid var(--border); }
.coffee { background: var(--maybe-soft); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.coffee-text strong { margin-right: 4px; }
.coffee-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.coffee-row code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; overflow-wrap: anywhere; min-width: 0; }
.footer-links { text-align: center; color: var(--muted); font-size: .9rem; margin: 18px 0 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 600px) {
  h1 { font-size: 1.5rem; margin-top: 20px; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .vote-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .choices { width: 100%; }
  .choice { flex: 1; padding: 8px 4px; }
  .sum-row { grid-template-columns: 1fr auto; }
  .sum-row .bar { grid-column: 1 / -1; grid-row: 2; }
  .calendar { max-width: none; }
}
