:root {
  --bg: #f7f5f0;
  --paper: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #4a4a50;
  --ink-3: #7a7a82;
  --rule: #e3dfd6;
  --rule-2: #d2ccbf;
  --accent: #b5462b;
  --yes: #1f7a4d;
  --yes-bg: #e3f2ea;
  --no: #b3261e;
  --no-bg: #fbe5e2;
  --neu: #6b6b73;
  --neu-bg: #ececef;
  --pick: #2b5fb3;
  --pick-bg: #e3ecfa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
#app { padding-top: 28px; padding-bottom: 60px; outline: none; min-height: 70vh; }

/* ---------- Header ---------- */
.site-header {
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  background: var(--accent); color: #fff; font-weight: 800; letter-spacing: .02em;
  width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; font-size: 15px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--serif); font-size: 19px; }
.brand-text small { color: var(--ink-3); font-size: 12px; }
.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none; padding: 8px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 500; font-size: 15px;
  white-space: nowrap;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--ink); color: #fff; }
.nav-count:empty { display: none; }
.nav-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 2px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; text-align: center; }

.site-footer { border-top: 1px solid var(--rule); color: var(--ink-3); font-size: 13px; padding: 24px 0 40px; }
.site-footer a { color: var(--ink-2); }

/* ---------- Common ---------- */
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0; }
h1 { font-size: 34px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
.lede { color: var(--ink-2); font-size: 17px; max-width: 760px; margin: 8px 0 0; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 26px 0 12px; padding: 10px 0 8px; border-bottom: 2px solid var(--ink);
  /* Stays pinned under the site header while its section scrolls by; --header-h is set from app.js. */
  position: sticky; top: var(--header-h, 64px); z-index: 10; background: var(--bg);
  box-shadow: -12px 0 0 var(--bg), 12px 0 0 var(--bg); /* hide card shadows peeking out at the sides */
}
.section-head h2 { font-size: 22px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap;
}
.pill.yes { background: var(--yes-bg); color: var(--yes); }
.pill.no { background: var(--no-bg); color: var(--no); }
.pill.neutral { background: var(--neu-bg); color: var(--neu); }
.pill.pick { background: var(--pick-bg); color: var(--pick); text-transform: none; letter-spacing: 0; }

.btn {
  border: 1px solid var(--rule-2); background: var(--paper); border-radius: 8px; padding: 7px 14px; cursor: pointer;
  font-weight: 500; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--rule); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--rule-2); background: var(--paper);
  border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer; user-select: none;
}
.chip input { margin: 0; accent-color: var(--ink); }
.chip.off { opacity: .5; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 18px 0 4px; }
.toolbar .label { font-size: 13px; color: var(--ink-3); margin-right: 4px; }

