:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1e23;
  --text-muted: #5b6270;
  --border: #dde1e6;
  --accent: #2f6fed;
  --button-bg: #2a63d8;
  --button-text: #ffffff;
  --danger-bg: #c73e29;
  --shadow: rgba(20, 24, 33, 0.08);
  --map-ocean: #4d9bdc;
  --map-fill: #fbfcfd;
  --map-stroke: #5f6b7a;
  --map-nodata: #e4e7eb;
  --map-highlight: #e8590c;
  --map-hover: var(--map-highlight);
  --map-atmosphere: #8cc8f5;
  --globe-ocean: #5eadeb;
  --globe-backdrop: #dbe7f1;
  --grain-opacity: 0.025;
}

:root.dark {
  color-scheme: dark;
  --bg: #12141c;
  --surface: #1e2126;
  --text: #eef0f3;
  --text-muted: #9aa2ad;
  --border: #2c3038;
  --accent: #6fa1ff;
  --button-bg: #2f6fed;
  --shadow: rgba(0, 0, 0, 0.4);
  --map-ocean: #123a63;
  --map-fill: #9db4cb;
  --map-stroke: #0b1d30;
  --map-nodata: #6f8296;
  --map-highlight: #ffb02e;
  --map-hover: var(--map-highlight);
  --map-atmosphere: #3f86c9;
  --globe-ocean: #1d5a99;
  --globe-backdrop: #090e17;
  --grain-opacity: 0.07;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --content-max: 1100px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 240px 240px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  /* Align the header's contents with <main>'s column on wide screens. */
  padding: 1.5rem max(1.5rem, calc((100% - var(--content-max)) / 2 + 1.5rem));
  border-bottom: 1px solid var(--border);
}

.app-header-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.app-header h1 {
  font-size: 1.375rem;
  margin: 0;
}

.app-subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.browse-link,
.fact-card .full-page-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.browse-link {
  align-self: flex-start;
  margin-top: 0.15rem;
}

.fact-card .full-page-link {
  display: inline-block;
  margin-top: 1rem;
}

.browse-link:hover,
.fact-card .full-page-link:hover {
  text-decoration: underline;
}

#dark-mode-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

#dark-mode-toggle:hover {
  transform: scale(1.05);
}

main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.section-nav {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  width: 100%;
  max-width: 420px;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border);
}

.section-nav button {
  position: relative;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 500;
  padding: 0 0 0.75rem;
  cursor: pointer;
  transition: color 0.15s ease;
}

.section-nav button:hover {
  color: var(--text);
}

.section-nav button.active {
  color: var(--accent);
}

.section-nav button.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
}

.segmented-control {
  display: inline-flex;
  gap: 0.15rem;
  margin-bottom: 1.75rem;
  padding: 0.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
}

.segmented-control button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.4rem 1.1rem;
  border-radius: 0.4rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.segmented-control button:hover {
  color: var(--text);
}

.segmented-control button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px var(--shadow);
}

.explore-section,
.quiz-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.explore-layout,
.explore-picker,
.fact-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fact-placeholder {
  display: none;
}

.search-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.map-section {
  width: 100%;
}

