/* Reset and base */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* aion44 brand tokens. Light is the default theme. body.dark-mode and the
   app bars (always Mitternacht) switch the same tokens to the dark palette,
   so components only reference tokens. Signalgelb is a fill on light ground
   and only becomes a line/text colour (--signal, --accent-text) on dark. */
:root {
  --night: #0B1020;
  --light: #E9ECF5;
  --dim: #1F2740;
  --yellow: #FFF500;
  --font-display: "Chakra Petch", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";

  --bg: #E9ECF5;
  --surface: #FFFFFF;
  --surface-2: #F3F5FA;
  --surface-3: #E3E7F1;
  --line: #DCE1EC;
  --line-strong: #BCC4D6;
  --text: #0B1020;
  --text-2: #3B4560;
  --text-3: #5A6380;
  --signal: #0B1020;
  --on-signal: #FFFFFF;
  --accent-text: #0B1020;
  --btn-edge: #D9CF00;
  --knob: #FFFFFF;
  --correct: #0B7F4A;
  --correct-fill: #0B7F4A;
  --correct-bright: #19B36B;
  --correct-soft: #E1F5EA;
  --wrong: #C62A3C;
  --wrong-fill: #C62A3C;
  --wrong-bright: #E5484D;
  --wrong-soft: #FCE6E8;
  --unseen: #A3ABC0;
  --overlay: rgba(11, 16, 32, 0.72);
  --shadow-card: 0 1px 2px rgba(11, 16, 32, 0.05), 0 6px 20px rgba(11, 16, 32, 0.06);
  --shadow-pop: 0 20px 60px rgba(11, 16, 32, 0.28);
  color-scheme: light;
}

body.dark-mode,
.app-header,
.us-header {
  --bg: #0B1020;
  --surface: #111832;
  --surface-2: #18203D;
  --surface-3: #1F2740;
  --line: #1F2740;
  --line-strong: #2E3858;
  --text: #E9ECF5;
  --text-2: #BAC1D6;
  --text-3: #8C95B0;
  --signal: #FFF500;
  --on-signal: #0B1020;
  --accent-text: #FFF500;
  --btn-edge: #FFF500;
  --knob: #E9ECF5;
  --correct: #3FD58A;
  --correct-soft: #0F2B26;
  --wrong: #FF7A85;
  --wrong-soft: #2E1424;
  --unseen: #3A4466;
  --shadow-card: none;
  --shadow-pop: 0 20px 60px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, button, label, legend, select {
  font-family: var(--font-display);
}

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

/* Header: a Mitternacht app bar in both themes. */
.app-header {
  background: var(--night);
  color: var(--text);
  border-bottom: 1px solid var(--line);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  transition: all 0.3s ease;
  padding-bottom: 20px;
  box-shadow: 0 12px 32px rgba(11, 16, 32, 0.35);
}
.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;
}
.app-logo {
  display: block;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-right: -2px;
}
.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: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
  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 var(--line);
  border-radius: 8px;
  padding: 2px;
  background: var(--surface-2);
  vertical-align: middle;
}
button.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 5px 7px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}
button.lang-btn:hover {
  color: var(--text);
  background: var(--surface-3);
}
button.lang-btn.active {
  background: var(--yellow);
  color: var(--night);
}

.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: var(--text-3);
}
.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.controls {
  display: grid;
  grid-template-columns: minmax(180px, 220px) auto auto auto 1fr auto;
  gap: 12px 16px;
  padding: 4px 20px 12px 20px;
  align-items: start;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
/* Group titles: small uppercase eyebrows. */
.control-group > label:first-child:not(.checkbox) {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
}
.control-group select {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: all 0.2s ease;
}
.control-group select:hover {
  border-color: var(--text-3);
}
.control-group select:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 22%, transparent);
}
.control-group select option {
  padding: 4px;
  background: var(--surface);
  color: var(--text);
}
.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: var(--text-2); }
.hint { color: var(--text-3); font-size: 11px; margin-top: -2px; }

.mode { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.checkbox { display: flex; gap: 7px; align-items: center; font-weight: 500; font-size: 12.5px; color: var(--text); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--signal); }

