/* ============================================================
   POLIS — synthetic electorate forecasting
   Design system: modern-fintech, light, restrained blue.
   Type: IBM Plex Sans (UI) · IBM Plex Mono (data) · IBM Plex Sans SC (中文)
   ============================================================ */

:root {
  /* surfaces — cool near-whites */
  --bg:          oklch(0.984 0.003 256);
  --bg-sunken:   oklch(0.968 0.004 256);
  --surface:     #ffffff;
  --surface-2:   oklch(0.992 0.002 256);
  --border:      oklch(0.918 0.006 256);
  --border-2:    oklch(0.872 0.009 256);
  --hover:       oklch(0.972 0.006 256);

  /* ink */
  --ink:    oklch(0.255 0.022 264);
  --ink-2:  oklch(0.455 0.021 264);
  --ink-3:  oklch(0.605 0.016 264);
  --ink-4:  oklch(0.72 0.012 264);

  /* accents — shared chroma/lightness, varied hue */
  --accent:      oklch(0.555 0.165 262);
  --accent-700:  oklch(0.475 0.16 262);
  --accent-weak: oklch(0.955 0.03 262);
  --accent-line: oklch(0.88 0.06 262);

  --pos:      oklch(0.60 0.125 165);  /* YES / up */
  --pos-weak: oklch(0.955 0.04 165);
  --neg:      oklch(0.605 0.17 25);   /* NO / down */
  --neg-weak: oklch(0.96 0.03 25);
  --warn:     oklch(0.72 0.12 78);

  --crowd-yes: var(--accent);
  --crowd-no:  oklch(0.80 0.018 264);

  --radius:   14px;
  --radius-sm: 9px;
  --radius-xs: 6px;

  --shadow-sm: 0 1px 2px oklch(0.4 0.03 264 / 0.05), 0 1px 3px oklch(0.4 0.03 264 / 0.04);
  --shadow-md: 0 2px 6px oklch(0.4 0.03 264 / 0.06), 0 8px 24px oklch(0.4 0.03 264 / 0.07);
  --shadow-lg: 0 12px 48px oklch(0.4 0.03 264 / 0.12);

  --sans: "IBM Plex Sans", "IBM Plex Sans SC", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  --maxw: 1320px;
  --motion: 1; /* 0..1 scalar set by tweaks */
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[lang-zh] { font-feature-settings: normal; }

::selection { background: var(--accent-weak); }

.mono { font-family: var(--mono); font-feature-settings: "tnum" 1, "zero" 1; }
.tnum { font-variant-numeric: tabular-nums; }

.kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}

button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  padding: 0 26px; height: 60px;
  background: oklch(0.99 0.003 256 / 0.85);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(150deg, var(--accent), var(--accent-700));
  position: relative; flex: none;
  box-shadow: inset 0 0 0 1px oklch(1 0 0 / 0.25), var(--shadow-sm);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle at center, oklch(1 0 0 / 0.9) 0.9px, transparent 1.2px);
  background-size: 5px 5px; background-position: 1px 1px;
  opacity: 0.55; border-radius: inherit;
}
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: 0.16em; }
.brand-tag { font-size: 11px; color: var(--ink-3); letter-spacing: 0.02em; border-left: 1px solid var(--border-2); padding-left: 11px; }

.appbar-spacer { flex: 1; }

.searchbox {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px; min-width: 230px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 9px; color: var(--ink-3);
  transition: border-color .15s, background .15s;
}
.searchbox:focus-within { border-color: var(--accent-line); background: var(--surface); }
.searchbox input { border: none; background: none; outline: none; flex: 1; font: inherit; font-size: 13.5px; color: var(--ink); }
.searchbox .kbd { font-family: var(--mono); font-size: 10px; padding: 2px 5px; border: 1px solid var(--border-2); border-radius: 4px; color: var(--ink-4); }

/* segmented control */
.seg { display: inline-flex; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: none; color: var(--ink-3);
  font-size: 12.5px; font-weight: 500; padding: 5px 11px; border-radius: 6px;
  display: flex; align-items: center; gap: 6px; transition: all .15s;
}
.seg button:hover { color: var(--ink); }
.seg button[data-on="1"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.livepill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  padding: 5px 11px 5px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.livedot { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 0 0 var(--pos); animation: pulse calc(2.4s / max(var(--motion),0.15)) infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 oklch(0.6 0.125 165 / 0.5);} 70%{box-shadow:0 0 0 6px oklch(0.6 0.125 165 / 0);} 100%{box-shadow:0 0 0 0 oklch(0.6 0.125 165 / 0);} }