/* ---------- Ballot list ---------- */
.item-list { display: grid; gap: 10px; }
.item-row {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 16px; align-items: center;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 16px;
  text-decoration: none; box-shadow: var(--shadow); transition: border-color .12s, transform .12s;
}
.item-row:hover { border-color: var(--ink-3); }
.item-badge {
  font-family: var(--serif); font-weight: 700; font-size: 26px; width: 56px; height: 56px; border-radius: 10px;
  display: grid; place-items: center; background: var(--bg); border: 1px solid var(--rule);
}
.item-badge.long { font-size: 16px; }
.item-main { min-width: 0; }
.item-title { font-weight: 600; font-size: 16px; }
.item-sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.dots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; max-width: 300px; }
.dot {
  width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center; font-size: 10px; font-weight: 700;
  border: 1px solid transparent;
}
.dot.yes { background: var(--yes); color: #fff; }
.dot.no { background: var(--no); color: #fff; }
.dot.neutral { background: var(--neu-bg); color: var(--neu); border-color: var(--rule-2); }
/* Guide squares and their header key share one fixed grid so columns always align. */
.dots.votes { display: grid; grid-auto-flow: column; grid-auto-columns: 22px; gap: 3px; max-width: none; justify-content: end; }
.dots.key { padding-right: 17px; align-self: flex-end; } /* matches .item-row padding + border */
.dot.key { background: transparent; color: var(--ink-3); font-size: 9px; letter-spacing: -.02em; }
.dot.none { background: transparent; border: 1px dashed var(--rule-2); color: var(--rule-2); }
.tally { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.tally b.y { color: var(--yes); } .tally b.n { color: var(--no); }
.my-tag { font-size: 12px; font-weight: 600; }

.split-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--neu-bg); width: 160px; }
.split-bar span.y { background: var(--yes); }
.split-bar span.n { background: var(--no); }
.split-bar span.u { background: #c9c9cf; }

/* ---------- Detail page ---------- */
.crumbs { font-size: 14px; color: var(--ink-3); margin-bottom: 14px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.detail-head { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: start; }
.detail-badge {
  font-family: var(--serif); font-size: 44px; font-weight: 700; min-width: 86px; height: 86px; padding: 0 12px; border-radius: 14px;
  background: var(--ink); color: #fff; display: grid; place-items: center;
}
.detail-badge.long { font-size: 26px; }
.kicker { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 700; color: var(--accent); }
.detail-head h1 { margin-top: 4px; font-size: 30px; }

.what-box {
  margin-top: 22px; background: var(--paper); border: 1px solid var(--rule); border-left: 4px solid var(--ink);
  border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow);
}
.what-box h3 { font-family: var(--sans); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 6px; }
.what-box p { margin: 0; font-size: 16px; }
.what-meta { margin-top: 10px; font-size: 13px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 6px 14px; }
.what-meta a { color: var(--ink-2); }

.vote-bar {
  margin-top: 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px;
}
.vote-bar .q { font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--rule-2); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--paper); padding: 7px 16px; cursor: pointer; font-weight: 600; font-size: 14px; border-right: 1px solid var(--rule-2); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--bg); }
.seg button.on.yes { background: var(--yes); color: #fff; }
.seg button.on.no { background: var(--no); color: #fff; }
.seg button.on.neutral { background: var(--ink-2); color: #fff; }
.seg button.on.plain { background: var(--ink); color: #fff; }

.view-tabs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 28px 0 14px; }
.view-tabs .label { color: var(--ink-3); font-size: 13px; margin-right: 4px; }

/* Columns by position */
.cols { display: grid; gap: 18px; align-items: start; }
.cols.n2 { grid-template-columns: 1fr 1fr; }
.cols.n3 { grid-template-columns: 1fr 1fr 1fr; }
.col-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-radius: var(--radius) var(--radius) 0 0; font-weight: 700; font-size: 15px;
}
.col-head.yes { background: var(--yes); color: #fff; }
.col-head.no { background: var(--no); color: #fff; }
.col-head.neutral { background: var(--ink-2); color: #fff; }
.col-head.pick { background: var(--pick); color: #fff; }
.col-head .count { font-weight: 500; opacity: .85; font-size: 13px; }
.col-body { display: grid; gap: 10px; padding: 10px; background: rgba(0,0,0,.025); border: 1px solid var(--rule); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); }

.reason {
  background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 14px 16px; box-shadow: var(--shadow);
}
.reason-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.reason-guide { font-weight: 700; }
.reason-kind { font-size: 12px; color: var(--ink-3); }
.reason p { margin: 0 0 10px; font-size: 15px; color: var(--ink-2); }
.reason blockquote {
  margin: 0 0 10px; padding: 8px 12px; border-left: 3px solid var(--rule-2); background: var(--bg);
  font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--ink); border-radius: 0 6px 6px 0;
}
.reason .src { font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }
.reason .src:hover { text-decoration: underline; }
.reason.agree { outline: 2px solid var(--ink); outline-offset: -1px; }
.only-pos { font-size: 13px; color: var(--ink-3); padding: 4px 4px 2px; }
.only-pos a { color: var(--ink-2); }
.empty { color: var(--ink-3); font-size: 14px; padding: 8px 4px; font-style: italic; }

/* Compare mode */
.compare-pickers { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.compare-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; }
.compare-grid .reason { border-top-width: 4px; }
.compare-grid .reason.yes { border-top-color: var(--yes); }
.compare-grid .reason.no { border-top-color: var(--no); }
.compare-grid .reason.neutral { border-top-color: var(--neu); }
.compare-grid .reason.pick { border-top-color: var(--pick); }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--rule); }
.pager a { text-decoration: none; color: var(--ink-2); font-size: 14px; max-width: 48%; }
.pager a strong { display: block; color: var(--ink); font-size: 16px; }
.pager a.next { text-align: right; margin-left: auto; }

/* Candidates */
.cand-list { display: grid; gap: 8px; margin-top: 8px; }
.cand {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 10px 14px;
}
.cand-name { font-weight: 600; }
.cand-endorse { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.cand-endorse .pill { font-size: 11px; }
.cand-endorse .pill.no { text-transform: none; letter-spacing: 0; }
.cand .seg button { padding: 5px 12px; font-size: 13px; }
.cand.mine { border-color: var(--pick); box-shadow: 0 0 0 1px var(--pick); }
.note { background: #fff7e0; border: 1px solid #efd99b; border-radius: 8px; padding: 8px 12px; font-size: 14px; margin-top: 12px; }

/* ---------- Matrix ---------- */
.matrix-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 14px; }
table.matrix { border-collapse: collapse; width: 100%; font-size: 13px; }
.matrix th, .matrix td { border-bottom: 1px solid var(--rule); padding: 0; text-align: center; }
.matrix thead th {
  position: sticky; top: 0; background: var(--paper); z-index: 2; padding: 10px 4px; font-weight: 600; font-size: 12px;
  vertical-align: bottom; min-width: 64px;
}
.matrix thead th.rowhead { text-align: left; padding-left: 14px; min-width: 240px; }
.matrix thead th.me { background: var(--ink); color: #fff; }
.matrix tbody th { text-align: left; font-weight: 500; padding: 8px 14px; white-space: nowrap; position: sticky; left: 0; background: var(--paper); z-index: 1; }
.matrix tbody th a { text-decoration: none; }
.matrix tbody th a:hover { text-decoration: underline; }
.matrix tbody th .id { display: inline-block; min-width: 38px; font-family: var(--serif); font-weight: 700; }
.matrix tr.group th { background: var(--bg); font-family: var(--serif); font-weight: 700; font-size: 14px; padding: 8px 14px; text-align: left; }
.matrix td button {
  width: 100%; height: 100%; min-height: 36px; border: 0; background: transparent; cursor: pointer; font-weight: 700; font-size: 12px;
}
.matrix td.yes button { background: var(--yes-bg); color: var(--yes); }
.matrix td.no button { background: var(--no-bg); color: var(--no); }
.matrix td.neutral button { background: #f4f4f6; color: var(--neu); }
.matrix td.pick button { background: var(--pick-bg); color: var(--pick); font-weight: 600; font-size: 11px; padding: 4px; line-height: 1.25; }
.matrix td.none { color: var(--rule-2); }
.matrix td button:hover { filter: brightness(.95); box-shadow: inset 0 0 0 2px rgba(0,0,0,.25); }
.matrix td.me { border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); }
.matrix td.agree button { box-shadow: inset 0 0 0 2px var(--ink); }
.matrix tfoot td, .matrix tfoot th { padding: 10px 4px; font-weight: 700; background: var(--bg); position: static; }
.matrix tfoot th { text-align: left; padding-left: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-3); margin-top: 10px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

/* ---------- Guides ---------- */
.guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-top: 18px; }
.guide-card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.guide-card h3 { font-size: 20px; }
.guide-card .kind { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }
.guide-card p { margin: 0; color: var(--ink-2); font-size: 14px; }
.guide-stats { display: flex; gap: 16px; font-size: 13px; color: var(--ink-3); flex-wrap: wrap; }
.guide-stats b { color: var(--ink); }
.guide-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 8px; gap: 8px; flex-wrap: wrap; }
.meter { height: 8px; background: var(--neu-bg); border-radius: 4px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ink); }

/* ---------- My ballot ---------- */
.mine-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; align-items: start; margin-top: 20px; }
.card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.mine-list { list-style: none; margin: 0; padding: 0; }
.mine-list li { display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); align-items: center; }
.mine-list li:last-child { border-bottom: 0; }
.mine-list .id { font-family: var(--serif); font-weight: 700; font-size: 18px; }
.mine-list a { text-decoration: none; }
.mine-list a:hover { text-decoration: underline; }
.mine-list .who { font-size: 12px; color: var(--ink-3); }
.rank { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 12px; }
.rank li .top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.cta { text-align: center; padding: 40px 20px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20,20,25,.45); }
.modal-card { position: relative; background: var(--paper); border-radius: 14px; max-width: 620px; width: 100%; max-height: 85vh; overflow: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-x { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--ink-3); line-height: 1; }
.modal-card .reason { box-shadow: none; border: 0; padding: 0; }
.modal-card h2 { font-size: 20px; margin-bottom: 4px; padding-right: 30px; }