/* Buttons */
button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all 0.2s ease;
}
button:hover { background: var(--surface-3); }
button.primary {
  background: var(--yellow);
  border-color: var(--btn-edge);
  color: var(--night);
  font-weight: 700;
  letter-spacing: 0.04em;
}
button.primary:hover { background: var(--yellow); filter: brightness(0.95); }
button.secondary {
  background: var(--correct-fill);
  border-color: var(--correct-fill);
  color: white;
}
button.ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--text-2);
}
button.ghost:hover {
  background: var(--surface-2);
  border-color: var(--text-3);
  color: var(--text);
}
button:active { transform: translateY(1px); }
button.small { padding: 4px 9px; font-size: 12px; border-radius: 6px; }

/* Stats */
.stats { font-size: 12px; color: var(--text-2); display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }

/* Overall progress bar */
.control-group.overall-progress {
  gap: 6px;
}
.progress-bar {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
}
.progress-segment {
  height: 100%;
  transition: width 0.3s ease;
}
.progress-correct {
  background: var(--correct-bright);
}
.progress-wrong {
  background: var(--wrong-bright);
}
.progress-unseen {
  background: var(--unseen);
}
.progress-legend {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-2);
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.legend-color {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.legend-color.correct {
  background: var(--correct-bright);
}
.legend-color.wrong {
  background: var(--wrong-bright);
}
.legend-color.unseen {
  background: var(--unseen);
}

/* 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: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}
.flag-panel {
  position: relative;
}

/* Flag card */
.flag-card {
  padding: 40px 16px 32px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  border-bottom: 1px solid var(--line);
}
.flag-card img {
  max-width: 100%;
  max-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: 0 2px 4px rgba(11, 16, 32, 0.06), 0 12px 28px rgba(11, 16, 32, 0.12);
  cursor: zoom-in;
}
.flag-card img:not([src]) {
  cursor: default;
}
/* Desktop: make room for the feedback card so the flag never spills out of
   its card on shorter screens. */
@media (min-width: 769px) {
  .flag-card img { transition: max-height 0.2s ease; }
  body.feedback-visible .flag-card { min-height: 0; padding: 22px 16px 18px; }
  body.feedback-visible .flag-card img { max-height: 170px; }
}

/* Flag zoom lightbox */
.flag-zoom-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: rgba(11, 16, 32, 0.92);
  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(233, 236, 245, 0.15);
  border-radius: 8px;
  background: var(--light);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  cursor: default;
  object-fit: contain;
  object-position: center;
  image-rendering: auto;
}
button.flag-zoom-close {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 10002;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: rgba(233, 236, 245, 0.12);
  color: var(--light);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}
button.flag-zoom-close:hover {
  background: rgba(233, 236, 245, 0.22);
}
body.flag-zoom-open {
  overflow: hidden;
}
.flag-meta {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-2);
}
.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: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  transition: all 0.2s ease;
}
.multiple-choice-option:hover {
  background: var(--surface-3);
  border-color: var(--line-strong);
}
.multiple-choice-option:disabled {
  opacity: 0.3;
  cursor: not-allowed !important;
  text-decoration: line-through;
  background: var(--surface);
  pointer-events: none;
}

