/* -------------------------------------------------
   Shared project styles
   - Homepage uses Tailwind for layout and surface styling
   - This file keeps custom D3, table, tooltip, loading, and country-page rules
-------------------------------------------------- */

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

html {
  scroll-behavior: smooth;
}

body,
h1,
h2,
h3,
p,
ul,
ol {
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

a {
  color: #2563eb;
}

:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 48px;
  --space-10: 64px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --shadow-sm: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 16px 42px rgba(15, 23, 42, 0.09);

  --text: #152033;
  --text-mid: #425067;
  --text-dim: #6a778d;
  --surface: #ffffff;
  --surface-muted: #eef3f8;
  --row-stripe: #f8fbff;
  --row-hover: #edf4ff;
  --row-selected: #dfeaff;
  --border: #d7e0ea;
  --border-strong: #b7c4d4;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #ba2d2d;
  --danger-soft: #fff1f1;
  --map-bg: #dbe8f5;
  --sticky-offset: 56px;
}

/* Loading */

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  background: rgba(247, 250, 255, 0.98);
  transition: opacity 0.3s ease;
}

.loading-screen.done {
  opacity: 0;
  pointer-events: none;
}

.loading-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.loading-bar-wrap {
  width: 176px;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.loading-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #5ea2ff);
  animation: loading-sweep 1s ease-in-out infinite;
}

@keyframes loading-sweep {
  0% {
    width: 0;
    margin-left: 0;
  }

  50% {
    width: 52%;
    margin-left: 24%;
  }

  100% {
    width: 0;
    margin-left: 100%;
  }
}

.loading-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Map */

#world-map {
  display: block;
  width: 100%;
  height: 100%;
}

.tt-grid-olympiads {
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

.map-value-layer {
  pointer-events: none;
}

.map-value-label {
  fill: #0f172a;
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", "Roboto Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.02em;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 3px;
  stroke-linejoin: round;
  text-anchor: middle;
}

.map-page .map-page-wrap {
  height: clamp(520px, 68vh, 820px);
}

@media (min-width: 768px) {
  .map-page .map-page-wrap {
    height: clamp(620px, 74vh, 980px);
  }
}

@media (min-width: 1024px) {
  .map-page .map-page-wrap {
    height: clamp(720px, 78vh, 1100px);
  }
}

.sphere-fill {
  fill: var(--map-bg);
}

.sphere-stroke {
  fill: none;
  stroke: #b5cade;
  stroke-width: 0.8px;
}

.graticule {
  fill: none;
  stroke: rgba(74, 112, 152, 0.08);
  stroke-width: 0.25px;
}

.country {
  cursor: pointer;
  stroke: rgba(51, 65, 85, 0.68);
  stroke-width: var(--country-stroke-width, 0.9px);
  vector-effect: non-scaling-stroke;
  transition: stroke 0.12s ease, stroke-width 0.12s ease, filter 0.12s ease;
}

.country:hover {
  stroke: #0f172a;
  stroke-width: var(--country-hover-stroke-width, 1.45px);
  filter: brightness(1.03);
}

.country.no-data {
  fill: #c9d3de;
}

.region-map-active .country {
  stroke: rgba(15, 23, 42, 0.82);
  stroke-width: max(var(--country-stroke-width, 0.9px), 1.3px);
}

.region-map-active .country.no-data {
  fill: #d7e0ea;
  stroke: rgba(15, 23, 42, 0.72);
  stroke-dasharray: 3 2;
}

.country.selected {
  stroke: var(--accent);
  stroke-width: 2.25px;
}

.zoom-btn:active {
  transform: translateY(1px) scale(0.98);
}

.legend-bar {
  width: 100%;
  height: 10px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 999px;
  background: linear-gradient(
    to right,
    #8b1a1a 0%,
    #c0392b 12%,
    #d35400 26%,
    #e67e22 38%,
    #f0b429 50%,
    #c8d800 56%,
    #52b788 68%,
    #27ae60 80%,
    #0d7a42 100%
  );
}

/* Tooltip */

#tooltip {
  position: fixed;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

#tooltip.visible {
  opacity: 1;
  pointer-events: auto;
}

.tt-card {
  min-width: 172px;
  max-width: 210px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.07),
    0 10px 28px -4px rgba(0, 0, 0, 0.14);
  overflow: hidden;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.tt-accent-bar {
  height: 3px;
  background: linear-gradient(90deg, #3b82f6 0%, #6366f1 100%);
}

.tt-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px 9px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
}

