html, body {
  margin: 0;
  height: 100%;
}

.profile-page {
  min-height: 100%;
  display: flex;
  justify-content: center;
  padding: 48px 16px;
  box-sizing: border-box;
  background: #f5f7fa;
}

.profile-card {
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.profile-avatar {
  width: 128px;
  height: 128px;
  margin: 0 auto 20px;
  border-radius: 50%;
  overflow: hidden;
  background: #e2e8f0;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 600;
  color: #64748b;
}

.profile-name {
  margin: 0 0 12px;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.75rem;
  color: #1e293b;
}

.profile-description {
  margin: 0 0 20px;
  color: #475569;
  line-height: 1.5;
  white-space: pre-line;
}

.profile-contacts {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.profile-contact a {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  color: #2b5f92;
  text-decoration: none;
  font-size: 0.95rem;
}

.profile-contact a:hover {
  background: #eef2f7;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.profile-edit,
.profile-editor,
.profile-logout {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}

.profile-edit {
  background: #2b5f92;
  border: 1px solid #2b5f92;
  color: #fff;
}

.profile-edit:hover {
  background: #24507d;
  border-color: #24507d;
}

.profile-editor {
  background: #fff;
  border: 1px solid #2b5f92;
  color: #2b5f92;
}

.profile-editor:hover {
  background: #eef4fb;
}

.profile-logout {
  background: #fff;
  border: 1px solid #c0392b;
  color: #c0392b;
}

.profile-logout:hover {
  background: #fdecec;
}

.profile-back {
  margin: 0;
  padding-top: 24px;
  border-top: 1px solid #e2e8f0;
  text-align: center;
}

.profile-back a {
  color: #2b5f92;
  text-decoration: none;
}

.profile-back a:hover {
  text-decoration: underline;
}

#map {
  position: absolute;
  inset: 0;
}

.lang-hint {
  display: block;
  margin-top: 2px;
  font-size: 0.85em;
  color: #5a6b78;
}

.copy-hint {
  display: block;
  margin-top: 2px;
  font-size: 0.8em;
  color: #8a97a2;
}

#copy-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 40;
  transform: translate(-50%, 8px);
  padding: 9px 16px;
  border-radius: 20px;
  background: rgba(26, 42, 56, 0.92);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#copy-toast.open {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#toolbar label {
  font-size: 13px;
  color: #333;
}

/* Keep a label and its field together so they never wrap separately. */
.field-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* The collapse toggle is only relevant on small screens. */
#toolbar-toggle {
  display: none;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: #333;
  cursor: pointer;
  line-height: 1;
}

#word {
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
  min-width: 200px;
}

#word:focus {
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

#threshold,
#cluster-basis,
#user-country {
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
  background: #fff;
  color: #333;
  cursor: pointer;
}

#threshold:focus,
#cluster-basis:focus,
#user-country:focus {
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

#translate-btn {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #4a90d9;
  color: #fff;
  cursor: pointer;
}

#translate-btn:hover {
  background: #3b7dc0;
  border-color: #3b7dc0;
}

#clusterize-btn {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  cursor: pointer;
}

#clusterize-btn:hover:not(:disabled) {
  background: #eef4fb;
}

#clusterize-btn:disabled {
  border-color: #ccc;
  color: #9aa5ae;
  background: #f2f3f5;
  cursor: not-allowed;
}

/* Group the База field, state lamp and Кластеризовать button inside a
   framed box with a little breathing room on each side. */
.cluster-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 8px;
  padding: 4px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

/* Clustering-state indicator ("lamp") next to the Кластеризовать button.
   Dim when clustering is off; lit (and clickable to exit) when it is on. */
.cluster-lamp {
  width: 16px;
  height: 16px;
  padding: 0;
  flex: 0 0 auto;
  border: 1px solid #b9c2cb;
  border-radius: 50%;
  background: #e4e8ec;
  cursor: default;
  transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.cluster-lamp.on {
  border-color: #2e9e5b;
  background: #35c46b;
  box-shadow: 0 0 6px rgba(53, 196, 107, 0.7);
  cursor: pointer;
}

#export-btn {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  cursor: pointer;
}

#export-btn:hover {
  background: #eef4fb;
}

#map-edit-toggle {
  font-size: 15px;
  line-height: 1;
  padding: 7px 12px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  cursor: pointer;
}

#map-edit-toggle:hover {
  background: #eef4fb;
}

#share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 6px 10px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  cursor: pointer;
}

#share-btn:hover {
  background: #eef4fb;
}

#similarity-spinner {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  /* Transparent overlay that also intercepts clicks while active. */
  background: rgba(255, 255, 255, 0.05);
  cursor: progress;
}

#similarity-spinner.open {
  display: flex;
}

