/* The static country pages (scripts/build-country-pages.mjs): the app's colours and fonts, no JavaScript. */
@font-face {
  font-family: 'Fredoka Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url('/fonts/fredoka-latin.woff2') format('woff2-variations');
}

@font-face {
  font-family: 'Nunito Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url('/fonts/nunito-latin.woff2') format('woff2-variations');
}

:root {
  --font: 'Nunito Variable', 'Nunito', ui-rounded, system-ui, sans-serif;
  --display: 'Fredoka Variable', 'Fredoka', ui-rounded, system-ui, sans-serif;
  --paper: #121831;
  --land: #1b2347;
  --land-muted: #222b55;
  --land-raised: #27315f;
  --ink: #f2f4ff;
  --ink-2: #c9cfee;
  --ink-3: #9ea6cf;
  --rule: #2e3868;
  --ledge: #0b1026;
  --cta: #ffc93c;
  --sky: #45b6ff;
  --sea: #0e142b;
  --radius: 20px;
  color-scheme: dark;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--sky);
}

a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 2px;
  border-radius: 6px;
}

h1,
h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  line-height: 1.1;
}

h1 {
  font-size: clamp(2.2rem, 1.6rem + 2.5vw, 3.4rem);
}

h2 {
  margin-bottom: 14px;
  font-size: 1.35rem;
}

.cp-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 20px;
}

.cp-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 700;
  text-decoration: none;
}

.cp-top nav {
  display: flex;
  gap: 18px;
}

.cp-top nav a {
  color: var(--ink-2);
  font-weight: 700;
  text-decoration: none;
}

.cp-top nav a:hover {
  color: var(--ink);
}

.cp {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 8px 20px 64px;
}

.cp-crumbs {
  color: var(--ink-3);
  font-size: 0.9rem;
}

.cp-crumbs a {
  color: var(--ink-2);
}

.cp-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px 28px;
}

/* A flag in its 4:3 frame (framedFlag in scripts/build-country-pages.mjs): whole, at its true shape,
   the edge and corners on the flag. */
.cp-frame {
  position: relative;
  display: block;
  flex: none;
  width: 100%;
  aspect-ratio: 4 / 3;
}

.cp-frame img {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: var(--round, 4px);
  /* A faint line just inside the edge, as in the app: shows where a white flag ends. */
  outline: 1px solid rgba(128, 136, 170, 0.45);
  outline-offset: -1px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
}

.cp-frame.is-shaped img {
  border-radius: 0;
  outline: none;
  box-shadow: none;
  filter: drop-shadow(0 0 1px rgba(242, 244, 255, 0.35));
}

.cp-flag {
  width: 180px;
}

.cp-flag img {
  box-shadow: 0 4px 0 0 var(--ledge);
}

.cp-official {
  margin: 6px 0 0;
  color: var(--ink-3);
}

.cp-lead {
  max-width: 60ch;
  margin: 10px 0 0;
  color: var(--ink-2);
  font-size: 1.15rem;
}

.cp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 24px;
}

.cp-card {
  margin: 0;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--land);
  box-shadow: 0 0 0 2px var(--rule), 0 6px 0 0 var(--ledge);
}

.cp-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 18px;
  margin: 0;
}

.cp-facts dt {
  color: var(--ink-3);
}

.cp-facts dd {
  margin: 0;
  font-weight: 700;
}

.cp-map {
  padding: 0;
  overflow: hidden;
}

.cp-map svg {
  display: block;
  width: 100%;
  height: auto;
}

.cp-map .sea {
  fill: var(--sea);
}

.cp-map path {
  fill: var(--land-raised);
  stroke: var(--rule);
  stroke-width: 0.6;
}

.cp-map .is-near {
  fill: #33407a;
}

.cp-map .is-this {
  fill: var(--cta);
  stroke: #fff3cc;
  stroke-width: 1;
}

.cp-map figcaption {
  padding: 10px 16px;
  color: var(--ink-3);
  font-size: 0.9rem;
}