.tt-flag {
  font-size: 1.45rem;
  line-height: 1;
  flex-shrink: 0;
}

.tt-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.25;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tt-metrics {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  align-items: stretch;
  padding: 10px 13px 11px;
  gap: 0;
}

.tt-metric {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tt-metric:last-child {
  padding-left: 12px;
}

.tt-metric-sep {
  width: 1px;
  background: rgba(226, 232, 240, 0.9);
  margin: 2px 0;
}

.tt-metric-label {
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #94a3b8;
}

.tt-metric-value {
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", "Roboto Mono", Consolas, monospace;
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
  color: #0f172a;
  transition: color 0.12s ease;
}

.tt-metric-value.dimmed {
  color: #94a3b8;
  font-weight: 500;
  font-size: 1.1rem;
}

/* Table */

.table-wrap {
  -webkit-overflow-scrolling: touch;
}

#data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: separate;
  border-spacing: 0;
}

#data-table thead th {
  /* Keep the first data row visible instead of hiding it under a sticky header. */
  position: static;
  z-index: 20;
  padding: 0;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
}

#data-table thead th:first-child {
  border-top-left-radius: var(--radius-lg);
}

#data-table thead th:last-child {
  border-top-right-radius: var(--radius-lg);
}

.th-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.th-button-static {
  cursor: default;
}

.th-button:hover {
  background: rgba(20, 89, 182, 0.04);
}

.th-button-static:hover,
.th-button-static:active {
  background: transparent;
}

.th-button:active {
  background: rgba(20, 89, 182, 0.08);
}

#data-table thead th:hover .th-main,
#data-table thead th:hover .sort-icon {
  color: var(--accent);
}

#data-table thead th.sorted .th-main,
#data-table thead th.sorted .sort-icon {
  color: var(--text);
  opacity: 1;
}

#data-table tbody tr {
  cursor: pointer;
  background: var(--surface);
  transition: background-color 0.12s ease;
}

#data-table tbody tr:nth-child(even) {
  background: var(--row-stripe);
}

#data-table tbody tr:hover {
  background: var(--row-hover);
}

#data-table tbody tr.row-selected {
  background: var(--row-selected) !important;
}

#data-table td {
  padding: 14px 18px;
  vertical-align: middle;
  border-bottom: 1px solid rgba(215, 224, 234, 0.72);
}

#data-table tbody tr:last-child td {
  border-bottom: 0;
}

.col-right,
.td-rank,
.td-num,
.td-iq,
.td-na {
  text-align: right;
}