/* ---------- Hero ---------- */
.hero { display: grid; grid-template-columns: 1.5fr 1fr; gap: 28px; align-items: end; }
.hero-side { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 16px; font-size: 14px; color: var(--ink-2); box-shadow: var(--shadow); }
.hero-side ol { margin: 6px 0 0; padding-left: 18px; }
.hero-side li { margin: 3px 0; }
.countdown { font-weight: 700; color: var(--accent); }

@media (max-width: 860px) {
  .cols.n2, .cols.n3 { grid-template-columns: 1fr; }
  .hero, .mine-grid { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 52px 1fr; }
  .item-side { grid-column: 1 / -1; align-items: flex-start; }
  .dots { justify-content: flex-start; }
  .dots.votes { justify-content: start; }
  .dots.key { display: none; }
  .item-badge { width: 48px; height: 48px; font-size: 22px; }
  h1 { font-size: 28px; }
  .detail-badge { min-width: 64px; height: 64px; font-size: 32px; }
  .nav a { padding: 6px 8px; font-size: 14px; }
  .brand-text small { display: none; }
}
@media (max-width: 520px) {
  .header-inner { height: auto; flex-direction: column; align-items: stretch; padding: 10px 0; gap: 8px; }
  .nav { justify-content: space-between; }
}

@media print {
  .site-header, .site-footer, .toolbar, .btn, .seg, .view-tabs { display: none !important; }
  body { background: #fff; }
  .card, .reason { box-shadow: none; }
}

/* ---------- Guide filter & presets ---------- */
.filter { margin: 18px 0 4px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.filter-row { display: grid; grid-template-columns: 90px 1fr; gap: 10px; align-items: start; padding: 4px 0; }
.filter-row .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--ink-3); padding-top: 7px; }
.presets, .chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.preset {
  border: 1px solid var(--rule-2); background: var(--paper); border-radius: 999px; padding: 5px 12px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.preset:hover { border-color: var(--ink-3); color: var(--ink); }
.preset.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.preset.custom { cursor: default; background: var(--accent); border-color: var(--accent); }
.chips .chip { padding: 0 4px 0 0; gap: 0; cursor: default; }
.chips .chip label { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; cursor: pointer; }
.chip .only {
  border: 0; background: transparent; font-size: 11px; color: var(--ink-3); cursor: pointer; padding: 2px 6px; border-radius: 999px;
  opacity: 0; transition: opacity .1s;
}
.chip:hover .only, .chip .only:focus { opacity: 1; }
.chip .only:hover { background: var(--bg); color: var(--ink); }
.filter-desc { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); }
.filter-compact { margin: -4px 0 18px; }
.filter-compact > summary { cursor: pointer; font-size: 14px; color: var(--ink-2); list-style: none; display: inline-block; padding: 4px 10px; border: 1px solid var(--rule-2); border-radius: 999px; background: var(--paper); }
.filter-compact > summary::-webkit-details-marker { display: none; }
.filter-compact[open] > summary { background: var(--ink); color: #fff; border-color: var(--ink); }
.filter-compact[open] > summary .muted { color: #ccc; }
.filter-compact .filter { margin-top: 10px; }
@media (max-width: 860px) {
  .filter-row { grid-template-columns: 1fr; gap: 4px; }
  .filter-row .label { padding-top: 0; }
  .chip .only { opacity: 1; }
}
@media print { .filter, .filter-compact { display: none !important; } }
.hidden-line { font-size: 13px; color: var(--ink-3); padding: 6px 4px 2px; border-top: 1px dashed var(--rule-2); }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; font-size: inherit; }
.site-footer .credit { margin-top: 8px; }