.map-container {
  position: relative;
  width: 100%;
  aspect-ratio: 360 / 174;
  background: var(--map-ocean);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px var(--shadow);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.map-container svg,
.map-container canvas {
  -webkit-user-select: none;
  user-select: none;
}

.map-container.dragging {
  cursor: grabbing;
}

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

.map-container path.country {
  fill: var(--map-fill);
  stroke: var(--map-stroke);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
  transition: fill 0.1s ease;
}

.map-container path.country:not(.no-code) {
  cursor: pointer;
}

.map-container path.country.hovered {
  fill: var(--map-hover);
}

.map-container path.country.no-code {
  fill: var(--map-nodata);
  pointer-events: none;
}

.map-container circle.hit-target {
  fill: transparent;
  cursor: pointer;
}

/* A country too small to see gets a dot; the pointer picks it by proximity
   (see updateTinyTargets), so the circle itself takes no events. */
.map-container circle.hit-target.tiny {
  fill: var(--map-fill);
  stroke: var(--map-stroke);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.map-container svg.snapping {
  cursor: pointer;
}

/* While a tiny country's dot is picked, the country drawn under it is not. */
.map-container svg.snapping path.country.hovered:not(.selected) {
  fill: var(--map-fill);
}

.map-container path.country.selected {
  fill: var(--map-highlight);
}

.map-container circle.hit-target.selected,
.map-container circle.hit-target.active {
  fill: var(--map-hover);
  opacity: 0.85;
}

/* Pulsing ring on a small selected country, like the globe's */
.map-container circle.select-ring {
  fill: none;
  stroke: var(--map-highlight);
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: map-select-pulse 1.4s ease-out infinite;
}

@keyframes map-select-pulse {
  from {
    transform: scale(0.2);
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
  to {
    transform: scale(1);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .map-container circle.select-ring {
    animation: none;
    opacity: 0.8;
  }
}

.map-controls {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 5;
}

.map-controls button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 0.4rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px var(--shadow);
}

.map-controls button:hover {
  background: var(--button-bg);
  color: var(--button-text);
}

.map-hint {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.globe-section {
  width: 100%;
}

.globe-container {
  cursor: grab;
  /* Space behind the globe: kept distinct from the ocean so the ball reads as a ball. */
  background: var(--globe-backdrop);
}

/* Panels are sized from the window height so header + tabs + panel + hint fit
   without scrolling. --panel-chrome is roughly everything else on screen. */
:root {
  --panel-chrome: 330px;
  --panel-max-height: max(240px, calc(100vh - var(--panel-chrome)));
}

@supports (height: 100dvh) {
  :root {
    --panel-max-height: max(240px, calc(100dvh - var(--panel-chrome)));
  }
}

#globe-container {
  aspect-ratio: auto;
  height: min(var(--panel-max-height), 780px);
}

#map-container {
  /* keep the map's 360:174 shape, shrinking its width when height is short */
  width: min(100%, calc(var(--panel-max-height) * 360 / 174));
  margin: 0 auto;
}

.globe-container:active {
  cursor: grabbing;
}

.globe-container canvas {
  outline: none;
}

/* globe.gl's built-in hover label, restyled to match .map-tooltip */
#globe-container .float-tooltip-kap {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem !important;
  border-radius: 0.4rem !important;
  font: 0.8rem -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
  box-shadow: 0 4px 12px var(--shadow);
}

.map-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  border-radius: 0.4rem;
  font-size: 0.8rem;
  white-space: nowrap;
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 10;
}

.search-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

#country-input {
  width: 100%;
  max-width: 420px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
}

#country-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.status {
  min-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.status.error {
  color: #e0553f;
}

.fact-card {
  width: 100%;
  max-width: 420px;
  margin-top: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px var(--shadow);
  overflow: hidden;
}

.fact-card .card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 1.75rem;
  border-bottom: 1px solid var(--border);
}

.fact-card img.flag {
  width: 4rem;
  height: 2.67rem;
  flex-shrink: 0;
  display: block;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 0.2rem;
  background: var(--map-nodata);
}

.fact-card .card-body {
  padding: 1.75rem;
}

.fact-card h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
}

