:root {
  --bg: #080b13;
  --bg-2: #0d1220;
  --panel: #111827;
  --panel-2: #151d30;
  --border: #1f2a41;
  --border-soft: #1a2338;
  --text: #e8edf6;
  --text-dim: #9aa6bd;
  --text-faint: #66708a;
  --opp: #e8112d;
  --tido: #2f6fbf;
  --accent: #ffd54a;
  --green: #34d399;
  --radius: 16px;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(8, 11, 19, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -0.02em; }
.brand strong { color: var(--accent); font-weight: 900; }
.brand-mark { color: var(--opp); font-size: 20px; }
.topbar-meta { display: flex; gap: 8px; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.pill-live { color: #fff; background: #b91c1c; border-color: #b91c1c; }
.pill-live .dot { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* Live-uppdatering: subtil glow när ett värde ändras (ingen page-refresh-look) */
.flash { animation: flashNum 0.9s ease; }
@keyframes flashNum {
  0% { text-shadow: 0 0 16px rgba(255,213,74,0.95); }
  100% { text-shadow: 0 0 0 rgba(255,213,74,0); }
}

/* Progress rail (thin, top) */
.progress-rail {
  position: fixed; top: 60px; left: 0; height: 3px; width: 0%;
  background: linear-gradient(90deg, var(--opp), var(--accent));
  z-index: 60; transition: width 0.6s ease;
}

/* Hero */
.hero { padding: 34px 0 8px; }
.hero-head { text-align: center; margin-bottom: 26px; }
.hero-head h1 { margin: 0; font-size: clamp(26px, 5vw, 40px); font-weight: 900; letter-spacing: -0.03em; }
.hero-head .accent { color: var(--accent); }
.hero-sub { margin: 6px 0 0; color: var(--text-dim); font-size: 15px; }

.showdown {
  display: grid; grid-template-columns: 1fr auto 1fr;
  gap: 16px; align-items: stretch;
}
.block-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
}
.block-opp { border-top: 3px solid var(--opp); }
.block-tido { border-top: 3px solid var(--tido); }
.block-card-top { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.block-name { font-size: 15px; font-weight: 800; letter-spacing: -0.01em; }
.block-opp .block-name { color: var(--opp); }
.block-tido .block-name { color: #6ea8ff; }
.block-parties { font-size: 12px; color: var(--text-faint); font-weight: 600; }
.block-mandates { font-size: 44px; font-weight: 900; letter-spacing: -0.03em; line-height: 1; }
.block-mandates .unit { font-size: 15px; color: var(--text-faint); font-weight: 600; margin-left: 6px; }
.block-votes { margin-top: 6px; font-size: 13px; color: var(--text-dim); font-family: var(--mono); }
.block-extra { margin-top: 3px; font-size: 12px; color: var(--text-faint); font-family: var(--mono); }
.bar-track { margin-top: 16px; height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; transition: width 0.8s cubic-bezier(.22,.8,.4,1); }
.bar-fill-opp { background: linear-gradient(90deg, #7f0e1c, var(--opp)); }
.bar-fill-tido { background: linear-gradient(90deg, #14355e, var(--tido)); }
.block-status { margin-top: 10px; font-size: 12px; font-weight: 700; }
.block-status.win { color: var(--green); }
.block-status.lose { color: var(--text-faint); }

.showdown-center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 110px; }
.vs-badge {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim);
}
.gap-number { font-size: 40px; font-weight: 900; letter-spacing: -0.03em; color: var(--accent); line-height: 1; }
.gap-label { font-size: 11px; color: var(--text-faint); font-weight: 600; }

/* Majority line */
.majority-line {
  margin: 22px 0 6px; position: relative; height: 22px;
  display: flex; align-items: center; justify-content: center;
}
.majority-marker {
  background: var(--accent); color: #1a1200; font-weight: 900; font-size: 12px;
  padding: 3px 10px; border-radius: 999px;
}
.majority-cap { margin-left: 8px; font-size: 12px; color: var(--text-faint); font-weight: 600; }

/* Stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 24px 0; }
.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 30px; font-weight: 900; letter-spacing: -0.02em; margin-top: 6px; }
.stat-note { font-size: 12px; color: var(--text-faint); margin-top: 2px; font-family: var(--mono); }

/* Panels */
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin: 20px 0;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.panel-head h2 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.panel-total { font-size: 14px; color: var(--text-dim); font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--text-faint); }

/* Dot fan */
.dotfan-wrap { display: flex; justify-content: center; overflow-x: auto; }
.dotfan { display: flex; flex-direction: column; align-items: center; }
.dotfan-row { display: flex; gap: 4px; }
.dot {
  width: 14px; height: 14px; border-radius: 50%;
  opacity: 0.92; transition: transform 0.15s ease;
}
.dot:hover { transform: scale(1.35); }
.legend { display: flex; flex-wrap: wrap; gap: 10px 18px; justify-content: center; margin-top: 18px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-dim); font-weight: 600; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.legend-item b { color: var(--text); font-weight: 800; margin-left: 2px; }

/* Party table */
.party-table { display: flex; flex-direction: column; }
.party-row {
  display: grid;
  grid-template-columns: 44px 170px 1fr 60px 70px 84px 56px;
  gap: 12px; align-items: center;
  padding: 11px 6px; border-bottom: 1px solid var(--border-soft);
}
.party-row:last-child { border-bottom: none; }
.party-row:hover { background: var(--panel-2); border-radius: 8px; }
.pr-short {
  width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 15px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.pr-name { font-weight: 700; font-size: 14px; }
.pr-bar-wrap { position: relative; height: 20px; border-radius: 6px; background: var(--bg); overflow: hidden; }
.pr-bar { height: 100%; border-radius: 6px; transition: width 0.8s cubic-bezier(.22,.8,.4,1); }
.pr-bar-label { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.4); }
.pr-pct { text-align: right; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }
.pr-change { font-size: 12px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.pr-change.up { color: var(--green); }
.pr-change.down { color: #f87171; }
.pr-votes { text-align: right; font-size: 13px; color: var(--text-dim); font-family: var(--mono); }
.pr-mandates { text-align: right; font-weight: 800; font-size: 15px; }

.party-row.is-other { opacity: 0.55; }
.party-head {
  display: grid; grid-template-columns: 44px 170px 1fr 60px 70px 84px 56px; gap: 12px;
  padding: 6px 6px 10px; font-size: 11px; color: var(--text-faint); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border);
}
.party-head span:nth-child(4), .party-head span:nth-child(6) { text-align: right; }
.party-head span:nth-child(5), .party-head span:nth-child(7) { text-align: right; }

/* Minsta nya röster för +1 mandat */
.marginal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.marginal-card {
  background: var(--panel-2); border: 1px solid var(--border); border-top: 3px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.marginal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.marginal-label { font-size: 15px; font-weight: 800; letter-spacing: -0.01em; }
.marginal-min { font-size: 13px; color: var(--text-dim); }
.marginal-min b { color: var(--accent); font-size: 15px; }
.marginal-block { margin-top: 6px; font-family: var(--mono); font-size: 13px; color: var(--text-faint); letter-spacing: 0.02em; }
.marginal-moves { margin-top: 10px; font-size: 14px; color: var(--text); }
.marginal-changes { margin-top: 5px; font-size: 13px; color: var(--text-dim); font-family: var(--mono); }

/* Footer */
.foot {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
  color: var(--text-faint); font-size: 12px; padding: 20px 0 40px;
}
.foot .sep { opacity: 0.5; }
.foot a { color: var(--text-dim); }

/* Responsive */
@media (max-width: 820px) {
  .showdown { grid-template-columns: 1fr; }
  .showdown-center { order: -1; flex-direction: row; justify-content: center; gap: 10px; min-width: 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .party-head { display: none; }
  .party-row { grid-template-columns: 44px 1fr 60px 56px; }
  .pr-bar-wrap, .pr-votes { display: none; }
  .pr-pct { grid-column: 3; }
  .pr-mandates { grid-column: 4; }
  .pr-change { display: none; }
  .block-mandates { font-size: 36px; }
  .gap-number { font-size: 32px; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .party-row { grid-template-columns: 40px 1fr 54px 48px; }
}
