/* Geography typing quizzes (/js/geo-quiz/, continents spec §4.1): one stylesheet for every
   configuration. Countries quizzes are scoped under .q-countries, capitals quizzes under .q-capitals,
   flags quizzes under .q-flags.
   Functional layout before the design pass; existing tokens only.
   Map colors and states: /css/geo-map.css; each view's aspect ratio: /css/geo-views.css (generated). */

/* ========== Countries quizzes ==========
   Mobile: sticky bar (clock, counter, buttons, input), guessed list, map.
   900 px and up: map left (about two thirds), bar, input and list right. */

.q-countries { padding-block: var(--s5) var(--s7); }
.q-countries__intro { display: grid; gap: var(--s2); margin-bottom: var(--s5); max-width: 60ch; }
.q-countries__intro h1 { font-size: 28px; }

.q-countries__game { max-width: none; display: grid; gap: var(--s4); padding: var(--s3); }
.q-countries__game:focus { outline: none; }
.q-countries__side { display: grid; gap: var(--s3); align-content: start; min-width: 0; }

/* ---------- control bar ---------- */
.q-countries__bar {
  position: sticky; top: 0; z-index: 4;
  display: grid; gap: var(--s2);
  margin: calc(-1 * var(--s3)) calc(-1 * var(--s3)) 0; padding: var(--s3);
  background: var(--surface); border-radius: var(--r-card) var(--r-card) 0 0;
}
.q-countries__row { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.q-countries__actions { display: flex; gap: var(--s2); margin-left: auto; }
.q-countries__input {
  width: 100%; min-height: 48px; padding: 0 var(--s4);
  font-size: 18px; /* 16 px or more keeps iOS from zooming on focus */
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-pill);
}
.q-countries__input:disabled { opacity: .5; }
.q-countries__feedback { margin-top: var(--s1); padding-inline: var(--s4); font-size: 15px; }

/* ---------- guessed list ---------- */
.q-countries__list {
  max-height: calc(4 * 36px + 32px); /* about four rows on mobile, own scroll */
  overflow-y: auto; overscroll-behavior: contain;
  border-top: 1px solid var(--line);
}
.q-countries__table { width: 100%; border-collapse: collapse; font-size: 15px; }
.q-countries__table thead th {
  position: sticky; top: 0; background: var(--surface);
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: var(--s2);
}
.q-countries__table td { padding: 6px var(--s2); border-bottom: 1px solid var(--line); height: 36px; }
.q-countries__table th:first-child, .q-countries__table td:first-child { width: 3.5em; color: var(--ink-2); }

.q-countries__result { display: grid; gap: var(--s3); padding-block: var(--s2); }
.q-countries__result .fig dd { font-size: 24px; }

/* ---------- map (colors and states: /css/geo-map.css) ---------- */
.q-countries__mapwrap { position: relative; min-width: 0; }

/* ---------- named and missed countries after the game (D8) ---------- */
.q-countries__endlist { display: grid; gap: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line); }
.q-countries__groups { display: grid; gap: var(--s4); }
.q-countries__group { display: grid; gap: var(--s2); }
.q-countries__group h3 { display: flex; gap: var(--s2); align-items: baseline; }
.q-countries__bubbles { display: flex; flex-wrap: wrap; gap: 6px; }
.q-countries__bubbles .state { padding: 2px 10px; border-radius: var(--r-pill); font-size: 14px; line-height: 1.5; }

/* ---------- after the game: names on hover or tap (D8) ---------- */
.q-countries__caption { min-height: 1.5em; margin-top: var(--s2); font-size: 15px; }

/* ---------- your stats ---------- */
.q-countries__stats { max-width: none; display: grid; gap: var(--s4); margin-top: var(--s5); padding: var(--s4); }
.q-countries__stats .figs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.q-countries__stats .fig dd { font-size: 24px; }
.q-countries__recent { overflow-x: auto; }
.q-countries__recent caption { text-align: left; padding-bottom: var(--s2); }
.q-countries__recent th:first-child, .q-countries__recent td:first-child { width: auto; color: inherit; }

/* ---------- page text below the quiz ---------- */
.q-countries__about { display: grid; gap: var(--s3); max-width: 72ch; margin-top: var(--s7); }
.q-countries__about h2 { margin-top: var(--s4); }
.q-countries__about h3 { margin-top: var(--s2); }
.q-countries__about ol, .q-countries__about ul { margin: 0; padding-left: 1.4em; display: grid; gap: var(--s1); }
.q-countries__names th[scope="row"] { font-weight: 600; text-align: left; padding: 6px var(--s2); border-bottom: 1px solid var(--line); }
.q-countries__names th:first-child { width: 40%; color: inherit; } /* not the narrow "#" column of the guessed list */
.q-countries__names thead th { position: static; } /* not in a scroll box: don't stick to the viewport */
.q-countries__more { display: grid; gap: var(--s3); }
.q-countries__more summary { cursor: pointer; font-weight: 600; padding-block: 10px; } /* about 44 px tall, as .q-capitals__more */

