body {
  min-height: 100vh;
}

.option-group,
#setupExtra,
#scopeSection,
.scope-panel,
.qcount-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.option-group {
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

#setupExtra,
#scopeSection,
.scope-panel,
.qcount-group,
.create-quiz-wrap {
  align-self: stretch;
}

.option-group .nav-pills {
  align-self: center;
}

.field-wrap,
.country-list-wrap {
  width: 100%;
  max-width: 280px;
  align-self: center;
}

.nav-pills .nav-link {
  background-color: #e9ecef;
  color: #495057;
  border: 1px solid #dee2e6;
  border-radius: 50rem;
  padding: 0.45rem 1.2rem;
  font-size: 1.2rem;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-pills .nav-link:hover {
  background-color: #dee2e6;
  color: #212529;
}

.nav-pills .nav-link.active {
  background-color: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}

.nav-pills .nav-link:focus {
  outline: none;
  box-shadow: none;
}

/* Explore map on the start page */
.explore-section {
  max-width: 900px;
}

.explore-map {
  height: 380px;
  width: 100%;
  z-index: 0;
  border: 1px solid #dee2e6;
  background: #e3edfc;
}

@media (max-width: 576px) {
  .explore-map {
    height: 280px;
  }
}

.explore-map path.leaflet-interactive:focus {
  outline: none;
}

/* Challenge below the explore map: a proposed question, or the running click-the-place quiz. */
.challenge-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  text-align: left;
  background: #eef4ff;
  border: 1px solid #cfe0f7;
  border-radius: 0.5rem;
}

.challenge-main {
  display: flex;
  flex: 1 1 260px;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
  min-width: 0;
}

.challenge-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.challenge-text {
  font-size: 1.1rem;
  overflow-wrap: anywhere;
}

.challenge-bar.is-active .challenge-text {
  font-size: 1.35rem;
}

.challenge-feedback,
.challenge-score {
  flex-basis: 100%;
  font-size: 0.9rem;
}

.challenge-score {
  color: #6c757d;
}

.challenge-fact {
  color: #495057;
}

/* While answering, hover names and the print button would give the answer away. */
.explore-map.challenge-on .leaflet-tooltip-pane,
.explore-map.challenge-on .map-print-control {
  display: none;
}

.fact-popup .leaflet-popup-content {
  margin: 12px 14px;
  text-align: left;
}

.fact-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.fact-flag {
  height: 28px;
  width: auto;
  border: 1px solid #dee2e6;
}

.fact-name {
  font-size: 1.05rem;
}

.fact-list {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.75rem;
  row-gap: 0.15rem;
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.fact-list dt {
  font-weight: 600;
  color: #495057;
}

.fact-list dd {
  margin: 0;
}

.fact-popup .leaflet-popup-content p.fact-text {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

/* Match (drag and drop) answer mode */
.match-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) repeat(var(--match-cols, 1), minmax(0, 2fr));
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 0.5rem;
  text-align: left;
}

.match-country {
  display: flex;
  align-items: center;
  font-weight: 600;
}

.match-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  padding: 4px;
  border: 2px dashed #adb5bd;
  border-radius: 0.5rem;
  background: #f8f9fa;
}

.match-slot.over,
.match-tray.over {
  border-color: #0d6efd;
  background: #e7f1ff;
}

.match-slot-label {
  color: #adb5bd;
  font-size: 0.8rem;
}

.match-slot.filled .match-slot-label,
.match-checked .match-slot-label {
  display: none;
}

.match-tray-fact .match-card-fact {
  flex: 1 1 220px;
}

.match-slot.match-correct {
  border-style: solid;
  border-color: #198754;
  background: #d1e7dd;
}

.match-slot.match-wrong {
  border-style: solid;
  border-color: #dc3545;
  background: #f8d7da;
}

.match-solution {
  margin-top: 4px;
  font-size: 0.75rem;
  color: #146c43;
  text-align: center;
}

.match-solution img {
  height: 22px;
  width: auto;
  border: 1px solid #dee2e6;
}

.match-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  min-height: 64px;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border: 1px solid #dee2e6;
  border-radius: 0.5rem;
}

