/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  background: linear-gradient(135deg, #e3f2fd 0%, #e8f5e8 100%);
  line-height: 1.6;
  color: #333;
}

/* Main container with vertical grid */
.container {
  height: 100vh;
  display: grid;
  grid-template-rows: 3fr 12fr 1fr;
  max-width: 100vw;
}

.paper {
  display: grid;
  grid-template-rows: subgrid;
  grid-row: 1 / -1;
  padding: 1.5rem;
}

/* Header section */
.header-section {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Combined header and controls grid */
.header-controls-grid {
  display: grid;
  grid-template-columns: 2fr 1.35fr 1.35fr 1fr;
  grid-template-rows: auto auto;
  gap: 2rem;
  align-items: start;
  padding: 0.6rem 0;
  position: relative;
}

/* Grid positioning */
.title-section {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
}

.intro-column-1 {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
}

.intro-column-2 {
  grid-column: 3;
  grid-row: 1;
  align-self: start;
}

.gap-column {
  grid-column: 4;
  grid-row: 1;
}

.legend-container {
  position: absolute;
  top: 0;
  right: 0;
  width: calc((1fr / (2fr + 1.35fr + 1.35fr + 0.5fr + 1fr)) * 100%);
  min-width: 180px;
  max-width: 220px;
  align-self: start;
  z-index: 10;
}

.chip-group {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-self: center;
}

.range-slider-container .range-slider-gdp {
  grid-column: 2;
  grid-row: 2;
  align-self: center;
}

.range-slider-container .range-slider-population {
  grid-column: 3;
  grid-row: 2;
  align-self: center;
}

.gap-column-2 {
  grid-column: 4;
  grid-row: 2;
}

/* Typography */
.title {
  margin: 0 0 0.5rem 0;
  font-size: 4.25rem;
  font-weight: 700;
  line-height: 94%;
  color: #212529;
  letter-spacing: -0.025em;
}

.intro-column-1 p,
.intro-column-2 p {
  font-size: 0.9rem;
  line-height: 1.4;
  color: #495057;
  margin: 0;
  text-align: left;
  hyphens: auto;
  padding-top: 0.5rem;
}

/* Legend styling */
.legend-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

.legend-header {
  font-size: 1rem;
  font-weight: 700;
  font-style: italic;
  color: #212529;
  margin: 0;
}

.legend-subheader {
  font-size: 0.75rem;
  font-style: italic;
  color: #495057;
  margin: 0;
  line-height: 1.3;
}

.legend-image {
  max-width: 80%;
  height: auto;
  margin-top: 0.25rem;
}

/* Continent buttons */
.continent-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.continent-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 1rem;
  border: 1px solid #ced4da;
  border-radius: 2rem;
  background: rgba(255, 255, 255, 0.8);
  color: #495057;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s ease;
  outline: none;
  min-height: 2.25rem;
  backdrop-filter: blur(10px);
}

.continent-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: #adb5bd;
}

.continent-btn.active {
  background-color: #54927c;
  border-color: #54927c;
  color: white;
  box-shadow: 0 2px 8px rgba(84, 146, 124, 0.3);
}

.continent-btn:focus {
  box-shadow: 0 0 0 2px rgba(84, 146, 124, 0.25);
}

/* Range slider styles */
.range-slider-container {
  display: flex;
  flex-direction: column;
  min-width: 200px;
  align-items: center;
  padding: 0 0.5rem;
}

.range-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #495057;
  text-align: center;
}

.range-slider-wrapper {
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
  width: 100%;
}

.range-track-base {
  position: absolute;
  width: 100%;
  height: 4px;
  background: #b9d7cd;
  border-radius: 2px;
  pointer-events: none;
  z-index: 1;
}

.range-track {
  position: absolute;
  height: 4px;
  background: #54927c;
  border-radius: 2px;
  pointer-events: none;
  transition: all 0.2s ease;
  opacity: 0.9;
  z-index: 2;
}

.range-slider {
  position: absolute;
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  pointer-events: none;
  outline: none;
  z-index: 3;
}

/* WebKit slider */
.range-slider::-webkit-slider-track {
  width: 100%;
  height: 4px;
  background: transparent;
  border-radius: 2px;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: #54927c;
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.15s ease;
}

.range-slider::-webkit-slider-thumb:hover {
  background: #4a7f6b;
  transform: scale(1.1);
}

.range-slider::-webkit-slider-thumb:active {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Firefox slider */
.range-slider::-moz-range-track {
  width: 100%;
  height: 4px;
  background: transparent;
  border-radius: 2px;
  border: none;
}

.range-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: #54927c;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.15s ease;
}

.range-slider::-moz-range-thumb:hover {
  background: #4a7f6b;
  transform: scale(1.1);
}

.range-slider::-moz-range-thumb:active {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.range-values {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #6c757d;
  font-weight: 500;
  width: 100%;
}

/* Chart container */
.chart-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

/* D3 Chart styles */
.axis text {
  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  font-size: 12px;
  fill: #495057;
}

.axis-label {
  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  font-size: 14px;
  font-weight: 600;
  fill: #343a40;
}

.axis path,
.axis line {
  fill: none;
  stroke: #dee2e6;
  stroke-width: 1;
  shape-rendering: crispEdges;
}

/* Chart elements */
.country-label {
  user-select: none;
}

.flower {
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.flower.selected {
  filter: drop-shadow(0 0 8px rgba(84, 146, 124, 0.5));
}

/* Footer */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 12px;
  color: #666;
}

.footer-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-label {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-links a {
  color: #242b35;
  text-decoration: none;
  transition: color 0.2s ease;
  white-space: nowrap;
}

.footer-links a:hover {
  color: #4c61ff;
}

.footer-separator {
  color: #adb5bd;
  margin: 0 4px;
}

.author-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.author-link {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
  color: #666;
  text-decoration: none;
  transition: all 0.2s ease;
  backdrop-filter: blur(5px);
}

.author-link:hover {
  background: #54927c;
  color: white !important;
}

.author-link svg {
  width: 12px;
  height: 12px;
}

/* Responsive design */
@media (max-width: 1024px) {
  .header-controls-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(6, auto);
    gap: 1rem;
  }

  .title-section,
  .intro-column-1,
  .intro-column-2,
  .legend-container,
  .chip-group,
  .range-slider-gdp,
  .range-slider-population {
    grid-column: 1;
    grid-row: auto;
  }

  .gap-column,
  .gap-column-2 {
    display: none;
  }

  .range-slider-container {
    min-width: 100%;
  }
}

@media (max-width: 768px) {
  .paper {
    padding: 1rem;
  }

  .title {
    font-size: 1.75rem;
  }

  .header-controls-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1rem 0;
    padding: 1rem 0;
  }

  .intro-column-1 p,
  .intro-column-2 p {
    font-size: 0.95rem;
  }

  .chip-group {
    gap: 0.25rem;
    flex-direction: column;
  }

  .continent-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
  }

  .range-slider-container {
    min-width: 100%;
  }

  .legend-container {
    grid-column: 1;
    margin-top: 1rem;
  }

  .footer {
    flex-direction: column;
    gap: 8px;
    padding: 8px 1rem;
    text-align: center;
  }

  .footer-section {
    justify-content: center;
    flex-wrap: wrap;
  }

  .author-links {
    justify-content: center;
  }
}
