:root {
  color-scheme: light;
  --ink: #14212b;
  --muted: #66737f;
  --line: #d7dee5;
  --paper: #f8fafc;
  --panel: #ffffff;
  --shadow: 0 18px 50px rgba(20, 33, 43, 0.14);
  --ucp: #1f6feb;
  --ndp: #f97316;
  --alp: #d946ef;
  --grn: #16a34a;
  --oth: #64748b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef3f7;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

button:hover {
  border-color: #92a4b5;
  box-shadow: 0 8px 22px rgba(20, 33, 43, 0.1);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  border-color: #14532d;
  background: #14532d;
  color: #fff;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  min-height: 100vh;
}

.tool-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.brand-block h1 {
  margin: 4px 0 10px;
  font-size: clamp(2rem, 5vw, 3.7rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.brand-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  color: #14532d !important;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.control-group {
  display: grid;
  gap: 8px;
}

label {
  color: #40505d;
  font-size: 0.84rem;
  font-weight: 700;
}

input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  color: var(--ink);
  background: #fff;
}

input[type="range"] {
  width: 100%;
  accent-color: #14532d;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.summary-strip div {
  display: grid;
  gap: 2px;
  padding: 12px 8px;
  background: #fff;
  text-align: center;
}

.summary-strip span {
  font-size: 1.5rem;
  font-weight: 800;
}

.summary-strip small {
  color: var(--muted);
  font-size: 0.72rem;
}

.results-panel {
  display: grid;
  gap: 14px;
  padding-top: 4px;
}

.election-call {
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-heading button {
  min-height: 36px;
  padding: 0 12px;
}

.seat-chart {
  display: grid;
  gap: 8px;
}

.seat-row {
  display: grid;
  grid-template-columns: 42px minmax(74px, 1fr) 24px;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 800;
}

.seat-row > span:last-child {
  text-align: right;
}

.seat-bar {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4eaf0;
}

.seat-bar span {
  display: block;
  width: var(--width);
  height: 100%;
  background: var(--party);
}

.riding-results {
  display: grid;
  gap: 8px;
}

.riding-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  background: #fff;
}

.riding-card strong,
.riding-card span {
  display: block;
}

.riding-card span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.data-note {
  margin: auto 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.map-stage {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  padding: 22px;
  background:
    linear-gradient(90deg, rgba(20, 33, 43, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(20, 33, 43, 0.05) 1px, transparent 1px),
    #dce8ee;
  background-size: 38px 38px;
}

.map-toolbar {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 50px;
  margin-bottom: 14px;
}

.mode-pill,
.legend,
.scale-toggle {
  border: 1px solid rgba(20, 33, 43, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 28px rgba(20, 33, 43, 0.1);
}

.mode-pill {
  min-width: 0;
  flex: 1 1 auto;
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  color: #304351;
  font-size: 0.9rem;
  line-height: 1.25;
  overflow: hidden;
}

.legend {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  color: #304351;
  font-size: 0.78rem;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend .ucp { background: var(--ucp); }
.legend .ndp { background: var(--ndp); }
.legend .alp { background: var(--alp); }
.legend .grn { background: var(--grn); }
.legend .oth { background: var(--oth); }

.scale-toggle {
  flex: 0 0 auto;
  display: flex;
  gap: 2px;
  padding: 4px;
}

.scale-toggle button {
  min-height: 30px;
  border: 0;
  border-radius: 5px;
  padding: 0 10px;
  background: transparent;
  color: #40505d;
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: none;
}

.scale-toggle button.active {
  background: #14532d;
  color: #fff;
}

#map {
  align-self: stretch;
  justify-self: center;
  width: min(100%, 850px);
  height: 100%;
  min-height: 620px;
  max-height: calc(100vh - 88px);
  filter: drop-shadow(var(--shadow));
  touch-action: none;
  user-select: none;
}

.province {
  fill: #f9fbf5;
  stroke: #546575;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.riding {
  stroke: rgba(20, 33, 43, 0.86);
  stroke-width: 1.6;
  cursor: pointer;
  fill-opacity: 1;
  vector-effect: non-scaling-stroke;
}

.riding:hover {
  stroke-width: 2.4;
}

#scale-layer {
  pointer-events: none;
  user-select: none;
}

.voter-marker {
  opacity: 0.84;
  pointer-events: none;
}

.voter-marker.neutral,
.voter-cluster.neutral {
  fill: rgba(255, 255, 255, 0.86);
  stroke: rgba(20, 33, 43, 0.54);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.voter-marker.ucp,
.voter-cluster.ucp {
  fill: var(--ucp);
  stroke: rgba(255, 255, 255, 0.84);
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
}

.voter-marker.ndp,
.voter-cluster.ndp {
  fill: var(--ndp);
  stroke: rgba(255, 255, 255, 0.84);
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
}

.voter-cluster {
  opacity: 0.76;
  pointer-events: none;
}

.city-limit {
  fill: rgba(255, 255, 255, 0.08);
  stroke: rgba(15, 23, 42, 0.58);
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

#city-layer,
#town-layer,
.city-label-anchor,
.town-label-anchor {
  pointer-events: none;
  user-select: none;
}

.city-label {
  fill: rgba(15, 23, 42, 0.78);
  paint-order: stroke;
  stroke: rgba(248, 250, 252, 0.86);
  stroke-width: 3;
  stroke-linejoin: round;
  font-size: 10px;
  font-weight: 800;
  text-anchor: middle;
  pointer-events: none;
}

.town-point {
  fill: rgba(255, 255, 255, 0.94);
  stroke: none;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.town-label {
  fill: rgba(15, 23, 42, 0.68);
  paint-order: stroke;
  stroke: rgba(248, 250, 252, 0.8);
  stroke-width: 2.4;
  stroke-linejoin: round;
  font-size: 8px;
  font-weight: 800;
  text-anchor: middle;
  pointer-events: none;
}

.draft-line {
  fill: transparent;
  stroke: #0f172a;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  paint-order: stroke;
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.95));
}

.draft-point {
  fill: #111827;
  stroke: #fff;
  stroke-width: 2;
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .tool-panel {
    display: contents;
  }

  .brand-block {
    order: 1;
    padding: 18px 18px 14px;
    background: var(--paper);
  }

  .brand-block h1 {
    font-size: 2.25rem;
    line-height: 1;
  }

  .map-stage {
    order: 2;
    grid-template-rows: minmax(0, 1fr);
    min-height: 76vh;
    padding: 0;
  }

  .button-grid,
  .summary-strip,
  .results-panel,
  .data-note {
    order: 3;
    margin-right: 18px;
    margin-left: 18px;
  }

  .button-grid {
    margin-top: 18px;
  }

  .data-note {
    margin-bottom: 18px;
  }

  .map-toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    left: 10px;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    margin-bottom: 0;
    pointer-events: none;
  }

  .mode-pill {
    flex: 0 0 auto;
    min-height: 44px;
    max-height: 44px;
    align-items: center;
    padding: 8px 10px;
    pointer-events: none;
  }

  .legend {
    align-self: flex-start;
    padding: 8px 10px;
    pointer-events: none;
  }

  .scale-toggle {
    align-self: flex-start;
    pointer-events: auto;
  }

  #map {
    width: 100%;
    min-height: 76vh;
    max-height: none;
  }
}
