/* ── Country profile pages (countries/{iso2}.html) ─────────────────────────── */

.cp-page {
  display: grid;
  grid-template-columns: 1fr 1.7fr;
  max-width: 1360px;
  margin: 0 auto;
  padding: 52px 48px 96px;
  gap: 0 52px;
  align-items: start;
}

.cp-left { min-width: 0; }

.cp-right {
  position: sticky;
  top: calc(var(--nav-h, 64px) + 20px);
  align-self: start;
}

/* ── Country map ─────────────────────────────────────────────────────────── */
.cp-map {
  height: clamp(420px, calc(100vh - var(--nav-h, 64px) - 80px), 920px);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--rule);
  background: var(--bg);
  /* Contain Leaflet's internal z-indexes (panes/controls reach ~1000) in their
     own stacking context so they can't paint over the nav menu/overlays. */
  isolation: isolate;
}

@media (max-width: 860px) {
  .cp-page {
    grid-template-columns: 1fr;
    padding: 36px 24px 64px;
  }
  .cp-right { position: static; }
  .cp-map { height: 260px; border-radius: 10px; }
}

/* Leaflet attribution in theme */
.cp-map .leaflet-control-attribution {
  font-size: 10px;
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  color: var(--ink-faint);
}
.cp-map .leaflet-control-attribution a { color: var(--ink-soft); }

/* breadcrumb */
.cp-breadcrumb {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cp-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}
.cp-breadcrumb a:hover { text-decoration: underline; }

/* hero */
.cp-hero {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-bottom: 40px;
}
.cp-flag-img {
  width: 56px;
  height: 40px;
  object-fit: cover;
  border-radius: 5px;
  flex-shrink: 0;
  display: block;
}
.cp-title {
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.05;
  color: var(--ink);
  margin: 0 0 6px;
}
.cp-subtitle {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0;
}

/* facts grid */
.cp-facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 48px;
}
.cp-fact {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cp-fact-l {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.cp-fact-v {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* diplomatic / status note */
.cp-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ink-faint);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 28px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
}
.cp-note-icon {
  flex-shrink: 0;
  margin-top: 1px;
  opacity: 0.5;
}

/* languages section */
.cp-section { margin-bottom: 48px; }
.cp-section-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 20px;
}

.cp-langs {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cp-lang-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 20px 22px;
}
.cp-lang-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.cp-lang-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.cp-lang-native {
  font-size: 14px;
  color: var(--ink-soft);
}
.cp-lang-family {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-left: auto;
}