.iconbtn {
  width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); display: grid; place-items: center; transition: all .15s;
}
.iconbtn:hover { border-color: var(--border-2); color: var(--ink); }

/* ---------- Layout ---------- */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 26px; }
.page { flex: 1; }

.section-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 14px; }
.section-head h2 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.section-head .count { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.section-head .rule { flex: 1; height: 1px; background: var(--border); align-self: center; }

/* card primitive */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* ---------- Hero (silicon crowd) ---------- */
.hero { display: grid; grid-template-columns: 1.18fr 1fr; gap: 0; overflow: hidden; margin-bottom: 26px; }
.hero-left { padding: 26px 28px; display: flex; flex-direction: column; min-width: 0; }
.hero-right { border-left: 1px solid var(--border); background: var(--surface-2); position: relative; min-width: 0; }

.hero-cat { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.tag { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; padding: 3px 8px; border-radius: 5px; background: var(--accent-weak); color: var(--accent-700); font-weight: 500; }
.tag.gray { background: var(--bg-sunken); color: var(--ink-3); }
.tag.pos { background: var(--pos-weak); color: var(--pos); }

.hero-q { font-size: 26px; line-height: 1.18; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 4px; text-wrap: balance; }
.hero-sub { color: var(--ink-3); font-size: 13px; margin-bottom: 22px; }

.prob-row { display: flex; align-items: flex-end; gap: 22px; margin-bottom: 18px; }
.bigprob { font-family: var(--mono); font-weight: 600; font-size: 76px; line-height: 0.9; letter-spacing: -0.04em; color: var(--ink); }
.bigprob .pct { font-size: 30px; color: var(--ink-3); font-weight: 500; }
.prob-meta { display: flex; flex-direction: column; gap: 7px; padding-bottom: 10px; min-width: 0; }
.prob-tag { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.ci-text { font-family: var(--mono); font-size: 12px; color: var(--ink-3); white-space: nowrap; }

.vs-market { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin-top: auto; }
.vs-cell { background: var(--surface); padding: 12px 14px; }
.vs-cell .lab { font-size: 11px; color: var(--ink-3); margin-bottom: 4px; display:flex; align-items:center; gap:6px; }
.vs-cell .val { font-family: var(--mono); font-size: 21px; font-weight: 500; }
.edge-up { color: var(--pos); }
.edge-dn { color: var(--neg); }

/* confidence band bar */
.band { position: relative; height: 8px; background: var(--bg-sunken); border-radius: 4px; margin: 14px 0 6px; overflow: hidden; }
.band-ci { position: absolute; top: 0; bottom: 0; background: var(--accent-line); border-radius: 4px; }
.band-pt { position: absolute; top: -3px; width: 3px; height: 14px; background: var(--accent); border-radius: 2px; box-shadow: 0 0 0 3px var(--surface); }
.band-mkt { position: absolute; top: -2px; width: 2px; height: 12px; background: var(--ink-3); border-radius: 1px; }
.band-scale { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; color: var(--ink-4); }

/* crowd canvas overlay */
.crowd-wrap { position: absolute; inset: 0; }
.crowd-canvas { width: 100%; height: 100%; display: block; }
.crowd-stat { position: absolute; left: 18px; bottom: 16px; display: flex; gap: 18px; }
.crowd-stat .s { }
.crowd-stat .n { font-family: var(--mono); font-size: 18px; font-weight: 600; }
.crowd-stat .l { font-size: 10.5px; color: var(--ink-3); letter-spacing: .02em; }
.crowd-leg { position: absolute; right: 16px; top: 16px; display: flex; flex-direction: column; gap: 7px; align-items: flex-end; }
.crowd-leg .item { display: flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 11px; color: var(--ink-2); white-space: nowrap; }
.crowd-leg .sw { width: 9px; height: 9px; border-radius: 2px; }

/* ---------- Board ---------- */
.board { display: grid; gap: 0; }
.board-head, .row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 96px 92px 84px 140px 110px;
  align-items: center; gap: 16px;
}
.board-head { padding: 0 18px 10px; }
.board-head .h { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); }
.board-head .h.r, .row .r { text-align: right; justify-self: end; }
.board-rows { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.row { padding: 14px 18px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; position: relative; }
.row:last-child { border-bottom: none; }
.row:hover { background: var(--hover); }
.row.active { background: var(--accent-weak); }
.row.active::before { content:""; position:absolute; left:0; top:0; bottom:0; width:3px; background: var(--accent); }

.q-cell { min-width: 0; }
.q-text { font-size: 14px; font-weight: 500; margin: 0 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-meta { display: flex; align-items: center; gap: 9px; font-size: 11.5px; color: var(--ink-3); }
.q-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-4); }

.rowprob { font-family: var(--mono); font-size: 19px; font-weight: 600; justify-self: end; }
.minibar { height: 5px; border-radius: 3px; background: var(--bg-sunken); overflow: hidden; }
.minibar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.edge-pill { font-family: var(--mono); font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; justify-self: end; }
.edge-pill.up { color: var(--pos); background: var(--pos-weak); }
.edge-pill.dn { color: var(--neg); background: var(--neg-weak); }
.edge-pill.fl { color: var(--ink-3); background: var(--bg-sunken); }

.spark { width: 100%; height: 30px; display: block; }

.status-cell { justify-self: end; display: flex; align-items: center; gap: 7px; font-size: 11.5px; font-family: var(--mono); }
.status-cell .ico { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.hit { background: var(--pos-weak); color: var(--pos); }
.miss { background: var(--neg-weak); color: var(--neg); }
.open { color: var(--accent); }

/* calibration chip */
.calib { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-family: var(--mono); color: var(--ink-3); }
.calib .b { width: 6px; height: 6px; border-radius: 50%; }
.calib.good .b { background: var(--pos); }
.calib.wide .b { background: var(--warn); }

/* ---------- Sidebar / panels (track record + calibration) ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.panel { padding: 20px 22px; }
.panel h3 { font-size: 13.5px; font-weight: 600; margin: 0 0 3px; }
.panel .desc { font-size: 12px; color: var(--ink-3); margin: 0 0 18px; }

.stat-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 26px; }
.stat { background: var(--surface); padding: 16px 18px; }
.stat .n { font-family: var(--mono); font-size: 27px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; margin-bottom: 7px; }
.stat .l { font-size: 11.5px; color: var(--ink-3); }
.stat .n small { font-size: 14px; color: var(--ink-3); font-weight: 500; }

/* brier bars */
.brier { display: flex; flex-direction: column; gap: 9px; }
.brier-row { display: grid; grid-template-columns: 132px 1fr 52px; align-items: center; gap: 12px; }
.brier-row .name { font-size: 12px; color: var(--ink-2); }
.brier-row .name b { color: var(--ink); font-weight: 600; }
.brier-track { height: 18px; background: var(--bg-sunken); border-radius: 5px; position: relative; overflow: hidden; }
.brier-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; background: var(--ink-4); transition: width 1s cubic-bezier(.2,.7,.2,1); }
.brier-fill.best { background: var(--accent); }
.brier-val { font-family: var(--mono); font-size: 12.5px; text-align: right; color: var(--ink); }
.brier-base { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--neg); z-index: 2; }
.brier-base::after { content: attr(data-l); position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-family: var(--mono); font-size: 9.5px; color: var(--neg); white-space: nowrap; }

