:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f4f4f3;
  --surface-strong: #e9e9e7;
  --ink: #191918;
  --muted: #686865;
  --line: #d6d6d3;
  --accent: #315f75;
  --focus: #1b6f99;
  font-family: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171817;
  --surface: #222422;
  --surface-strong: #2d302d;
  --ink: #f2f1ed;
  --muted: #b7b7b1;
  --line: #454844;
  --accent: #87b8cd;
  --focus: #95d4ef;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  color: inherit;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent);
  outline-offset: 2px;
}

.tool {
  width: min(700px, 100vw);
  height: min(600px, 100vh);
  min-height: 0;
  margin: 0 auto;
  padding: 14px 16px 12px;
  overflow: hidden;
  background: var(--bg);
}

.tool-header {
  height: 52px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 850;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.info-button,
.dialog-header button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font-family: Georgia, serif;
  font-size: 21px;
  font-weight: 700;
  cursor: pointer;
}

.toolbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  align-self: stretch;
}

.tab {
  min-width: 132px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--ink);
}

.year-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.year-control span,
.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

select {
  height: 34px;
  min-width: 92px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font-weight: 700;
}

.panel {
  height: calc(100% - 106px);
  min-height: 0;
}

.results-panel {
  display: grid;
  grid-template-columns: 238px 1fr;
  gap: 16px;
  padding-top: 14px;
}

[hidden] {
  display: none !important;
}

.party-inputs {
  min-width: 0;
  padding-right: 14px;
  border-right: 1px solid var(--line);
}

.party-input {
  height: 49px;
  display: grid;
  grid-template-columns: 10px 34px 1fr 14px 30px;
  align-items: center;
  gap: 7px;
  border-bottom: 1px solid var(--line);
}

.party-input:last-child {
  border-bottom: 0;
}

.party-dot,
.mandate-item > span:first-child {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.party-name {
  font-weight: 800;
}

.party-input input {
  width: 100%;
  height: 34px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.input-unit {
  color: var(--muted);
  font-size: 13px;
}

.row-seats {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.result-column {
  min-width: 0;
}

.result-heading {
  height: 55px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.result-heading > div {
  display: grid;
  gap: 3px;
}

.result-heading strong {
  font-size: 20px;
  line-height: 1.1;
}

.text-button {
  padding: 5px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.mandate-band {
  height: 86px;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.mandate-band span {
  min-width: 2px;
  border-right: 1px solid color-mix(in srgb, #ffffff 42%, transparent);
}

.majority-scale {
  position: relative;
  height: 28px;
  display: flex;
  justify-content: space-between;
  padding-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.majority-scale::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  height: 8px;
  border-left: 1px solid var(--ink);
}

.majority-mark {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.mandate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 18px;
  border-top: 1px solid var(--line);
}

.mandate-item {
  height: 39px;
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 7px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.mandate-item strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.model-note,
.government-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.government-panel {
  padding-top: 14px;
}

.government-summary {
  min-height: 92px;
  display: grid;
  grid-template-columns: 105px 1fr 240px;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: var(--surface);
}

.government-summary > div:nth-child(2) {
  display: grid;
  gap: 3px;
}

.government-summary strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.government-summary div span {
  color: var(--muted);
  font-size: 13px;
}

.majority-meter {
  position: relative;
  height: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
}

.majority-meter span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.majority-meter i {
  position: absolute;
  inset: 0 auto 0 50%;
  border-left: 2px solid var(--ink);
}

.drop-section {
  margin-top: 14px;
}

.outside-section {
  margin-top: 18px;
}

.drop-label {
  min-height: 34px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.drop-label strong {
  font-size: 17px;
}

.drop-label span {
  color: var(--muted);
  font-size: 12px;
}

.party-zone {
  min-height: 82px;
  display: flex;
  align-content: flex-start;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  transition: border-color 120ms ease, background 120ms ease;
}

.party-zone.is-dragover {
  border-color: var(--accent);
  background: var(--surface-strong);
}

.party-block {
  flex: 0 0 calc(var(--party-width) - 4px);
  min-width: 30px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 0 6px;
  border: 0;
  border-radius: 5px;
  background: var(--party-color);
  color: var(--party-ink);
  cursor: grab;
  font-variant-numeric: tabular-nums;
}

.party-block:active {
  cursor: grabbing;
}

.party-block strong {
  font-size: 15px;
}

.party-block span {
  font-size: 12px;
  font-weight: 700;
}

.party-block.is-small span {
  display: none;
}

.government-note {
  margin-top: 10px;
}

.info-dialog {
  width: min(600px, calc(100vw - 32px));
  max-height: 540px;
  padding: 0 22px 20px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

.info-dialog::backdrop {
  background: rgba(0, 0, 0, 0.46);
}

.dialog-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
  font-size: 24px;
}

.dialog-header button {
  border: 0;
  font-family: inherit;
  font-size: 28px;
  font-weight: 400;
}

.info-dialog p {
  margin: 15px 0 0;
  font-size: 15px;
  line-height: 1.42;
}

.info-dialog .sources {
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.info-dialog a {
  color: var(--accent);
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
