: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; }

/* ---------- "Which district am I?" callout ---------- */
.district-callout {
  background: var(--pick-bg); border: 1px solid #c5d5f0; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  display: grid; gap: 8px;
}
.district-callout .dc-text { font-size: 15px; }
.district-callout .dc-text .small { display: block; margin-top: 2px; }
.dc-row { display: flex; gap: 8px; flex-wrap: wrap; }
.dc-row input {
  flex: 1 1 260px; min-width: 0; font: inherit; font-size: 15px; padding: 8px 12px; border: 1px solid var(--rule-2); border-radius: 8px; background: var(--paper);
}
.dc-row input:focus { outline: 2px solid var(--pick); outline-offset: 0; border-color: var(--pick); }
.dc-error { color: var(--no); font-weight: 600; font-size: 14px; }
.dc-note { font-size: 12px; color: var(--ink-3); }
.dc-note a { color: var(--ink-2); }
.district-callout.found { grid-template-columns: 1fr auto; align-items: center; }
.dc-actions { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 860px) { .district-callout.found { grid-template-columns: 1fr; } }

/* =====================================================================
   Upside Down mode (body.upside): see the opposite of chosen guides.
   A Stranger Things–style dark theme so the mode is impossible to miss.
   ===================================================================== */
.upside-toggle {
  border: 1px solid var(--rule-2); background: var(--paper); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--ink-2); white-space: nowrap; margin-left: 6px;
}
.upside-toggle:hover { border-color: var(--ink-3); color: var(--ink); }
.upside-toggle .flip-icon { display: inline-block; transition: transform .4s; }
.ud-lights, .ud-spores { display: none; }

