* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* Avoid mobile viewport jump with dynamic browser chrome */
  height: 100dvh;
}

#topbar {
  flex: 0 0 auto;
  /* Pad past the status bar / notch on devices with viewport-fit=cover. */
  padding: calc(0.6rem + env(safe-area-inset-top)) 1rem 0.6rem;
  background: #1f2933;
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

#topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

/* Game-mode switcher (dropdown) */
.mode-select {
  margin-left: auto;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: #2b3744;
  color: #fff;
  cursor: pointer;
}

/* Icon button (settings gear) */
.icon-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Text button (e.g. the Filtres toggle) */
.text-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

.text-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* A small chevron that flips when the filters panel is open. */
.text-btn[aria-controls]::after {
  content: " \25be"; /* ▾ */
  display: inline-block;
  transition: transform 0.15s ease;
}

.text-btn[aria-expanded="true"]::after {
  transform: rotate(180deg);
}

.text-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.18);
}

/* Collapsible filters panel (toggled by the Filtres button) */
.filters[hidden] {
  display: none;
}

/* Data / settings panel */
.settings-panel {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1300;
  width: min(280px, calc(100vw - 1rem));
  background: #fff;
  color: #1f2933;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  padding: 0.8rem;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.settings-panel h2 {
  margin: 0;
  font-size: 0.95rem;
}

.icon-btn.dark {
  color: #1f2933;
  border-color: #cbd2d9;
  width: 1.7rem;
  height: 1.7rem;
  font-size: 0.85rem;
}

.icon-btn.dark:hover {
  background: #e8eef2;
}

.panel-btn {
  display: block;
  width: 100%;
  text-align: center;
  border: 1px solid #cbd2d9;
  background: #f5f7fa;
  color: #1f2933;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.panel-btn:hover {
  background: #e8eef2;
}

.panel-btn.danger {
  color: #c0392b;
  border-color: #e6b0aa;
}

.settings-status {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  min-height: 1em;
  color: #1e8449;
}


/* Department filter + stats row */
.topbar-controls {
  margin-top: 0.4rem;
  font-size: 0.8rem;
}

/* Beat the `.topbar-row { display: flex }` rule so [hidden] takes effect. */
.topbar-controls[hidden] {
  display: none;
}

/* Region picker row (always visible, even in Explore) */
.topbar-region {
  margin-top: 0.4rem;
  font-size: 0.8rem;
}

.dept-filter,
.pop-filter,
.region-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.dept-filter span,
.pop-filter span,
.region-filter span {
  opacity: 0.8;
}

#dept-select,
#pop-select,
#region-select {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: #2b3744;
  color: #fff;
}

.srs-stats {
  opacity: 0.85;
  white-space: nowrap;
}

#topbar .hint {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  opacity: 0.8;
}

/* Flashcard rating bar */
.rating-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1200;
  background: #1f2933;
  color: #fff;
  padding: 0.5rem 0.75rem calc(0.85rem + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
}

.rating-city {
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
}

.rating-buttons {
  display: flex;
  gap: 0.4rem;
  max-width: 560px;
  margin: 0 auto;
}

.rate-btn {
  flex: 1 1 0;
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.3rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  line-height: 1.1;
}

.rate-btn small {
  font-weight: 400;
  font-size: 0.7rem;
  opacity: 0.85;
}

.rate-btn:active {
  transform: translateY(1px);
}

.rate-again { background: #c0392b; }
.rate-hard  { background: #d68910; }
.rate-good  { background: #1e8449; }
.rate-easy  { background: #2471a3; }

/* Review-mode prompt / result bar */
.review-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1200;
  background: #1f2933;
  color: #fff;
  padding: 0.6rem 0.75rem calc(0.95rem + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.review-msg {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.review-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
}

.review-btn {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.4rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  color: #fff;
  background: #2471a3;
  cursor: pointer;
}

.review-btn.secondary {
  background: #566573;
}

.review-btn:active {
  transform: translateY(1px);
}

#map {
  flex: 1 1 auto;
  width: 100%;
  background: #e8eef2;
}

/* Background-labels toggle control (sits below the zoom +/- buttons) */
.label-toggle a {
  font-weight: 700;
  font-size: 15px;
  line-height: 30px; /* matches Leaflet's default control height */
  text-align: center;
  color: #1f2933;
}

.label-toggle a.active {
  background: #1f2933;
  color: #fff;
}

/* Mastery choropleth toggle (below the label toggle) */
.mastery-toggle a {
  font-size: 16px;
  line-height: 30px;
  text-align: center;
  color: #1f2933;
}

.mastery-toggle a.active {
  background: #1e8449;
  color: #fff;
}

/* Mastery legend */
.mastery-legend {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.75rem;
  color: #1f2933;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  line-height: 1.5;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.legend-swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 3px;
  border: 1px solid #999;
}

/* Revealed commune label */
.commune-label {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #1f2933;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #1f2933;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* Hide the little tooltip arrow for a cleaner badge look */
.commune-label.leaflet-tooltip-left::before,
.commune-label.leaflet-tooltip-right::before {
  display: none;
}