/* ---------- pause: cover map and list ---------- */
.q-countries__pause { inset: 0; padding: var(--s4); align-content: center; }
.q-countries__pause p { font-size: 18px; }
.q-countries.is-paused .q-countries__map,
.q-countries.is-paused .q-countries__list { visibility: hidden; }

@media (min-width: 900px) {
  .q-countries__game { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); padding: var(--s5); gap: var(--s5); }
  .q-countries__mapwrap { grid-column: 1; grid-row: 1; align-self: start; }
  .q-countries__side { grid-column: 2; grid-row: 1; }
  .q-countries__bar { margin: 0; padding: 0; position: static; }
  .q-countries__list { max-height: 420px; }
  .q-countries__endlist { grid-column: 1 / -1; }
}

/* ========== Capitals quizzes ==========
   Mobile: sticky bar (clock, counter, buttons, input, "Last named" line), map, the full country list.
   900 px and up: map left; bar, input and the list (scrolling in its column) right. */

.q-capitals { padding-block: var(--s5) var(--s7); }
.q-capitals__intro { display: grid; gap: var(--s2); margin-bottom: var(--s5); max-width: 60ch; }
.q-capitals__intro h1 { font-size: 28px; }

.q-capitals__game { max-width: none; display: grid; gap: var(--s4); padding: var(--s3); }
.q-capitals__game:focus { outline: none; }
.q-capitals__side { display: grid; gap: var(--s3); align-content: start; min-width: 0; }
/* Mobile: the bar sticks for the whole card (list included), not only inside the side column */
@media (max-width: 899px) { .q-capitals__side { display: contents; } }

/* ---------- control bar ---------- */
.q-capitals__bar {
  position: sticky; top: 0; z-index: 4;
  display: grid; gap: var(--s2);
  margin: calc(-1 * var(--s3)) calc(-1 * var(--s3)) 0; padding: var(--s3);
  background: var(--surface); border-radius: var(--r-card) var(--r-card) 0 0;
}
.q-capitals__row { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.q-capitals__actions { display: flex; gap: var(--s2); margin-left: auto; }
.q-capitals__input {
  width: 100%; min-height: 48px; padding: 0 var(--s4);
  font-size: 18px; /* 16 px or more keeps iOS from zooming on focus */
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-pill);
}
.q-capitals__input:disabled { opacity: .5; }
/* "Last named: Paris, France" / "Already named: Bolivia": one line, reserved so nothing shifts */
.q-capitals__feedback {
  min-height: 1.5em; margin-top: var(--s1); padding-inline: var(--s4); font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.q-capitals__result { display: grid; gap: var(--s3); padding-block: var(--s2); }
.q-capitals__result .fig dd { font-size: 24px; }

/* ---------- map ---------- */
.q-capitals__mapwrap { position: relative; min-width: 0; }

/* ---------- country list ---------- */
.q-capitals__list { min-width: 0; border-top: 1px solid var(--line); }
.q-capitals__table { width: 100%; border-collapse: collapse; font-size: 15px; }
.q-capitals__table thead th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: var(--s2);
}
.q-capitals__table tbody th[scope="row"] { font-weight: 400; text-align: left; width: 50%; }
.q-capitals__table tbody th, .q-capitals__table td { padding: 6px var(--s2); border-bottom: 1px solid var(--line); height: 36px; vertical-align: top; }
.q-capitals__table td { font-weight: 600; }
.q-capitals__group th {
  text-align: left; font-size: 15px; font-weight: 700; padding-top: var(--s4);
}
.q-capitals__group .num { font-weight: 400; margin-left: var(--s1); }
.q-capitals__table tr.is-new { background: color-mix(in srgb, var(--state-correct) 16%, var(--surface)); }
.q-capitals__table tr { transition: background-color 1s var(--ease); }
.q-capitals__missed { color: var(--state-wrong); font-style: italic; }
.q-capitals__also { display: block; font-size: 13px; font-weight: 400; color: var(--ink-2); }

/* ---------- pause: cover map and list ---------- */
.q-capitals__pause { inset: 0; padding: var(--s4); align-content: center; }
.q-capitals__pause p { font-size: 18px; }
.q-capitals.is-paused .q-capitals__map,
.q-capitals.is-paused .q-capitals__list { visibility: hidden; }