/* Toast */
.toast {
  margin: 12px 16px 16px;
  padding: 9px 12px;
  background: var(--night);
  color: var(--light);
  border-radius: 8px;
  opacity: 0;
  transform: translateY(6px);
  transition: all 240ms ease;
  pointer-events: none;
  font-family: var(--font-display);
  font-weight: 600;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success {
  background: var(--correct-fill);
  color: white;
}
.toast.error {
  background: var(--wrong-fill);
  color: white;
}
.toast.info {
  background: var(--night);
  color: var(--light);
  box-shadow: inset 4px 0 0 var(--yellow);
}
body.dark-mode .toast.info { box-shadow: inset 4px 0 0 var(--yellow), 0 0 0 1px var(--line-strong); }

/* 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: #0E1A36;
}
.flag-panel { min-height: 0; }
.map-legend {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: var(--text-2);
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(11, 16, 32, 0.12);
  transition: all 0.3s ease;
}
.legend-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend-toggle-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  white-space: nowrap;
  color: var(--text);
}
.legend-divider {
  width: 1px;
  height: 20px;
  background: var(--line-strong);
}
.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);
}
/* Night look: land tones unchanged, the sea leans towards the aion44 navy. */
body.dark-mode #map.handmap {
  --hm-ocean: #0c1530; --hm-ripple: #1d2a4f; --hm-sea-label: #5a6c96;
  --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: #19213a;
  --hm-shadow: rgba(120, 150, 240, 0.15);
  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: var(--night); color: var(--light); padding: 5px 10px; border-radius: 6px;
  font-family: var(--font-display); font-weight: 600; font-size: 12px; letter-spacing: 0.02em;
  box-shadow: 0 4px 14px rgba(11, 16, 32, 0.3);
}
.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; padding: 0; border-radius: 8px; border: 1px solid rgba(11, 16, 32, 0.14);
  background: rgba(255, 255, 255, 0.94); color: var(--night); font-size: 18px; line-height: 1;
  cursor: pointer; box-shadow: 0 1px 4px rgba(11, 16, 32, 0.14);
}
.handmap-controls button:hover { background: #fff; }
body.dark-mode .handmap-controls button {
  background: rgba(17, 24, 50, 0.94); color: var(--light); border-color: var(--line-strong);
}
body.dark-mode .handmap-controls button:hover { background: var(--surface-3); }
@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: var(--line-strong);
  transition: 0.3s;
  border-radius: 18px;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: var(--knob);
  transition: 0.3s;
  border-radius: 50%;
}
.toggle-switch input:checked + .toggle-slider {
  background-color: var(--signal);
}
.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(14px);
  background-color: var(--on-signal);
}
.toggle-switch input:focus-visible + .toggle-slider {
  outline: 3px solid var(--signal);
  outline-offset: 3px;
}

/* 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(17, 24, 50, 0.94);
  border-color: var(--line-strong);
  color: var(--text);
}
/* 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: var(--night);
  border-color: #dce1ec;
}

/* 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: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0;
  color: var(--text-3);
}
.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: var(--surface-2);
}
.history-item .icon {
  width: 22px;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}
.history-item.correct .icon {
  color: var(--correct);
}
.history-item.wrong .icon {
  color: var(--wrong);
}
.history-item.gave-up .icon {
  color: var(--text-3);
}
.history-item .label {
  font-size: 13px;
  color: var(--text-2);
  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: var(--text);
}
.history-item .label-row.guess .text {
  color: var(--text-3);
}
.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: var(--surface-3);
  border: 1px dashed var(--line-strong);
  box-shadow: none;
}
.history-item .flag-img {
  width: 42px;
  height: 28px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  box-shadow: 0 1px 3px rgba(11, 16, 32, 0.08);
}
.history-item .flag-arrow {
  color: var(--text-3);
  font-size: 12px;
}

/* Flag hover tooltip */
#flagHoverTooltip {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  box-shadow: var(--shadow-pop);
  display: none;
  transition: all 0.2s ease;
}
#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: var(--surface);
  border: 2px solid var(--signal);
  border-radius: 10px;
  padding: 12px;
  box-shadow: var(--shadow-pop);
  display: none;
  transition: all 0.2s ease;
}
.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-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

/* 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: var(--overlay);
  z-index: 10000;
  /* Auto margins on the dialog centre it while it fits and let it scroll from
     the top when it is taller than the screen (phones). */
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 20px;
}

.welcome-content {
  margin: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 36px 40px 32px;
  max-width: 800px;
  width: 100%;
  box-shadow: var(--shadow-pop);
}

.welcome-logo {
  display: block;
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
}

.welcome-content h2 {
  margin: 0 0 10px 0;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  color: var(--text);
}

.welcome-content > p {
  text-align: center;
  margin: 0 0 28px 0;
  font-size: 16px;
  color: var(--text-3);
}

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

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

@media (max-width: 600px) {
  .welcome-modal { padding: 12px; }
  .welcome-content { padding: 24px 18px 22px; border-radius: 16px; }
  .welcome-logo { width: 36px; height: 36px; margin-bottom: 12px; }
  .welcome-content h2 { font-size: 24px; }
  .welcome-content > p { margin-bottom: 20px; }
  .version-selection { gap: 14px; margin-bottom: 18px; }
  .version-card { padding: 16px; }
  .version-header { margin-bottom: 14px; padding-bottom: 12px; }
  .version-header h3 { font-size: 20px; }
}

.version-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  background: var(--surface-2);
}