.cp-hooks {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cp-hooks li {
  padding-left: 14px;
  border-left: 3px solid var(--cta);
}

.cp-hooks strong {
  display: block;
  color: var(--cta);
  font-family: var(--display);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cp-fact h2 {
  color: var(--sky);
}

.cp-fact p {
  margin: 0;
}

.cp-quiz details {
  margin-bottom: 10px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--land-muted);
}

.cp-quiz summary {
  font-weight: 800;
  cursor: pointer;
}

.cp-quiz details p {
  margin: 8px 0 0;
  color: var(--cta);
  font-weight: 800;
}

.cp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 18px 0 0;
}

.cp-cta,
.cp-button {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 800;
  text-decoration: none;
}

.cp-cta {
  background: var(--cta);
  color: #1b2147;
  box-shadow: 0 4px 0 0 #c99410;
}

.cp-button {
  background: var(--land-raised);
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--rule);
}

.cp-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

/* The same pills as the neighbours in the atlas's country sheet (src/atlas.css). */
.cp-links a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 14px 4px 8px;
  border-radius: 999px;
  background: var(--land);
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--rule);
  font-weight: 650;
  text-decoration: none;
}

.cp-links a:hover {
  background: var(--land-raised);
}

.cp-links img {
  border-radius: 3px;
}

section > h2:only-child {
  margin: 0;
}

.cp-foot {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  border-top: 2px solid var(--rule);
  color: var(--ink-3);
}

@media (max-width: 600px) {
  .cp-flag {
    width: 120px;
  }

  .cp-facts {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }

  .cp-facts dd {
    margin-bottom: 8px;
  }
}

.cp-facts small {
  display: block;
  color: var(--ink-3);
  font-size: 0.88rem;
  font-weight: 600;
}

.cp-parts-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 20px;
  align-items: start;
}

.cp-parts-map {
  margin: 0;
  overflow: hidden;
  border-radius: 14px;
}

.cp-parts-map svg {
  display: block;
  width: 100%;
  height: auto;
}

.cp-parts-map .sea {
  fill: var(--sea);
}

.cp-parts-map path {
  stroke: var(--paper);
  stroke-width: 0.8;
}

/* Far islands (Canaries, Galápagos …) in a box of their own, as in the app. */
.cp-parts-map .inset {
  fill: none;
  stroke: #56619e;
  stroke-dasharray: 4 3;
}

