*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: #2c3e50;
  background: #f0f0f0;
}

/* ── Karte ──────────────────────────────────────────────────── */

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
}

/* ── Join-Dialog ────────────────────────────────────────────── */

#join-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
}

#join-overlay.hidden {
  display: none;
}

#join-dialog {
  background: #fff;
  border-radius: 12px;
  padding: 32px 28px;
  width: 340px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
}

#join-dialog h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 6px;
}

#join-dialog .subtitle {
  font-size: 0.85rem;
  color: #7f8c8d;
  margin-bottom: 24px;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #7f8c8d;
  margin-bottom: 6px;
}

.field input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #dce1e7;
  border-radius: 7px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.field input[type="text"]:focus {
  border-color: #3498db;
}

.field.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field.checkbox-field label {
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.9rem;
  font-weight: 500;
  color: #2c3e50;
  margin: 0;
}

.field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #3498db;
  cursor: pointer;
  flex-shrink: 0;
}

.field input[type="range"] {
  width: 100%;
  accent-color: #3498db;
}

.field .range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #95a5a6;
  margin-top: 4px;
}

.field .range-value {
  font-size: 0.8rem;
  color: #3498db;
  font-weight: 600;
  text-align: center;
  margin-top: 4px;
}

#session-id-display {
  font-size: 0.78rem;
  color: #95a5a6;
  background: #f8f9fa;
  border-radius: 5px;
  padding: 6px 10px;
  margin-bottom: 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

#session-id-display strong {
  color: #2c3e50;
  letter-spacing: 0.08em;
}

#copy-link-btn {
  background: none;
  border: none;
  color: #3498db;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0;
}

#join-btn {
  width: 100%;
  padding: 11px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#join-btn:hover {
  background: #2980b9;
}

/* ── User-Liste (oben rechts) ───────────────────────────────── */

#user-list {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 20px;
  padding: 5px 12px 5px 5px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 0.82rem;
  font-weight: 500;
  max-width: 160px;
  transition: opacity 0.3s;
}

.user-chip.disconnected {
  opacity: 0.45;
}

.user-chip.own-chip {
  cursor: pointer;
  outline: 1.5px solid rgba(52, 152, 219, 0.35);
  outline-offset: 1px;
}

.user-chip.own-chip:hover {
  background: #fff;
  outline-color: #3498db;
}

.chip-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pos-eye {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: #3498db;
}

.pos-eye.muted {
  color: #bdc3c7;
}

.chip-target {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #bdc3c7;
  line-height: 0;
}

.chip-target:hover {
  color: #3498db;
}

/* ── Profil-Edit-Panel ──────────────────────────────────────── */

#user-edit-panel {
  position: fixed;
  top: 16px;
  right: 185px;
  z-index: 20;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  width: 230px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
}

#user-edit-panel.hidden {
  display: none;
}

#user-edit-save {
  width: 100%;
  padding: 8px;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#user-edit-save:hover {
  background: #2980b9;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Leaflet-Marker ─────────────────────────────────────────── */

.user-marker {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: default;
}

.user-marker.emoji-label,
.user-avatar.emoji-label {
  font-size: 1rem;
}

/* ── Verbindungs-Status ─────────────────────────────────────── */

#status-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 0.8rem;
  pointer-events: none;
  transition: opacity 0.4s;
}

#status-bar.hidden {
  opacity: 0;
}

/* ── Session-Info (oben mittig) ─────────────────────────────── */

#session-info {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 7px;
}

.share-icon {
  width: 13px;
  height: 13px;
  color: #7f8c8d;
  flex-shrink: 0;
  opacity: 0.8;
}

#session-info:hover {
  background: rgba(255, 255, 255, 1);
}

#session-info strong {
  color: #2c3e50;
  letter-spacing: 0.08em;
}

/* ── Share-Panel ─────────────────────────────────────────────── */

#share-panel {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: #fff;
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
}

#share-panel.hidden {
  display: none;
}

.share-btn {
  padding: 8px 12px;
  border: none;
  border-radius: 7px;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
  color: #2c3e50;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

.share-btn:hover {
  background: #f0f4f8;
}

.share-qr-wrap {
  padding: 6px 6px 4px;
  border-top: 1px solid #f0f0f0;
  margin-top: 2px;
  display: flex;
  justify-content: center;
}

.share-qr {
  width: 160px;
  height: 160px;
  border-radius: 6px;
  display: block;
}

/* ── Toolbar ────────────────────────────────────────────────── */

#toolbar {
  position: fixed;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.tool-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  transition: background 0.12s, color 0.12s;
}

.tool-btn:hover {
  background: #f0f4f8;
  color: #2c3e50;
}

.tool-btn.active {
  background: #3498db;
  color: #fff;
}

.tool-sep {
  height: 1px;
  background: #e8ecf0;
  margin: 3px 4px;
}

/* ── Basemap-Auswahl ─────────────────────────────────────────── */

#basemap-panel {
  position: fixed;
  left: 68px;
  z-index: 20;
  background: #fff;
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
}

#basemap-panel.hidden {
  display: none;
}

.basemap-option {
  padding: 8px 12px;
  border-radius: 7px;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: #2c3e50;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

.basemap-option input[type="radio"] {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #3498db;
}

.basemap-option:hover {
  background: #f0f4f8;
}

.basemap-option.active {
  font-weight: 600;
  color: #3498db;
}

.layer-section-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: #7f8c8d;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 12px 2px;
}

.layer-separator {
  height: 1px;
  background: #eaecef;
  margin: 4px 2px;
}

