:root {
  --bg: #0b1020;
  --surface: rgba(17, 24, 39, 0.9);
  --surface-2: rgba(255, 255, 255, 0.045);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f4f6fb;
  --muted: #9aa8c7;
  --accent: #5b9aff;
  --accent-2: #2dd4bf;
  --ppp: #ef4444;
  --dpk: #3b82f6;
  --rkp: #0f9f8e;
  --progressive: #f59e0b;
  --innovation: #22c55e;
  --ind: #6b7280;
  --gold: #fbbf24;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  --radius: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  height: 100%;
}

body {
  font-family: "Noto Sans KR", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  text-align: center;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(4rem, 8vh, 6rem) 0 7.5rem;
}

.page {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1.25rem;
  flex-shrink: 0;
}

.backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(79, 140, 255, 0.14), transparent 45%),
    radial-gradient(circle at 20% 80%, rgba(34, 199, 184, 0.08), transparent 40%),
    radial-gradient(circle at 80% 60%, rgba(229, 57, 53, 0.06), transparent 35%),
    linear-gradient(180deg, #0b1020 0%, #0f172a 100%);
  z-index: -1;
}

.site-header {
  padding: 0 0 1.35rem;
}

.header-inner {
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.eyebrow {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

.site-header h1 {
  margin: 0;
  font-size: 2.35rem;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.2;
}

.header-desc {
  margin: 0.65rem 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.status-bar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.pulse {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--accent-2);
  opacity: 0.7;
  flex-shrink: 0;
}

.main {
  width: 100%;
  margin: 0 auto;
  padding: 0 0 2rem;
  display: block;
}

.race-card {
  position: relative;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  overflow: hidden;
  transition: border-color 0.25s ease, transform 0.25s ease, box-shadow 0.4s ease;
}

.race-card.is-close-race {
  border-color: rgba(255, 168, 92, 0.22);
  box-shadow:
    var(--shadow),
    0 0 48px rgba(255, 120, 48, 0.07);
  overflow: visible;
}

.race-candidates {
  position: relative;
}

.race-candidates .race-sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  overflow: visible;
}

.race-sparks i {
  position: absolute;
  display: block;
  width: 2px;
  height: 11px;
  border-radius: 1px;
  background: linear-gradient(
    180deg,
    #ffe2b8 0%,
    #ff9a4d 42%,
    rgba(255, 72, 32, 0.35) 100%
  );
  box-shadow:
    0 0 6px 1px rgba(255, 150, 70, 0.55),
    0 0 14px 2px rgba(255, 90, 40, 0.2);
  opacity: 0;
  transform-origin: 50% 100%;
  animation: spark-flick var(--dur, 0.85s) ease-out forwards;
  will-change: transform, opacity;
}

.race-sparks i.is-ash {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #ffd9a8;
  box-shadow: 0 0 8px 2px rgba(255, 170, 90, 0.65);
  animation-name: spark-ash;
}

@keyframes spark-flick {
  0% {
    opacity: 0;
    transform: translate(0, 2px) rotate(var(--rot, -18deg)) scaleY(0.4);
  }
  12% {
    opacity: 0.95;
  }
  45% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 0), var(--dy, -36px)) rotate(calc(var(--rot, -18deg) + 32deg))
      scaleY(0.2);
  }
}

@keyframes spark-ash {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }
  15% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 0), var(--dy, -24px)) scale(0.1);
  }
}

@media (min-width: 900px) {
  .global-error {
    grid-column: 1 / -1;
  }
}

.race-card:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

.race-card.is-loading {
  opacity: 0.92;
  pointer-events: none;
}

.race-card.is-loading .candidate-list {
  opacity: 0.85;
  transition: opacity 0.3s ease;
}

body.is-forecast-mode .race-card {
  border-color: rgba(126, 232, 216, 0.2);
}

.race-head {
  padding: 1.65rem 1.65rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.race-head h2 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: 0;
}

.race-head p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.race-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.85rem 1.25rem 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.chip {
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.forecast {
  margin: 1.1rem 1.65rem 0;
  padding: 0.72rem 0.9rem;
  border: 1px solid rgba(126, 232, 216, 0.2);
  border-radius: 8px;
  background: rgba(45, 212, 191, 0.055);
  text-align: center;
}

.forecast-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.28rem 0.45rem;
  line-height: 1.4;
}

.forecast-label {
  flex-shrink: 0;
  padding: 0.1rem 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(126, 232, 216, 0.3);
  background: rgba(126, 232, 216, 0.08);
  color: #99f6e4;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.forecast-name {
  font-size: 0.96rem;
  font-weight: 600;
  color: rgba(244, 246, 251, 0.9);
}

.forecast-final {
  flex-shrink: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: #7ee8d8;
  font-variant-numeric: tabular-nums;
}