.cp-parts-map .part-0 { fill: #3b4a8f; }
.cp-parts-map .part-1 { fill: #2f6f8f; }
.cp-parts-map .part-2 { fill: #5a4a8f; }
.cp-parts-map .part-3 { fill: #2f7f6a; }

.cp-parts-map path:hover {
  fill: var(--cta);
}

.cp-parts table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.cp-parts th {
  color: var(--ink-3);
  font-weight: 700;
  text-align: left;
}

.cp-parts th,
.cp-parts td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--rule);
}

.cp-parts td:last-child,
.cp-parts th:last-child {
  text-align: right;
  white-space: nowrap;
}

/* The list of parts beside the map: as tall as the map, scrolling inside. */
.cp-parts-list {
  max-height: 360px;
  overflow: auto;
  border-radius: 12px;
  overscroll-behavior: contain;
}

.cp-parts thead th {
  position: sticky;
  top: 0;
  background: var(--land);
}

.cp-parts tbody tr.is-on td {
  background: color-mix(in srgb, var(--cta) 18%, transparent);
  color: var(--ink);
}

.cp-parts-map path.is-on {
  fill: var(--cta);
}

.cp-parts-hover {
  min-height: 1.6em;
  padding: 8px 4px 0;
  color: var(--ink-2);
  font-weight: 700;
}

.cp-quiz details small {
  display: block;
  margin-top: 4px;
  color: var(--ink-3);
  font-size: 0.88rem;
  font-weight: 600;
}

.cp-about p {
  max-width: 70ch;
  margin: 0;
  color: var(--ink-2);
}

/* The language switch is two links here (the pages of both languages), styled like the app's buttons. */
.lang-switch a.lang-switch-option {
  text-decoration: none;
}

/* "How to learn …": one line per aid, the label above. */
.cp-learn ul {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cp-learn li > strong {
  display: block;
  margin-bottom: 4px;
  color: var(--cta);
  font-family: var(--display);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cp-compass {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

.cp-compass em {
  margin-right: 4px;
  color: var(--ink-3);
  font-style: normal;
  font-weight: 700;
}

.cp-mixups {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}

.cp-mixups a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.cp-mixups img,
.cp-flag-options img {
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(242, 244, 255, 0.18);
}

.cp-lesson {
  font-weight: 800;
}

/* The flag question: three flags, numbered, under the question. */
.cp-flag-options {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: -2px 0 12px;
}

.cp-flag-options span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.cp-flag-options b {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--land-raised);
  font-size: 0.85rem;
}

.cp-flag-q {
  margin-bottom: 10px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--land-muted);
}

.cp-flag-question {
  margin: 0 0 10px;
  font-weight: 800;
}

.cp-flag-q .cp-flag-options {
  margin: 0 0 10px;
}

.cp-flag-q details {
  margin: 0;
  padding: 0;
  background: none;
}

.cp-flag-q summary {
  color: var(--sky);
  font-weight: 700;
}

/* ---------- Opening and closing the questions, smoothly ---------- */
/* The answer grows to its height and fades in (where the browser can animate to "auto"; elsewhere it
   simply opens), and the arrow turns. Calm, and off with reduced motion. */
:root {
  interpolate-size: allow-keywords;
}

.cp details::details-content {
  block-size: 0;
  overflow: hidden;
  opacity: 0;
  transition: block-size 0.28s ease, opacity 0.22s ease, content-visibility 0.28s allow-discrete;
}

.cp details[open]::details-content {
  block-size: auto;
  opacity: 1;
}

.cp summary {
  list-style: none;
}

.cp summary::-webkit-details-marker {
  display: none;
}

.cp summary::before {
  content: '';
  display: inline-block;
  width: 0.45em;
  height: 0.45em;
  margin: 0 0.6em 0.12em 0.1em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.25s ease;
}

.cp details[open] > summary::before {
  transform: rotate(45deg);
}

@media (prefers-reduced-motion: reduce) {
  .cp details::details-content,
  .cp summary::before {
    transition: none;
  }
}

/* Nepal's flag is two pennants, not a rectangle: no box or rim around it (small flags in a line). */
img[src$='/flags/NP.svg'] {
  border-radius: 0 !important;
  box-shadow: none !important;
  background: none !important;
}

/* The flags of the flag question are buttons: a tap answers. */
.cp-flag-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease;
}

.cp-flag-option:hover {
  background: var(--land-raised);
}

.cp-flag-option:focus {
  outline: none;
}

.cp-flag-option:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 2px;
}

.cp-flag-option.is-right {
  background: color-mix(in srgb, #6ee09a 22%, transparent);
}

.cp-flag-option.is-right b {
  background: #3ba66a;
}

.cp-flag-option.is-wrong {
  background: color-mix(in srgb, #ff7a8a 22%, transparent);
}

.cp-flag-option.is-wrong b {
  background: #c74a5a;
}

/* Questions open by mouse without a focus box; the keyboard still shows where it is. */
.cp summary:focus:not(:focus-visible) {
  outline: none;
}

.cp summary {
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Topic pages: lists of capitals and flags ---------- */
.cp-table {
  padding: 8px 12px;
}

.cp-table table {
  width: 100%;
  border-collapse: collapse;
}

.cp-table th {
  color: var(--ink-3);
  font-weight: 700;
  text-align: left;
}

.cp-table th,
.cp-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
}

.cp-table tr:last-child td {
  border-bottom: 0;
}

.cp-table td a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.cp-table td a:hover {
  color: var(--sky);
}

.cp-table img {
  border-radius: 3px;
}

.cp-flag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cp-flag-grid a {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 12px;
  border-radius: 16px;
  background: var(--land);
  box-shadow: 0 0 0 2px var(--rule);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.cp-flag-grid a:hover {
  box-shadow: 0 0 0 2px var(--sky);
}

.cp-flag-grid .cp-frame img {
  --round: 8px;
}

/* ---------- The mini quiz: one question at a time ---------- */
.cp-mini-quiz {
  display: grid;
  gap: 12px;
  margin-bottom: 8px;
}

.cp-mq-count {
  margin: 0;
  color: var(--ink-3);
  font-size: 0.9rem;
  font-weight: 700;
}

.cp-mq-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--land-muted);
}

.cp-mq-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #6ee09a;
  transition: width 0.3s ease;
}

.cp-mq-question {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 1.3rem;
  font-weight: 700;
}

.cp-mq-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.cp-mq-options.is-flags {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cp-mq-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px 14px;
  border: 0;
  border-radius: 14px;
  background: var(--land-muted);
  box-shadow: 0 0 0 2px var(--rule), 0 4px 0 0 var(--ledge);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.cp-mq-option:hover:not(:disabled) {
  background: var(--land-raised);
}

.cp-mq-option:active:not(:disabled) {
  transform: translateY(2px);
}

.cp-mq-option:focus {
  outline: none;
}

.cp-mq-option:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 2px;
}

.cp-mq-option:disabled {
  cursor: default;
}

.cp-mq-option b {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--land-raised);
  color: var(--ink-3);
  font-size: 0.85rem;
}