.overlay-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #2c3e50;
}

.overlay-option:hover {
  background: #f0f4f8;
}

.overlay-option input[type="checkbox"] {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #3498db;
}

/* Zeichenwerkzeuge-Submenü */
#draw-tools {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#draw-tools.hidden {
  display: none;
}

/* ── Kompass-Overlay ─────────────────────────────────────────── */

#compass-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(2px);
}

#compass-overlay.hidden {
  display: none;
}

.compass-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.compass-svg {
  width: min(82vw, 82vh, 420px);
  height: min(82vw, 82vh, 420px);
  pointer-events: none;
}

.compass-footer {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.82rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* ── Shape-Label (permanentes Tooltip) ──────────────────────── */

.shape-label-tooltip {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  font-weight: 700;
  font-size: 0.78rem;
  white-space: nowrap;
  text-shadow:
    1px  1px 3px rgba(255,255,255,1),
   -1px -1px 3px rgba(255,255,255,1),
    1px -1px 3px rgba(255,255,255,1),
   -1px  1px 3px rgba(255,255,255,1);
}

.shape-label-tooltip::before {
  display: none !important;
}

/* ── Settings-Panel ─────────────────────────────────────────── */

#settings-panel {
  position: fixed;
  bottom: 50px;
  left: 66px;
  z-index: 20;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  width: 230px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
}

#settings-panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 14px;
  color: #2c3e50;
}

#settings-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: #95a5a6;
  padding: 0;
}

#settings-close:hover {
  color: #2c3e50;
}

#settings-panel .field {
  margin-bottom: 14px;
}

#settings-panel select {
  width: 100%;
  padding: 7px 10px;
  border: 1.5px solid #dce1e7;
  border-radius: 7px;
  font-size: 0.9rem;
  outline: none;
  background: #fff;
}

/* ── Sprach-Switcher ─────────────────────────────────────────── */

.lang-switch {
  display: flex;
  gap: 6px;
}

.lang-btn {
  flex: 1;
  padding: 5px 0;
  border: 1.5px solid #dce1e7;
  border-radius: 6px;
  background: #fff;
  color: #7f8c8d;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.lang-btn:hover {
  border-color: #3498db;
  color: #3498db;
}

.lang-btn.active {
  border-color: #3498db;
  background: #3498db;
  color: #fff;
}

/* ── Shape-Marker (Punkt-Form) ──────────────────────────────── */

.shape-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* ── Map-Popup (User + Shapes) ──────────────────────────────── */

.map-popup {
  min-width: 130px;
  font-size: 0.85rem;
}

.map-popup strong {
  display: block;
  color: #2c3e50;
  margin-bottom: 5px;
  font-size: 0.9rem;
}

.popup-row {
  color: #555;
  margin-bottom: 3px;
  line-height: 1.5;
}

.map-popup .shape-delete-btn {
  margin-top: 8px;
}

.popup-label-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.popup-lock-icon {
  font-size: 0.8rem;
  flex-shrink: 0;
}

.popup-label-input {
  flex: 1;
  min-width: 0;
  padding: 3px 7px;
  border: 1.5px solid #dce1e7;
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #2c3e50;
  outline: none;
  background: #f8f9fa;
}

.popup-label-input:focus {
  border-color: #3498db;
  background: #fff;
}

/* ── Shape-Popup (Legacy) ───────────────────────────────────── */

.shape-popup {
  min-width: 100px;
}

.shape-popup-label {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: #2c3e50;
}

.shape-delete-btn {
  width: 100%;
  padding: 6px;
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.12s;
}

.shape-delete-btn:hover:not(:disabled) {
  background: #c0392b;
}

.shape-delete-btn:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
}

/* ── Touch: 300ms-Tap-Delay entfernen ───────────────────────── */

button, a, input[type="checkbox"], input[type="range"], select {
  touch-action: manipulation;
}

/* ── Mobile Layout (≤ 640px) ────────────────────────────────── */

@media (max-width: 640px) {
  /* Join-Dialog: volle Breite */
  #join-dialog {
    width: calc(100vw - 32px);
    padding: 24px 20px;
  }

  /* Session-Info: kompakter */
  #session-info {
    font-size: 0.72rem;
    padding: 5px 10px;
    gap: 6px;
  }

  /* Toolbar: horizontal, unten mittig */
  #toolbar {
    top: auto;
    bottom: 24px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    flex-direction: row;
    padding: 6px 8px;
    border-radius: 24px;
    gap: 4px;
  }

  .tool-sep {
    width: 1px;
    height: 24px;
    background: #e8ecf0;
    margin: 0 2px;
  }

  #draw-tools {
    flex-direction: row;
  }

  /* Größere Touch-Targets */
  .tool-btn {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
  }

  /* Profil-Edit-Panel: über Toolbar */
  #user-edit-panel {
    top: auto;
    bottom: 90px;
    right: 16px;
    width: calc(100vw - 32px);
    max-width: 320px;
  }

  /* Settings-Panel: über Toolbar, volle Breite */
  #settings-panel {
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100vw - 32px);
    max-width: 320px;
  }

  /* Status-Bar: höher, damit Toolbar nicht überlappt */
  #status-bar {
    bottom: 90px;
  }

  /* User-Liste: kleinere Chips */
  .user-chip {
    font-size: 0.75rem;
    padding: 4px 10px 4px 4px;
    max-width: 130px;
  }

  .user-avatar {
    width: 24px;
    height: 24px;
    font-size: 0.65rem;
  }
}
