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

:root {
  --primary: #6c63ff;
  --primary-dark: #5a52d5;
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --text: #eee;
  --text-muted: #aaa;
  --online: #4ade80;
  --offline: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* ===== Map ===== */
#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ===== Status bar ===== */
#status-bar {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(26, 26, 46, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 14px;
}

.indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.indicator.online { background: var(--online); }
.indicator.offline { background: var(--offline); }
.indicator.connecting {
  background: #fbbf24;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#status-text {
  flex: 1;
}

#user-count {
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Map controls ===== */
#map-controls {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.map-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(26, 26, 46, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}

.map-btn:active {
  transform: scale(0.92);
}

.map-btn.active {
  background: var(--primary);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.modal-content h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.modal-content p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
}

/* ===== Emoji picker ===== */
.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.emoji-option {
  width: 44px;
  height: 44px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.emoji-option:hover {
  background: rgba(255, 255, 255, 0.1);
}

.emoji-option.selected {
  border-color: var(--primary);
  background: rgba(108, 99, 255, 0.15);
}

/* ===== Input ===== */
#nickname-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

#nickname-input:focus {
  border-color: var(--primary);
}

#nickname-input::placeholder {
  color: var(--text-muted);
}

/* ===== Button ===== */
#join-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

#join-btn:hover:not(:disabled) {
  background: var(--primary-dark);
}

#join-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Leaflet marker overrides ===== */
.user-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.user-marker .marker-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

.user-marker.me .marker-dot {
  background: var(--online);
}

.user-marker .marker-label {
  margin-top: 2px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(26, 26, 46, 0.85);
  color: white;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.2;
}

.accuracy-circle {
  fill: rgba(108, 99, 255, 0.12);
  stroke: rgba(108, 99, 255, 0.3);
  stroke-width: 1;
}

.accuracy-circle.me {
  fill: rgba(74, 222, 128, 0.12);
  stroke: rgba(74, 222, 128, 0.3);
}

/* ===== Festival POI markers ===== */
.poi-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(26, 26, 46, 0.75);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.poi-icon {
  font-size: 18px;
  line-height: 1;
}

/* ===== Feature labels (Leaflet tooltips) ===== */
.feature-label {
  background: rgba(26, 26, 46, 0.8) !important;
  border: none !important;
  border-radius: 4px !important;
  color: white !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  padding: 2px 6px !important;
  box-shadow: none !important;
  white-space: nowrap;
}

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

/* ===== Grid overlay ===== */
.grid-sub-label {
  color: #333333;
  font-size: 10px;
  font-weight: 700;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  pointer-events: none;
  user-select: none;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  padding: 1px 3px;
  line-height: 1;
  white-space: nowrap;
}

.grid-header-label {
  color: #ffffff;
  font-size: 20px;
  font-weight: 900;
  font-family: Arial, Helvetica, sans-serif;
  text-align: center;
  pointer-events: none;
  user-select: none;
  background: #000000;
  border-radius: 3px;
  padding: 3px 6px;
  line-height: 1;
  white-space: nowrap;
}

/* ===== User list panel ===== */
.user-panel {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 72px;
  z-index: 1000;
  background: rgba(22, 33, 62, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  width: 220px;
  max-height: 320px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

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

.user-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.user-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

#user-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

#user-list:empty::after {
  content: 'Inga användare online';
  display: block;
  padding: 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.user-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.user-list-item:active {
  background: rgba(255, 255, 255, 0.08);
}

.user-list-item .user-emoji {
  font-size: 20px;
  flex-shrink: 0;
}

.user-list-item .user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-list-item .user-grid {
  font-size: 12px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  color: var(--primary);
}

.user-list-item.me .user-name {
  color: var(--online);
}

#grid-ref {
  color: var(--primary);
  font-weight: 800;
  font-family: 'Courier New', Courier, monospace;
  font-size: 15px;
  letter-spacing: 1px;
}