.cp-mq-option .cp-frame {
  width: 36px;
}

.is-flags .cp-mq-option {
  flex-direction: column;
  justify-content: center;
  padding: 10px;
}

.is-flags .cp-mq-option .cp-frame {
  width: 100%;
  max-width: 140px;
}

.cp-mq-option.is-right {
  background: color-mix(in srgb, #6ee09a 24%, var(--land-muted));
  box-shadow: 0 0 0 2px #3ba66a, 0 4px 0 0 var(--ledge);
}

.cp-mq-option.is-wrong {
  background: color-mix(in srgb, #ff7a8a 22%, var(--land-muted));
  box-shadow: 0 0 0 2px #c74a5a, 0 4px 0 0 var(--ledge);
}

.cp-mq-feedback {
  min-height: 1.4em;
  margin: 0;
  font-weight: 700;
}

.cp-mq-feedback.is-right {
  color: #6ee09a;
}

.cp-mq-feedback.is-wrong {
  color: #ff9aa6;
}

.cp-mini-quiz > .cp-cta {
  justify-self: start;
  border: 0;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.cp-mq-end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.cp-mq-result {
  margin: 0;
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 700;
}

.cp-mq-end .cp-button {
  border: 0;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

@media (max-width: 600px) {
  .cp-mq-options {
    grid-template-columns: minmax(0, 1fr);
  }

  .cp-mq-options.is-flags {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ---------- All countries: continent filter, one card per continent ---------- */
.cp-filter {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  margin: 28px -20px 0;
  padding: 12px 20px;
  overflow-x: auto;
  background: var(--paper);
  scrollbar-width: none;
}

.cp-filter::-webkit-scrollbar {
  display: none;
}

.cp-filter a {
  flex: none;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--land);
  box-shadow: 0 0 0 1px var(--rule);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.cp-filter a:hover {
  background: var(--land-raised);
}

.cp-filter a[aria-current='true'] {
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
}

.cp-groups {
  display: grid;
  gap: 20px;
  margin-top: 16px;
}

.cp-group {
  padding: 22px 24px 24px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--land) 45%, transparent);
  box-shadow: 0 0 0 1px var(--rule);
  scroll-margin-top: 72px;
}

.cp-group[hidden] {
  display: none;
}

.cp-group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 18px;
}

.cp-group-head h2 {
  margin: 0;
}

.cp-group-head h2 span {
  margin-left: 6px;
  color: var(--ink-3);
  font-family: inherit;
  font-size: 0.6em;
  font-weight: 700;
}

.cp-group-practise {
  min-height: 40px;
  padding: 8px 18px;
}

@media (max-width: 600px) {
  .cp-group {
    margin: 0 -8px;
    padding: 18px 16px 20px;
  }
}