.version-header {
  text-align: center;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.version-header h3 {
  margin: 0 0 6px 0;
  font-size: 22px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.version-desc {
  margin: 0;
  font-size: 14px;
  color: var(--text-3);
}

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

.mode-btn {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  width: 100%;
  color: var(--text);
}

.mode-btn.primary {
  background: var(--yellow);
  border-color: var(--btn-edge);
  color: var(--night);
  text-align: center;
  padding: 24px 16px;
}

.mode-btn:hover {
  background: var(--surface);
  border-color: var(--signal);
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(11, 16, 32, 0.16);
}

.mode-btn.primary:hover {
  background: var(--yellow);
  border-color: var(--btn-edge);
  filter: none;
  box-shadow: 0 10px 28px rgba(11, 16, 32, 0.16), 0 0 0 1px var(--btn-edge);
}

body.dark-mode .mode-btn:hover { box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4); }
body.dark-mode .mode-btn.primary:hover { box-shadow: 0 10px 32px rgba(255, 245, 0, 0.18); }

.mode-btn h4 {
  margin: 0 0 8px 0;
  font-size: 17px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.mode-btn.primary h4 {
  color: var(--night);
  font-size: 18px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.mode-btn p {
  margin: 2px 0;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  line-height: 1.5;
  letter-spacing: 0;
}

.mode-btn.primary p {
  color: rgba(11, 16, 32, 0.82);
}

/* Links to the separate US states mode (/states). */
.mode-switch-link {
  flex-shrink: 0;
  padding: 4px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.mode-switch-link:hover { border-color: var(--signal); background: var(--surface-3); }
.welcome-us-link {
  display: block;
  margin-top: 4px;
  text-align: center;
  color: var(--accent-text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent-text) 40%, transparent);
  text-underline-offset: 4px;
}
.welcome-us-link:hover { text-decoration-color: currentColor; }

.welcome-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
  margin: 14px 0 0;
}

/* Account modal */
.account-modal {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.account-modal[hidden] {
  display: none !important;
}
.account-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-pop);
}
.account-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.account-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}
.account-info {
  font-size: 14px;
  color: var(--text-2);
  margin: 0 0 16px;
}
.account-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.account-actions button.danger {
  color: var(--wrong);
  border-color: color-mix(in srgb, var(--wrong) 40%, transparent);
}
.account-actions button.danger:hover {
  background: var(--wrong-soft);
  border-color: var(--wrong);
}
.account-hint {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--text-3);
}

/* Auth modal (sign-in / register) */
.auth-modal-content {
  max-width: 400px;
}
.auth-tabs {
  display: flex;
  gap: 4px;
  margin: 14px 0 16px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.auth-tab {
  flex: 1;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-2);
}
.auth-tab:hover { background: var(--surface-3); }
.auth-tab.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--surface);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-2);
}
.auth-field input {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text);
}
.auth-field input:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 22%, transparent);
}
.auth-form-error {
  margin: 0;
  font-size: 13px;
  color: var(--wrong);
}
.auth-submit {
  width: 100%;
  margin-top: 4px;
  text-align: center;
}
.mode-btn.auth-submit {
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.auth-google-section {
  margin-top: 16px;
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--text-3);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.auth-google-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
}

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

:where(button, a, input, select, [tabindex]):focus-visible {
  outline: 3px solid var(--signal);
  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: var(--text);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.session-due-label {
  color: var(--text-3);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
}

.session-progress-track {
  height: 6px;
  margin: 0 16px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.session-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--signal);
  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 var(--line-strong);
  border-radius: 9px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.free-recall-row input:focus {
  outline: none;
  border-color: var(--signal);
}

button.text-action {
  display: block;
  margin: 8px auto 0;
  border: 0;
  background: transparent;
  color: var(--accent-text);
  padding: 6px 8px;
  font-size: 13px;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent-text) 40%, transparent);
  text-underline-offset: 4px;
}
button.text-action:hover { background: transparent; text-decoration-color: currentColor; }

.multiple-choice-option.answer-correct {
  border-color: var(--correct-fill) !important;
  background: var(--correct-fill) !important;
  color: #fff !important;
  opacity: 1 !important;
  text-decoration: none !important;
}

.multiple-choice-option.answer-selected-wrong {
  border-color: var(--wrong-fill) !important;
  background: var(--wrong-fill) !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 var(--line);
  border-left: 4px solid var(--signal);
  border-radius: 12px;
  background: var(--surface-2);
}