.forecast-party {
  font-size: 0.73rem;
  font-weight: 500;
  color: var(--muted);
}

.forecast-party::before {
  content: "·";
  margin-right: 0.38rem;
  color: rgba(154, 168, 199, 0.42);
}

.race-alert {
  margin: 0.75rem 1.25rem 0;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 0.81rem;
  text-align: center;
  background: rgba(255, 193, 7, 0.08);
  border: 1px solid rgba(255, 193, 7, 0.22);
  color: #fde68a;
}

.candidate-list {
  position: relative;
  z-index: 1;
  list-style: none;
  margin: 0;
  padding: 1.25rem 1.65rem 1.45rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  text-align: left;
}

@media (min-width: 820px) {
  .candidate-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.candidate {
  position: relative;
  display: grid;
  gap: 0.85rem;
  padding: 1rem 1rem 1.05rem;
  border-left: 4px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.028);
  transition: background 0.35s ease, box-shadow 0.35s ease, border-color 0.35s ease;
}

.candidate-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.75rem;
}

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

.candidate-name {
  font-weight: 700;
  font-size: 1.32rem;
  letter-spacing: 0;
}

.candidate-party {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.15rem;
  font-weight: 500;
}

.candidate-stats {
  text-align: right;
  white-space: nowrap;
  flex-shrink: 0;
}

.vote-count,
.vote-percent,
.chip [data-anim-progress],
.race-foot [data-anim-total],
.metric-value {
  font-variant-numeric: tabular-nums;
  transition: color 0.35s ease, text-shadow 0.35s ease, background 0.35s ease;
}

.vote-count.is-rising,
.vote-percent.is-rising,
[data-anim-progress].is-rising,
[data-anim-total].is-rising,
[data-anim-margin].is-rising {
  color: #7ee8d8;
  text-shadow: 0 0 22px rgba(45, 212, 191, 0.55);
}

.vote-count.is-falling,
.vote-percent.is-falling,
[data-anim-progress].is-falling,
[data-anim-total].is-falling,
[data-anim-margin].is-falling {
  color: #fca5a5;
  text-shadow: 0 0 22px rgba(248, 113, 113, 0.45);
}

.vote-percent {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text);
}

.vote-count {
  margin-top: 0.15rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--muted);
}

body.is-forecast-mode .vote-count {
  display: none;
}

.vote-percent.is-rising,
.vote-percent.is-falling {
  color: inherit;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1), filter 0.35s ease;
  min-width: 2px;
}