.match-card {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  padding: 4px 8px;
  font-size: 0.85rem;
  background: #fff;
  border: 1px solid #ced4da;
  border-radius: 0.5rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.match-card-flag img {
  display: block;
  height: 40px;
  width: auto;
  border: 1px solid #dee2e6;
}

.match-card-fact {
  max-width: 280px;
  text-align: left;
}

.match-slot .match-card {
  width: 100%;
  max-width: none;
  display: flex;
  justify-content: center;
}

.match-slot .match-card-fact {
  display: block;
}

.match-card.selected {
  outline: 3px solid #0d6efd;
  outline-offset: 1px;
}

.match-card.drag-source {
  opacity: 0.35;
}

.match-checked .match-card {
  cursor: default;
}

.match-ghost {
  position: fixed;
  z-index: 2000;
  pointer-events: none;
  opacity: 0.9;
  transform: translate(-50%, -50%) rotate(2deg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

@media (max-width: 576px) {
  .match-row {
    grid-template-columns: repeat(var(--match-cols, 1), minmax(0, 1fr));
  }

  .match-country {
    grid-column: 1 / -1;
  }
}

#map-container {
  height: 400px;
  width: 100%;
  z-index: 0;
}

.flag-image {
  max-width: 320px;
  width: 100%;
  height: auto;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.flag-crossword-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.flag-crossword-item img {
  width: 64px;
  height: 43px;
  object-fit: cover;
  border: 1px solid #dee2e6;
  border-radius: 4px;
}

.flag-crossword-item .flag-number {
  font-weight: 700;
  font-size: 0.8rem;
  color: #495057;
}

/* "Point on the map": the place to find, shown above the map. */
.point-prompt {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.point-mode.leaflet-container {
  cursor: crosshair;
}

/* Text symbols (e.g. landskapsblomma or landskapsdjur) shown in place of a flag image. */
.symbol-text {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 220px;
  min-height: 120px;
  padding: 1rem 1.5rem;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  background-color: #f8f9fa;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.symbol-name {
  font-size: 1.6rem;
  font-weight: 700;
}

.symbol-sub {
  font-style: italic;
  color: #6c757d;
}

.flag-crossword-item .symbol-text,
.match-card .symbol-text {
  min-width: 0;
  min-height: 0;
  padding: 0.35rem 0.6rem;
  box-shadow: none;
}

.flag-crossword-item .symbol-name,
.match-card .symbol-name {
  font-size: 0.95rem;
}

.flag-crossword-item .symbol-sub,
.match-card .symbol-sub {
  font-size: 0.75rem;
}

.country-list {
  max-height: 260px;
  overflow-y: auto;
}

.country-list .form-check {
  padding-left: 1.75em;
}

#answerOptions .btn {
  white-space: normal;
}

#answerOptions .btn.correct {
  background-color: var(--bs-success);
  border-color: var(--bs-success);
  color: #fff;
}

#answerOptions .btn.wrong {
  background-color: var(--bs-danger);
  border-color: var(--bs-danger);
  color: #fff;
}

#historyTableBody tr.latest-result,
#resultHistoryTableBody tr.latest-result {
  background-color: var(--bs-warning-bg-subtle);
}

/* "Världen | Sverige" switch next to the site name in the navbar */
.site-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
}

.site-switch a {
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.95rem;
  text-decoration: none;
  white-space: nowrap;
}

.site-switch a:hover,
.site-switch a:focus-visible {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.15);
}

.site-switch a.active {
  color: #212529;
  background-color: #fff;
  font-weight: 600;
}

/* Below the lg breakpoint the navbar items are hidden under the burger button and stacked:
   site switch first, then language, recommend and feedback. */
@media (max-width: 991.98px) {
  .navbar .navbar-collapse {
    padding: 0.75rem 0 0.25rem;
  }

  .navbar .navbar-collapse .site-switch {
    margin-bottom: 0.75rem;
  }
}

.country-label {
  font-weight: 600;
  font-size: 0.95rem;
  padding: 3px 8px;
}

.numbered-pin {
  background: transparent;
  border: none;
}

.numbered-pin-inner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.crossword-table {
  border-collapse: collapse;
}

.crossword-table td {
  width: 30px;
  height: 30px;
  padding: 0;
  text-align: center;
}

.crossword-table td.xw-cell {
  border: 1px solid #495057;
  position: relative;
  background: #fff;
}

.crossword-table td.xw-blank {
  border: none;
}

.crossword-table .xw-num {
  position: absolute;
  top: 0;
  left: 1px;
  font-size: 0.55rem;
  line-height: 1;
  font-weight: 700;
  color: #6c757d;
}

.crossword-table input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  text-transform: uppercase;
  font-weight: 700;
  padding: 0;
  background: transparent;
}

.crossword-table input:focus {
  outline: 2px solid var(--bs-primary);
  outline-offset: -2px;
}

.crossword-table input.xw-correct {
  background: var(--bs-success-bg-subtle);
  color: var(--bs-success);
}

.crossword-table input.xw-incorrect {
  background: var(--bs-danger-bg-subtle);
  color: var(--bs-danger);
}

