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

:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e0ddd8;
  --accent: #c8553d;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --chart-bg: #141414;
  --chart-text: #808080;
  --chart-grid: rgba(255,255,255,0.07);
}

/* Ensure hidden attribute works even when element has an explicit display rule */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 20px 56px;
}

/* Header */
header { margin-bottom: 32px; }

h1 {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin-bottom: 0;
}

h1::after {
  content: '';
  display: block;
  width: 48px;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  margin-top: 16px;
}

.subtitle {
  color: var(--muted);
  max-width: 660px;
  font-size: 1rem;
  line-height: 1.65;
  margin-top: 16px;
}

/* Controls */
#controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

#play-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 7px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
#play-btn:hover { opacity: 0.85; }
#play-btn:disabled { opacity: 0.4; cursor: default; }

#slider-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

#year-label {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  color: var(--accent);
}

#year-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

#search-wrap {
  position: relative;
  flex-shrink: 0;
}

#country-search {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px 6px 28px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 8px center;
  width: 180px;
  outline: none;
  transition: border-color 0.15s;
}
#country-search:focus { border-color: var(--accent); }
#country-search::placeholder { color: #aaa; }

/* Pin controls */
#pin-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

#trajectory-btn {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 7px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#trajectory-btn:hover {
  background: var(--accent);
  color: #fff;
}

#reset-btn {
  background: none;
  color: var(--muted);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#reset-btn:hover { border-color: var(--text); color: var(--text); }

/* Legend */
#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  padding: 4px 10px 4px 6px;
  border-radius: 20px;
  border: 1.5px solid transparent;
  transition: border-color 0.15s, opacity 0.15s;
  font-size: 0.85rem;
  user-select: none;
}
.legend-item.inactive { opacity: 0.3; }
.legend-item.active { border-color: currentColor; }

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Chart */
#chart-wrap {
  position: relative;
  background: var(--chart-bg);
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  overflow: hidden;
}

#chart { display: block; width: 100%; }

/* Axis text/lines scoped to main chart (dark background) */
#chart .axis-label { font-size: 11px; fill: var(--chart-text); }
#chart .tick line  { stroke: var(--chart-grid); }
#chart .tick text  { font-size: 11px; fill: var(--chart-text); }
#chart .domain     { display: none; }

.bubble {
  stroke-width: 1;
  cursor: pointer;
  transition: stroke-width 0.1s;
}
.bubble:hover  { stroke-width: 2.5; }
.bubble.pinned { stroke-width: 2.5; }

.trace-line {
  fill: none;
  stroke-width: 1.5;
  opacity: 0.65;
  pointer-events: none;
}

/* Tooltip — light on dark chart */
#tooltip {
  position: absolute;
  background: rgba(255,255,255,0.95);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 13px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  line-height: 1.6;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  max-width: 220px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
#tooltip.visible { opacity: 1; }
#tooltip strong { font-size: 0.9rem; display: block; margin-bottom: 2px; }

/* Detail panel */
#detail-panel {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px 24px;
}

#detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

#detail-country-name {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
}

#detail-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
#detail-close:hover { background: var(--bg); }

#detail-charts h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

/* Detail chart uses light background — keep its tick styles separate */
#detail-svg { display: block; width: 100%; }
#detail-svg .tick line  { stroke: #e8e5e0; }
#detail-svg .tick text  { font-size: 11px; fill: var(--muted); }
#detail-svg .domain     { display: none; }

/* Footer */
footer {
  margin-top: 32px;
  font-size: 0.78rem;
  color: var(--muted);
}
footer a { color: var(--muted); }
footer a:hover { color: var(--text); }