.td-rank,
.td-num,
.td-iq,
.td-na {
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", "Roboto Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.td-rank {
  width: 44px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.td-country {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.td-flag {
  flex-shrink: 0;
  font-size: 1.05rem;
  line-height: 1;
}

.td-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-weight: 600;
  text-overflow: ellipsis;
}

.country-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  margin-left: auto;
  border-radius: 999px;
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.country-link:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.td-num,
.td-iq {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.td-na {
  color: var(--text-dim);
  font-size: 0.88rem;
  white-space: nowrap;
}

.iq-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: var(--space-2);
  vertical-align: middle;
  border-radius: 50%;
}

/* Shared focus states */

.th-button:focus-visible,
.zoom-btn:focus-visible,
.country-link:focus-visible,
.tt-link:focus-visible,
.compare-page button:focus-visible,
.compare-page a:focus-visible,
.compare-page input:focus-visible,
.sim-page button:focus-visible,
.sim-page a:focus-visible,
.sim-page input:focus-visible,
.sim-page select:focus-visible,
.country-page .lang-btn:focus-visible,
.country-page .back-link:focus-visible {
  outline: 3px solid rgba(20, 89, 182, 0.18);
  outline-offset: 2px;
}

/* Compare page */

.compare-grid line {
  stroke: #e5edf6;
}

.compare-grid text,
.compare-axis text {
  fill: var(--text-dim);
  font-size: 11px;
}

.compare-axis line,
.compare-axis path {
  stroke: #d0d5dd;
}

.compare-hover-dot {
  cursor: pointer;
}

.compare-band-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.compare-band-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(208, 213, 221, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 700;
}

.compare-band-chip-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.compare-band-rect {
  pointer-events: none;
}

.compare-band-label {
  fill: #475467;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.compare-rolling-line {
  stroke-dasharray: 10 6;
}

.compare-series-dot {
  stroke: #fff;
  stroke-width: 2px;
  pointer-events: none;
}

.compare-line-label {
  font-size: 12px;
  font-weight: 700;
}

.compare-tooltip {
  position: fixed;
  z-index: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.compare-tooltip.visible {
  opacity: 1;
}

.compare-tooltip-inner {
  min-width: 168px;
  max-width: 240px;
  padding: 12px 14px;
  border: 1px solid rgba(21, 32, 51, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px);
}

.compare-tooltip-kicker {
  margin-bottom: 4px;
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.compare-tooltip-title {
  margin-bottom: 10px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.compare-tooltip-grid {
  display: grid;
  gap: 6px;
}

.compare-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compare-tooltip-label {
  color: var(--text-dim);
  font-size: 0.78rem;
}

.compare-tooltip-value {
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", "Roboto Mono", Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 700;
}

@media (max-width: 640px) {
  .compare-band-legend {
    justify-content: flex-start;
  }
}

/* Simulator page */

.sim-grid line {
  stroke: #e7eef6;
}

.sim-axis line,
.sim-axis path {
  stroke: #d0d5dd;
}

.sim-axis text {
  fill: var(--text-dim);
  font-size: 11px;
}

.sim-axis-title {
  fill: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#sim-chart-wrap {
  position: relative;
}

#sim-chart {
  width: 100%;
  height: 100%;
}

.sim-reference-line {
  stroke: rgba(148, 163, 184, 0.45);
  stroke-dasharray: 4 4;
}

.sim-reference-label {
  fill: #64748b;
  font-size: 10px;
  font-weight: 800;
}

.sim-area {
  pointer-events: none;
}

.sim-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.sim-hover-capture {
  fill: transparent;
  pointer-events: all;
}

.sim-hover-line {
  stroke: rgba(15, 23, 42, 0.38);
  stroke-dasharray: 5 5;
  stroke-width: 1.5;
}

.sim-hover-point {
  stroke: #fff;
  stroke-width: 2;
}

.sim-hover-tooltip {
  position: absolute;
  z-index: 5;
  width: min(320px, calc(100% - 20px));
  padding: 12px;
  border: 1px solid rgba(203, 213, 225, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.16);
  color: var(--text);
  font-size: 0.78rem;
  pointer-events: none;
}

.sim-hover-title {
  margin-bottom: 10px;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 850;
}

.sim-hover-row + .sim-hover-row,
.sim-hover-compare {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(226, 232, 240, 0.95);
}

.sim-hover-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 800;
}

.sim-hover-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 12px;
}

.sim-hover-grid span {
  color: var(--text-dim);
  font-weight: 700;
}

.sim-hover-grid strong {
  color: var(--text);
  font-weight: 850;
  text-align: right;
}

.sim-hover-compare-title {
  margin-bottom: 8px;
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sim-legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(208, 213, 221, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
}

.sim-primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(37, 99, 235, 0.28);
  border-radius: 10px;
  background: #2563eb;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 800;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.sim-primary-action:hover {
  border-color: rgba(29, 78, 216, 0.5);
  background: #1d4ed8;
}

.sim-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.sim-threshold-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(208, 213, 221, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
}

.sim-zoom-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 96px 96px auto;
  align-items: end;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 16px;
  background: rgba(248, 250, 252, 0.72);
}

.sim-zoom-field span {
  display: block;
  margin-bottom: 8px;
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sim-zoom-field input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(208, 213, 221, 0.95);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
}

.sim-zoom-actions {
  display: flex;
  gap: 8px;
}

.sim-zoom-actions button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(208, 213, 221, 0.95);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.sim-zoom-actions button:hover {
  border-color: rgba(180, 188, 200, 0.95);
  background: rgba(248, 250, 252, 0.96);
}

.sim-summary-card,
.sim-stat-card {
  padding: 12px 14px;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
}

.sim-stat-label {
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sim-stat-value {
  margin-top: 8px;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.sim-stat-value-tight {
  font-size: 1rem;
  line-height: 1.35;
}

.sim-stat-note {
  display: block;
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
}

.sim-stats-table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
}

.sim-stats-table th,
.sim-stats-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.95);
  text-align: left;
  vertical-align: middle;
}