.answer-feedback.feedback-correct { border-left-color: var(--correct); }
.answer-feedback.feedback-wrong { border-left-color: var(--wrong); }

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

.feedback-heading h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.25;
}

.feedback-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
}

.feedback-correct .feedback-icon { background: var(--correct-soft); color: var(--correct); }
.feedback-wrong .feedback-icon { background: var(--wrong-soft); color: var(--wrong); }

.feedback-comparison,
.feedback-region,
.feedback-review {
  margin: 4px 0 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.4;
}

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

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

.feedback-map-button:hover .feedback-mini-map,
.feedback-map-button:focus-visible .feedback-mini-map {
  border-color: var(--signal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 22%, transparent);
}

.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;
}

.feedback-mini-map {
  display: block;
  width: 100%;
  max-height: 112px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #dfe5f1;
}

body.dark-mode .feedback-mini-map { background: #0c1530; }
.feedback-mini-map .world-land { fill: #b9c1d3; stroke: #9aa3ba; stroke-width: 0.35; }
body.dark-mode .feedback-mini-map .world-land { fill: #2a3456; stroke: #3a4466; }
.feedback-mini-map .target-land { fill: var(--night); stroke: var(--night); stroke-width: 0.8; }
body.dark-mode .feedback-mini-map .target-land { fill: var(--light); stroke: var(--light); }
.feedback-mini-map .target-marker { fill: var(--yellow); stroke: var(--night); 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 {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  color: var(--accent-text);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

/* Four dots, as on the landing page. */
.recap-eyebrow::before {
  content: "";
  width: 30px;
  height: 6px;
  background: radial-gradient(circle at 3px 3px, var(--accent-text) 2.5px, transparent 3px) 0 0 / 8px 6px repeat-x;
}

.session-recap h2 { margin: 0; font-size: 30px; font-weight: 700; }
.recap-score { margin: 8px 0 16px; color: var(--text-2); font-size: 18px; }

.recap-mastery {
  margin: 0 auto 18px;
  padding: 12px 14px;
  max-width: 360px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--signal);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
}

.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 var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.recap-list img { width: 38px; height: 25px; object-fit: cover; border: 1px solid var(--line); border-radius: 3px; }
.recap-list .recap-result { margin-left: auto; font-weight: 800; }
.recap-list .correct .recap-result { color: var(--correct); }
.recap-list .wrong .recap-result { color: var(--wrong); }

.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: var(--text-3); text-underline-offset: 3px; }
.legal-links a:hover { color: var(--text); }

.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: var(--overlay);
}

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

.mobile-settings-content {
  display: flex;
  flex-direction: column;
  width: min(100%, 500px);
  max-height: 90dvh;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}

.mobile-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.mobile-settings-header h2 { margin: 0; font-size: 20px; font-weight: 700; }

.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-settings-body .lang-switch { display: flex; padding: 3px; }
.mobile-settings-body .lang-switch button.lang-btn { flex: 1; margin-top: 0; font-size: 13px; }
.mobile-settings-body .mode-switch-link { align-self: flex-start; padding: 8px 14px; font-size: 13px; }
.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: var(--bg);
  }

  .flag-panel,
  body[data-mobile-mode="beginner"] .flag-panel {
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    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; }

  /* Leave room for the round settings button in the top-right corner. */
  .session-question-header { padding: 18px 68px 10px 16px; }

  .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: var(--surface) !important;
    border-color: var(--line-strong) !important;
    color: var(--text) !important;
    font-size: 15px !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;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  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;
  }

  button.mobile-settings-btn {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid #2e3858;
    border-radius: 50%;
    background: var(--night);
    color: var(--yellow);
    box-shadow: 0 4px 14px rgba(11, 16, 32, .28);
  }
  button.mobile-settings-btn:hover { background: var(--night); }

  .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: var(--night);
    color: var(--light);
    font-family: var(--font-display);
    font-weight: 600;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }
  .mobile-toast.show { opacity: 1; }
  .mobile-toast.success { background: var(--correct-fill); color: #fff; }
  .mobile-toast.error { background: var(--wrong-fill); color: #fff; }
  .mobile-toast.info { background: var(--night); box-shadow: inset 4px 0 0 var(--yellow); }
}

@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;
  }
}
