/* Reset and base */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: #111827;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Dark mode */
body.dark-mode {
  background: #111827;
  color: #f9fafb;
}

/* Desktop: overflow hidden to prevent scrolling */
@media (min-width: 600px) {
  body {
    overflow: hidden;
  }
}

/* Header */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  transition: all 0.3s ease;
  padding-bottom: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
body.dark-mode .app-header {
  background: #1f2937;
  border-bottom-color: #374151;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.app-header.collapsed {
  padding-bottom: 0;
  box-shadow: none;
}
.app-header.collapsed #headerControls {
  display: none;
}
/* Stable top row: title | progress (collapsed only) | auth (always right) */
.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  min-height: 44px;
}
.header-title h1 {
  flex-shrink: 0;
}
.collapsed-content {
  display: none;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  justify-content: center;
}
.app-header.collapsed .collapsed-content {
  display: flex;
}
.collapsed-progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.collapsed-progress-bar {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  background: #e5e7eb;
  width: 200px;
  max-width: 100%;
}
.collapsed-actions {
  display: none;
}
.app-header.collapsed .collapsed-actions {
  display: flex;
  gap: 8px;
}
.collapsed-actions button {
  padding: 6px 16px;
  font-size: 13px;
}
.lang-switch {
  display: inline-flex;
  gap: 2px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 2px;
  background: #fff;
  vertical-align: middle;
}
.lang-btn {
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
.lang-btn:hover {
  color: #111827;
  background: #f3f4f6;
}
.lang-btn.active {
  background: #2563eb;
  color: #fff;
}
body.dark-mode .lang-switch {
  background: #111827;
  border-color: #374151;
}
body.dark-mode .lang-btn {
  color: #9ca3af;
}
body.dark-mode .lang-btn:hover {
  color: #f3f4f6;
  background: #1f2937;
}
body.dark-mode .lang-btn.active {
  background: #2563eb;
  color: #fff;
}

.auth-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
  margin-left: auto; /* pin top-right; does not shift when progress shows/hides */
  flex-shrink: 0;
}
.auth-status-text {
  color: #6b7280;
}
body.dark-mode .auth-status-text {
  color: #9ca3af;
}
.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}
.controls {
  display: grid;
  grid-template-columns: minmax(180px, 220px) auto auto auto 1fr auto;
  gap: 12px 16px;
  padding: 0 20px 12px 20px;
  align-items: start;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.control-group select {
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: #111827;
  transition: all 0.2s ease;
}
.control-group select:hover {
  border-color: #9ca3af;
}
.control-group select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
body.dark-mode .control-group select {
  background: #374151;
  border-color: #4b5563;
  color: #f9fafb;
}
body.dark-mode .control-group select:hover {
  border-color: #6b7280;
}
body.dark-mode .control-group select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}
.control-group select option {
  padding: 4px;
}
body.dark-mode .control-group select option {
  background: #374151;
  color: #f9fafb;
}
.control-group.right-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.action-buttons {
  display: flex;
  gap: 8px;
}
.progress-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}
.progress-buttons button {
  white-space: nowrap;
  font-size: 12px;
  padding: 6px 10px;
}
label { font-weight: 600; font-size: 13px; color: #374151; }
body.dark-mode label { color: #d1d5db; }
.hint { color: #6b7280; font-size: 11px; margin-top: -2px; }
body.dark-mode .hint { color: #9ca3af; }

.mode { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.checkbox { display: flex; gap: 6px; align-items: center; font-weight: 500; font-size: 12px; }

/* Buttons */
button {
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f3f4f6;
  color: #111827;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}
body.dark-mode button {
  background: #374151;
  color: #f9fafb;
}
button.primary {
  background: #2563eb;
  color: white;
}
button.secondary {
  background: #10b981;
  color: white;
}
button.ghost {
  background: transparent;
  border-color: #e5e7eb;
  color: #374151;
}
body.dark-mode button.ghost {
  border-color: #4b5563;
  color: #d1d5db;
}
button:hover { filter: brightness(0.98); }
body.dark-mode button:hover { filter: brightness(1.2); }
button:active { transform: translateY(1px); }
button.small { padding: 4px 8px; font-size: 12px; border-radius: 6px; }

/* Stats */
.stats { font-size: 12px; color: #374151; display: flex; flex-direction: column; gap: 2px; }
body.dark-mode .stats { color: #d1d5db; }

/* Overall progress bar */
.control-group.overall-progress {
  gap: 6px;
}
.progress-bar {
  display: flex;
  width: 100%;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  background: #e5e7eb;
}
.progress-segment {
  height: 100%;
  transition: width 0.3s ease;
}
.progress-correct {
  background: #10b981;
}
.progress-wrong {
  background: #ef4444;
}
.progress-unseen {
  background: #9ca3af;
}
.progress-legend {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: #374151;
  flex-wrap: wrap;
}
body.dark-mode .progress-legend {
  color: #d1d5db;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.legend-color {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.legend-color.correct {
  background: #10b981;
}
.legend-color.wrong {
  background: #ef4444;
}
.legend-color.unseen {
  background: #9ca3af;
}

/* Main layout */
.app-main {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  padding: 16px 20px;
  /* Fill entire viewport - header overlaps */
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding-top: 60px; /* Space for collapsed header */
}
.flag-panel, .map-panel {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}
.flag-panel {
  position: relative;
}
body.dark-mode .flag-panel,
body.dark-mode .map-panel {
  background: #1f2937;
  border-color: #374151;
}

/* Flag card */
.flag-card {
  padding: 40px 16px 32px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  border-bottom: 1px solid #f3f4f6;
}
.flag-card img {
  max-width: 100%;
  max-height: 280px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  cursor: zoom-in;
}
.flag-card img:not([src]) {
  cursor: default;
}

/* Flag zoom lightbox */
.flag-zoom-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(0, 0, 0, 0.88);
  align-items: center;
  justify-content: center;
  padding: 48px 24px 24px;
  cursor: zoom-out;
}
.flag-zoom-overlay.show {
  display: flex;
}
.flag-zoom-overlay img {
  /* Force a large box — flag assets are often only ~320px; without this they stay tiny */
  width: min(92vw, 1100px);
  height: min(78vh, 720px);
  max-width: 92vw;
  max-height: 78vh;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: #f9fafb;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  cursor: default;
  object-fit: contain;
  object-position: center;
  image-rendering: auto;
}
.flag-zoom-close {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 10002;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #f9fafb;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}
.flag-zoom-close:hover {
  background: rgba(255, 255, 255, 0.22);
}
body.flag-zoom-open {
  overflow: hidden;
}
.flag-meta {
  padding: 12px 16px;
  font-size: 13px;
  color: #4b5563;
}
body.dark-mode .flag-meta {
  color: #9ca3af;
}
.dont-know-container {
  padding: 12px 16px 12px 16px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
#multipleChoiceBtn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#multipleChoiceBtn.disabled:hover {
  filter: none;
}
.multiple-choice-options {
  padding: 8px 16px;
  display: none;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  /* Reserve space for 4 options to prevent layout shift */
  min-height: 200px;
  transition: min-height 0.2s ease;
}
.multiple-choice-options:not([style*="display: flex"]) {
  padding: 0;
  min-height: 0;
}
.multiple-choice-option {
  padding: 12px 16px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #111827;
  cursor: pointer;
  font-weight: 500;
  text-align: center;
  transition: all 0.2s ease;
}
body.dark-mode .multiple-choice-option {
  background: #374151;
  border-color: #4b5563;
  color: #f9fafb;
}
.multiple-choice-option:hover {
  background: #e5e7eb;
  border-color: #d1d5db;
}
body.dark-mode .multiple-choice-option:hover {
  background: #4b5563;
  border-color: #6b7280;
}
.multiple-choice-option:disabled {
  opacity: 0.3;
  cursor: not-allowed !important;
  text-decoration: line-through;
  background: #f9fafb;
  pointer-events: none;
}
body.dark-mode .multiple-choice-option:disabled {
  background: #1f2937;
}

/* Toast */
.toast {
  margin: 12px 16px 16px;
  padding: 8px 12px;
  background: #111827;
  color: #f9fafb;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(6px);
  transition: all 240ms ease;
  pointer-events: none;
  font-weight: 600;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success {
  background: #10b981;
  color: white;
}
.toast.error {
  background: #ef4444;
  color: white;
}
.toast.info {
  background: #3b82f6;
  color: white;
}
body.dark-mode .toast.success {
  background: #059669;
}
body.dark-mode .toast.error {
  background: #dc2626;
}
body.dark-mode .toast.info {
  background: #2563eb;
}

/* Map panel */
#map {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}
.map-panel { position: relative; min-height: 0; }

/* Solid ocean basemap (no OSM tiles) */
.leaflet-container {
  background: #7eb8d9;
}
body.dark-mode .leaflet-container {
  background: #0c4a6e;
}
.flag-panel { min-height: 0; }
.map-legend {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(255,255,255,0.95);
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 6px 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: #374151;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}
body.dark-mode .map-legend {
  background: rgba(31,41,55,0.95);
  border-color: #4b5563;
  color: #d1d5db;
}
.legend-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend-toggle-label {
  font-weight: 600;
  font-size: 11px;
  white-space: nowrap;
}
.legend-divider {
  width: 1px;
  height: 20px;
  background: #d1d5db;
}
.legend-items {
  display: flex;
  gap: 6px;
  align-items: center;
}
.leg { display: inline-flex; gap: 4px; align-items: center; font-size: 11px; }
.chip {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid #d1d5db;
  margin-right: 3px;
}
.chip-neutral { background: #e5e7eb; }
.chip-correct { background: #10b981; border-color: #059669; }
.chip-wrong { background: #ef4444; border-color: #dc2626; }
.chip-hover { background: #6366f1; border-color: #4f46e5; } /* Indigo for hover */
.chip-focus { background: #3b82f6; border-color: #1d4ed8; }

/* Hand-drawn quiz map (handmap.js). Atlas look in light mode, night look in
   dark mode; the SVG only references these tokens. */
#map.handmap {
  --hm-ocean: #d3e3e3; --hm-ripple: #a9c3c7; --hm-sea-label: #6d8d94;
  --hm-t0: #f1e0bb; --hm-t1: #e2d6ad; --hm-t2: #dce3bf; --hm-t3: #eed3c0; --hm-t4: #e2d9c6;
  --hm-coast: #6f5e48; --hm-border: #8f7f66; --hm-coast-w: 1.15px; --hm-border-w: 0.85px;
  --hm-hover: #e3a857; --hm-correct: #7fae6a; --hm-wrong: #cf5a4e; --hm-focus: #4f86c6;
  --hm-disabled: #cfc6b5;
  --hm-shadow: rgba(80, 60, 30, 0.22);
  --hm-label-font: Georgia, "Times New Roman", serif;
  position: relative;
  overflow: hidden;
  background: var(--hm-ocean);
  box-shadow: inset 0 0 90px rgba(90, 70, 40, 0.22);
}
body.dark-mode #map.handmap {
  --hm-ocean: #0d1b2a; --hm-ripple: #1f3a5a; --hm-sea-label: #4b6f96;
  --hm-t0: #34466a; --hm-t1: #2f5160; --hm-t2: #4a4068; --hm-t3: #2e4a6e; --hm-t4: #504a3f;
  --hm-coast: #a9c0e2; --hm-border: #7085a8; --hm-coast-w: 1.1px; --hm-border-w: 0.8px;
  --hm-hover: #818cf8; --hm-correct: #34d399; --hm-wrong: #f87171; --hm-focus: #60a5fa;
  --hm-disabled: #1c2638;
  --hm-shadow: rgba(96, 165, 250, 0.16);
  box-shadow: none;
}
/* Paper grain for the atlas look: a static texture over the whole map. */
#map.handmap::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .38 0 0 0 0 .28 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
body.dark-mode #map.handmap::after { opacity: 0; }
/* handmap.js sizes the SVG larger than the panel (overscan) and moves it with
   transforms while panning; its own compositing layer keeps that cheap. */
.handmap-svg {
  position: absolute; display: block; will-change: transform;
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
}
.handmap-svg.hm-dragging { cursor: grabbing; }
.hm-ocean { fill: var(--hm-ocean); }
.hm-ripple-a, .hm-ripple-b, .hm-ripple-c, .hm-ripple-d {
  fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none;
}
.hm-ripple-a { stroke: var(--hm-ripple); stroke-width: 12px; }
.hm-ripple-b { stroke: var(--hm-ocean); stroke-width: 10.9px; }
.hm-ripple-c { stroke: var(--hm-ripple); stroke-width: 6.6px; }
.hm-ripple-d { stroke: var(--hm-ocean); stroke-width: 5.5px; }
.hm-shadow {
  fill: none; stroke: var(--hm-shadow); stroke-width: 3.2px; stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke; pointer-events: none;
}
.hm-country { stroke: none; cursor: pointer; transition: fill 0.12s; }
.hm-country[data-tone="0"] { fill: var(--hm-t0); }
.hm-country[data-tone="1"] { fill: var(--hm-t1); }
.hm-country[data-tone="2"] { fill: var(--hm-t2); }
.hm-country[data-tone="3"] { fill: var(--hm-t3); }
.hm-country[data-tone="4"] { fill: var(--hm-t4); }
.hm-country[data-state="disabled"] { fill: var(--hm-disabled); pointer-events: none; cursor: default; }
.hm-hover-overlay { fill: var(--hm-hover); pointer-events: none; }
.hm-country[data-state="correct"] { fill: var(--hm-correct); }
.hm-country[data-state="wrong"] { fill: var(--hm-wrong); }
.hm-country[data-state="focus"] { fill: var(--hm-focus); }
.hm-lake {
  fill: var(--hm-ocean); stroke: var(--hm-coast); stroke-width: calc(var(--hm-coast-w) * 0.8);
  stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none;
}
.hm-borders, .hm-coastline {
  fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none;
}
.hm-borders { stroke: var(--hm-border); stroke-width: var(--hm-border-w); }
.hm-coastline { stroke: var(--hm-coast); stroke-width: var(--hm-coast-w); }
.hm-sea-label {
  fill: var(--hm-sea-label); font-family: var(--hm-label-font); font-style: italic; letter-spacing: 0.12em;
  text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: var(--hm-ocean);
  stroke-linejoin: round; pointer-events: none; user-select: none;
}
.handmap-tooltip {
  position: absolute; z-index: 2; pointer-events: none; display: none; white-space: nowrap;
  background: #111827; color: #fff; padding: 4px 9px; border-radius: 6px; font-size: 12px;
}
.handmap-tooltip.show { display: block; }
.handmap-controls {
  position: absolute; top: 10px; right: 10px; z-index: 3;
  display: flex; flex-direction: column; gap: 4px;
}
.handmap-controls button {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid rgba(0, 0, 0, 0.15);
  background: rgba(255, 255, 255, 0.92); color: #3f3528; font-size: 18px; line-height: 1;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.handmap-controls button:hover { background: #fff; }
body.dark-mode .handmap-controls button {
  background: rgba(17, 26, 44, 0.92); color: #e2e8f0; border-color: #1e2a40;
}
@media (hover: none) {
  .handmap-tooltip { display: none !important; }
}
/* Legend chips follow the hand map's palette while it is active. */
body.uses-handmap .chip-neutral { background: #f1e0bb; border-color: #b9a888; }
body.uses-handmap .chip-correct { background: #7fae6a; border-color: #5f8a4c; }
body.uses-handmap .chip-wrong { background: #cf5a4e; border-color: #a8443a; }
body.uses-handmap .chip-hover { background: #e3a857; border-color: #b9843c; }
body.uses-handmap .chip-focus { background: #4f86c6; border-color: #3a6aa3; }
body.dark-mode.uses-handmap .chip-neutral { background: #34466a; border-color: #4b6f96; }
body.dark-mode.uses-handmap .chip-correct { background: #34d399; border-color: #059669; }
body.dark-mode.uses-handmap .chip-wrong { background: #f87171; border-color: #dc2626; }
body.dark-mode.uses-handmap .chip-hover { background: #818cf8; border-color: #6366f1; }
body.dark-mode.uses-handmap .chip-focus { background: #60a5fa; border-color: #3b82f6; }

/* Applied on SVG path elements for inactive countries in the current pool filter */
.leaflet-interactive.disabled-country,
path.disabled-country {
  pointer-events: none;
}

/* Kill any leftover map path keyframe classes from older builds / SW cache */
.leaflet-interactive.animate-pulse-green,
.leaflet-interactive.animate-shake-red,
.leaflet-interactive.animate-pulse-focus,
path.animate-pulse-green,
path.animate-shake-red,
path.animate-pulse-focus {
  animation: none !important;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  transition: 0.3s;
  border-radius: 18px;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}
.toggle-switch input:checked + .toggle-slider {
  background-color: #2563eb;
}
.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(14px);
}

/* Leaflet overrides for nicer look */
.leaflet-container { font: inherit; }

/* Vatican label — subtle, like other map place names */
.leaflet-tooltip.vatican-hit-label {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  color: #6b7280;
  font-size: 10px;
  font-weight: 400;
  padding: 0;
  pointer-events: none;
}
.leaflet-tooltip.vatican-hit-label::before {
  display: none;
}
body.dark-mode .leaflet-tooltip.vatican-hit-label {
  background: transparent;
  color: #9ca3af;
}

.leaflet-tooltip.manual-territory-hit-label {
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}
body.dark-mode .leaflet-tooltip.manual-territory-hit-label {
  background: rgba(31, 41, 55, 0.94);
  border-color: #4b5563;
  color: #f3f4f6;
}
/* Smooth fill only — no stroke transition (avoids outline "blink" feel on state change) */
.leaflet-interactive {
  transition: fill 0.2s ease, fill-opacity 0.15s ease;
}
.leaflet-control-zoom a {
  width: 34px;
  height: 34px;
  line-height: 30px;
  font-size: 18px;
  border-radius: 8px;
}
.leaflet-bar a, .leaflet-bar a:hover {
  color: #111827;
  border-color: #e5e7eb;
}

/* History panel */
.history-panel {
  margin: 8px 16px 16px;
  flex-shrink: 0;
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 16px;
}
.history-header h2 {
  font-size: 14px;
  margin: 0;
  color: #111827;
}
body.dark-mode .history-header h2 {
  color: #f9fafb;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px 8px;
  max-height: 180px;
  overflow: auto;
}
.history-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.history-item:hover {
  background: #f9fafb;
}
body.dark-mode .history-item:hover {
  background: #374151;
}
.history-item .icon {
  width: 22px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}
.history-item.correct .icon {
  color: #059669;
}
.history-item.wrong .icon {
  color: #dc2626;
}
.history-item.gave-up .icon {
  color: #6b7280;
}
body.dark-mode .history-item.gave-up .icon {
  color: #9ca3af;
}
.history-item .label {
  font-size: 13px;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* New labeled layout with flags next to each label */
.history-item .label-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.history-item .label-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.history-item .label-row.correct .text {
  font-weight: 600;
  color: #111827;
}
body.dark-mode .history-item .label-row.correct .text {
  color: #f9fafb;
}
.history-item .label-row.guess .text {
  color: #6b7280;
}
body.dark-mode .history-item .label-row.guess .text {
  color: #9ca3af;
}
.history-item .label-row .text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

/* Flags in history */
.history-item .flags {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.history-item .flag-img.flag-redacted,
.mobile-last-history .flag-img.flag-redacted {
  object-fit: none;
  background: #e5e7eb;
  border: 1px dashed #9ca3af;
  box-shadow: none;
}
body.dark-mode .history-item .flag-img.flag-redacted,
body.dark-mode .mobile-last-history .flag-img.flag-redacted {
  background: #374151;
  border-color: #6b7280;
}
.history-item .flag-img {
  width: 42px;
  height: 28px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  background: #f9fafb;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.history-item .flag-arrow {
  color: #6b7280;
  font-size: 12px;
}

/* Flag hover tooltip */
#flagHoverTooltip {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  background: white;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: none;
  transition: all 0.2s ease;
}
body.dark-mode #flagHoverTooltip {
  background: #1f2937;
  border-color: #4b5563;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
#flagHoverTooltip.show {
  display: block;
}
#flagHoverTooltip img {
  display: block;
  width: 120px;
  height: auto;
  border-radius: 4px;
}

/* History item hover flag preview */
.history-flag-preview {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  background: white;
  border: 2px solid #3b82f6;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  display: none;
  transition: all 0.2s ease;
}
body.dark-mode .history-flag-preview {
  background: #1f2937;
  border-color: #3b82f6;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.history-flag-preview.show {
  display: block;
}
.history-flag-preview img {
  display: block;
  width: 200px;
  height: auto;
  border-radius: 6px;
}
.history-flag-preview .preview-label {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  text-align: center;
}
body.dark-mode .history-flag-preview .preview-label {
  color: #f9fafb;
}

/* Responsive */
/* Tablet: 600-899px */
@media (max-width: 899px) {
  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .control-group.right-controls {
    grid-column: span 2;
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
  }

  .app-main {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .flag-panel {
    order: 1;
  }

  .map-panel {
    order: 2;
    min-height: 400px;
  }

  #map { min-height: 400px; }
}

/* Phone layout is consolidated below. */
/* Mobile controls and dialog styles are defined with the learning-session UI below. */
/* Welcome Modal */
.welcome-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.welcome-content {
  background: white;
  border-radius: 16px;
  padding: 40px;
  max-width: 800px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

body.dark-mode .welcome-content {
  background: #1f2937;
  color: #f9fafb;
}

.welcome-content h2 {
  margin: 0 0 16px 0;
  font-size: 28px;
  text-align: center;
  color: #111827;
}

body.dark-mode .welcome-content h2 {
  color: #f9fafb;
}

.welcome-content > p {
  text-align: center;
  margin: 0 0 32px 0;
  font-size: 16px;
  color: #6b7280;
}

body.dark-mode .welcome-content > p {
  color: #9ca3af;
}

.version-selection {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  .version-selection {
    grid-template-columns: 1fr;
  }
}

.version-card {
  display: flex;
  flex-direction: column;
  border: 2px solid #e5e7eb;
  border-radius: 16px;
  padding: 24px;
  background: #fafafa;
}

body.dark-mode .version-card {
  background: #374151;
  border-color: #4b5563;
}

.version-header {
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

body.dark-mode .version-header {
  border-bottom-color: #4b5563;
}

.version-header h3 {
  margin: 0 0 8px 0;
  font-size: 24px;
  color: #111827;
  font-weight: 600;
}

body.dark-mode .version-header h3 {
  color: #f9fafb;
}

.version-desc {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
}

body.dark-mode .version-desc {
  color: #9ca3af;
}

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-btn {
  background: #ffffff;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  padding: 20px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
}

body.dark-mode .mode-btn {
  background: #1f2937;
  border-color: #4b5563;
}

.mode-btn.primary {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
  text-align: center;
  padding: 24px 16px;
}

body.dark-mode .mode-btn.primary {
  background: #2563eb;
  border-color: #2563eb;
}

.mode-btn:hover {
  border-color: #3b82f6;
  background: #eff6ff;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.2);
}

body.dark-mode .mode-btn:hover {
  background: #4b5563;
  border-color: #60a5fa;
}

.mode-btn.primary:hover {
  background: #2563eb;
  border-color: #2563eb;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3);
}

body.dark-mode .mode-btn.primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.mode-btn h4 {
  margin: 0 0 8px 0;
  font-size: 17px;
  color: #111827;
  font-weight: 600;
}

body.dark-mode .mode-btn h4 {
  color: #f9fafb;
}

.mode-btn.primary h4 {
  color: white;
  font-size: 18px;
}

.mode-btn p {
  margin: 2px 0;
  font-size: 13px;
  color: #6b7280;
  line-height: 1.5;
}

body.dark-mode .mode-btn p {
  color: #9ca3af;
}

.mode-btn.primary p {
  color: rgba(255, 255, 255, 0.9);
}

/* Links to the separate US states mode (/states). */
.mode-switch-link {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.mode-switch-link:hover { background: #dbeafe; }
body.dark-mode .mode-switch-link { background: #1e3a5f; border-color: #1e40af; color: #bfdbfe; }
.welcome-us-link {
  display: block;
  margin-top: 18px;
  text-align: center;
  color: #2563eb;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}
.welcome-us-link:hover { text-decoration: underline; }
body.dark-mode .welcome-us-link { color: #93c5fd; }

.welcome-hint {
  text-align: center;
  font-size: 13px;
  color: #9ca3af;
  margin-top: 24px;
}

/* Account modal */
.account-modal {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.account-modal[hidden] {
  display: none !important;
}
.account-content {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
body.dark-mode .account-content {
  background: #1f2937;
}
.account-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.account-header h2 {
  margin: 0;
  font-size: 18px;
}
.account-info {
  font-size: 14px;
  color: #4b5563;
  margin: 0 0 16px;
}
body.dark-mode .account-info {
  color: #d1d5db;
}
.account-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.account-actions button.danger {
  color: #dc2626;
  border-color: #fecaca;
}
body.dark-mode .account-actions button.danger {
  color: #f87171;
  border-color: #7f1d1d;
}
.account-hint {
  margin: 12px 0 0;
  font-size: 12px;
  color: #9ca3af;
}

/* Auth modal (sign-in / register) */
.auth-modal-content {
  max-width: 400px;
}
.auth-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 16px;
}
.auth-tab {
  flex: 1;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  color: #374151;
}
.auth-tab.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
body.dark-mode .auth-tab {
  background: #111827;
  border-color: #374151;
  color: #e5e7eb;
}
body.dark-mode .auth-tab.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #374151;
}
body.dark-mode .auth-field {
  color: #d1d5db;
}
.auth-field input {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: #111827;
}
body.dark-mode .auth-field input {
  background: #111827;
  border-color: #374151;
  color: #f3f4f6;
}
.auth-form-error {
  margin: 0;
  font-size: 13px;
  color: #dc2626;
}
body.dark-mode .auth-form-error {
  color: #f87171;
}
.auth-submit {
  width: 100%;
  margin-top: 4px;
  text-align: center;
}
.auth-google-section {
  margin-top: 16px;
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: #9ca3af;
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}
body.dark-mode .auth-divider::before,
body.dark-mode .auth-divider::after {
  background: #374151;
}
.auth-google-btn {
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}

body.dark-mode .welcome-hint {
  color: #6b7280;
}

/* Finite learning sessions */
[hidden] { display: none !important; }

:where(button, a, input, select, [tabindex]):focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}

.session-question-view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.session-question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 8px;
  color: #374151;
  font-size: 13px;
  font-weight: 700;
}

body.dark-mode .session-question-header { color: #d1d5db; }

.session-due-label {
  color: #6b7280;
  font-weight: 600;
}

.session-progress-track {
  height: 5px;
  margin: 0 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

body.dark-mode .session-progress-track { background: #374151; }

.session-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #2563eb;
  transition: width 180ms ease;
}

.free-recall-form {
  padding: 12px 16px 4px;
}

.free-recall-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.free-recall-row input {
  min-width: 0;
  flex: 1;
  border: 2px solid #d1d5db;
  border-radius: 9px;
  padding: 11px 12px;
  background: #fff;
  color: #111827;
  font: inherit;
}

body.dark-mode .free-recall-row input {
  border-color: #4b5563;
  background: #111827;
  color: #f9fafb;
}

.text-action {
  display: block;
  margin: 8px auto 0;
  border: 0;
  background: transparent;
  color: #2563eb;
  padding: 6px 8px;
  font-size: 13px;
}

body.dark-mode .text-action { color: #93c5fd; background: transparent; }

.multiple-choice-option.answer-correct {
  border-color: #047857 !important;
  background: #059669 !important;
  color: #fff !important;
  opacity: 1 !important;
  text-decoration: none !important;
}

.multiple-choice-option.answer-selected-wrong {
  border-color: #b91c1c !important;
  background: #dc2626 !important;
  color: #fff !important;
  opacity: 1 !important;
  text-decoration: none !important;
}

.multiple-choice-options.is-answered .multiple-choice-option:not(.answer-correct):not(.answer-selected-wrong) {
  opacity: 0.48;
}

.answer-feedback {
  margin: 12px 16px 16px;
  padding: 16px;
  border: 1px solid #d1d5db;
  border-left: 5px solid #2563eb;
  border-radius: 12px;
  background: #f8fafc;
}

.answer-feedback.feedback-correct { border-left-color: #059669; }
.answer-feedback.feedback-wrong { border-left-color: #dc2626; }

body.dark-mode .answer-feedback {
  border-color: #4b5563;
  background: #111827;
}

.feedback-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.feedback-heading h2 {
  margin: 0;
  font-size: 20px;
}

.feedback-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 20px;
  font-weight: 800;
}

.feedback-correct .feedback-icon { background: #d1fae5; color: #047857; }
.feedback-wrong .feedback-icon { background: #fee2e2; color: #b91c1c; }

.feedback-comparison,
.feedback-region,
.feedback-review {
  margin: 4px 0 0;
  color: #4b5563;
  font-size: 13px;
  line-height: 1.4;
}

body.dark-mode :is(.feedback-comparison, .feedback-region, .feedback-review) { color: #d1d5db; }

.feedback-map-wrap {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(100px, 0.8fr);
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.feedback-map-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #1d4ed8;
  cursor: pointer;
  text-align: left;
}

.feedback-map-button:hover .feedback-mini-map,
.feedback-map-button:focus-visible .feedback-mini-map {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .2);
}

.feedback-map-button:focus-visible { outline: none; }

.feedback-map-hint {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

body.dark-mode .feedback-map-button { color: #93c5fd; }

.feedback-mini-map {
  display: block;
  width: 100%;
  max-height: 112px;
  border: 1px solid #bfdbfe;
  border-radius: 9px;
  background: #dbeafe;
}

body.dark-mode .feedback-mini-map { border-color: #1e3a8a; background: #0c4a6e; }
.feedback-mini-map .world-land { fill: #d1d5db; stroke: #9ca3af; stroke-width: 0.35; }
body.dark-mode .feedback-mini-map .world-land { fill: #475569; stroke: #64748b; }
.feedback-mini-map .target-land { fill: #2563eb; stroke: #1d4ed8; stroke-width: 0.8; }
.feedback-mini-map .target-marker { fill: #f59e0b; stroke: #fff; stroke-width: 1.5; }

.continue-btn {
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
}

.session-recap {
  height: 100%;
  overflow: auto;
  padding: clamp(24px, 6vw, 48px) 24px;
  text-align: center;
}

.recap-eyebrow {
  margin: 0 0 6px;
  color: #2563eb;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.session-recap h2 { margin: 0; font-size: 28px; }
.recap-score { margin: 8px 0 16px; color: #4b5563; font-size: 18px; }
body.dark-mode .recap-score { color: #d1d5db; }

.recap-mastery {
  margin: 0 auto 18px;
  padding: 12px;
  max-width: 360px;
  border-radius: 10px;
  background: #eff6ff;
  color: #1e40af;
  font-weight: 700;
}

body.dark-mode .recap-mastery { background: #1e3a8a; color: #dbeafe; }

.recap-list {
  display: grid;
  gap: 7px;
  max-width: 420px;
  margin: 0 auto 20px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.recap-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

body.dark-mode .recap-list li { border-color: #374151; }
.recap-list img { width: 38px; height: 25px; object-fit: cover; border: 1px solid #d1d5db; border-radius: 3px; }
.recap-list .recap-result { margin-left: auto; font-weight: 800; }
.recap-list .correct .recap-result { color: #047857; }
.recap-list .wrong .recap-result { color: #b91c1c; }

.recap-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.legal-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
}

.legal-links a { color: #6b7280; }
body.dark-mode .legal-links a { color: #9ca3af; }

.play-legal-links {
  position: fixed;
  right: 12px;
  bottom: 5px;
  z-index: 1900;
  opacity: .8;
}

body[data-learning-mode="trainer"] .app-main {
  grid-template-columns: minmax(320px, 680px);
  justify-content: center;
}

body[data-learning-mode="trainer"] .map-panel { display: none; }

body.session-complete .app-main {
  grid-template-columns: minmax(320px, 720px);
  justify-content: center;
}

body.session-complete .map-panel { display: none; }

.mobile-bottom-bar,
.mobile-settings-overlay { display: none; }

.mobile-settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .68);
}

.mobile-settings-overlay.show { display: flex; }

.mobile-settings-content {
  display: flex;
  flex-direction: column;
  width: min(100%, 500px);
  max-height: 90dvh;
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .3);
}

body.dark-mode .mobile-settings-content { background: #1f2937; }

.mobile-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

body.dark-mode .mobile-settings-header { border-bottom-color: #374151; }
.mobile-settings-header h2 { margin: 0; font-size: 20px; }

.mobile-settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.mobile-settings-body .control-group { margin-bottom: 20px; }
.mobile-settings-body .control-group:last-child { margin-bottom: 0; }
.mobile-settings-body button { width: 100%; margin-top: 6px; }
.mobile-auth-controls .account-hint { margin: 0; }

@media (max-width: 768px) {
  body {
    min-height: 100dvh;
    height: auto;
    overflow: auto;
  }

  .app-header { display: none !important; }

  .app-main {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    min-height: 100dvh;
    overflow: visible;
    background: #f3f4f6;
  }

  body.dark-mode .app-main { background: #111827; }

  .flag-panel,
  body[data-mobile-mode="beginner"] .flag-panel {
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
    border-radius: 0;
    border: 0;
    padding: 0 0 72px;
  }

  body[data-mobile-mode="advanced"] .flag-panel {
    min-height: auto;
    max-height: none;
    overflow: visible;
    padding-bottom: 8px;
  }

  .session-question-view { height: auto; min-height: 100%; }

  button { min-height: 44px; }
  button.small { min-height: 38px; }
  select { min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { min-width: 20px; min-height: 20px; }

  .session-question-header { padding: 14px 16px 8px; }

  .flag-card,
  body[data-mobile-mode="beginner"] .flag-card {
    min-height: 150px;
    height: auto;
    padding: 18px 16px 12px;
  }

  .flag-card img,
  body[data-mobile-mode="beginner"] .flag-card img {
    max-height: 160px;
    max-width: min(88vw, 340px);
  }

  .free-recall-form { padding: 10px 16px; }
  .free-recall-row { flex-direction: column; }

  .multiple-choice-options,
  body[data-mobile-mode="beginner"] .multiple-choice-options {
    display: none !important;
    min-height: 0;
    padding: 10px 16px !important;
    gap: 9px !important;
  }

  .multiple-choice-options[style*="display: flex"],
  body[data-mobile-mode="beginner"] .multiple-choice-options[style*="display: flex"] {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .multiple-choice-option {
    min-height: 58px;
    padding: 12px 10px !important;
    border-width: 2px !important;
    background: #fff !important;
    border-color: #d1d5db !important;
    color: #111827 !important;
    font-size: 15px !important;
  }

  body.dark-mode .multiple-choice-option:not(.answer-correct):not(.answer-selected-wrong) {
    background: #1f2937 !important;
    border-color: #4b5563 !important;
    color: #f9fafb !important;
  }

  .dont-know-container,
  body[data-mobile-mode="beginner"] .dont-know-container,
  body[data-mobile-mode="advanced"] .dont-know-container {
    display: flex;
    padding: 8px 16px;
  }

  body[data-mobile-mode="beginner"] #multipleChoiceBtn { display: none !important; }
  #noIdeaBtn { flex: 1; }

  .answer-feedback {
    margin: 10px 16px 20px;
    padding: 14px;
  }

  .feedback-map-wrap { grid-template-columns: minmax(0, 1fr) minmax(90px, .65fr); }
  .feedback-mini-map { max-height: 96px; }

  .history-panel,
  .map-legend { display: none !important; }

  .flag-meta,
  #toast,
  #flagHoverTooltip,
  .history-flag-preview { display: none !important; }

  body[data-mobile-mode="beginner"] .map-panel { display: none !important; }

  body[data-mobile-mode="advanced"] .map-panel {
    display: block;
    min-height: 58dvh;
    max-height: none;
    height: 58dvh;
  }

  body[data-mobile-mode="advanced"] #map { min-height: 58dvh; height: 58dvh; }

  .mobile-bottom-bar,
  body[data-mobile-mode="beginner"] .mobile-bottom-bar {
    position: fixed;
    top: 8px;
    right: 8px;
    bottom: auto;
    left: auto;
    z-index: 3000;
    display: block;
    width: 44px;
    min-height: 44px;
    max-height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .mobile-settings-btn {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
  }

  .mobile-settings-btn .settings-icon { width: 22px; height: 22px; }
  .play-legal-links { display: none; }
  .session-recap { min-height: 100dvh; padding-top: 72px; }

  .mobile-toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    left: 16px;
    z-index: 10000;
    padding: 12px 16px;
    border-radius: 10px;
    background: #1f2937;
    color: #fff;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }
  .mobile-toast.show { opacity: 1; }
  .mobile-toast.success { background: #047857; }
  .mobile-toast.error { background: #b91c1c; }
  .mobile-toast.info { background: #1d4ed8; }
}

@media (max-width: 390px) {
  .multiple-choice-options[style*="display: flex"],
  body[data-mobile-mode="beginner"] .multiple-choice-options[style*="display: flex"] {
    grid-template-columns: 1fr;
  }
  .feedback-map-wrap { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