.lingo-grid {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 auto;
}

.lingo-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.lingo-tile {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 2px solid #ced4da;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  color: #212529;
  background: #fff;
}

.lingo-tile.correct {
  background: var(--bs-success);
  border-color: var(--bs-success);
  color: #fff;
}

.lingo-tile.reveal-fail {
  background: var(--bs-danger-bg-subtle);
  border-color: var(--bs-danger);
  color: var(--bs-danger);
}

.lingo-guess-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: #fff;
}

.lingo-guess-badge.correct {
  background: var(--bs-success);
}

.lingo-guess-badge.wrong {
  background: #6c757d;
}

#printMapContainer {
  position: relative;
  height: 500px;
  width: 100%;
  z-index: 0;
  --print-right-margin: 26px;
}

.print-leader-overlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 650;
}

.print-leader-labels {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 651;
}

.print-leader-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -50%);
}

.print-leader-badge {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.print-leader-name {
  position: absolute;
  white-space: nowrap;
  font-size: 0.68rem;
  font-weight: 600;
  color: #212529;
  background: rgba(255, 255, 255, 0.75);
  padding: 0 3px;
  border-radius: 2px;
}

#printAnswerList {
  columns: 2;
  column-gap: 2rem;
}

.print-answer-line {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
  break-inside: avoid;
}

.print-answer-number {
  font-weight: 700;
  min-width: 1.75em;
}

.print-answer-line input {
  flex: 1;
  border: none;
  border-bottom: 1px solid #495057;
  border-radius: 0;
  background: transparent;
  padding: 0.2rem 0.3rem;
}

.print-answer-line input:focus {
  outline: none;
  box-shadow: none;
  border-bottom-color: #0d6efd;
}

.print-answer-line input.pa-correct {
  color: #198754;
  border-bottom-color: #198754;
}

.print-answer-line input.pa-incorrect {
  color: #dc3545;
  border-bottom-color: #dc3545;
}

@media print {
  @page {
    margin: 10mm;
  }

  .navbar, header, footer, #quizStatusBar, #answerFeedback, .no-print, .leaflet-control-container {
    display: none !important;
  }

  body, main, .container, .row, #quizColumn, .card, .card-body {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .card, .card-body {
    box-shadow: none !important;
    border: none !important;
  }

  #printMapContainer {
    height: 50vh !important;
    width: 100% !important;
    break-inside: avoid;
    page-break-inside: avoid;
    --print-right-margin: 26px;
  }

  #printAnswerListWrap {
    break-before: page;
    page-break-before: always;
  }
}

@media print and (orientation: landscape) {
  #printMapContainer {
    height: 92vh !important;
    --print-right-margin: 26px;
  }
}

/* The printed map is a picture drawn at the printable size of the chosen paper orientation (js/app.js,
   buildPrintMapSvg). It is only shown on paper; the screen keeps the interactive map. */
.print-map-image {
  display: none;
}

.print-orientation .btn:first-child {
  border-top-left-radius: 50rem;
  border-bottom-left-radius: 50rem;
}

.print-orientation .btn:last-child {
  border-top-right-radius: 50rem;
  border-bottom-right-radius: 50rem;
}

@media print {
  #printContainer.print-image-ready #printMapContainer {
    display: none !important;
  }

  #printContainer.print-image-ready .print-map-image {
    display: block;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-map-image svg {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* Sweden and Germany are taller than they are wide, so their print map fills the whole first page under the heading
   (the answer lines start on the next page). */
@media print {
  .dataset-sweden #printMapContainer,
  .dataset-germany #printMapContainer {
    height: calc(100vh - 110px) !important;
  }
}

/* Maximize button on the maps: the maps take (almost) the whole window width and height,
   while the controls around them stay below the map and keep working. */
.map-maximize-control a.map-maximize-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

body.maps-maximized header .px-3,
body.maps-maximized main.container {
  max-width: none;
  padding-left: 8px;
  padding-right: 8px;
}

body.maps-maximized .explore-section {
  max-width: none;
}

body.maps-maximized header .lead {
  display: none;
}

body.maps-maximized .explore-map {
  height: calc(100vh - 110px);
  min-height: 300px;
}

body.maps-maximized #quizColumn {
  flex: 0 0 100%;
  max-width: 100%;
}

/* Leave room under the quiz map for the question heading and the answer buttons. */
body.maps-maximized #map-container {
  height: calc(100vh - 290px);
  min-height: 300px;
}

body.maps-maximized #printMapContainer {
  height: calc(100vh - 120px);
  min-height: 300px;
}