.sim-stats-table th {
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(248, 250, 252, 0.96);
}

.sim-stats-table td {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.sim-stats-name {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.sim-stats-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sim-stats-main {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.2;
}

.sim-stats-sub {
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

.sim-profile-card {
  padding: 16px;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 20px;
  background: rgba(248, 250, 252, 0.82);
}

.sim-profile-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.sim-profile-title-wrap {
  display: flex;
  align-items: start;
  gap: 10px;
  min-width: 0;
}

.sim-profile-title {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sim-profile-name-input {
  width: 100%;
  min-height: 28px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 800;
}

.sim-profile-name-input:hover,
.sim-profile-name-input:focus {
  border-color: rgba(208, 213, 221, 0.95);
  background: rgba(255, 255, 255, 0.96);
  outline: none;
}

.sim-profile-meta {
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 700;
}

.sim-profile-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.sim-profile-input {
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(208, 213, 221, 0.95);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.sim-remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(208, 213, 221, 0.95);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 800;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}

.sim-remove-btn:hover:not(:disabled) {
  border-color: rgba(180, 188, 200, 0.95);
  background: #fff;
  color: var(--text);
}

.sim-remove-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.sim-available-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  text-align: left;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.sim-available-btn:hover {
  border-color: rgba(180, 188, 200, 0.95);
  background: rgba(248, 250, 252, 0.96);
}

.sim-available-plus {
  color: var(--text-dim);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
}

.sim-large-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  width: 100%;
  max-width: 1536px;
  margin: 0 auto;
}

.sim-large-stage,
.sim-large-panel {
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.sim-large-stage {
  min-width: 0;
  padding: 18px;
}

.sim-large-stage-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.sim-large-chart-wrap {
  position: relative;
  height: min(72vh, 820px);
  min-height: 560px;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 14px;
  background: #fff;
}

#sim-large-chart {
  width: 100%;
  height: 100%;
}

.sim-large-panel {
  align-self: start;
  padding: 18px;
  position: sticky;
  top: var(--sticky-offset);
}

.sim-large-panel h2 {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 850;
}

.sim-large-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px 12px;
  margin-top: 14px;
}

.sim-large-field {
  display: block;
  margin-top: 14px;
}

.sim-large-field span,
.sim-large-control span {
  grid-column: span 2;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sim-large-field input[type="text"] {
  width: 100%;
  min-height: 40px;
  margin-top: 8px;
  padding: 0 12px;
  border: 1px solid rgba(208, 213, 221, 0.95);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

.sim-large-control input {
  width: 100%;
}

.sim-large-control strong {
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 850;
  text-align: right;
}

.sim-large-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 750;
}

.sim-large-check input {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.sim-large-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.7);
}

.sim-large-color-row > span {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.sim-large-color-row strong {
  overflow: hidden;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sim-large-color-row input {
  width: 46px;
  height: 34px;
  padding: 3px;
  border: 1px solid rgba(208, 213, 221, 0.95);
  border-radius: 9px;
  background: #fff;
  flex: 0 0 auto;
}

@media (max-width: 980px) {
  .sim-zoom-controls {
    grid-template-columns: 1fr 1fr;
  }

  .sim-zoom-actions {
    grid-column: span 2;
  }

  .sim-profile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sim-large-shell {
    grid-template-columns: 1fr;
  }

  .sim-large-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .sim-zoom-controls,
  .sim-profile-grid {
    grid-template-columns: 1fr;
  }

  .sim-zoom-actions {
    grid-column: auto;
  }

  .sim-large-stage-head {
    align-items: start;
    flex-direction: column;
  }

  .sim-large-chart-wrap {
    height: 68vh;
    min-height: 420px;
  }
}

/* Country page */

.country-page {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: #f8fafc;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.country-page .site-header {
  position: sticky;
  top: 0;
  z-index: 200;
}

.country-page .site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-5) var(--space-6);
  border-top: 1px solid #334155;
  background: #0f172a;
  color: #94a3b8;
  font-size: 0.83rem;
}

.country-shell {
  width: min(100%, 1120px);
  margin-inline: auto;
  padding: var(--space-8) var(--space-6) var(--space-10);
}

.country-hero {
  margin-bottom: var(--space-8);
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin-bottom: var(--space-4);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.country-hero-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--space-6);
  align-items: start;
}

.country-kicker {
  margin-bottom: var(--space-2);
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.country-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  font-size: clamp(2rem, 4vw, 2.35rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.country-flag {
  font-size: 2.2rem;
}

.country-intro {
  max-width: 62ch;
  line-height: 1.65;
  color: var(--text-mid);
}

.country-meta-cards {
  display: grid;
  gap: var(--space-3);
}

.metric-card,
.history-panel,
.history-list-card,
.olympiad-panel {
  border: 1px solid rgba(215, 224, 234, 0.95);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.metric-card {
  padding: var(--space-4);
}

.metric-card-label {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.metric-card-value {
  margin: var(--space-2) 0 var(--space-1);
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", "Roboto Mono", Consolas, monospace;
  font-size: 1.75rem;
  font-weight: 800;
}

.metric-card-sub {
  color: var(--text-dim);
  font-size: 0.82rem;
}

.history-panel,
.history-list-card,
.olympiad-panel {
  padding: var(--space-5);
}

.history-panel {
  margin-bottom: var(--space-6);
}

.history-panel-head,
.olympiad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1e293b;
}

.chart-legend {
  display: inline-flex;
  gap: var(--space-4);
  font-size: 0.78rem;
  font-weight: 800;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend-item::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.chart-legend-pisa::before {
  background: #2563eb;
}

.chart-legend-timss::before {
  background: #c0392b;
}

.chart-wrap {
  height: 360px;
}

#history-chart,
.olympiad-chart-wrap svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-grid line {
  stroke: #e5edf6;
}

.chart-grid text,
.chart-axis text {
  fill: var(--text-dim);
  font-size: 11px;
}

.history-empty,
.olympiad-empty {
  display: none;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.history-tables {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.history-list {
  margin-top: var(--space-3);
}

.history-list-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: var(--space-3);
  padding: 10px 0;
  border-bottom: 1px solid #e6edf5;
}

.history-list-row:last-child {
  border-bottom: 0;
}

.history-list-year,
.history-list-score,
.oly-year,
.oly-rank,
.medal-count {
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", "Roboto Mono", Consolas, monospace;
}

.history-list-label,
.history-list-empty,
.olympiad-note,
.medal-zero {
  color: var(--text-dim);
}

.olympiad-section {
  margin-top: var(--space-8);
}

.olympiad-section-title {
  margin-bottom: var(--space-5);
}

.olympiad-panel {
  margin-bottom: var(--space-6);
}

.olympiad-panel-title {
  font-size: 1rem;
  font-weight: 800;
}

.olympiad-note {
  font-size: 0.82rem;
  font-style: italic;
}

.olympiad-chart-wrap {
  height: 260px;
  margin-bottom: var(--space-4);
}

.olympiad-table-wrap {
  overflow-x: auto;
}

.olympiad-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.olympiad-table thead th {
  position: static;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  text-align: left;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.olympiad-table tbody tr {
  border-bottom: 1px solid #e6edf5;
}

.olympiad-table tbody tr:last-child {
  border-bottom: 0;
}

.olympiad-table td {
  padding: 8px 10px;
}

.oly-year {
  color: var(--text-dim);
}

.oly-rank {
  font-size: 0.95rem;
  font-weight: 800;
}

.medal-col,
.oly-medal {
  text-align: center;
}

.medal-count {
  display: inline-block;
  min-width: 24px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.medal-gold {
  color: #92400e;
  background: #fef3c7;
}

.medal-silver {
  color: #475569;
  background: #f1f5f9;
}

.medal-bronze {
  color: #7c3a1a;
  background: #fef0e6;
}

.medal-zero {
  font-size: 0.82rem;
}

/* Responsive */

@media (max-width: 960px) {
  .country-page .site-header,
  .country-page .site-footer,
  .country-shell {
    padding-inline: var(--space-5);
  }

  .country-hero-head,
  .history-tables {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .history-panel-head {
    align-items: stretch;
  }
}

@media (max-width: 540px) {
  .country-page .site-header,
  .country-page .site-footer,
  .country-shell {
    padding-inline: var(--space-4);
  }

  .history-panel,
  .history-list-card,
  .olympiad-panel {
    padding: var(--space-4);
  }

  .chart-wrap {
    height: 280px;
  }

  .history-list-row {
    grid-template-columns: 56px minmax(0, 1fr) auto;
  }
}