#similarity-spinner .spinner {
  width: 54px;
  height: 54px;
  border: 5px solid rgba(74, 144, 217, 0.25);
  border-top-color: #4a90d9;
  border-radius: 50%;
  animation: similarity-spin 0.8s linear infinite;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

@keyframes similarity-spin {
  to {
    transform: rotate(360deg);
  }
}

#export-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#export-modal.open {
  display: flex;
}

#export-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  padding: 20px 22px;
  width: 320px;
  max-width: calc(100vw - 32px);
}

#export-card h2 {
  margin: 0 0 12px;
  font-size: 17px;
  color: #222;
}

#export-card label {
  display: block;
  font-size: 13px;
  color: #444;
  margin-bottom: 6px;
}

#export-scale {
  width: 100%;
  box-sizing: border-box;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  outline: none;
}

#export-hint {
  font-size: 12px;
  color: #777;
  margin: 8px 0 16px;
}

#export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#export-actions button {
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid #ccc;
  background: #f4f4f4;
  color: #333;
}

#export-confirm {
  border-color: #4a90d9 !important;
  background: #4a90d9 !important;
  color: #fff !important;
}

#export-confirm:hover {
  background: #3b7dc0 !important;
  border-color: #3b7dc0 !important;
}

/* --- POI detail modal --- */
#poi-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#poi-modal.open {
  display: flex;
}

#poi-card {
  position: relative;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  padding: 20px 22px;
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

#poi-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  color: #666;
  cursor: pointer;
}

#poi-close:hover {
  color: #222;
}

#poi-title {
  margin: 0 0 10px;
  font-size: 19px;
  color: #1a2a38;
  padding-right: 28px;
}

#poi-description {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.5;
  color: #384652;
  white-space: pre-wrap;
}

#poi-link {
  display: inline-block;
  margin: 0 0 14px;
  font-size: 14px;
  color: #2f6fed;
  word-break: break-all;
}

#poi-gallery {
  position: relative;
  margin: 0 0 16px;
  background: #f2f4f7;
  border-radius: 8px;
  overflow: hidden;
}

#poi-image {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  background: #f2f4f7;
}

#poi-prev,
#poi-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(26, 42, 56, 0.55);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

#poi-prev:hover,
#poi-next:hover {
  background: rgba(26, 42, 56, 0.8);
}

#poi-prev {
  left: 10px;
}

#poi-next {
  right: 10px;
}

#poi-counter {
  position: absolute;
  right: 10px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(26, 42, 56, 0.6);
  color: #fff;
  font-size: 12px;
}

#poi-data {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(90px, auto) 1fr;
  gap: 6px 14px;
  font-size: 13px;
}

#poi-data dt {
  font-weight: 600;
  color: #55636e;
  word-break: break-word;
}

#poi-data dd {
  margin: 0;
  color: #1a2a38;
  word-break: break-word;
}

#about-btn {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 10;
  font-size: 14px;
  padding: 8px 14px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

#about-btn:hover {
  background: #eef4fb;
}

.map-footer-bar {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 30px;
}

/* Hamburger menu is mobile-only; shown via the max-width media query. */
#map-menu-wrap {
  display: none;
}

/* AI dialog: compact, collapsible dock centered at the bottom of the map.
   Sits between the footer bar (bottom-left) and the legend (bottom-right). */
.ai-dock {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 11;
  width: min(588px, calc(100vw - 24px));
  border: 1px solid #d4dde5;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.ai-dock-toggle,
#ai-dock-toggle {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: #2b5f92;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.ai-dock:not(.collapsed) #ai-dock-toggle {
  border-radius: 8px 8px 0 0;
}

#ai-dock-toggle::before {
  content: "\25B2\00A0";
  font-size: 10px;
}

.ai-dock.collapsed #ai-dock-toggle::before {
  content: "\25BC\00A0";
}

.ai-dock-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-dock-body[hidden] {
  display: none;
}

#ai-prompt {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  padding: 8px;
  border: 1px solid #d4dde5;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
}

.ai-dock-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#ai-send {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  cursor: pointer;
}

#ai-send:hover:not(:disabled) {
  background: #eef4fb;
}

#ai-send:disabled {
  opacity: 0.6;
  cursor: default;
}

#ai-publish {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #4a90d9;
  color: #fff;
  cursor: pointer;
}

#ai-publish[hidden] {
  display: none;
}

#ai-publish:hover:not(:disabled) {
  background: #3b7cc4;
}

#ai-publish:disabled {
  opacity: 0.6;
  cursor: default;
}

#ai-edit {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #4a90d9;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  cursor: pointer;
}

#ai-edit[hidden] {
  display: none;
}

#ai-edit:hover:not(:disabled) {
  background: #eef4fb;
}

