:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --line: #d9ded7;
  --text: #1d2521;
  --muted: #657169;
  --teal: #1e7a78;
  --teal-weak: #d8ece9;
  --gold: #b7791f;
  --coral: #ca5a3f;
  --blue: #4169a8;
  --green: #4f8a43;
  --violet: #7655a4;
  --shadow: 0 16px 40px rgba(32, 42, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  max-width: 1240px;
  margin: 0 auto 18px;
}

.brand {
  display: flex;
  align-items: start;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 7px 18px rgba(30, 122, 120, 0.18);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 10px;
}

.controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

select {
  min-width: 190px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 0 34px 0 10px;
}

.workspace {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(420px, 0.95fr) minmax(460px, 1.05fr);
  gap: 18px;
}

.map-pane,
.detail-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.map-pane {
  padding: 18px;
}

.map-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.map-head h2,
.detail-head h2 {
  font-size: 22px;
  line-height: 1.2;
}

.map-head p {
  color: var(--muted);
  font-size: 14px;
}

.map-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1.08;
  overflow: hidden;
  border-radius: 8px;
  background: #eef2ee;
}

.provider-map {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
}

.map-status {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 8;
  max-width: calc(100% - 20px);
  border: 1px solid rgba(29, 37, 33, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  box-shadow: 0 5px 16px rgba(29, 37, 33, 0.12);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.map-status.is-error {
  color: #8a3328;
  background: rgba(255, 239, 235, 0.96);
}

.map-frame.uses-provider-map .provider-map {
  display: block;
}

.map-frame.uses-provider-map #daejeonMap {
  display: none;
}

#daejeonMap {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
}

