:root {
  color-scheme: light dark;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --text: #1c2129;
  --muted: #5d6877;
  --border: #dde1e8;
  --accent: #3b5bdb;
  --accent-hover: #2f4bc0;
  --accent-text: #ffffff;
  --accent-soft: #e7ecff;
  --yes: #2b8a3e;
  --yes-soft: #d3f5da;
  --maybe: #b35c00;
  --maybe-soft: #ffefc2;
  --no: #6b7480;
  --no-soft: #eef0f3;
  --danger: #c92a2a;
  --best: #f6c344;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.08);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --text: #e8eaee;
    --muted: #9aa4b2;
    --border: #2d333c;
    --accent: #7491ff;
    --accent-hover: #8ea5ff;
    --accent-text: #0d1220;
    --accent-soft: #1f2a4d;
    --yes: #69db7c;
    --yes-soft: #17351f;
    --maybe: #ffc35a;
    --maybe-soft: #3a2d10;
    --no: #9aa4b2;
    --no-soft: #23282f;
    --danger: #ff8787;
    --best: #e0a922;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.95rem; }
p { margin: 0 0 0.75rem; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; max-width: 56rem; margin: 0 auto; padding: 1rem; }
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand svg { color: var(--accent); }
.wrap { max-width: 56rem; margin: 0 auto; padding: 0 1rem 4rem; display: grid; gap: 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.lede { color: var(--muted); font-size: 1.05rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem; font-weight: 700; color: var(--muted); margin: 0; }

/* Forms */
.field { display: grid; gap: 0.3rem; margin-bottom: 0.9rem; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
input, textarea, select { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.75rem; width: 100%; min-width: 0; }
input:focus, textarea:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
.check { display: flex; gap: 0.6rem; align-items: flex-start; margin: 0.5rem 0; cursor: pointer; }
.check input { width: auto; margin-top: 0.3rem; }
.step { margin-top: 1.5rem; display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.step small { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); font-weight: 600; min-height: 1.5em; margin: 1rem 0 0.5rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; font: inherit; font-weight: 600; font-size: 0.95rem; padding: 0.55rem 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.big { padding: 0.8rem 1.6rem; font-size: 1.05rem; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: default; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--danger); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0.25rem 0.4rem; border-radius: 6px; }
.icon-btn:hover:not(:disabled) { background: var(--no-soft); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

/* Duration chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 0.45rem 0.9rem; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-weight: 500; font-size: 0.92rem; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Date + time picker */
.picker { display: grid; grid-template-columns: minmax(0, 18rem) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
@media (max-width: 680px) { .picker { grid-template-columns: minmax(0, 1fr); } }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .wd { font-size: 0.75rem; color: var(--muted); font-weight: 600; padding-bottom: 0.25rem; }
.day { aspect-ratio: 1; border: 0; background: none; color: inherit; font: inherit; font-size: 0.92rem; border-radius: 999px; cursor: pointer; display: grid; place-items: center; }
.day:hover:not(:disabled) { background: var(--accent-soft); }
.day.today { font-weight: 700; color: var(--accent); }
.day[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.day:disabled { color: var(--muted); opacity: 0.4; cursor: default; }
.times-empty { border: 1px dashed var(--border); border-radius: 12px; padding: 1.5rem; text-align: center; color: var(--muted); }
.date-row { border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem; margin-bottom: 0.6rem; }
.date-row-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.date-row-head strong { font-size: 0.95rem; }
.time-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.time-chip { display: inline-flex; align-items: center; gap: 0.15rem; background: var(--accent-soft); border-radius: 999px; padding: 0.15rem 0.2rem 0.15rem 0.7rem; font-size: 0.88rem; font-weight: 500; }
.time-chip .icon-btn { font-size: 0.95rem; padding: 0.1rem 0.35rem; }
.add-time { display: flex; gap: 0.4rem; }
.add-time input { width: auto; flex: 1; max-width: 10rem; padding: 0.4rem 0.6rem; }
.add-time .btn { padding: 0.4rem 0.8rem; }
.date-row-foot { display: flex; justify-content: space-between; margin-top: 0.5rem; font-size: 0.85rem; }
.summary { color: var(--muted); font-size: 0.9rem; }
.settings { margin-top: 1.25rem; }
.settings summary { cursor: pointer; font-weight: 600; }

/* Home: your polls */
.poll-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.poll-list li { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.poll-list li:last-child { border-bottom: 0; }
.poll-list a { flex: 1; font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.75rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: 999px; background: var(--no-soft); color: var(--muted); }
.tag.admin { background: var(--accent-soft); color: var(--accent); }

/* Poll page */
.meta { list-style: none; padding: 0; margin: 0.25rem 0 0.75rem; display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; color: var(--muted); font-size: 0.92rem; }
.meta b { color: var(--text); font-weight: 600; }
.desc { white-space: pre-wrap; margin: 0; }
.share.new { border-color: var(--accent); background: linear-gradient(var(--accent-soft), var(--surface) 70%); }
.copy-field { display: flex; gap: 0.5rem; margin: 0.5rem 0; }
.copy-field input { font-size: 0.9rem; background: var(--bg); }
.final { border-color: var(--yes); background: linear-gradient(var(--yes-soft), var(--surface)); }
.final-time { font-size: 1.35rem; font-weight: 700; margin: 0.25rem 0 0.75rem; }
.notice { background: var(--no-soft); border-radius: 12px; padding: 0.75rem 1rem; margin: 0; }
.tzbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--muted); }
.tzbar select { width: auto; padding: 0.3rem 0.5rem; font-size: 0.9rem; }

.day-group { margin-top: 1rem; }
.day-group h3 { color: var(--muted); font-weight: 600; margin-bottom: 0.4rem; }
.opt { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "time seg" "tally seg" "admin admin"; align-items: center; gap: 0.2rem 1rem; padding: 0.75rem 0.9rem; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 0.5rem; }
.opt.best { border-color: var(--best); box-shadow: inset 3px 0 0 var(--best); }
.opt.final { border-color: var(--yes); box-shadow: inset 3px 0 0 var(--yes); }
.opt-time { grid-area: time; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.badge { font-size: 0.72rem; font-weight: 700; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--best); color: #3d2a00; }
.badge.final { background: var(--yes); color: var(--surface); }
.tally { grid-area: tally; display: flex; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.pill { padding: 0 0.45rem; border-radius: 999px; font-weight: 600; }
.pill.yes { background: var(--yes-soft); color: var(--yes); }
.pill.maybe { background: var(--maybe-soft); color: var(--maybe); }
.opt .seg { grid-area: seg; }
.opt-admin { grid-area: admin; display: flex; gap: 1rem; font-size: 0.85rem; margin-top: 0.25rem; }
@media (max-width: 560px) {
  .opt { grid-template-columns: minmax(0, 1fr); grid-template-areas: "time" "tally" "seg" "admin"; }
  .opt .seg { margin-top: 0.4rem; }
  .seg-btn { flex: 1; }
}
.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn { font: inherit; font-size: 0.88rem; font-weight: 600; border: 0; background: var(--surface); color: var(--muted); padding: 0.5rem 0.8rem; cursor: pointer; white-space: nowrap; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn:hover { background: var(--no-soft); }
.seg-btn.v-yes[aria-pressed="true"] { background: var(--yes); color: var(--surface); }
.seg-btn.v-maybe[aria-pressed="true"] { background: var(--maybe); color: var(--surface); }
.seg-btn.v-no[aria-pressed="true"] { background: var(--no); color: var(--surface); }
.vote-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 1rem; }
.bulk { display: flex; gap: 0.75rem; font-size: 0.85rem; align-items: center; color: var(--muted); }

/* Responses grid */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 0.9rem; min-width: 100%; }
.grid th, .grid td { border-bottom: 1px solid var(--border); padding: 0.45rem 0.5rem; text-align: center; }
.grid thead th { vertical-align: bottom; font-weight: 500; min-width: 4.25rem; }
.grid thead th.best { background: color-mix(in srgb, var(--best) 18%, transparent); border-radius: 10px 10px 0 0; }
.grid .wk, .grid .mo { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.grid .dd { display: block; font-size: 1.15rem; font-weight: 700; line-height: 1.1; }
.grid .tm { display: block; font-size: 0.78rem; font-weight: 600; margin-top: 0.15rem; white-space: nowrap; }
.grid .who { position: sticky; left: 0; background: var(--surface); text-align: left; font-weight: 600; white-space: nowrap; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; z-index: 1; }
.grid .who .icon-btn { font-size: 0.85rem; }
.grid td.v2 { background: var(--yes-soft); color: var(--yes); font-weight: 700; }
.grid td.v1 { background: var(--maybe-soft); color: var(--maybe); font-weight: 700; }
.grid td.v0 { color: var(--no); opacity: 0.6; }
.grid tr.me .who::after { content: " (you)"; color: var(--muted); font-weight: 400; }
.grid tfoot td, .grid tfoot th { font-weight: 700; border-bottom: 0; }
.comments { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: 0.5rem; }
.comments li { background: var(--bg); border-radius: 10px; padding: 0.5rem 0.75rem; white-space: pre-wrap; }

.admin details { border-top: 1px solid var(--border); padding: 0.75rem 0; }
.admin details:last-of-type { border-bottom: 1px solid var(--border); }
.admin summary { cursor: pointer; font-weight: 600; }
.admin details > :not(summary) { margin-top: 0.75rem; }

#toasts { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); display: grid; gap: 0.5rem; z-index: 10; width: max-content; max-width: calc(100vw - 2rem); }
.toast { background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 10px; font-weight: 600; box-shadow: 0 4px 16px rgb(0 0 0 / 0.2); }
.toast.error { background: var(--danger); color: #fff; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