body.maps-maximized #quiz-view .card-body {
  padding: 8px;
}

@media print {
  body.maps-maximized #quizColumn {
    max-width: 100%;
  }
}

/* Quiz history: repeat button first on each row, best three results of the same quiz last. */
.history-repeat-btn {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.history-top {
  text-align: center;
  color: #6c757d;
  white-space: nowrap;
}

@media (max-width: 576px) {
  .history-repeat-btn span {
    display: none;
  }
}

/* Sweden is tall and narrow, so its explore map is taller than the world map. */
.dataset-sweden .explore-map {
  height: 560px;
}

@media (max-width: 576px) {
  .dataset-sweden .explore-map {
    height: 460px;
  }
}

/* The USA (with Alaska and Hawaii) needs more room than the world map to keep small states clickable. */
.dataset-usa .explore-map {
  height: 520px;
}

@media (max-width: 576px) {
  .dataset-usa .explore-map {
    height: 420px;
  }
}

/* Germany is taller than it is wide and has small city-states, so its explore map is taller too. */
.dataset-germany .explore-map {
  height: 560px;
}

@media (max-width: 576px) {
  .dataset-germany .explore-map {
    height: 460px;
  }
}

/* Print button on the explore map. The printout is a separate map (#explorePrintMap, made by js/app.js)
   with the printable size of the paper, kept off screen and printed on its own; the explore map itself
   is never resized. The chosen names and symbols are drawn on the print map. */
.map-print-control a.map-print-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

.explore-print-map {
  position: fixed;
  left: -10000px;
  top: 0;
  background: #fff;
}

/* At print time the tiles must be fully drawn, not fading in. */
.explore-print-map .leaflet-tile {
  opacity: 1 !important;
  transition: none !important;
}

.explore-print-label span {
  position: absolute;
  left: 0;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font: 600 10px/1.15 "Segoe UI", Arial, sans-serif;
  color: #212529;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff;
  pointer-events: none;
}

.explore-print-area span {
  font-weight: 700;
}

/* The world map has many small countries, so its texts are smaller. */
body:not([class*="dataset-"]) .explore-print-label span {
  font-size: 7px;
}

.explore-print-below span {
  font-weight: 500;
  font-style: italic;
}

/* Flags and coats of arms stand just above the area name. */
.explore-print-symbol span {
  transform: translate(-50%, -100%);
  margin-top: -6px;
}

.explore-print-symbol img {
  display: block;
  height: 18px;
  width: auto;
}

body:not([class*="dataset-"]) .explore-print-symbol img {
  height: 9px;
  outline: 0.5px solid #adb5bd;
}

/* Places (residensstäder, capitals, mountains, lakes, rivers): a mark with the name to its right. */
.explore-print-city span,
.explore-print-mountain span,
.explore-print-lake span,
.explore-print-river span {
  transform: translate(6px, -50%);
}

.explore-print-city span::before,
.explore-print-lake span::before,
.explore-print-river span::before {
  content: "";
  position: absolute;
  left: -9px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  border: 1px solid #fff;
  background: #212529;
}

.explore-print-mountain span::before {
  content: "\25B2";
  position: absolute;
  left: -11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 8px;
  color: #7a4b1c;
}

.explore-print-mountain span {
  color: #5c3a16;
}

.explore-print-lake span,
.explore-print-river span {
  color: #0b4f8a;
  font-style: italic;
}

.explore-print-lake span::before {
  background: #1c7ed6;
}

.explore-print-river span::before {
  border-radius: 1px;
  height: 3px;
  margin-top: -1.5px;
  background: #1c7ed6;
}

@media print {
  body.explore-printing > :not(#explorePrintMap) {
    display: none !important;
  }

  /* The map attribution (OpenStreetMap, CARTO, border sources) stays on the printout. */
  body.explore-printing #explorePrintMap .leaflet-control-container {
    display: block !important;
  }

  body.explore-printing {
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Fixed at the top of the page and out of the flow, so the printout is always exactly one page. */
  body.explore-printing #explorePrintMap {
    position: fixed;
    left: 0;
    top: 0;
    margin: 0;
    break-inside: avoid;
    page-break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* Printouts page (printouts.html): one card per map page with print links and ready-made PDFs. */
.printouts-intro {
  max-width: 720px;
  font-size: 1.05rem;
}

.printout-sheet-row {
  margin-bottom: 0.35rem;
  line-height: 1.6;
}

/* City fact cards on the explore map (capitals and large cities). */
.city-card .city-capital-of {
  font-size: 0.85rem;
  font-style: italic;
  color: #6c757d;
}
