/* 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;
}
.app-header.collapsed .header-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  gap: 16px;
}
.app-header.collapsed .collapsed-content {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  justify-content: space-between;
}
.collapsed-content {
  display: none;
}
.collapsed-progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
}
.collapsed-progress-bar {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  background: #e5e7eb;
  width: 200px;
}
.app-header.collapsed .collapsed-actions {
  display: flex;
  gap: 8px;
}
.collapsed-actions {
  display: none;
}
.collapsed-actions button {
  padding: 6px 16px;
  font-size: 13px;
}
.header-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px 0;
}
.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);
}
.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;
}
.joker-counter {
  font-size: 13px;
  color: #6b7280;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
body.dark-mode .joker-counter {
  color: #9ca3af;
}
.joker-label {
  color: #9ca3af;
  font-weight: 500;
}
body.dark-mode .joker-label {
  color: #6b7280;
}
.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; }
.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: #f59e0b; border-color: #d97706; }
.chip-focus { background: #3b82f6; border-color: #1d4ed8; }

/* 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; }
.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 .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 {
  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; }
}

/* Mobile: < 600px */
@media (max-width: 599px) {
  body {
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
  }

  .app-main {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px;
    flex: none;
    min-height: auto;
    overflow: visible;
  }

  .header-title {
    padding: 8px 12px 0;
  }

  .app-header h1 {
    font-size: 16px;
  }

  .app-header.collapsed .header-title {
    padding: 6px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .app-header.collapsed .collapsed-content {
    width: 100%;
    flex-direction: column;
  }

  .collapsed-progress-bar {
    max-width: 100%;
  }

  .controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 0 12px 12px 12px;
  }

  .control-group {
    width: 100%;
  }

  .control-group.right-controls {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .action-buttons,
  .progress-buttons {
    width: 100%;
    justify-content: stretch;
  }

  .action-buttons button,
  .progress-buttons button {
    flex: 1;
  }

  .stats {
    flex-direction: row;
    justify-content: space-around;
    font-size: 13px;
  }

  .flag-panel {
    min-height: auto;
    /* Pin flag to top of viewport on mobile */
    position: sticky;
    top: 0;
    z-index: 100;
    max-height: 50vh;
    overflow: visible;
  }

  .flag-card {
    padding: 12px;
    min-height: 100px;
  }

  .flag-card img {
    max-height: 120px;
  }

  /* Hide/minimize non-essential elements on mobile */
  .history-panel {
    order: 10;
    margin: 8px 12px 12px;
  }

  .flag-meta {
    display: none; /* Hide metadata on mobile */
  }

  .dont-know-container {
    padding: 8px 12px;
  }

  .map-panel {
    min-height: calc(100vh - 60px);
    height: auto;
    flex-shrink: 0;
    /* Ensure map is visible when flag is sticky */
    margin-top: 0;
  }

  #map {
    min-height: calc(100vh - 60px);
    height: 100%;
  }

  .map-legend {
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    left: 8px;
    bottom: 8px;
    max-width: calc(100vw - 32px);
  }

  .legend-divider {
    width: 100%;
    height: 1px;
  }

  .legend-items {
    flex-wrap: wrap;
    gap: 8px;
    font-size: 11px;
  }

  /* Move history to bottom, make it collapsible */
  .history-header {
    cursor: pointer;
    user-select: none;
    padding: 8px 16px;
    background: #f9fafb;
    border-radius: 8px;
    margin-bottom: 8px;
  }

  body.dark-mode .history-header {
    background: #374151;
  }

  .history-header h2::after {
    content: ' ▼';
    font-size: 10px;
    color: #6b7280;
  }

  .history-list {
    max-height: 200px;
  }

  .history-item {
    gap: 8px;
    padding: 8px;
  }

  .history-item .flag-img {
    width: 36px;
    height: 24px;
  }

  .history-item .label-row .text {
    font-size: 13px;
  }

  /* Make touch targets larger */
  button {
    min-height: 44px;
    padding: 12px 16px;
  }

  button.small {
    min-height: 36px;
    padding: 8px 12px;
  }

  select {
    min-height: 44px;
    padding: 8px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
  }

  /* Hide flag hover tooltip on mobile (relies on hover) */
  #flagHoverTooltip {
    display: none !important;
  }

  .history-flag-preview {
    display: none !important;
  }
}