.fact-card .native-name {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.fact-card .parent-note {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.fact-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  row-gap: 1.25rem;
  column-gap: 1.5rem;
}

.fact-card .stat {
  min-width: 0;
}

.fact-card dt,
.fact-card .borders-section h3 {
  margin: 0 0 0.3rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.fact-card dd {
  margin: 0;
  font-weight: 400;
  color: var(--text);
  overflow-wrap: anywhere;
}

.fact-card .stat-note {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.fact-card .borders-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.fact-card .borders-section h3 {
  margin-bottom: 0.6rem;
}

.fact-card .borders-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.fact-card .border-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.3rem 0.75rem;
  margin: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.fact-card .border-chip .chip-via {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.fact-card .border-chip:hover .chip-via {
  color: inherit;
}

.fact-card .border-chip:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.fact-card .overview {
  margin: 1.75rem 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.quiz-mode-select {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.quiz-mode-select h2 {
  margin: 0 0 1.25rem;
  font-size: 1.1rem;
}

.quiz-mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.quiz-mode-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-align: left;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px var(--shadow);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.quiz-mode-btn:hover {
  border-color: var(--accent);
}

.quiz-mode-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.quiz-mode-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.quiz-mode-select .status {
  margin-top: 1rem;
}

.quiz-region-select {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.quiz-region-select h2 {
  margin: 0 0 1.25rem;
  font-size: 1.1rem;
}

.quiz-region-select .quiz-mode-buttons {
  margin-bottom: 1rem;
}

.quiz-region-btn {
  align-items: center;
  text-align: center;
}

.quiz-back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem;
}

.quiz-back-btn:hover {
  text-decoration: underline;
}

.quiz-question,
.quiz-geo-question,
.quiz-score-screen {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px var(--shadow);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Geography quiz mode gets a wider card than the other quiz modes so small
   island countries have more on-screen room to see and zoom into. */
.quiz-geo-question {
  max-width: 760px;
  padding: 1rem 1.25rem;
  gap: 0.75rem;
}

/* A shorter map so the question, country input and its feedback fit on a
   laptop screen; height follows the window (--quiz-chrome ≈ everything else). */
.quiz-geo-globe-container {
  --quiz-chrome: 540px;
  aspect-ratio: auto;
  height: clamp(150px, calc(100vh - var(--quiz-chrome)), 340px);
}

@supports (height: 100dvh) {
  .quiz-geo-globe-container {
    height: clamp(150px, calc(100dvh - var(--quiz-chrome)), 340px);
  }
}

.quiz-geo-answer-row .status {
  min-height: 0;
}

.quiz-geo-answer-row .status:empty {
  display: none;
}

.quiz-geo-answer-row .quiz-feedback {
  text-align: left;
}

.quiz-progress {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.quiz-progress--geo {
  max-width: 760px;
}

.quiz-progress-info {
  display: flex;
  gap: 0.75rem;
}

.quiz-exit-btn {
  flex-shrink: 0;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.quiz-exit-btn:hover {
  border-color: #e0553f;
  color: #e0553f;
}

.quiz-prompt {
  text-align: center;
}

.quiz-flag {
  display: block;
  width: 100%;
  max-width: 220px;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  background: var(--map-nodata);
}

.quiz-prompt-text {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

.quiz-geo-instruction {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  color: var(--text);
}

.quiz-geo-answer-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.quiz-geo-answer-row label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.quiz-guess-input {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--text);
}

.quiz-guess-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.quiz-guess-input:disabled {
  opacity: 0.65;
}

.quiz-bonus-row {
  padding: 0.75rem 0.9rem;
  background: rgba(47, 111, 237, 0.08);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.quiz-bonus-label {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.quiz-option-btn {
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.quiz-option-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.quiz-option-btn:disabled {
  cursor: default;
}

.quiz-option-btn.correct {
  border-color: #2f9e58;
  background: rgba(47, 158, 88, 0.12);
}

.quiz-option-btn.wrong {
  border-color: #e0553f;
  background: rgba(224, 85, 63, 0.12);
}

.quiz-feedback {
  margin: 0;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
}

.quiz-feedback.correct {
  color: #2f9e58;
}

.quiz-feedback.wrong {
  color: #e0553f;
}

.quiz-btn-primary {
  align-self: center;
  padding: 0.7rem 1.5rem;
  font-size: 0.95rem;
  color: var(--button-text);
  background: var(--button-bg);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.quiz-btn-primary:hover {
  opacity: 0.9;
}

.quiz-btn-secondary {
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.quiz-btn-secondary:hover {
  border-color: var(--accent);
}

.quiz-btn-danger {
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  color: var(--button-text);
  background: var(--danger-bg);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.quiz-btn-danger:hover {
  opacity: 0.9;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-dialog {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  box-shadow: 0 8px 24px var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-dialog h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

.modal-dialog p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.modal-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.quiz-score-screen {
  align-items: center;
  text-align: center;
}

.quiz-score-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#quiz-final-score {
  margin: 0;
  font-size: 2.25rem;
  color: var(--text);
}

.site-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.site-footer p {
  margin: 0.25rem 0;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer .data-credits {
  max-width: 44rem;
  margin-inline: auto;
  line-height: 1.6;
}

/* Phone-only shortcut back up to the map/globe picker. */
.fact-card .back-to-map {
  display: none;
  margin: 0.9rem 0 0 1.5rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}

@media (max-width: 700px) {
  .fact-card .back-to-map {
    display: inline-block;
  }
}

/* Side-by-side Explore: picker on the left, fact card in its own scrolling
   panel on the right. Below this width the card stacks under the picker. */
@media (min-width: 1024px) {
  :root {
    --content-max: 1280px;
    /* roughly the header + tabs above the panel, so it ends at the window bottom */
    --fact-panel-top: 13rem;
  }

  .explore-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 2rem;
    align-items: start;
  }

  .fact-panel {
    align-items: stretch;
    position: sticky;
    top: 1rem;
    max-height: max(22rem, calc(100vh - var(--fact-panel-top) - 1rem));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  @supports (height: 100dvh) {
    .fact-panel {
      max-height: max(22rem, calc(100dvh - var(--fact-panel-top) - 1rem));
    }
  }

  .fact-panel .fact-card {
    max-width: none;
    margin-top: 0;
    flex-shrink: 0;
  }

  .fact-card:not([hidden]) + .fact-placeholder {
    display: none;
  }

  .fact-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 16rem;
    margin: 0;
    padding: 2rem 1.5rem;
    border: 1px dashed var(--border);
    border-radius: 0.5rem;
    color: var(--text-muted);
    font-size: 1.05rem;
    text-align: center;
  }

  .fact-placeholder span {
    font-size: 0.85rem;
  }
}

/* "Did you mean…" buttons in the search status line */
.status-choice {
  margin: 0 0.35rem 0 0;
  padding: 0.1rem 0.6rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.status-choice:hover,
.status-choice:focus-visible {
  text-decoration: underline;
}

/* Dot on an island too small to see (fixed pixel size, round from any angle) */
.geo-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--map-highlight);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

/* Circle around a small target country on the quiz globe (fixed pixel size) */
.geo-marker {
  border: 3px solid var(--map-highlight);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75);
  pointer-events: none;
  transition: opacity 0.2s;
}

.quiz-suggestions {
  position: fixed;
  z-index: 1000;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.quiz-suggestions[hidden] {
  display: none;
}

.quiz-suggestions li {
  padding: 0.2rem 0.6rem;
  border-radius: 0.3rem;
  font-size: 0.9rem;
  line-height: 1.3;
  color: var(--text);
  cursor: pointer;
}

.quiz-suggestions li:hover,
.quiz-suggestions li.active {
  background: rgba(47, 111, 237, 0.15);
}

/* Phone suggestion row: single swipeable line of buttons under the answer box */
.suggestion-strip {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  justify-content: flex-start;
  gap: 0.4rem;
  margin-top: 0.1rem;
  padding: 0.3rem 0.15rem 0.35rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.suggestion-strip::-webkit-scrollbar {
  display: none;
}

.suggestion-strip[hidden] {
  display: none;
}

.suggestion-strip button {
  flex: 0 0 auto;
  padding: 0.45rem 0.8rem;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}

.suggestion-strip button:active {
  background: rgba(47, 111, 237, 0.15);
}

/* Soft fade at the right edge while more buttons are off-screen */
.suggestion-strip.has-more {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 2.5rem), transparent);
}

/* Touch never hovers: hide the globe's hover label while a finger is driving */
.globe-container.touch-input .float-tooltip-kap {
  display: none !important;
}

/* Landscape phone, Quiz tab: the question sits beside its globe or flag so the
   whole question fits on one screen without scrolling. Left: globe, flag or
   question text. Right: answer box or buttons, feedback and Next. Same
   condition as landscapePhoneQuery in app.js; portrait and laptop are untouched. */
@media (pointer: coarse) and (max-height: 500px) {
  .quiz-section {
    --lp-height: 100vh;
  }

  @supports (height: 100svh) {
    .quiz-section {
      --lp-height: 100svh;
    }
  }

  /* Enough page below the card that it can always be scrolled to the top. */
  .quiz-section:has(#quiz-progress-bar:not([hidden])) {
    min-height: var(--lp-height);
  }

  .quiz-progress,
  .quiz-progress--geo {
    max-width: none;
    margin-bottom: 0.35rem;
  }

  .quiz-question,
  .quiz-geo-question {
    max-width: none;
    display: grid;
    grid-template-rows: auto auto auto 1fr;
    column-gap: 1.25rem;
    row-gap: 0;
    padding: 0.5rem 0.9rem;
  }

  .quiz-question {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  }

  .quiz-question > * {
    grid-column: 2;
    align-self: start;
  }

  .quiz-question > .quiz-prompt {
    grid-column: 1;
    grid-row: 1 / 5;
    align-self: center;
  }

  .quiz-question > .quiz-options {
    grid-row: 1;
    gap: 0.35rem;
  }

  .quiz-question > .quiz-feedback {
    grid-row: 2;
    margin: 0.4rem 0 0;
    text-align: left;
  }

  .quiz-question > .quiz-btn-primary {
    grid-row: 3;
    justify-self: start;
    margin-top: 0.4rem;
  }

  .quiz-option-btn {
    padding: 0.45rem 0.8rem;
    font-size: 0.9rem;
  }

  .quiz-flag {
    max-width: none;
  }

  .quiz-prompt-text {
    font-size: 1.15rem;
  }

  /* Geography: the globe takes the full height the screen allows. */
  .quiz-geo-question {
    grid-template-columns: min(calc(var(--lp-height) - 3.9rem), calc(100% - 20rem)) minmax(0, 1fr);
  }

  .quiz-geo-question > * {
    grid-column: 2;
    align-self: start;
  }

  .quiz-geo-question > .quiz-geo-globe-container {
    grid-column: 1;
    grid-row: 1 / 5;
    align-self: center;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }

  .quiz-geo-question > .quiz-geo-instruction {
    grid-row: 1;
    text-align: left;
    font-size: 0.95rem;
    margin-bottom: 0.4rem;
  }

  .quiz-geo-question > .quiz-geo-answer-row:not(.quiz-bonus-row) {
    grid-row: 2;
  }

  .quiz-geo-question > .quiz-bonus-row {
    grid-row: 3;
    margin-top: 0.4rem;
    padding: 0.4rem 0.6rem;
  }

  .quiz-geo-question > .quiz-btn-primary {
    grid-row: 4;
    justify-self: start;
    margin-top: 0.4rem;
  }

  .quiz-geo-answer-row {
    gap: 0.25rem;
  }

  .quiz-guess-input {
    padding: 0.45rem 0.7rem;
  }

  .quiz-bonus-label {
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
  }
}