.provider-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 58px;
  height: 30px;
  border: 1px solid rgba(29, 37, 33, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: 0 5px 14px rgba(29, 37, 33, 0.18);
  padding: 0 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.provider-label::before {
  content: "";
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border: 1px solid rgba(29, 37, 33, 0.24);
  border-radius: 999px;
  background: var(--region-color, #cad2cb);
}

.provider-label.is-district {
  min-width: 44px;
  height: 24px;
  gap: 4px;
  padding: 0 7px;
  font-size: 11px;
}

.provider-label.is-district::before {
  width: 7px;
  height: 7px;
}

.provider-label.is-selected {
  border-color: var(--text);
  background: var(--text);
  color: #fff;
}

.gu-path {
  cursor: pointer;
  stroke: var(--region-stroke, #fff);
  stroke-width: 4;
  transition:
    transform 160ms ease,
    filter 160ms ease,
    stroke-width 160ms ease;
  transform-origin: center;
}

.gu-path:hover,
.gu-path.is-selected {
  filter: brightness(1.04) saturate(1.08);
  stroke-width: 7;
}

.gu-label {
  pointer-events: none;
  fill: #17211d;
  font-weight: 800;
  font-size: 24px;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.82);
  stroke-width: 5px;
  stroke-linejoin: round;
}

.gu-sub {
  pointer-events: none;
  fill: #29342f;
  font-size: 13px;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.82);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.detail-pane {
  min-width: 0;
  padding: 18px;
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.turnout-chip {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 11px;
  color: var(--teal);
  background: var(--teal-weak);
  font-size: 14px;
  font-weight: 700;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 13px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.tab-button.is-active {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.summary-metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.summary-metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.summary-metric strong {
  font-size: 20px;
  line-height: 1.1;
}

.contest-list {
  display: grid;
  gap: 12px;
}

.contest {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.contest-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.contest-title h3 {
  font-size: 17px;
}

.contest-title p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.seats {
  flex: none;
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
}

.candidate-list {
  display: grid;
}

.candidate-row {
  display: grid;
  grid-template-columns: minmax(108px, 1fr) minmax(84px, 0.8fr) 92px 74px;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-top: 1px solid #edf0ec;
  background: #fff;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.candidate-row:hover,
.candidate-row:focus-visible {
  background: #f8fbf8;
}

.candidate-row:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -2px;
}

.candidate-row:first-child {
  border-top: 0;
}

.candidate-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.candidate-photo {
  width: 38px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid #dce4df;
  border-radius: 6px;
  background: #eef2ef;
  object-fit: cover;
  object-position: center top;
}

.candidate-text {
  min-width: 0;
}

.candidate-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-weight: 800;
}

.candidate-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 19px;
  border-radius: 999px;
  background: #e7f2ec;
  color: var(--green);
  padding: 0 7px;
  font-size: 11px;
  font-weight: 800;
}

.party {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.party::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--candidate-color, #6d7470);
}

.bar-wrap {
  grid-column: 1 / -1;
  height: 8px;
  background: #ecf0ed;
  border-radius: 99px;
  overflow: hidden;
}

.bar {
  height: 100%;
  background: var(--candidate-color, var(--teal));
}

.votes,
.rate {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.votes {
  color: var(--text);
  font-weight: 700;
}

.rate {
  color: var(--muted);
}

.empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfa;
}

body.modal-open {
  overflow: hidden;
}

.candidate-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 32, 29, 0.52);
}

.candidate-modal[hidden] {
  display: none;
}

.candidate-dialog {
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid #dce4df;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(19, 30, 26, 0.24);
}

.candidate-dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.candidate-dialog-head h2 {
  margin-top: 2px;
  font-size: 22px;
}

.modal-close {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 11px;
  font-weight: 800;
  cursor: pointer;
}

.modal-close:hover,
.modal-close:focus-visible {
  border-color: var(--green);
}

.candidate-dialog-body {
  padding: 20px;
}

.candidate-modal-profile {
  display: grid;
  grid-template-columns: 88px 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.candidate-modal-photo {
  width: 88px;
  height: 106px;
  border: 1px solid #dce4df;
  border-radius: 7px;
  background: #eef2ef;
  object-fit: cover;
  object-position: center top;
}

.candidate-modal-photo.is-empty::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
}

.candidate-modal-name {
  font-size: 24px;
  font-weight: 900;
}

.candidate-modal-party {
  margin-top: 5px;
  color: var(--muted);
  font-weight: 800;
}

.candidate-detail-grid {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.candidate-detail-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.candidate-detail-row dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.candidate-detail-row dd {
  margin: 0;
  color: var(--text);
  line-height: 1.55;
}

.candidate-pledges {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.candidate-pledges summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
  list-style: none;
}

.candidate-pledges summary::-webkit-details-marker {
  display: none;
}

.candidate-pledges summary::after {
  content: "펼치기";
  flex: none;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
}

.candidate-pledges[open] summary {
  border-bottom: 1px solid var(--line);
}

.candidate-pledges[open] summary::after {
  content: "접기";
}

.candidate-pledges summary span {
  color: var(--muted);
  font-size: 12px;
}

.candidate-pledges-body {
  padding: 14px;
}

.candidate-pledge-note {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.55;
}

.candidate-pledge-link,
.candidate-pledge-list a {
  color: var(--green);
  font-weight: 900;
  text-decoration: none;
}

.candidate-pledge-link:hover,
.candidate-pledge-link:focus-visible,
.candidate-pledge-list a:hover,
.candidate-pledge-list a:focus-visible {
  text-decoration: underline;
}

.candidate-pledge-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.candidate-pledge-list li {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.candidate-pledge-list li:first-child {
  padding-top: 0;
  border-top: 0;
}

.candidate-pledge-list p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .controls {
    justify-content: stretch;
  }

  .controls label,
  select {
    width: 100%;
  }

  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 24px;
  }

  .brand {
    gap: 10px;
  }

  .brand-icon {
    width: 34px;
    height: 34px;
  }

  .map-head,
  .detail-head {
    display: grid;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .candidate-row {
    grid-template-columns: 1fr 74px;
    gap: 8px;
  }

  .candidate-dialog {
    max-height: calc(100vh - 24px);
  }

  .candidate-dialog-head,
  .candidate-dialog-body {
    padding: 16px;
  }

  .candidate-modal-profile,
  .candidate-detail-row {
    grid-template-columns: 1fr;
  }

  .candidate-main {
    grid-column: 1 / -1;
  }

  .party,
  .bar-wrap {
    grid-column: 1 / -1;
  }

  .votes {
    grid-column: 1;
    text-align: left;
  }
}