#ai-edit:disabled {
  opacity: 0.6;
  cursor: default;
}

#ai-reset {
  font-size: 14px;
  padding: 6px 14px;
  border: 1px solid #d98a8a;
  border-radius: 6px;
  background: #fff;
  color: #a13b3b;
  cursor: pointer;
}

#ai-reset:hover:not(:disabled) {
  background: #fbeeee;
}

#ai-reset:disabled {
  opacity: 0.6;
  cursor: default;
}

.ai-dock .spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(74, 144, 217, 0.25);
  border-top-color: #4a90d9;
  border-radius: 50%;
  animation: similarity-spin 0.8s linear infinite;
}

.ai-dock .spinner[hidden] {
  display: none;
}

.ai-comment {
  margin: 0;
  font-size: 13px;
  color: #334155;
  white-space: pre-wrap;
}

.ai-comment:empty {
  display: none;
}

.ai-error {
  margin: 0;
  font-size: 13px;
  color: #b3261e;
}

.ai-error:empty {
  display: none;
}

/* Viewer badge, top-right next to the map zoom control (right: 10px). */
.user-badge {
  position: fixed;
  top: 12px;
  right: 52px;
  z-index: 12;
}

.user-badge-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: #2b5f92;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.user-badge-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-badge-login {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.home-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  box-sizing: border-box;
  background: linear-gradient(160deg, #1a3a5c 0%, #2b5f92 45%, #4a7fb5 100%);
  color: #fff;
  text-align: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.home-gate-text {
  margin: 0 0 20px;
  max-width: 28em;
  font-size: 18px;
  line-height: 1.45;
}

.home-gate-text a,
.home-gate-text a:visited,
.home-gate-text a:hover {
  color: inherit;
  text-decoration: underline;
}

.home-gate-login {
  display: inline-block;
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  background: #fff;
  color: #2b5f92;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  font-family: inherit;
}

.home-gate-login:hover {
  background: #f4f7fb;
}

.map-footer-bar #about-btn {
  position: static;
  left: auto;
  bottom: auto;
}

.map-footer-bar #export-btn,
.map-footer-bar #map-edit-toggle {
  flex: 0 0 auto;
  padding: 8px 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.map-footer-bar #share-btn {
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.map-author {
  font-size: 14px;
  color: #2b3b47;
  white-space: nowrap;
}

.map-author a {
  color: #2b5f92;
  text-decoration: none;
}

#map-author-link {
  text-shadow:
    -1px -1px 0 #fff,
    1px -1px 0 #fff,
    -1px 1px 0 #fff,
    1px 1px 0 #fff,
    0 -1px 0 #fff,
    0 1px 0 #fff,
    -1px 0 0 #fff,
    1px 0 0 #fff;
}

.map-author a:hover {
  text-decoration: underline;
}

/* Clustered-point donut markers (DOM overlays, see map_point_layer.js). */
.cluster-donut {
  cursor: pointer;
}

#map-legend {
  position: fixed;
  right: 44px;
  bottom: 12px;
  z-index: 10;
  max-width: 360px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 10px 12px;
  border: 1px solid #d4dde5;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color: #2b3b47;
}

#map-legend[hidden] {
  display: none;
}

#map-legend-toggle {
  display: none;
}

/* Keep the attribution "i" control clickable above the legend. */
.maplibregl-ctrl-bottom-right {
  z-index: 11;
}

.legend-title {
  font-family: "Playfair Display", Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  color: #1a2a38;
  margin-bottom: 8px;
}

.legend-title:not(:last-child) {
  padding-bottom: 8px;
  border-bottom: 1px solid #e2e8ee;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 2px 4px;
  margin: 0 -4px;
  border-radius: 4px;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

.legend-row + .legend-row {
  margin-top: 4px;
}

.legend-row:hover {
  background: #eef4fb;
}

.legend-row.active {
  background: #e2edf9;
  font-weight: 600;
}

.legend-row.inactive {
  opacity: 0.45;
}

.legend-swatch {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

#about-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#about-modal.open {
  display: flex;
}

#about-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  padding: 20px 22px;
  width: 360px;
  max-width: calc(100vw - 32px);
}

#about-card h2 {
  margin: 0 0 12px;
  font-size: 17px;
  color: #222;
}

p.about-text {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: #444;
}

#about-actions {
  display: flex;
  justify-content: flex-end;
}

#about-actions button {
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid #4a90d9;
  background: #4a90d9;
  color: #fff;
}

#about-actions button:hover {
  background: #3b7dc0;
  border-color: #3b7dc0;
}

#login-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#login-modal.open {
  display: flex;
}

#login-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  padding: 20px 22px;
  width: 340px;
  max-width: calc(100vw - 32px);
}

#login-card h2 {
  margin: 0 0 14px;
  font-size: 17px;
  color: #222;
}