.bar-fill.party-ppp {
  background: linear-gradient(90deg, #f87171, var(--ppp));
}

.bar-fill.party-dpk {
  background: linear-gradient(90deg, #60a5fa, var(--dpk));
}

.bar-fill.party-rkp {
  background: linear-gradient(90deg, #34d399, var(--rkp));
}

.bar-fill.party-progressive {
  background: linear-gradient(90deg, #fbbf24, var(--progressive));
}

.bar-fill.party-innovation {
  background: linear-gradient(90deg, #86efac, var(--innovation));
}

.bar-fill.party-ind {
  background: linear-gradient(90deg, #a1a1aa, var(--ind));
}

.bar-fill.party-default {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.candidate.leading .candidate-name {
  color: #fff;
}

.candidate.leading {
  border-left-color: rgba(45, 212, 191, 0.9);
  background: linear-gradient(90deg, rgba(45, 212, 191, 0.12), rgba(255, 255, 255, 0.035));
}

.race-card.is-close-race .candidate.leading {
  border-left-color: rgba(255, 176, 108, 0.75);
  background: linear-gradient(90deg, rgba(255, 140, 64, 0.1), rgba(255, 255, 255, 0.035));
}

.race-card.is-close-race .bar-track {
  box-shadow: inset 0 0 12px rgba(255, 120, 48, 0.08);
}

.race-card.is-close-race .bar-fill {
  filter: saturate(1.08) brightness(1.04);
}

.candidate.leading .vote-count {
  color: rgba(244, 246, 251, 0.74);
}

.candidate.leading .vote-percent {
  color: #fff;
  font-size: 2.15rem;
}

.leader-badge {
  display: inline-block;
  margin-left: 0.42rem;
  padding: 0.08rem 0.42rem 0.1rem;
  border-radius: 999px;
  border: 1px solid rgba(45, 212, 191, 0.34);
  background: rgba(45, 212, 191, 0.08);
  font-size: 0.68rem;
  font-weight: 700;
  color: #8ef4e8;
  vertical-align: middle;
}

.leader-badge.likely-badge {
  border-color: rgba(251, 191, 36, 0.32);
  background: rgba(251, 191, 36, 0.08);
  color: #fcd34d;
}

.leader-badge.confirmed-badge {
  border-color: rgba(251, 191, 36, 0.48);
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
}

.race-foot {
  padding: 1rem 1.65rem 1.2rem;
  font-size: 0.76rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  text-align: center;
}

.site-footer {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 0 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.65;
}

.footer-note {
  margin: 0 0 0.75rem;
}

.footer-badge {
  margin: 1.1rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: rgba(154, 168, 199, 0.85);
}

.forecast-control {
  position: fixed;
  left: 50%;
  bottom: 1.1rem;
  z-index: 20;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(calc(100% - 2rem), 400px);
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0.42rem;
  pointer-events: none;
}

.control-toggle,
.forecast-toggle {
  flex: 0 1 auto;
  min-height: 41px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  padding: 0.48rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(18, 26, 48, 0.94);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
}

.control-toggle input,
.forecast-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  width: 36px;
  height: 21px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(154, 168, 199, 0.26);
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.toggle-thumb {
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.forecast-toggle input:checked + .toggle-track {
  background: rgba(45, 212, 191, 0.76);
}

.music-toggle input:checked + .toggle-track {
  background: rgba(251, 191, 36, 0.76);
}

.control-toggle input:checked + .toggle-track .toggle-thumb,
.forecast-toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(15px);
}

.toggle-text {
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.yt-player-host {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.global-error {
  flex: 0 0 min(100%, 520px);
  width: 100%;
  max-width: 520px;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
  color: #fecaca;
  text-align: center;
}

.global-loading {
  flex: 0 0 min(100%, 520px);
  width: 100%;
  max-width: 520px;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid rgba(91, 154, 255, 0.28);
  background: rgba(91, 154, 255, 0.08);
  color: #bfdbfe;
  text-align: center;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  padding: 1.25rem 1.65rem 0;
}

@media (min-width: 860px) {
  .overview-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.metric-card {
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.3rem;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: var(--surface-2);
  text-align: left;
  transition: border-color 0.35s ease, background 0.35s ease, box-shadow 0.35s ease;
}

.metric-primary {
  border-color: rgba(45, 212, 191, 0.22);
  background: rgba(45, 212, 191, 0.065);
}

.metric-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric-value {
  color: var(--text);
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0;
}

.metric-rising {
  border-color: rgba(45, 212, 191, 0.5);
  background: rgba(45, 212, 191, 0.13);
  box-shadow: 0 0 0 1px rgba(45, 212, 191, 0.1), 0 0 26px rgba(45, 212, 191, 0.18);
}

.metric-falling {
  border-color: rgba(248, 113, 113, 0.44);
  background: rgba(248, 113, 113, 0.11);
  box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.1), 0 0 26px rgba(248, 113, 113, 0.14);
}

.detail-section {
  margin: 0.35rem 1.65rem 1.45rem;
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.85rem;
  text-align: left;
}

.section-kicker {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.section-head h3 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.segment-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.segment-summary span {
  padding: 0.24rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
}

.detail-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.detail-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.88rem;
}

.detail-table th,
.detail-table td {
  padding: 0.72rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.065);
  white-space: nowrap;
}

.detail-table thead th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.035);
}

.detail-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.035);
}

.detail-table th:first-child,
.detail-table td:first-child {
  text-align: left;
}

.detail-table td strong {
  display: inline-block;
  min-width: 5.5rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.detail-table td span {
  margin-left: 0.35rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.district-leading strong {
  color: #7ee8d8;
}

.race-card.is-close-race .bar-fill {
  position: relative;
}

.race-card.is-close-race .candidate.leading .bar-fill::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 100%;
  width: 14px;
  margin-left: -4px;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, rgba(255, 200, 130, 0.22), transparent);
  opacity: 0;
  animation: bar-spark-glint 4.8s ease-in-out infinite;
  pointer-events: none;
}

@keyframes bar-spark-glint {
  0%,
  78%,
  100% {
    opacity: 0;
    transform: translateX(0);
  }
  82% {
    opacity: 0.55;
  }
  88% {
    opacity: 0;
    transform: translateX(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .race-sparks i {
    animation: none;
    opacity: 0;
  }

  .race-card.is-close-race .candidate.leading .bar-fill::after {
    animation: none;
    opacity: 0;
  }

  .race-card.is-close-race {
    box-shadow: var(--shadow);
  }
}

@media (max-width: 720px) {
  body {
    padding-top: 2.5rem;
  }

  .site-header h1 {
    font-size: 1.7rem;
  }

  .race-head,
  .overview-grid,
  .candidate-list,
  .race-foot {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .forecast,
  .detail-section {
    margin-left: 1rem;
    margin-right: 1rem;
  }

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

  .metric-card {
    min-height: 92px;
  }

  .metric-value,
  .vote-percent,
  .candidate.leading .vote-percent {
    font-size: 1.55rem;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .segment-summary {
    justify-content: flex-start;
  }
}
