@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400&family=EB+Garamond:wght@700&display=swap');

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

:root {
  --black:  #000;
  --white:  #fff;
  --rule:   #ccc;
  --muted:  #666;
  --light:  #f5f5f5;
  --serif:  'EB Garamond', Georgia, 'Times New Roman', serif;
  --mono:   'Courier New', Courier, monospace;
  --max:    860px;
  --gutter: clamp(1.5rem, 5vw, 3rem);
}

html { font-size: 18px; }
body {
  font-family: var(--serif);
  background: var(--white);
  color: var(--black);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ── layout ── */
.page { max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }

header {
  border-bottom: 1px solid var(--black);
  padding: 2.5rem 0 1.25rem;
  margin-bottom: 3rem;
}
header h1 { font-size: 1.55rem; font-weight: 600; letter-spacing: .02em; }
header h1 a { color: inherit; text-decoration: none; }
header p  { font-size: .9rem; color: var(--muted); margin-top: .3rem; }

footer {
  border-top: 1px solid var(--rule);
  padding: 2rem 0;
  margin-top: 5rem;
  font-size: .8rem;
  color: var(--muted);
}

/* ── nav breadcrumb ── */
.breadcrumb { font-size: .85rem; margin-bottom: 2.5rem; color: var(--muted); }
.breadcrumb a { color: var(--black); text-decoration: underline; }

/* ── search ── */
.search-wrap { margin-bottom: 2.5rem; }
.search-wrap input {
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--black);
  padding: .55rem .8rem;
  font-family: var(--serif);
  font-size: 1rem;
  background: var(--white);
  outline: none;
}
.search-wrap input:focus { box-shadow: 0 0 0 2px var(--black); }

/* ── country index list ── */
.filter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .8rem;
  margin-bottom: 2rem;
}
.filter-controls button {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--serif);
  font-size: .82rem;
  letter-spacing: .05em;
  color: var(--muted);
  cursor: pointer;
  text-transform: uppercase;
}
.filter-controls button:hover { color: var(--black); }
.filter-controls button.active {
  color: var(--black);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.country-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .05rem 0;
}
.country-grid a {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .28rem 0;
  color: var(--black);
  text-decoration: none;
  font-size: .95rem;
}
.country-grid a:hover { text-decoration: underline; }
img.flag     { border-radius: 2px; flex-shrink: 0; }
img.flag-lg  { border-radius: 3px; display: block; }

/* ── country page ── */
.country-name {
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.2;
  margin-bottom: .5rem;
}
.country-meta {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 3rem;
}

/* category nav */
.cat-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.2rem;
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1rem;
}
.cat-nav a {
  font-size: .82rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}
.cat-nav a:hover, .cat-nav a.active { color: var(--black); border-bottom: 1px solid var(--black); }

/* sections */
.data-section { margin-bottom: 2.5rem; }
.data-section h2 {
  font-size: .72rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  padding-bottom: .35rem;
  margin-bottom: .9rem;
}

/* data table */
.data-table { width: 100%; border-collapse: collapse; }
.data-table tr { border-bottom: 1px solid var(--rule); }
.data-table tr:last-child { border-bottom: none; }
.data-table td {
  padding: .42rem 0;
  vertical-align: baseline;
}
.data-table td:first-child {
  width: 36%;
  padding-right: 1.2rem;
  font-size: .83rem;
  color: var(--muted);
  line-height: 1.4;
}
.data-table .val {
  font-size: .93rem;
  font-weight: 500;
  line-height: 1.35;
}
.data-table .val .unit {
  font-weight: 400;
  font-size: .78rem;
  color: var(--muted);
  margin-left: .25rem;
}
.data-table .provenance {
  font-size: .7rem;
  color: var(--muted);
  margin-top: .15rem;
  font-style: italic;
  line-height: 1.35;
}
.data-table .provenance a {
  color: var(--muted);
  text-decoration: underline;
}
.data-table .provenance a:hover { color: var(--black); }

/* api hint */
.api-hint {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  background: var(--light);
  border: 1px solid var(--rule);
  padding: .15rem .45rem;
  border-radius: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  display: inline-block;
}

/* loading / state */
.loading { color: var(--muted); font-style: italic; padding: 3rem 0; }
.error-msg { color: var(--black); border-left: 3px solid var(--black); padding-left: 1rem; }

/* stats bar on index */
.stats-bar {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 1.2rem;
}

/* api-hint inside table rows is smaller */
.data-table .api-hint {
  font-size: .65rem;
  padding: .1rem .35rem;
  margin-top: .15rem;
}

/* compare link on metric labels */
.compare-link {
  color: var(--muted);
  text-decoration: none;
}
.compare-link:hover {
  color: var(--black);
  text-decoration: underline;
}

/* compare page */
.compare-field-name {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.2;
  margin-bottom: .4rem;
}
.compare-field-meta {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 2rem;
}
.compare-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.compare-table thead th {
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--black);
  padding: .4rem 0;
  padding-right: 1rem;
  text-align: left;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.compare-table thead th:hover { color: var(--black); }
.compare-table thead th.sort-asc::after  { content: ' ↑'; font-style: normal; }
.compare-table thead th.sort-desc::after { content: ' ↓'; font-style: normal; }
.compare-table tbody tr { border-bottom: 1px solid var(--rule); }
.compare-table tbody tr:last-child { border-bottom: none; }
.compare-table tbody td {
  padding: .38rem 0;
  padding-right: 1rem;
  font-size: .9rem;
  vertical-align: baseline;
}
.col-rank    { width: 3rem; color: var(--muted); font-size: .78rem !important; }
.col-country a { display: inline-flex; align-items: center; gap: .65rem; color: var(--black); text-decoration: none; }
.col-country a:hover { text-decoration: underline; }
.col-value   { font-weight: 500; }
.col-year    { color: var(--muted); font-size: .78rem !important; }

/* download button */
.dl-btn {
  display: inline-block;
  background: none;
  border: 1px solid var(--rule);
  padding: .2rem .55rem;
  font-family: var(--serif);
  font-size: .75rem;
  color: var(--muted);
  cursor: pointer;
  letter-spacing: .03em;
  vertical-align: middle;
}
.dl-btn:hover { border-color: var(--black); color: var(--black); }

/* metrics page */
.metrics-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.2rem;
  margin-bottom: 2rem;
}
.metrics-nav a {
  font-size: .82rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
}
.metrics-nav a:hover { color: var(--black); }

/* responsive */
@media (max-width: 540px) {
  .data-table td:first-child { width: 45%; }
  .country-grid { grid-template-columns: repeat(2, 1fr); }
  .col-year { display: none; }
}