.cp-phrases {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px 16px;
  margin: 0;
}
.cp-phrase-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cp-phrase-row dt {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.cp-phrase-row dd {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

/* ── Interactive phrasebook (phrases + audio playback) ─────────────────────── */
.cp-phrasebook .cp-pb-head {
  display: flex;
  align-items: center;
  gap: 8px 18px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.cp-pb-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0;
  flex-wrap: wrap;
}
.cp-pb-meta-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.cp-pb-meta-native { font-size: 14px; color: var(--ink-soft); }
.cp-pb-meta-family {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.cp-phrasebook .cp-pb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.cp-phrasebook .cp-pb-langtabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 0;
  padding: 4px;
  background: var(--bg-warm, var(--bg));
  border: 1px solid var(--rule);
  border-radius: 999px;
}
.cp-pb-tab {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.cp-pb-tab:hover { color: var(--ink); border-color: var(--ink-faint); }
.cp-pb-tab.is-active {
  color: #fff;
  background: var(--accent, #e8634a);
  border-color: var(--accent, #e8634a);
}
.cp-pb-cattabs .cp-pb-tab { font-size: 12px; }

/* Language chooser: a segmented pill-group, visually distinct from the
   accent-filled category tabs above the phrase list. */
.cp-pb-langtabs .cp-pb-tab {
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  padding: 6px 16px;
}
.cp-pb-langtabs .cp-pb-tab:hover {
  color: var(--ink);
  border-color: transparent;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
.cp-pb-langtabs .cp-pb-tab.is-active {
  color: var(--ink);
  background: var(--paper);
  border-color: transparent;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

.cp-pb-panels {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 6px 8px;
}
.cp-pb-panel { display: none; }
.cp-pb-panel.is-active { display: block; }

.cp-pb-list { list-style: none; margin: 0; padding: 0; }
.cp-pb-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 12px;
  border-radius: 10px;
}
.cp-pb-row + .cp-pb-row { border-top: 1px solid var(--rule); }
.cp-pb-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  flex: 0 0 100px;
}
.cp-pb-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  flex: 1 1 auto;
  min-width: 0;
}
.cp-pb-play {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent, #e8634a);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.85;
  transition: transform 0.12s, opacity 0.15s;
}
.cp-pb-play:hover { opacity: 1; transform: scale(1.08); }
.cp-pb-play.is-playing { animation: cpPbPulse 1.2s ease-out infinite; }
@keyframes cpPbPulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #e8634a) 55%, transparent); }
  70%  { box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent, #e8634a) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #e8634a) 0%, transparent); }
}
.cp-pb-empty {
  list-style: none;
  padding: 16px 12px;
  color: var(--ink-faint);
  font-size: 14px;
}
@media (max-width: 640px) {
  .cp-pb-label { flex-basis: 74px; }
  .cp-pb-text { font-size: 15px; }
}

/* ── Lead sentence ─────────────────────────────────────────────────────────── */
.cp-lead {
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: 0 0 28px;
  max-width: 62ch;
}

/* GDP income-tier sub-label inside a fact value */
.cp-fact-sub {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin-top: 2px;
}

/* ── Trend sparklines (population / life expectancy) ───────────────────────── */
.cp-trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.cp-trend {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 16px 18px;
}
.cp-trend-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.cp-trend-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.cp-trend-now {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.cp-spark {
  display: block;
  width: 100%;
  height: 46px;
  overflow: visible;
}

/* Interactive mini charts (population / life expectancy) */
.cp-chart { position: relative; width: 100%; margin: 2px 0 2px; }
.cp-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  touch-action: pan-y;
}
.cp-chart-line {
  fill: none;
  stroke: var(--accent, #e8634a);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.cp-chart-dot { fill: var(--accent, #e8634a); }
.cp-chart-grid { stroke: var(--rule); stroke-width: 1; }
.cp-chart-axis {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  fill: var(--ink-faint);
}
.cp-chart-hoverline {
  stroke: var(--ink-faint);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0;
  transition: opacity 0.1s;
}
.cp-chart-hoverdot {
  fill: var(--accent, #e8634a);
  stroke: var(--paper);
  stroke-width: 2;
  opacity: 0;
  transition: opacity 0.1s;
}
.cp-chart-tip {
  position: absolute;
  transform: translate(-50%, -145%);
  background: var(--ink);
  color: var(--paper);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.2;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
  transition: opacity 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 3;
}
.cp-chart-tip b { font-weight: 800; }
.cp-chart-tip span { font-size: 10px; opacity: 0.75; }
.cp-trend-cap {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
}

/* ── Bordering countries ───────────────────────────────────────────────────── */
.cp-nb-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cp-nb {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.cp-nb:hover { border-color: var(--accent, #e8634a); background: var(--bg-warm, var(--paper)); }
.cp-nb-flag { border-radius: 2px; display: block; }

/* ── FAQ ───────────────────────────────────────────────────────────────────── */
.cp-faq-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cp-faq-item {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0 16px;
}
.cp-faq-q {
  cursor: pointer;
  list-style: none;
  padding: 14px 24px 14px 0;
  position: relative;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.cp-faq-q::-webkit-details-marker { display: none; }
.cp-faq-q::after {
  content: '';
  position: absolute;
  right: 4px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--ink-faint);
  border-bottom: 2px solid var(--ink-faint);
  transform: translateY(-70%) rotate(45deg);
  transition: transform 0.15s;
}
.cp-faq-item[open] .cp-faq-q::after { transform: translateY(-30%) rotate(-135deg); }
.cp-faq-a {
  margin: 0;
  padding: 0 0 16px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-soft);
}

/* ── Thematic map deep-links ───────────────────────────────────────────────── */
.cp-maplinks {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 40px;
}
.cp-maplinks-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 2px;
}
.cp-maplink {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 5px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.cp-maplink:hover {
  color: #fff;
  background: var(--accent, #e8634a);
  border-color: var(--accent, #e8634a);
}

/* CTA */
.cp-cta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .cp-facts { grid-template-columns: repeat(2, 1fr); }
}

html[data-theme="dark"] .leaflet-bar a,
html[data-theme="dark"] .leaflet-control-zoom a {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--rule);
}
html[data-theme="dark"] .leaflet-bar a:hover {
  background: var(--bg-warm);
}
html[data-theme="dark"] .leaflet-control-attribution {
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  color: var(--ink-soft);
}
html[data-theme="dark"] .leaflet-control-attribution a {
  color: var(--ink-soft);
}