/* reliability diagram */
.reli-wrap { display: flex; gap: 18px; align-items: flex-start; }
.reli { flex: none; }
.reli-legend { font-size: 11.5px; color: var(--ink-2); display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.reli-legend .item { display: flex; gap: 9px; align-items: flex-start; }
.reli-legend .key { width: 18px; height: 0; border-top: 2px solid; margin-top: 8px; flex: none; }

/* ---------- Detail panel ---------- */
.scrim { position: fixed; inset: 0; background: oklch(0.2 0.02 264 / 0.32); backdrop-filter: blur(2px); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim[data-open="1"] { opacity: 1; pointer-events: auto; }
.detail {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 94vw); z-index: 61;
  background: var(--bg); border-left: 1px solid var(--border-2); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .32s cubic-bezier(.4,.0,.1,1);
  display: flex; flex-direction: column;
}
.detail[data-open="1"] { transform: translateX(0); }
.detail-head { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 14px; align-items: flex-start; }
.detail-body { flex: 1; overflow-y: auto; padding: 22px 24px 40px; }
.detail-body::-webkit-scrollbar { width: 10px; }
.detail-body::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 5px; border: 3px solid var(--bg); }

.dblock { margin-bottom: 26px; }
.dblock > .lab { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); margin-bottom: 11px; }