/* ---------- your stats ---------- */
.q-capitals__stats { max-width: none; display: grid; gap: var(--s4); margin-top: var(--s5); padding: var(--s4); }
.q-capitals__stats .figs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.q-capitals__stats .fig dd { font-size: 24px; }
.q-capitals__recent { overflow-x: auto; }
.q-capitals__recent caption { text-align: left; padding-bottom: var(--s2); }
.q-capitals__recent td { font-weight: 400; }

/* ---------- page text below the quiz ---------- */
.q-capitals__about { display: grid; gap: var(--s3); max-width: 72ch; margin-top: var(--s7); }
.q-capitals__about h2 { margin-top: var(--s4); }
.q-capitals__about h3 { margin-top: var(--s2); }
.q-capitals__about ol, .q-capitals__about ul { margin: 0; padding-left: 1.4em; display: grid; gap: var(--s1); }
.q-capitals__more { display: grid; gap: var(--s3); }
.q-capitals__more summary { cursor: pointer; font-weight: 600; padding-block: 10px; } /* about 44 px tall */
.q-capitals__more[open] summary { margin-bottom: var(--s2); }
.q-capitals__names td { font-weight: 400; }
.q-capitals__names tbody th[scope="row"] { font-weight: 600; }

@media (min-width: 900px) {
  .q-capitals__game {
    grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); grid-template-rows: auto 1fr;
    padding: var(--s5); gap: var(--s4) var(--s5);
  }
  .q-capitals__mapwrap { grid-column: 1; grid-row: 1 / 3; align-self: start; }
  .q-capitals__side { grid-column: 2; grid-row: 1; }
  .q-capitals__list { grid-column: 2; grid-row: 2; max-height: 60vh; overflow-y: auto; overscroll-behavior: contain; }
  .q-capitals__table thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
  .q-capitals__bar { margin: 0; padding: 0; position: static; }
}

/* ========== Flags quizzes (flags spec §6) ==========
   Mobile: sticky bar (clock, counter, buttons; the active flag enlarged beside the input), then the
   grid, 4 columns. Wider: more columns (8 to 10 on desktop), a larger preview.
   Every tile frames its flag at 3:2; the flag keeps its own proportions inside (D7). */

.q-flags { padding-block: var(--s5) var(--s7); }
.q-flags__intro { display: grid; gap: var(--s2); margin-bottom: var(--s5); max-width: 60ch; }
.q-flags__intro h1 { font-size: 28px; }

.q-flags__game { max-width: none; display: grid; gap: var(--s3); padding: var(--s3); }
.q-flags__game:focus { outline: none; }

/* ---------- control bar ---------- */
.q-flags__bar {
  position: sticky; top: 0; z-index: 4;
  display: grid; gap: var(--s2);
  margin: calc(-1 * var(--s3)) calc(-1 * var(--s3)) 0; padding: var(--s3);
  background: var(--surface); border-radius: var(--r-card) var(--r-card) 0 0;
  border-bottom: 1px solid var(--line);
}
.q-flags__row { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.q-flags__actions { display: flex; gap: var(--s2); margin-left: auto; }
.q-flags__loading { font-size: 15px; }
.q-flags__ask { display: flex; gap: var(--s3); align-items: flex-start; }
.q-flags__ask:has(> [data-preview][hidden]):has(> [data-entry][hidden]) { display: none; }
.q-flags__preview { flex: none; margin: 0; display: grid; gap: var(--s1); justify-items: start; }
.q-flags__preview img { display: block; width: 108px; height: 72px; object-fit: contain; object-position: left center; }
/* A hairline that follows the flag's own shape, so white edges show (Indonesia vs Monaco, Nepal; D7) */
.q-flags__preview img, .flag-tile__frame img { filter: drop-shadow(0 0 1px var(--line-strong)); }
.q-flags__preview-name { font-size: 18px; font-weight: 700; }
.q-flags__preview-name:empty { display: none; }
.q-flags__entry { flex: 1 1 auto; min-width: 0; }
.q-flags__input {
  width: 100%; min-height: 48px; padding: 0 var(--s4);
  font-size: 18px; /* 16 px or more keeps iOS from zooming on focus */
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--r-pill);
}
.q-flags__input:disabled { opacity: .5; }
.q-flags__keys { display: none; margin-top: var(--s1); padding-inline: var(--s4); font-size: 13px; }
@media (pointer: fine) { .q-flags__keys { display: block; } }
.q-flags__feedback { margin-top: var(--s1); padding-inline: var(--s4); font-size: 15px; }

.q-flags__result { display: grid; gap: var(--s3); padding-block: var(--s2); }
.q-flags__result .fig dd { font-size: 24px; }
.q-flags__after { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); }
.q-flags__after:not(:has(> :not([hidden]))) { display: none; }
.q-flags__hint, .q-flags__practice { font-size: 15px; }
.q-flags__practice { flex-basis: 100%; }