/* Mobile-specific components (hidden on desktop) */
.mobile-bottom-bar {
  display: none;
}

.mobile-settings-overlay {
  display: none;
}

/* Mobile Layout: 768px and below */
@media (max-width: 768px) {
  /* Hide desktop header */
  .app-header {
    display: none !important;
  }

  /* Reset body for mobile */
  body {
    overflow: auto;
    height: auto;
  }

  /* Mobile layout: vertical stack */
  .app-main {
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 0;
    min-height: 100vh;
    padding-top: 0;
    overflow: visible;
  }

  /* Flag at top: adjusts based on mode */
  .flag-panel {
    order: 1;
    min-height: 20vh;
    max-height: 20vh;
    border-radius: 0;
    border: none;
    border-bottom: 2px solid #e5e7eb;
    position: relative;
    overflow: auto;
    display: flex;
    flex-direction: column;
  }

  /* Beginner mode: flag panel takes more space for multiple choice */
  body[data-mobile-mode="beginner"] .flag-panel {
    min-height: 85vh;
    max-height: 85vh;
    z-index: 200;
    overflow-y: auto;
  }

  body.dark-mode .flag-panel {
    border-bottom-color: #374151;
  }

  .flag-card {
    padding: 8px;
    min-height: auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: none;
  }

  /* In beginner mode, flag card should not take full height */
  body[data-mobile-mode="beginner"] .flag-card {
    height: auto;
    flex: 0 0 auto;
    padding: 16px;
  }

  .flag-card img {
    max-height: calc(20vh - 20px);
    max-width: 90%;
  }

  /* In beginner mode, make flag smaller to fit with buttons */
  body[data-mobile-mode="beginner"] .flag-card img {
    max-height: 120px;
  }

  /* Mobile joker container - only visible on mobile in beginner mode */
  .mobile-joker-container {
    display: none;
  }

  body[data-mobile-mode="beginner"] .mobile-joker-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    gap: 12px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
  }

  body.dark-mode[data-mobile-mode="beginner"] .mobile-joker-container {
    background: #374151;
    border-bottom-color: #4b5563;
  }

  .mobile-joker-counter {
    font-size: 14px;
    color: #6b7280;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  body.dark-mode .mobile-joker-counter {
    color: #9ca3af;
  }

  .mobile-joker-btn {
    background: #f59e0b;
    color: white;
    border: 2px solid #d97706;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
  }

  .mobile-joker-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  .mobile-joker-btn:not(:disabled):hover {
    background: #d97706;
    border-color: #b45309;
  }

  /* Hide desktop controls on flag panel - but show multiple choice in beginner mode */
  .dont-know-container {
    display: none;
  }

  /* Multiple choice options are shown in beginner mode via JS */
  .multiple-choice-options {
    padding: 12px 16px !important;
    gap: 12px !important;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
  }

  /* In beginner mode, ensure multiple choice is visible */
  body[data-mobile-mode="beginner"] .multiple-choice-options {
    display: flex !important;
    flex-direction: column;
  }

  /* When options are visible in beginner mode, make them prominent */
  .multiple-choice-option {
    padding: 16px 20px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    background: #2563eb !important;
    color: white !important;
    border: 2px solid #1d4ed8 !important;
    position: relative;
    z-index: 15;
  }

  body.dark-mode .multiple-choice-option {
    background: #1d4ed8 !important;
    border-color: #1e40af !important;
  }

  .multiple-choice-option:hover {
    background: #1d4ed8 !important;
    border-color: #1e40af !important;
  }

  body.dark-mode .multiple-choice-option:hover {
    background: #1e40af !important;
    border-color: #1e3a8a !important;
  }

  .multiple-choice-option:disabled {
    background: #9ca3af !important;
    border-color: #6b7280 !important;
    opacity: 0.4 !important;
  }

  .flag-meta {
    display: none;
  }

  #toast {
    display: none;
  }

  .history-panel {
    display: none;
  }

  /* Map: 60% of viewport in advanced mode, hidden in beginner mode */
  .map-panel {
    order: 2;
    min-height: 60vh;
    max-height: 60vh;
    border-radius: 0;
    border: none;
    position: relative;
  }

  /* Hide map in beginner mode on mobile */
  body[data-mobile-mode="beginner"] .map-panel {
    display: none;
  }

  #map {
    min-height: 60vh;
    height: 60vh;
  }

  /* Adjust map legend for mobile */
  .map-legend {
    display: none;
  }

  /* Mobile bottom bar: 20% of viewport */
  .mobile-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #ffffff;
    border-top: 2px solid #e5e7eb;
    min-height: 20vh;
    max-height: 20vh;
    gap: 12px;
    order: 3;
    position: relative;
    z-index: 100;
  }

  /* In beginner mode, bottom bar is smaller */
  body[data-mobile-mode="beginner"] .mobile-bottom-bar {
    min-height: 15vh;
    max-height: 15vh;
  }

  body.dark-mode .mobile-bottom-bar {
    background: #1f2937;
    border-top-color: #374151;
  }

  /* Mobile last history item */
  .mobile-last-history {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 8px;
    background: #f9fafb;
    cursor: pointer;
    transition: background-color 0.2s ease;
  }

  body.dark-mode .mobile-last-history {
    background: #374151;
  }

  .mobile-last-history:hover {
    background: #e5e7eb;
  }

  body.dark-mode .mobile-last-history:hover {
    background: #4b5563;
  }

  .mobile-last-history.empty {
    opacity: 0.5;
    cursor: default;
    font-size: 13px;
    color: #6b7280;
    justify-content: center;
  }

  .mobile-last-history .icon {
    width: 24px;
    text-align: center;
    font-weight: 700;
    font-size: 18px;
  }

  .mobile-last-history.correct .icon {
    color: #059669;
  }

  .mobile-last-history.wrong .icon {
    color: #dc2626;
  }

  .mobile-last-history .flag-img {
    width: 48px;
    height: 32px;
    object-fit: cover;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background: #f9fafb;
    flex-shrink: 0;
  }

  .mobile-last-history .text {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.dark-mode .mobile-last-history .text {
    color: #f9fafb;
  }

  .mobile-last-history .score {
    margin-left: auto;
    font-size: 13px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    background: #e5e7eb;
    color: #374151;
    flex-shrink: 0;
  }

  body.dark-mode .mobile-last-history .score {
    background: #4b5563;
    color: #d1d5db;
  }

  /* Mobile settings button */
  .mobile-settings-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #2563eb;
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  }

  .mobile-settings-btn .settings-icon {
    width: 28px;
    height: 28px;
    stroke-width: 2.5;
  }

  .mobile-settings-btn:hover {
    filter: brightness(1.1);
    transform: scale(1.05);
  }

  .mobile-settings-btn:active {
    transform: scale(0.95);
  }

  /* Mobile settings overlay */
  .mobile-settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
  }

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

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

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

  .mobile-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    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;
    font-weight: 700;
    color: #111827;
  }

  body.dark-mode .mobile-settings-header h2 {
    color: #f9fafb;
  }

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

  .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: 8px;
  }

  /* Mobile toast feedback */
  .mobile-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 20px 32px;
    border-radius: 12px;
    font-size: 20px;
    font-weight: 700;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  }

  .mobile-toast.show {
    opacity: 1;
  }

  .mobile-toast.success {
    background: #10b981;
  }

  .mobile-toast.error {
    background: #ef4444;
  }

  .mobile-toast.info {
    background: #3b82f6;
  }
}

/* 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);
}

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

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