body.upside {
  --bg: #07090d; --paper: #10151c; --ink: #ece4d4; --ink-2: #c7bdac; --ink-3: #8c8273;
  --rule: #2b1d21; --rule-2: #4d2a30; --accent: #ff2a2a;
  --yes: #3fd0b5; --yes-bg: rgba(63, 208, 181, .13); --no: #ff4040; --no-bg: rgba(255, 64, 64, .15);
  --neu: #a49a8a; --neu-bg: #1b2028; --pick: #8ea6ff; --pick-bg: rgba(142, 166, 255, .14);
  --shadow: 0 0 0 1px rgba(255, 42, 42, .05), 0 6px 20px rgba(0, 0, 0, .5);
  --serif: "ITC Benguiat", Benguiat, "Bookman Old Style", Bookman, "URW Bookman", Georgia, serif;
  color-scheme: dark;
  background:
    radial-gradient(ellipse 80% 40% at 50% -5%, rgba(255, 30, 30, .22), transparent 70%),
    radial-gradient(ellipse 60% 50% at 100% 100%, rgba(120, 0, 30, .25), transparent 70%),
    linear-gradient(#07090d, #0a0d12);
  background-attachment: fixed;
}
body.upside main, body.upside .site-footer { position: relative; z-index: 1; }
body.upside .site-header { background: rgba(10, 12, 17, .92); backdrop-filter: blur(6px); border-bottom-color: #3a1418; box-shadow: 0 2px 24px rgba(255, 0, 0, .12); }

/* Neon-red serif headings */
body.upside h1, body.upside h2, body.upside .brand-text strong, body.upside .section-head h2, body.upside .ub-title {
  color: #ff2a2a; font-weight: 800; letter-spacing: .01em;
  text-shadow: 0 0 2px rgba(255, 120, 120, .9), 0 0 10px rgba(255, 0, 0, .55), 0 0 26px rgba(255, 0, 0, .3);
}
body.upside .brand-mark { transform: rotate(180deg); background: #ff2a2a; box-shadow: 0 0 14px rgba(255, 0, 0, .6); }
body.upside .section-head { border-bottom-color: #ff2a2a; box-shadow: -12px 0 0 var(--bg), 12px 0 0 var(--bg), 0 1px 12px rgba(255, 0, 0, .25); }

/* Controls that used dark ink as a fill need light-on-red in the dark theme */
body.upside .nav a.active, body.upside .btn.primary, body.upside .preset.on, body.upside .detail-badge,
body.upside .matrix thead th.me, body.upside .filter-compact[open] > summary, body.upside .seg button.on.plain {
  background: #ff2a2a; border-color: #ff2a2a; color: #0a0a0a;
}
body.upside .btn.primary:disabled { opacity: .45; cursor: not-allowed; }
body.upside .upside-toggle { background: #ff2a2a; border-color: #ff2a2a; color: #0a0a0a; box-shadow: 0 0 12px rgba(255, 0, 0, .5); }
body.upside .upside-toggle .flip-icon { transform: rotate(180deg); }
body.upside .note { background: #2a1d10; border-color: #6b4a1a; color: var(--ink); }
body.upside .district-callout { border-color: #2e3a66; }
body.upside .matrix td.neutral button { background: #161b22; }
body.upside .item-row:hover { border-color: #ff2a2a; box-shadow: 0 0 0 1px rgba(255, 42, 42, .4), 0 0 18px rgba(255, 0, 0, .18); }
body.upside .reason blockquote { background: #0c1016; }

/* The suggested opposite action, always visually separate from the guide's real recommendation */
.flip-note {
  font-size: 13px; color: var(--ink-2); background: rgba(255, 42, 42, .08); border: 1px solid rgba(255, 42, 42, .45);
  border-left: 3px solid #ff2a2a; border-radius: 6px; padding: 7px 10px; margin: 10px 0 0;
}
.ud-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: #ff4d4d; }
.ud-row-action { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.ud-result {
  margin-top: 18px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center;
  border: 1px solid #5a1f25; border-radius: var(--radius); padding: 14px 18px;
  background: linear-gradient(90deg, var(--paper), rgba(255, 42, 42, .1));
}
.ud-step { display: grid; gap: 6px; font-size: 15px; line-height: 1.7; }
.ud-step:last-child { border-left: 1px solid #5a1f25; padding-left: 18px; }
.ud-arrow { font-size: 28px; color: #ff2a2a; text-shadow: 0 0 10px rgba(255, 0, 0, .6); }
.pill.big { font-size: 18px; padding: 4px 16px; }
.matrix th.ud-col, .matrix td.ud-col { background: rgba(255, 42, 42, .08); border-left: 2px solid #ff2a2a; border-right: 2px solid #ff2a2a; padding: 4px 6px; white-space: nowrap; }
.matrix th.ud-col { color: #ff4d4d; }
@media (max-width: 860px) {
  .ud-result { grid-template-columns: 1fr; }
  .ud-arrow { transform: rotate(90deg); justify-self: start; }
  .ud-step:last-child { border-left: 0; padding-left: 0; border-top: 1px solid #5a1f25; padding-top: 10px; }
}
.flip-note b { color: var(--ink); }
.pill.inv { background: rgba(255, 42, 42, .16); color: #ff6b6b; text-transform: none; letter-spacing: 0; font-size: 13px; }
.pill.avoid { text-transform: none; letter-spacing: 0; }

/* Banner that replaces the guide filter while upside down */
.upside-bar { border-color: #5a1f25; background: linear-gradient(180deg, rgba(255, 42, 42, .08), transparent), var(--paper); }
.upside-bar .ub-title { font-family: var(--serif); font-size: 22px; }
.upside-bar p { margin: 6px 0 10px; color: var(--ink-2); }
.ub-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Christmas lights strung along the bottom of the header */
body.upside .ud-lights {
  display: block; position: fixed; left: 0; right: 0; top: calc(var(--header-h, 64px) - 6px); height: 20px; z-index: 25; pointer-events: none;
  background:
    radial-gradient(circle at 12px 11px, #ff3b3b 4px, rgba(255, 59, 59, .35) 6px, transparent 9px),
    radial-gradient(circle at 44px 13px, #ffd23b 4px, rgba(255, 210, 59, .35) 6px, transparent 9px),
    radial-gradient(circle at 76px 11px, #3bff8a 4px, rgba(59, 255, 138, .35) 6px, transparent 9px),
    radial-gradient(circle at 108px 13px, #3bb5ff 4px, rgba(59, 181, 255, .35) 6px, transparent 9px),
    radial-gradient(circle at 140px 11px, #ff7b3b 4px, rgba(255, 123, 59, .35) 6px, transparent 9px),
    linear-gradient(transparent 6px, #1a1a1a 6px, #1a1a1a 7px, transparent 7px);
  background-size: 160px 20px;
  animation: ud-flicker 5s steps(1) infinite;
}
@keyframes ud-flicker {
  0%, 100% { opacity: 1; filter: brightness(1.1); }
  12% { opacity: .55; filter: brightness(.7); }
  14% { opacity: 1; filter: brightness(1.2); }
  47% { opacity: .85; }
  49% { opacity: .3; filter: brightness(.5); }
  51% { opacity: 1; filter: brightness(1.15); }
  78% { opacity: .7; }
}

/* Drifting spores */
body.upside .ud-spores {
  display: block; position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .55;
  background-image:
    radial-gradient(1.5px 1.5px at 20px 30px, #fff, transparent),
    radial-gradient(1px 1px at 120px 80px, #ffd7d7, transparent),
    radial-gradient(2px 2px at 200px 160px, #fff, transparent),
    radial-gradient(1px 1px at 300px 40px, #fbe, transparent),
    radial-gradient(1.5px 1.5px at 380px 220px, #fff, transparent),
    radial-gradient(1px 1px at 60px 260px, #ffe, transparent);
  background-size: 420px 300px;
  animation: ud-drift 40s linear infinite;
}
@keyframes ud-drift { from { background-position: 0 0; } to { background-position: 140px -600px; } }

/* The flip when switching modes */
body.flipping #app { animation: ud-flip .8s cubic-bezier(.2, .7, .2, 1); transform-origin: 50% 0; }
@keyframes ud-flip { from { transform: perspective(1200px) rotateX(-75deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* Guide picker modal */
.upside-modal .modal-card { max-width: 680px; }
body.upside .modal-card { border: 1px solid #5a1f25; box-shadow: 0 0 40px rgba(255, 0, 0, .25); }
.inv-section { margin-top: 14px; }
.inv-section > .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--ink-3); margin-bottom: 6px; }
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.inv-guide { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--rule-2); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.inv-guide.on { border-color: #ff2a2a; background: rgba(255, 42, 42, .08); }
.inv-guide input { margin-top: 3px; accent-color: #ff2a2a; }
.inv-guide small { display: block; color: var(--ink-3); font-size: 12px; }
.inv-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.upside-go:not(:disabled) { background: #b3121b; border-color: #b3121b; color: #fff; }

@media (max-width: 520px) { .upside-toggle .label { display: none; } }
@media (prefers-reduced-motion: reduce) {
  body.upside .ud-lights, body.upside .ud-spores, body.flipping #app { animation: none; }
}
@media print { .ud-lights, .ud-spores, .upside-toggle { display: none !important; } }