/* ---------- grid ---------- */
.q-flags__gridwrap { position: relative; min-width: 0; }
.q-flags__grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s3) var(--s2);
}
.flag-tile__btn {
  display: grid; gap: var(--s1); width: 100%; padding: var(--s1);
  background: none; border: 0; border-radius: 8px; color: inherit; font: inherit; text-align: center;
}
button.flag-tile__btn { cursor: pointer; }
.flag-tile__frame {
  display: grid; place-items: center; aspect-ratio: 3 / 2;
  background: var(--surface-2); border-radius: 4px; padding: 2px;
  font-size: 11px; color: var(--ink-2); /* the neutral alt text, if a flag fails to load */
}
.q-flags.is-playing .flag-tile__frame, .q-flags__grid:not([aria-hidden]) .flag-tile__frame { background: none; }
/* Absolutely placed so the frame's 3:2 box is definite and every flag fits inside it */
.flag-tile__frame { position: relative; }
.flag-tile__frame img { position: absolute; inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); object-fit: contain; }
.flag-tile__label { min-height: 2.5em; font-size: 12px; line-height: 1.25; hyphens: auto; overflow-wrap: break-word; }
.flag-tile.is-active .flag-tile__btn { box-shadow: inset 0 0 0 3px var(--ink); }
.flag-tile.is-named .flag-tile__frame { opacity: .35; }
.flag-tile.is-named .flag-tile__label { color: var(--state-correct); font-weight: 600; }
.flag-tile.is-missed .flag-tile__label { color: var(--state-wrong); font-weight: 600; }
.flag-tile.is-named button.flag-tile__btn { cursor: default; }
.q-flags:not(.is-playing) .flag-tile.is-named button.flag-tile__btn { cursor: pointer; } /* after the game: review */
.q-flags:not(.is-playing) .flag-tile.is-named .flag-tile__frame { opacity: 1; }

/* ---------- pause: cover the grid and hide the preview ---------- */
.q-flags__pause { inset: 0; padding: var(--s4); align-content: start; }
.q-flags__pause p { font-size: 18px; }
.q-flags.is-paused .q-flags__grid,
.q-flags.is-paused .q-flags__preview { visibility: hidden; }

/* ---------- your stats ---------- */
.q-flags__stats { max-width: none; display: grid; gap: var(--s4); margin-top: var(--s5); padding: var(--s4); }
.q-flags__stats .figs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.q-flags__stats .fig dd { font-size: 24px; }
.q-flags__recent { overflow-x: auto; }
.q-flags__recent caption { text-align: left; padding-bottom: var(--s2); }
.q-flags__table { width: 100%; border-collapse: collapse; font-size: 15px; }
.q-flags__table thead th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: var(--s2); }
.q-flags__table td { padding: 6px var(--s2); border-bottom: 1px solid var(--line); height: 36px; }

/* ---------- page text below the quiz ---------- */
.q-flags__about { display: grid; gap: var(--s3); max-width: 72ch; margin-top: var(--s7); }
.q-flags__about h2 { margin-top: var(--s4); }
.q-flags__about ol, .q-flags__about ul { margin: 0; padding-left: 1.4em; display: grid; gap: var(--s1); }
.q-flags__about h3 { margin-top: var(--s2); }
.q-flags__more { display: grid; gap: var(--s3); }
.q-flags__more summary { cursor: pointer; font-weight: 600; padding-block: 10px; } /* about 44 px tall, as .q-capitals__more */
.q-flags__more[open] summary { margin-bottom: var(--s2); }
/* Look-alike flags: the same height, so the proportions show (D7) */
.q-flags__alike { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s4); align-items: flex-end; }
.q-flags__alike figure { margin: 0; display: grid; gap: var(--s1); font-size: 14px; }
.q-flags__alike img { display: block; height: 60px; width: auto; max-width: 100%; filter: drop-shadow(0 0 1px var(--line-strong)); }
.q-flags__names th[scope="row"] { font-weight: 600; text-align: left; padding: 6px var(--s2); border-bottom: 1px solid var(--line); width: 40%; }

@media (min-width: 600px) {
  .q-flags__grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}
@media (min-width: 900px) {
  .q-flags__game { padding: var(--s5); gap: var(--s4); }
  .q-flags__bar { margin: calc(-1 * var(--s5)) calc(-1 * var(--s5)) 0; padding: var(--s4) var(--s5); }
  .q-flags__preview img { width: 160px; height: 107px; }
  .q-flags__entry { max-width: 480px; align-self: center; }
  .q-flags__grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--s4) var(--s3); }
  .flag-tile__label { font-size: 13px; }
}
