/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-elevated: #242836;
  --text-primary: #e4e6eb;
  --text-secondary: #8b8fa3;
  --text-muted: #5c6078;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: #7c9deb;
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: #a0b8f0;
  text-decoration: underline;
}

/* === Layout === */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 2.5rem;
}

/* === Header === */
.header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.header__title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  background: linear-gradient(135deg, #e4e6eb 0%, #8b8fa3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header__subtitle {
  margin-top: 0.5rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* === Controls (Search + Clear) === */
.controls {
  --control-btn-height: 40px;
  --control-stack-gap: 0.4rem;
  display: flex;
  align-items: stretch;
  gap: 0.8rem;
  margin-bottom: 1.5rem;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.search-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
  min-height: calc((var(--control-btn-height) * 2) + var(--control-stack-gap));
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-subtle);
  border-radius: 12px;
  transition: border-color 0.2s;
  cursor: text;
}

.search-wrapper:focus-within {
  border-color: rgba(255, 255, 255, 0.2);
}

.search-input {
  flex: 1;
  min-width: 120px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.85rem;
  padding: 0.3rem 0.2rem;
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* === Tags === */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: color-mix(in srgb, var(--tag-color) 20%, transparent);
  border: 1px solid color-mix(in srgb, var(--tag-color) 40%, transparent);
  border-radius: 100px;
  padding: 0.2rem 0.2rem 0.2rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  animation: tagIn 0.2s ease-out;
}

@keyframes tagIn {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

.tag__label {
  line-height: 1;
}

.tag__remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s;
}

.tag__remove:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

/* === Button column === */
.controls-btns {
  display: flex;
  gap: 0.8rem;
  flex-shrink: 0;
}

.controls-btns__stack {
  display: flex;
  flex-direction: column;
  gap: var(--control-stack-gap);
  min-width: 126px;
}

.controls-btns__stack--secondary {
  margin-left: 0.2rem;
}

/* === Clear Button === */
.clear-btn {
  width: 100%;
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 500;
  height: var(--control-btn-height);
  padding: 0 1rem;
  border-radius: 10px;
  border: 1.5px solid rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.08);
  color: #f87171;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.clear-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.5);
}

/* === Show All Button === */
.showall-btn {
  width: 100%;
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 500;
  height: var(--control-btn-height);
  padding: 0 1rem;
  border-radius: 10px;
  border: 1.5px solid rgba(52, 211, 153, 0.3);
  background: rgba(52, 211, 153, 0.08);
  color: #6ee7b7;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.showall-btn:hover {
  background: rgba(52, 211, 153, 0.15);
  border-color: rgba(52, 211, 153, 0.5);
}

/* === Averages Button === */
.avg-btn {
  width: 100%;
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 500;
  height: var(--control-btn-height);
  padding: 0 1rem;
  border-radius: 10px;
  border: 1.5px solid rgba(124, 157, 235, 0.3);
  background: rgba(124, 157, 235, 0.08);
  color: #7c9deb;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.avg-btn:hover {
  background: rgba(124, 157, 235, 0.15);
  border-color: rgba(124, 157, 235, 0.5);
}

.avg-btn--active {
  background: rgba(124, 157, 235, 0.2);
  border-color: rgba(124, 157, 235, 0.6);
  color: #a0b8f0;
}

/* === Search Dropdown === */
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: none;
}

.search-dropdown.dropdown--open {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: background 0.1s;
}

.dropdown-item:first-child {
  border-radius: 12px 12px 0 0;
}

.dropdown-item:last-child {
  border-radius: 0 0 12px 12px;
}

.dropdown-item:hover,
.dropdown-item--active {
  background: rgba(255, 255, 255, 0.06);
}

.dropdown-item__flag {
  font-size: 1.1rem;
  line-height: 1;
}

.dropdown-item__name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}