.subg { display: flex; flex-direction: column; gap: 13px; }
.subg-group .gname { font-size: 11.5px; color: var(--ink-3); margin-bottom: 8px; }
.subg-bar { display: grid; grid-template-columns: 76px 1fr 38px; align-items: center; gap: 10px; margin-bottom: 6px; }
.subg-bar .k { font-size: 12px; color: var(--ink-2); }
.subg-bar .track { height: 7px; background: var(--bg-sunken); border-radius: 4px; overflow: hidden; }
.subg-bar .track > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.subg-bar .v { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); text-align: right; }

.method { display: flex; flex-direction: column; gap: 9px; }
.mstep { display: flex; gap: 12px; align-items: flex-start; padding: 11px 13px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.mstep .ix { font-family: var(--mono); font-size: 11px; color: var(--accent-700); background: var(--accent-weak); width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; flex: none; font-weight: 600; }
.mstep .mt { font-size: 12.5px; font-weight: 600; margin-bottom: 2px; }
.mstep .md { font-size: 11.5px; color: var(--ink-3); line-height: 1.45; }

.btn { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 500; transition: all .15s; }
.btn:hover { border-color: var(--border-2); background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn.primary:hover { background: var(--accent-700); }

/* proof lead + resolved calls */
.proof-lead { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; padding: 24px 26px; margin-bottom: 22px; }
.proof-lead .bigcmp { display: flex; align-items: baseline; gap: 12px; }
.proof-lead .bigcmp .me { font-family: var(--mono); font-size: 46px; font-weight: 600; letter-spacing: -0.03em; color: var(--accent); line-height: 1; }
.proof-lead .bigcmp .vs { font-family: var(--mono); font-size: 15px; color: var(--ink-3); }
.proof-lead .bigcmp .them { font-family: var(--mono); font-size: 22px; color: var(--ink-2); font-weight: 500; }
.proof-lead .lead-txt h3 { font-size: 17px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.01em; }
.proof-lead .lead-txt p { font-size: 12.5px; color: var(--ink-3); margin: 0; line-height: 1.5; max-width: 60ch; }
.proof-lead .lab { font-size: 10.5px; color: var(--ink-4); font-family: var(--mono); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 8px; }

.callout-note { margin-top: 16px; padding: 11px 13px; background: var(--accent-weak); border-radius: 8px; font-size: 12px; color: var(--accent-700); display: flex; gap: 9px; align-items: center; line-height: 1.4; }
.callout-note svg { flex: none; }

.calls { display: flex; flex-direction: column; }
.call-row { display: grid; grid-template-columns: 1fr 56px 96px 24px; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.call-row:last-child { border-bottom: none; }
.call-q { min-width: 0; }
.call-q .qt { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-q .qm { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); margin-top: 2px; }
.call-p { font-family: var(--mono); font-size: 14.5px; font-weight: 600; text-align: right; }
.call-out { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 5px; justify-self: start; white-space: nowrap; }
.call-out.y { background: var(--pos-weak); color: var(--pos); }
.call-out.n { background: var(--neg-weak); color: var(--neg); }
.res-ico { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; justify-self: end; }
.calls-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.calls-head .pill { font-family: var(--mono); font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--pos-weak); color: var(--pos); font-weight: 500; white-space: nowrap; }

/* footer note */.footnote { color: var(--ink-4); font-size: 11.5px; text-align: center; padding: 30px 0 50px; line-height: 1.6; }
.footnote a { color: var(--ink-3); }

/* direction variants */
[data-direction="proof"] .hero { grid-template-columns: 1fr 1.2fr; }
[data-direction="proof"] .order-hero { order: 2; }
[data-direction="proof"] .order-proof { order: 1; }
[data-direction="crowd"] .hero { grid-template-columns: 0.92fr 1fr; }
[data-direction="crowd"] .hero-right { min-height: 380px; }

[data-density="compact"] .row { padding: 9px 18px; }
[data-density="compact"] .wrap { padding: 18px; }
[data-density="comfy"] .row { padding: 18px; }

@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.001ms !important; } }

@media (max-width: 1080px) {
  .hero { grid-template-columns: 1fr; }
  .hero-right { border-left: none; border-top: 1px solid var(--border); min-height: 320px; }
  .grid-2 { grid-template-columns: 1fr; }
  .board-head, .row { grid-template-columns: minmax(0,1fr) 80px 84px 120px; }
  .board-head .h.hide, .row .hide { display: none; }
}