#login-form label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: #444;
}

#login-form input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 12px;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid #ccd6df;
  border-radius: 6px;
}

#login-form input:focus {
  outline: none;
  border-color: #4a90d9;
}

.login-error {
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fdecec;
  color: #c0392b;
  font-size: 13px;
}

#login-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#login-actions button {
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid #4a90d9;
  background: #4a90d9;
  color: #fff;
}

#login-actions button:hover {
  background: #3b7dc0;
  border-color: #3b7dc0;
}

#login-cancel {
  background: #fff;
  color: #2b5f92;
}

#login-cancel:hover {
  background: #eef4fb;
  border-color: #4a90d9;
}

@media (max-width: 640px) {
  #toolbar {
    left: 8px;
    right: 8px;
    top: 8px;
    flex-wrap: wrap;
    gap: 6px 8px;
    padding: 8px;
  }

  /* Show the hamburger and let it sit on its own row. */
  #toolbar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 18px;
    padding: 6px 12px;
  }

  /* When collapsed, shrink the toolbar to just the toggle button. */
  #toolbar.collapsed {
    right: auto;
  }

  #toolbar.collapsed > *:not(#toolbar-toggle) {
    display: none;
  }

  /* Input takes a full row and shrinks freely. */
  #word {
    flex: 1 1 100%;
    min-width: 0;
    font-size: 16px; /* prevents auto-zoom on focus in iOS Safari */
  }

  /* Label+field groups share a row and stay intact. */
  .field-group {
    flex: 1 1 auto;
    min-width: 0;
    gap: 6px;
  }

  /* Framed clustering group spans the full row and wraps cleanly. */
  .cluster-box {
    flex: 1 1 100%;
    flex-wrap: wrap;
    margin: 0;
  }

  #user-country,
  #threshold {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 16px;
  }

  /* Buttons stretch into comfortable touch targets. */
  #translate-btn,
  #export-btn {
    flex: 1 1 auto;
    font-size: 15px;
    padding: 8px 12px;
  }

  #about-btn {
    font-size: 13px;
    padding: 7px 12px;
  }

  /* Footer bar controls are replaced by the hamburger menu on mobile. The bar
     itself stays in the DOM so the included #about-modal keeps working. */
  .map-footer-bar #about-btn,
  .map-footer-bar #export-btn,
  .map-footer-bar #map-edit-toggle,
  .map-footer-bar #share-btn,
  .map-footer-bar #map-author {
    display: none;
  }

  /* Hamburger menu, top-left. */
  #map-menu-wrap {
    display: block;
    position: fixed;
    left: 12px;
    top: 12px;
    z-index: 20;
  }

  #map-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid #d4dde5;
    border-radius: 6px;
    background: #fff;
    color: #2b5f92;
    font-size: 20px;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    cursor: pointer;
  }

  #map-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 190px;
    background: #fff;
    border: 1px solid #d4dde5;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #map-menu[hidden] {
    display: none;
  }

  .map-menu-item {
    display: block;
    width: 100%;
    padding: 11px 14px;
    border: 0;
    border-bottom: 1px solid #eef2f6;
    background: none;
    font-size: 15px;
    color: #2b5f92;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
  }

  .map-menu-item:last-child {
    border-bottom: 0;
  }

  .map-menu-item:hover {
    background: #eef4fb;
  }

  /* Legend is controlled from the menu: hidden until opened, no own toggle. */
  #map-legend {
    right: 44px;
    bottom: 12px;
    max-width: min(240px, calc(100vw - 72px));
    max-height: 45vh;
    overflow-y: auto;
    font-size: 12px;
    padding: 10px 12px;
    display: none;
  }

  #map-legend.mobile-open {
    display: block;
  }

  #map-legend-toggle {
    display: none;
  }

  #map-legend-content {
    padding: 0;
    border-top: 0;
  }

  .legend-title {
    font-size: 13px;
    margin-bottom: 6px;
  }

  .legend-title:not(:last-child) {
    padding-bottom: 6px;
  }

  .legend-row {
    gap: 6px;
    padding: 2px 3px;
    margin: 0 -3px;
  }

  .legend-swatch {
    width: 12px;
    height: 12px;
  }

  .ai-dock {
    width: calc(100vw - 16px);
    bottom: 8px;
  }

  #ai-dock-toggle,
  #ai-send,
  #ai-publish,
  #ai-edit,
  #ai-reset {
    font-size: 15px;
    padding: 10px 14px;
  }

  #ai-prompt {
    font-size: 16px;
  }

  #ai-send,
  #ai-publish,
  #ai-edit,
  #ai-reset {
    flex: 1;
  }

  .ai-dock-body {
    max-height: 40vh;
    overflow-y: auto;
  }
}