.dropdown-item__count {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.dropdown-empty {
  padding: 0.8rem 1rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Scrollbar for dropdown */
.search-dropdown::-webkit-scrollbar {
  width: 6px;
}

.search-dropdown::-webkit-scrollbar-track {
  background: transparent;
}

.search-dropdown::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

/* === Chart === */
.chart-wrapper {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  background: var(--bg-secondary);
  border-radius: 16px;
  border: 1px solid var(--border-subtle);
  padding: 1rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.chart-container {
  flex: 1;
  min-width: 0;
}

.chart-container svg {
  display: block;
  width: 100%;
  height: auto;
}

.axis-panel {
  width: 260px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.axis-panel__title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.axis-panel__subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.2rem;
}

.axis-panel__label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.axis-panel__select {
  appearance: none;
  width: 100%;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.78rem;
  padding: 0.5rem 0.55rem;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.axis-panel__select:hover {
  background: rgba(255, 255, 255, 0.08);
}

.axis-panel__select:focus {
  border-color: rgba(124, 157, 235, 0.65);
}

.axis-panel__select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.axis-panel__note {
  margin-top: 0.35rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.paths-btn {
  margin-top: 0.5rem;
  width: 100%;
  font-family: var(--font-main);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.paths-btn:hover {
  background: rgba(167, 210, 167, 0.12);
  border-color: rgba(167, 210, 167, 0.4);
}

.paths-btn--active {
  background: rgba(167, 210, 167, 0.15);
  border-color: rgba(167, 210, 167, 0.55);
  color: #a8d5a8;
}

/* === Quadrant Panel === */
.quadrant-panel {
  width: 260px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow-y: auto;
}

.quadrant-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.quadrant-panel__title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.quadrant-panel__back {
  font-family: var(--font-main);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.quadrant-panel__back:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.quadrant-panel__subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.quadrant-panel__list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.quadrant-panel__country {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  cursor: default;
}

.quadrant-panel__country:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-subtle);
}

.quadrant-panel__country-rank {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 1.1rem;
  text-align: right;
}

.quadrant-panel__country-flag {
  font-size: 1rem;
  line-height: 1;
}

.quadrant-panel__country-name {
  flex: 1;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-primary);
}

.quadrant-panel__country-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.quadrant-panel__empty {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.5rem 0;
}

/* Axis styling */
.axis text {
  font-family: var(--font-main);
  font-size: 10px;
  fill: var(--text-muted);
}

.axis-endpoint-label {
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 600;
  fill: var(--text-secondary);
}

.axis-title {
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 500;
  fill: var(--text-muted);
}

.quadrant-label {
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  fill: rgba(255, 255, 255, 0.06);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  user-select: none;
  pointer-events: none;
}

.dot-label {
  font-family: var(--font-main);
  font-weight: 600;
  pointer-events: none;
  user-select: none;
}

.party-dot,
.avg-dot {
  outline: none;
}

.avg-flag-label {
  pointer-events: none;
  user-select: none;
}

.party-dot:focus circle,
.avg-dot:focus circle {
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 3;
}

.dot--dimmed {
  opacity: 0.15;
}

.dot--country-highlight circle {
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 3;
  filter: url(#dot-glow);
}

/* === Tooltip === */
.tooltip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 0;
  min-width: 200px;
  max-width: 280px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.tooltip--visible {
  opacity: 1;
  transform: translateY(0);
}

.tooltip__header {
  padding: 0.65rem 0.85rem;
  border-left: 3px solid transparent;
  background: rgba(255, 255, 255, 0.03);
}

.tooltip__name {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.tooltip__abbr {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.tooltip__country {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.tooltip__scores {
  display: flex;
  gap: 0;
  padding: 0.55rem 0.85rem;
}

.tooltip__score {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.tooltip__score:first-child {
  border-right: 1px solid var(--border-subtle);
  padding-right: 0.75rem;
}

.tooltip__score:last-child {
  padding-left: 0.75rem;
}

.tooltip__score-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.tooltip__score-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.tooltip__score-max {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
}

.tooltip__score-tag {
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.tooltip__vote {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.85rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* === Footer === */
.footer {
  text-align: center;
  padding-top: 0.5rem;
}

.footer__source {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.footer__note {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

/* === Alignment Button === */
.alignment-btn {
  width: 100%;
  font-family: var(--font-main);
  font-size: 0.8rem;
  font-weight: 500;
  height: var(--control-btn-height);
  padding: 0 1rem;
  border-radius: 10px;
  border: 1.5px solid rgba(251, 146, 60, 0.3);
  background: rgba(251, 146, 60, 0.08);
  color: #fb923c;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.alignment-btn:hover {
  background: rgba(251, 146, 60, 0.15);
  border-color: rgba(251, 146, 60, 0.5);
}

.alignment-btn--active {
  background: rgba(251, 146, 60, 0.2);
  border-color: rgba(251, 146, 60, 0.6);
  color: #fdba74;
}

/* === Alignment Bar Chart === */
.alignment-wrapper {
  background: var(--bg-secondary);
  border-radius: 16px;
  border: 1px solid var(--border-subtle);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.alignment-wrapper__title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.15rem;
}

.alignment-wrapper__subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.alignment-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.hull-overlay {
  pointer-events: none;
}

/* === Responsive === */
@media (max-width: 600px) {
  .container {
    padding: 1.25rem 1rem;
  }

  .header__title {
    font-size: 1.3rem;
  }

  .header__subtitle {
    font-size: 0.85rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .controls-btns {
    justify-content: flex-end;
    gap: 0.65rem;
  }

  .controls-btns__stack {
    flex: 1;
    min-width: 0;
  }

  .controls-btns__stack--secondary {
    margin-left: 0;
  }

  .chart-wrapper {
    flex-direction: column;
    padding: 0.5rem;
    border-radius: 12px;
  }

  .axis-panel {
    width: 100%;
  }

  .quadrant-panel {
    width: 100%;
  }

  .quadrant-label {
    font-size: 10px;
  }

  .alignment-wrapper {
    padding: 0.75rem;
    border-radius: 12px;
  }
}
